diff options
author | John MacFarlane <jgm@berkeley.edu> | 2021-01-22 20:49:41 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2021-01-22 20:49:41 -0800 |
commit | 198ce0cde99731680b62294a7dff1b218b29bd4d (patch) | |
tree | 1d10434dca1d01742f8639a9f3ba505f1ca9652c /src/Text | |
parent | f5e3c1dad678732f59d7bd655993cd5ba61a7621 (diff) | |
download | pandoc-198ce0cde99731680b62294a7dff1b218b29bd4d.tar.gz |
ImageSize: use viewBox for svg if no length, width.
This change allows pandoc to extract size information
from more SVGs. Closes #7045.
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/ImageSize.hs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/Text/Pandoc/ImageSize.hs b/src/Text/Pandoc/ImageSize.hs index 098c16721..e19958f6a 100644 --- a/src/Text/Pandoc/ImageSize.hs +++ b/src/Text/Pandoc/ImageSize.hs @@ -328,12 +328,16 @@ getSize img = svgSize :: WriterOptions -> ByteString -> Maybe ImageSize svgSize opts img = do doc <- Xml.parseXMLDoc $ UTF8.toString img + let viewboxSize = do + vb <- Xml.findAttrBy (== Xml.QName "viewBox" Nothing Nothing) doc + [_,_,w,h] <- mapM safeRead (T.words (T.pack vb)) + return (w,h) let dpi = fromIntegral $ writerDpi opts let dirToInt dir = do dim <- Xml.findAttrBy (== Xml.QName dir Nothing Nothing) doc >>= lengthToDim . T.pack return $ inPixel opts dim - w <- dirToInt "width" - h <- dirToInt "height" + w <- dirToInt "width" <|> (fst <$> viewboxSize) + h <- dirToInt "height" <|> (snd <$> viewboxSize) return ImageSize { pxX = w , pxY = h |