mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-22 07:25:36 +00:00
Docx writer: fix sizing for images.
Setting size to a percent now scales image to percent of page width. Previously a percent width or height would just provide a maximum bound rather than scaling. Closes #11838.
This commit is contained in:
@@ -995,10 +995,23 @@ inlineToOpenXML' opts (Image attr@(imgident, _, _) alt (src, title)) = do
|
||||
(xpt,ypt) = desiredSizeInPoints opts attr
|
||||
(either (const def) id (imageSize opts img))
|
||||
-- 12700 emu = 1 pt
|
||||
pageWidthPt = case dimension Width attr of
|
||||
Just (Percent a) -> pageWidth * floor (a * 127)
|
||||
_ -> pageWidth * 12700
|
||||
(xemu,yemu) = fitToPage (xpt * 12700, ypt * 12700) pageWidthPt
|
||||
pageWidthPt = fromIntegral pageWidth
|
||||
pageWidthEmu = pageWidth * 12700
|
||||
(xpt', ypt') =
|
||||
case (dimension Width attr, dimension Height attr) of
|
||||
(Just (Percent a), Just (Percent b))
|
||||
-> ((a / 100.0) * pageWidthPt, (b / 100.0) * pageWidthPt)
|
||||
-- note, should use pageHeightPt but we don't have this
|
||||
-- information.
|
||||
(Just (Percent a), _)
|
||||
-> ((a / 100.0) * pageWidthPt,
|
||||
(a / 100.0) * pageWidthPt * (ypt / xpt))
|
||||
(_, Just (Percent b))
|
||||
-> ((b / 100.0) * pageWidthPt * (xpt / ypt),
|
||||
(b / 100.0) * pageWidthPt)
|
||||
(_, _) -> (xpt, ypt)
|
||||
(xemu,yemu) = fitToPage (xpt' * 12700,
|
||||
ypt' * 12700) pageWidthEmu
|
||||
cNvPicPr = mknode "pic:cNvPicPr" [] $
|
||||
mknode "a:picLocks" [("noChangeArrowheads","1")
|
||||
,("noChangeAspect","1")] ()
|
||||
|
||||
@@ -87,7 +87,7 @@ data WriterEnv = WriterEnv
|
||||
, envInNote :: Bool
|
||||
, envChangesAuthor :: Text
|
||||
, envChangesDate :: Text
|
||||
, envPrintWidth :: Integer
|
||||
, envPrintWidth :: Integer -- in points
|
||||
, envLang :: Maybe Text
|
||||
, envSectPr :: Maybe Element
|
||||
}
|
||||
|
||||
@@ -89,8 +89,8 @@ isElem ns prefix name element =
|
||||
|
||||
type NameSpaces = [(Text, Text)]
|
||||
|
||||
-- | Scales the image to fit the page
|
||||
-- sizes are passed in emu
|
||||
-- | Scales the image to fit the page if it would overflow.
|
||||
-- Sizes are passed in emu.
|
||||
fitToPage :: (Double, Double) -> Integer -> (Integer, Integer)
|
||||
fitToPage (x, y) pageWidth
|
||||
-- Fixes width to the page width and scales the height
|
||||
|
||||
Reference in New Issue
Block a user