aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-08-11 10:44:52 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2014-08-11 10:44:52 -0700
commit4a535211d8a9ef80e859925694e1b06e76f62196 (patch)
treecd9e4cbc02f3b321b8a00091328b8b461d4d0e77 /src/Text
parenta67e5e877dd87fcb19d6d2dcedb399cf2b5bf4f1 (diff)
parentd4d7a14dddf860521473167d1dcb53d5cfab2b7b (diff)
downloadpandoc-4a535211d8a9ef80e859925694e1b06e76f62196.tar.gz
Merge pull request #1365 from gbataille/docx-margin
Scale images to fit the page for DOCX
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Writers/Docx.hs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs
index 5e02419d8..38031b7dc 100644
--- a/src/Text/Pandoc/Writers/Docx.hs
+++ b/src/Text/Pandoc/Writers/Docx.hs
@@ -842,7 +842,7 @@ inlineToOpenXML opts (Image alt (src, tit)) = do
let size = imageSize img
let (xpt,ypt) = maybe (120,120) sizeInPoints size
-- 12700 emu = 1 pt
- let (xemu,yemu) = (xpt * 12700, ypt * 12700)
+ let (xemu,yemu) = fitToPage (xpt * 12700, ypt * 12700)
let cNvPicPr = mknode "pic:cNvPicPr" [] $
mknode "a:picLocks" [("noChangeArrowheads","1"),("noChangeAspect","1")] ()
let nvPicPr = mknode "pic:nvPicPr" []
@@ -907,3 +907,11 @@ parseXml refArchive distArchive relpath =
>>= parseXMLDoc . UTF8.toStringLazy . fromEntry) of
Just d -> return d
Nothing -> fail $ relpath ++ " corrupt or missing in reference docx"
+
+-- | Scales the image to fit the page
+fitToPage :: (Integer, Integer) -> (Integer, Integer)
+fitToPage (x, y)
+ --5440680 is the emu width size of a letter page in portrait, minus the margins
+ | x > 5440680 =
+ (5440680, round $ (5440680 / ((fromIntegral :: Integer -> Double) x)) * (fromIntegral y))
+ | otherwise = (x, y)