git.iko.soy/typeable/pandoc
on master help sign in
ImageSize: use viewBox for svg if no length, width.
198ce0cJohn MacFarlane
src/Text/Pandoc/ImageSize.hs+6−2
@@ -328,12 +328,16 @@ getSize img =
328svgSize :: WriterOptions -> ByteString -> Maybe ImageSize
328svgSize :: WriterOptions -> ByteString -> Maybe ImageSize
329svgSize opts img = do
329svgSize opts img = do
330 doc <- Xml.parseXMLDoc $ UTF8.toString img
330 doc <- Xml.parseXMLDoc $ UTF8.toString img
331+ let viewboxSize = do
332+ vb <- Xml.findAttrBy (== Xml.QName "viewBox" Nothing Nothing) doc
333+ [_,_,w,h] <- mapM safeRead (T.words (T.pack vb))
334+ return (w,h)
331 let dpi = fromIntegral $ writerDpi opts
335 let dpi = fromIntegral $ writerDpi opts
332 let dirToInt dir = do
336 let dirToInt dir = do
333 dim <- Xml.findAttrBy (== Xml.QName dir Nothing Nothing) doc >>= lengthToDim . T.pack
337 dim <- Xml.findAttrBy (== Xml.QName dir Nothing Nothing) doc >>= lengthToDim . T.pack
334 return $ inPixel opts dim
338 return $ inPixel opts dim
335− w <- dirToInt "width"
339+ w <- dirToInt "width" <|> (fst <$> viewboxSize)
336− h <- dirToInt "height"
340+ h <- dirToInt "height" <|> (snd <$> viewboxSize)
337 return ImageSize {
341 return ImageSize {
338 pxX = w
342 pxX = w
339 , pxY = h
343 , pxY = h
test/command/svg.md+14−16
@@ -36,28 +36,27 @@
36% pandoc -f latex -t icml
36% pandoc -f latex -t icml
37\includegraphics{command/SVG_logo.svg}
37\includegraphics{command/SVG_logo.svg}
38^D
38^D
39−[WARNING] Could not determine image size for 'command/SVG_logo.svg': could not determine SVG size
40<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Paragraph">
39<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Paragraph">
41 <CharacterStyleRange AppliedCharacterStyle="$ID/NormalCharacterStyle">
40 <CharacterStyleRange AppliedCharacterStyle="$ID/NormalCharacterStyle">
42− <Rectangle Self="uec" StrokeWeight="0" ItemTransform="1 0 0 1 150 -100">
41+ <Rectangle Self="uec" StrokeWeight="0" ItemTransform="1 0 0 1 37.5 -37.5">
43 <Properties>
42 <Properties>
44 <PathGeometry>
43 <PathGeometry>
45 <GeometryPathType PathOpen="false">
44 <GeometryPathType PathOpen="false">
46 <PathPointArray>
45 <PathPointArray>
47− <PathPointType Anchor="-150 -100" LeftDirection="-150 -100" RightDirection="-150 -100" />
46+ <PathPointType Anchor="-37.5 -37.5" LeftDirection="-37.5 -37.5" RightDirection="-37.5 -37.5" />
48− <PathPointType Anchor="-150 100" LeftDirection="-150 100" RightDirection="-150 100" />
47+ <PathPointType Anchor="-37.5 37.5" LeftDirection="-37.5 37.5" RightDirection="-37.5 37.5" />
49− <PathPointType Anchor="150 100" LeftDirection="150 100" RightDirection="150 100" />
48+ <PathPointType Anchor="37.5 37.5" LeftDirection="37.5 37.5" RightDirection="37.5 37.5" />
50− <PathPointType Anchor="150 -100" LeftDirection="150 -100" RightDirection="150 -100" />
49+ <PathPointType Anchor="37.5 -37.5" LeftDirection="37.5 -37.5" RightDirection="37.5 -37.5" />
51 </PathPointArray>
50 </PathPointArray>
52 </GeometryPathType>
51 </GeometryPathType>
53 </PathGeometry>
52 </PathGeometry>
54 </Properties>
53 </Properties>
55− <Image Self="ue6" ItemTransform="1 0 0 1 -150 -100">
54+ <Image Self="ue6" ItemTransform="1 0 0 1 -37.5 -37.5">
56 <Properties>
55 <Properties>
57 <Profile type="string">
56 <Profile type="string">
58 $ID/Embedded
57 $ID/Embedded
59 </Profile>
58 </Profile>
60− <GraphicBounds Left="0" Top="0" Right="300" Bottom="200" />
59+ <GraphicBounds Left="0" Top="0" Right="75" Bottom="75" />
61 </Properties>
60 </Properties>
62 <Link Self="ueb" LinkResourceURI="file:command/SVG_logo.svg" />
61 <Link Self="ueb" LinkResourceURI="file:command/SVG_logo.svg" />
63 </Image>
62 </Image>
@@ -70,28 +69,27 @@
70% pandoc -f latex -t icml
69% pandoc -f latex -t icml
71\includegraphics{command/SVG_logo-without-xml-declaration.svg}
70\includegraphics{command/SVG_logo-without-xml-declaration.svg}
72^D
71^D
73−[WARNING] Could not determine image size for 'command/SVG_logo-without-xml-declaration.svg': could not determine SVG size
74<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Paragraph">
72<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Paragraph">
75 <CharacterStyleRange AppliedCharacterStyle="$ID/NormalCharacterStyle">
73 <CharacterStyleRange AppliedCharacterStyle="$ID/NormalCharacterStyle">
76− <Rectangle Self="uec" StrokeWeight="0" ItemTransform="1 0 0 1 150 -100">
74+ <Rectangle Self="uec" StrokeWeight="0" ItemTransform="1 0 0 1 37.5 -37.5">
77 <Properties>
75 <Properties>
78 <PathGeometry>
76 <PathGeometry>
79 <GeometryPathType PathOpen="false">
77 <GeometryPathType PathOpen="false">
80 <PathPointArray>
78 <PathPointArray>
81− <PathPointType Anchor="-150 -100" LeftDirection="-150 -100" RightDirection="-150 -100" />
79+ <PathPointType Anchor="-37.5 -37.5" LeftDirection="-37.5 -37.5" RightDirection="-37.5 -37.5" />
82− <PathPointType Anchor="-150 100" LeftDirection="-150 100" RightDirection="-150 100" />
80+ <PathPointType Anchor="-37.5 37.5" LeftDirection="-37.5 37.5" RightDirection="-37.5 37.5" />
83− <PathPointType Anchor="150 100" LeftDirection="150 100" RightDirection="150 100" />
81+ <PathPointType Anchor="37.5 37.5" LeftDirection="37.5 37.5" RightDirection="37.5 37.5" />
84− <PathPointType Anchor="150 -100" LeftDirection="150 -100" RightDirection="150 -100" />
82+ <PathPointType Anchor="37.5 -37.5" LeftDirection="37.5 -37.5" RightDirection="37.5 -37.5" />
85 </PathPointArray>
83 </PathPointArray>
86 </GeometryPathType>
84 </GeometryPathType>
87 </PathGeometry>
85 </PathGeometry>
88 </Properties>
86 </Properties>
89− <Image Self="ue6" ItemTransform="1 0 0 1 -150 -100">
87+ <Image Self="ue6" ItemTransform="1 0 0 1 -37.5 -37.5">
90 <Properties>
88 <Properties>
91 <Profile type="string">
89 <Profile type="string">
92 $ID/Embedded
90 $ID/Embedded
93 </Profile>
91 </Profile>
94− <GraphicBounds Left="0" Top="0" Right="300" Bottom="200" />
92+ <GraphicBounds Left="0" Top="0" Right="75" Bottom="75" />
95 </Properties>
93 </Properties>
96 <Link Self="ueb" LinkResourceURI="file:command/SVG_logo-without-xml-declaration.svg" />
94 <Link Self="ueb" LinkResourceURI="file:command/SVG_logo-without-xml-declaration.svg" />
97 </Image>
95 </Image>