git.iko.soy/typeable/pandoc
on master help sign in
Fix percentage image scaling in ODT (#4881)

Image scaling in ODT was broken when a width was set to a percentage. The width was passed to the svg:width field as a pecentage, which is not correct according to the ODT standard. Instead the real dimensions should be passed as width and height and the style:rel-width attribute should be set to the percentage while style:rel-heigh attribute should be set to "scale". The converse is true if a percentage height is given. This is now fixed and documents produced are now properly scaled.

commit12cec8f08233ea5836af77aff27771b800a35ce7 authorNils Carlson <pyssling@ludd.ltu.se> dateFri 7 Sep 2018, 23:37 (8 years ago) parent0178544
2 files changed+4−2
src/Text/Pandoc/Writers/ODT.hs+2−2 src/Text/Pandoc/Writers/OpenDocument.hs+2
src/Text/Pandoc/Writers/ODT.hs+2−2
@@ -189,8 +189,8 @@ transformPicMath opts (Image attr@(id', cls, _) lab (src,t)) = catchError
189189 let dims =
190190 case (getDim Width, getDim Height) of
191191 (Just w, Just h) -> [("width", show w), ("height", show h)]
192− (Just w@(Percent p), Nothing) -> [("width", show w), ("height", show (p / ratio) ++ "%")]
193− (Nothing, Just h@(Percent p)) -> [("width", show (p * ratio) ++ "%"), ("height", show h)]
192+ (Just w@(Percent _), Nothing) -> [("rel-width", show w),("rel-height", "scale"),("width", show ptX ++ "pt"),("height", show ptY ++ "pt")]
193+ (Nothing, Just h@(Percent _)) -> [("rel-width", "scale"),("rel-height", show h),("width", show ptX ++ "pt"),("height", show ptY ++ "pt")]
194194 (Just w@(Inch i), Nothing) -> [("width", show w), ("height", show (i / ratio) ++ "in")]
195195 (Nothing, Just h@(Inch i)) -> [("width", show (i * ratio) ++ "in"), ("height", show h)]
196196 _ -> [("width", show ptX ++ "pt"), ("height", show ptY ++ "pt")]
src/Text/Pandoc/Writers/OpenDocument.hs+2
@@ -506,7 +506,9 @@ inlineToOpenDocument o ils
506506 modify (\st -> st{ stImageId = id' + 1 })
507507 let getDims [] = []
508508 getDims (("width", w) :xs) = ("svg:width", w) : getDims xs
509+ getDims (("rel-width", w):xs) = ("style:rel-width", w) : getDims xs
509510 getDims (("height", h):xs) = ("svg:height", h) : getDims xs
511+ getDims (("rel-height", w):xs) = ("style:rel-height", w) : getDims xs
510512 getDims (_:xs) = getDims xs
511513 return $ inTags False "draw:frame"
512514 (("draw:name", "img" ++ show id') : getDims kvs) $