diff --git a/src/Text/Pandoc/ImageSize.hs b/src/Text/Pandoc/ImageSize.hs index 727be238c7e37..08e84868e356a 100644 --- a/src/Text/Pandoc/ImageSize.hs +++ b/src/Text/Pandoc/ImageSize.hs @@ -166,8 +166,8 @@ sizeInPoints s = (pxXf * 72 / dpiXf, pxYf * 72 / dpiYf) -- | Calculate (height, width) in points, considering the desired dimensions in the -- attribute, while falling back on the image file's dpi metadata if no dimensions -- are specified in the attribute (or only dimensions in percentages). -desiredSizeInPoints :: WriterOptions -> Attr -> ImageSize -> (Double, Double) -desiredSizeInPoints opts attr s = +desiredSizeInPoints :: WriterOptions -> Attr -> Maybe Integer -> ImageSize -> (Double, Double) +desiredSizeInPoints opts attr pageWidth' s = case (getDim Width, getDim Height) of (Just w, Just h) -> (w, h) (Just w, Nothing) -> (w, w / ratio) @@ -176,7 +176,11 @@ desiredSizeInPoints opts attr s = where ratio = fromIntegral (pxX s) / fromIntegral (pxY s) getDim dir = case dimension dir attr of - Just (Percent _) -> Nothing + Just (Percent a) -> + case (dir, pageWidth') of + (Width, Just pageWidth) -> + Just $ fromIntegral pageWidth * a + _ -> Nothing Just dim -> Just $ inPoints opts dim Nothing -> Nothing diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs index 1465d5569dd9f..53123403ab7f0 100644 --- a/src/Text/Pandoc/Writers/Docx.hs +++ b/src/Text/Pandoc/Writers/Docx.hs @@ -1538,7 +1538,7 @@ inlineToOpenXML' opts (Image attr@(imgident, _, _) alt (src, title)) = do docprid <- getUniqueId nvpicprid <- getUniqueId let - (xpt,ypt) = desiredSizeInPoints opts attr + (xpt,ypt) = desiredSizeInPoints opts attr (Just pageWidth) (either (const def) id (imageSize opts img)) -- 12700 emu = 1 pt pageWidthPt = case dimension Width attr of diff --git a/src/Text/Pandoc/Writers/ICML.hs b/src/Text/Pandoc/Writers/ICML.hs index a19121968b5dd..7247d39b72b8f 100644 --- a/src/Text/Pandoc/Writers/ICML.hs +++ b/src/Text/Pandoc/Writers/ICML.hs @@ -613,7 +613,7 @@ imageICML opts style attr (src, _) = do report $ CouldNotFetchResource src $ tshow e return def) let (ow, oh) = sizeInPoints imgS - (imgWidth, imgHeight) = desiredSizeInPoints opts attr imgS + (imgWidth, imgHeight) = desiredSizeInPoints opts attr Nothing imgS hw = showFl $ ow / 2 hh = showFl $ oh / 2 scale = showFl (imgWidth / ow) <> " 0 0 " <> showFl (imgHeight / oh) diff --git a/src/Text/Pandoc/Writers/RTF.hs b/src/Text/Pandoc/Writers/RTF.hs index 0b1d36edaa053..ecd41459694a9 100644 --- a/src/Text/Pandoc/Writers/RTF.hs +++ b/src/Text/Pandoc/Writers/RTF.hs @@ -64,7 +64,7 @@ rtfEmbedImage opts x@(Image attr _ (src,_)) = catchError <> "\\pichgoal" <> tshow (floor (ypt * 20) :: Integer) -- twip = 1/1440in = 1/20pt where (xpx, ypx) = sizeInPixels sz - (xpt, ypt) = desiredSizeInPoints opts attr sz + (xpt, ypt) = desiredSizeInPoints opts attr Nothing sz let raw = "{\\pict" <> filetype <> sizeSpec <> " " <> T.concat bytes <> "}" if B.null imgdata diff --git a/test/command/9288.md b/test/command/9288.md new file mode 100644 index 0000000000000..84250dcc0671b --- /dev/null +++ b/test/command/9288.md @@ -0,0 +1,49 @@ +``` +% pandoc -f native -t docx -o /dev/null --trace --quiet +[ Figure + ( "" , [] , [] ) + (Caption Nothing [ Plain [ Str "5in" ] ]) + [ Plain + [ Image + ( "" , [] , [ ( "width" , "5in" ) ] ) + [ Str "5in" ] + ( "command/SVG_logo.svg" , "" ) + ] + ] +, Figure + ( "" , [] , [] ) + (Caption Nothing [ Plain [ Str "5in" ] ]) + [ Plain + [ Image + ( "" , [] , [ ( "width" , "5in" ) ] ) + [ Str "5in" ] + ( "command/SVG_logo.svg" , "" ) + ] + ] +, Figure + ( "" , [] , [] ) + (Caption Nothing [ Plain [ Str "80%" ] ]) + [ Plain + [ Image + ( "" , [] , [ ( "width" , "80%" ) ] ) + [ Str "5in" ] + ( "command/SVG_logo.svg" , "" ) + ] + ] +, Figure + ( "" , [] , [] ) + (Caption Nothing [ Plain [ Str "default" ] ]) + [ Plain + [ Image + ( "" , [] , [] ) + [ Str "5in" ] + ( "command/SVG_logo.svg" , "" ) + ] + ] +] +^D +2> [trace] rsvg-convert -f png -a --dpi-x 96 --dpi-y 96 --width 360.000000pt --height 360.000000pt +2> [trace] rsvg-convert -f png -a --dpi-x 96 --dpi-y 96 --width 360.000000pt --height 360.000000pt +2> [trace] rsvg-convert -f png -a --dpi-x 96 --dpi-y 96 --width 336.000000pt --height 336.000000pt +2> [trace] rsvg-convert -f png -a --dpi-x 96 --dpi-y 96 --width 75.000000pt --height 75.000000pt +```