git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #1365 from gbataille/docx-margin

Scale images to fit the page for DOCX

commit4a535211d8a9ef80e859925694e1b06e76f62196 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 11 Aug 2014, 10:44 (12 years ago) parenta67e5e8d4d7a14
1 file changed+9−1
src/Text/Pandoc/Writers/Docx.hs+9−1
src/Text/Pandoc/Writers/Docx.hs+9−1
@@ -842,7 +842,7 @@ inlineToOpenXML opts (Image alt (src, tit)) = do
842842 let size = imageSize img
843843 let (xpt,ypt) = maybe (120,120) sizeInPoints size
844844 -- 12700 emu = 1 pt
845− let (xemu,yemu) = (xpt * 12700, ypt * 12700)
845+ let (xemu,yemu) = fitToPage (xpt * 12700, ypt * 12700)
846846 let cNvPicPr = mknode "pic:cNvPicPr" [] $
847847 mknode "a:picLocks" [("noChangeArrowheads","1"),("noChangeAspect","1")] ()
848848 let nvPicPr = mknode "pic:nvPicPr" []
@@ -907,3 +907,11 @@ parseXml refArchive distArchive relpath =
907907 >>= parseXMLDoc . UTF8.toStringLazy . fromEntry) of
908908 Just d -> return d
909909 Nothing -> fail $ relpath ++ " corrupt or missing in reference docx"
910+
911+-- | Scales the image to fit the page
912+fitToPage :: (Integer, Integer) -> (Integer, Integer)
913+fitToPage (x, y)
914+ --5440680 is the emu width size of a letter page in portrait, minus the margins
915+ | x > 5440680 =
916+ (5440680, round $ (5440680 / ((fromIntegral :: Integer -> Double) x)) * (fromIntegral y))
917+ | otherwise = (x, y)