git.iko.soy/typeable/pandoc
on master help sign in
Scale images to fit the page for DOCX
d4d7a14Grégory Bataille
src/Text/Pandoc/Writers/Docx.hs+9−1
@@ -825,7 +825,7 @@ inlineToOpenXML opts (Image alt (src, tit)) = do
825 let size = imageSize img
825 let size = imageSize img
826 let (xpt,ypt) = maybe (120,120) sizeInPoints size
826 let (xpt,ypt) = maybe (120,120) sizeInPoints size
827 -- 12700 emu = 1 pt
827 -- 12700 emu = 1 pt
828− let (xemu,yemu) = (xpt * 12700, ypt * 12700)
828+ let (xemu,yemu) = fitToPage (xpt * 12700, ypt * 12700)
829 let cNvPicPr = mknode "pic:cNvPicPr" [] $
829 let cNvPicPr = mknode "pic:cNvPicPr" [] $
830 mknode "a:picLocks" [("noChangeArrowheads","1"),("noChangeAspect","1")] ()
830 mknode "a:picLocks" [("noChangeArrowheads","1"),("noChangeAspect","1")] ()
831 let nvPicPr = mknode "pic:nvPicPr" []
831 let nvPicPr = mknode "pic:nvPicPr" []
@@ -890,3 +890,11 @@ parseXml refArchive distArchive relpath =
890 >>= parseXMLDoc . UTF8.toStringLazy . fromEntry) of
890 >>= parseXMLDoc . UTF8.toStringLazy . fromEntry) of
891 Just d -> return d
891 Just d -> return d
892 Nothing -> fail $ relpath ++ " corrupt or missing in reference docx"
892 Nothing -> fail $ relpath ++ " corrupt or missing in reference docx"
893+
894+-- | Scales the image to fit the page
895+fitToPage :: (Integer, Integer) -> (Integer, Integer)
896+fitToPage (x, y)
897+ --5440680 is the emu width size of a letter page in portrait, minus the margins
898+ | x > 5440680 =
899+ (5440680, round $ (5440680 / ((fromIntegral :: Integer -> Double) x)) * (fromIntegral y))
900+ | otherwise = (x, y)