aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Text/Pandoc/ImageSize.hs8
-rw-r--r--test/command/svg.md30
2 files changed, 20 insertions, 18 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
diff --git a/test/command/svg.md b/test/command/svg.md
index 57506570b..4ba836b20 100644
--- a/test/command/svg.md
+++ b/test/command/svg.md
@@ -36,28 +36,27 @@
% pandoc -f latex -t icml
\includegraphics{command/SVG_logo.svg}
^D
-[WARNING] Could not determine image size for 'command/SVG_logo.svg': could not determine SVG size
<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Paragraph">
<CharacterStyleRange AppliedCharacterStyle="$ID/NormalCharacterStyle">
- <Rectangle Self="uec" StrokeWeight="0" ItemTransform="1 0 0 1 150 -100">
+ <Rectangle Self="uec" StrokeWeight="0" ItemTransform="1 0 0 1 37.5 -37.5">
<Properties>
<PathGeometry>
<GeometryPathType PathOpen="false">
<PathPointArray>
- <PathPointType Anchor="-150 -100" LeftDirection="-150 -100" RightDirection="-150 -100" />
- <PathPointType Anchor="-150 100" LeftDirection="-150 100" RightDirection="-150 100" />
- <PathPointType Anchor="150 100" LeftDirection="150 100" RightDirection="150 100" />
- <PathPointType Anchor="150 -100" LeftDirection="150 -100" RightDirection="150 -100" />
+ <PathPointType Anchor="-37.5 -37.5" LeftDirection="-37.5 -37.5" RightDirection="-37.5 -37.5" />
+ <PathPointType Anchor="-37.5 37.5" LeftDirection="-37.5 37.5" RightDirection="-37.5 37.5" />
+ <PathPointType Anchor="37.5 37.5" LeftDirection="37.5 37.5" RightDirection="37.5 37.5" />
+ <PathPointType Anchor="37.5 -37.5" LeftDirection="37.5 -37.5" RightDirection="37.5 -37.5" />
</PathPointArray>
</GeometryPathType>
</PathGeometry>
</Properties>
- <Image Self="ue6" ItemTransform="1 0 0 1 -150 -100">
+ <Image Self="ue6" ItemTransform="1 0 0 1 -37.5 -37.5">
<Properties>
<Profile type="string">
$ID/Embedded
</Profile>
- <GraphicBounds Left="0" Top="0" Right="300" Bottom="200" />
+ <GraphicBounds Left="0" Top="0" Right="75" Bottom="75" />
</Properties>
<Link Self="ueb" LinkResourceURI="file:command/SVG_logo.svg" />
</Image>
@@ -70,28 +69,27 @@
% pandoc -f latex -t icml
\includegraphics{command/SVG_logo-without-xml-declaration.svg}
^D
-[WARNING] Could not determine image size for 'command/SVG_logo-without-xml-declaration.svg': could not determine SVG size
<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Paragraph">
<CharacterStyleRange AppliedCharacterStyle="$ID/NormalCharacterStyle">
- <Rectangle Self="uec" StrokeWeight="0" ItemTransform="1 0 0 1 150 -100">
+ <Rectangle Self="uec" StrokeWeight="0" ItemTransform="1 0 0 1 37.5 -37.5">
<Properties>
<PathGeometry>
<GeometryPathType PathOpen="false">
<PathPointArray>
- <PathPointType Anchor="-150 -100" LeftDirection="-150 -100" RightDirection="-150 -100" />
- <PathPointType Anchor="-150 100" LeftDirection="-150 100" RightDirection="-150 100" />
- <PathPointType Anchor="150 100" LeftDirection="150 100" RightDirection="150 100" />
- <PathPointType Anchor="150 -100" LeftDirection="150 -100" RightDirection="150 -100" />
+ <PathPointType Anchor="-37.5 -37.5" LeftDirection="-37.5 -37.5" RightDirection="-37.5 -37.5" />
+ <PathPointType Anchor="-37.5 37.5" LeftDirection="-37.5 37.5" RightDirection="-37.5 37.5" />
+ <PathPointType Anchor="37.5 37.5" LeftDirection="37.5 37.5" RightDirection="37.5 37.5" />
+ <PathPointType Anchor="37.5 -37.5" LeftDirection="37.5 -37.5" RightDirection="37.5 -37.5" />
</PathPointArray>
</GeometryPathType>
</PathGeometry>
</Properties>
- <Image Self="ue6" ItemTransform="1 0 0 1 -150 -100">
+ <Image Self="ue6" ItemTransform="1 0 0 1 -37.5 -37.5">
<Properties>
<Profile type="string">
$ID/Embedded
</Profile>
- <GraphicBounds Left="0" Top="0" Right="300" Bottom="200" />
+ <GraphicBounds Left="0" Top="0" Right="75" Bottom="75" />
</Properties>
<Link Self="ueb" LinkResourceURI="file:command/SVG_logo-without-xml-declaration.svg" />
</Image>