From 03cb05f4c614f08600bcd8e90a7fd1ca13ae33a2 Mon Sep 17 00:00:00 2001 From: Marc Schreiber Date: Thu, 20 Apr 2017 11:11:01 +0200 Subject: Improve SVG image size code. The old code made some unwise assumptions about how the svg file would look. See #3580. --- pandoc.cabal | 4 + src/Text/Pandoc/ImageSize.hs | 2 +- test/command/SVG_logo-without-xml-declaration.svg | 32 ++++++ test/command/SVG_logo.svg | 33 ++++++ test/command/corrupt.svg | 5 + test/command/inkscape-cube.svg | 119 ++++++++++++++++++++ test/command/svg.md | 129 ++++++++++++++++++++++ 7 files changed, 323 insertions(+), 1 deletion(-) create mode 100644 test/command/SVG_logo-without-xml-declaration.svg create mode 100644 test/command/SVG_logo.svg create mode 100644 test/command/corrupt.svg create mode 100644 test/command/inkscape-cube.svg create mode 100644 test/command/svg.md diff --git a/pandoc.cabal b/pandoc.cabal index 61ef5c522..14a407b85 100644 --- a/pandoc.cabal +++ b/pandoc.cabal @@ -136,6 +136,10 @@ Extra-Source-Files: test/*.native test/command/*.md test/command/abbrevs + test/command/SVG_logo-without-xml-declaration.svg + test/command/SVG_logo.svg + test/command/corrupt.svg + test/command/inkscape-cube.svg test/command/sub-file-chapter-1.tex test/command/sub-file-chapter-2.tex test/command/3510-subdoc.org diff --git a/src/Text/Pandoc/ImageSize.hs b/src/Text/Pandoc/ImageSize.hs index a0800e499..4d914a10c 100644 --- a/src/Text/Pandoc/ImageSize.hs +++ b/src/Text/Pandoc/ImageSize.hs @@ -116,7 +116,7 @@ imageType img = case B.take 4 img of _ -> mzero findSvgTag :: ByteString -> Bool -findSvgTag img = B.null $ snd (B.breakSubstring img " ByteString -> Either String ImageSize imageSize opts img = diff --git a/test/command/SVG_logo-without-xml-declaration.svg b/test/command/SVG_logo-without-xml-declaration.svg new file mode 100644 index 000000000..febcab6ca --- /dev/null +++ b/test/command/SVG_logo-without-xml-declaration.svg @@ -0,0 +1,32 @@ + +SVG Logo + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/command/SVG_logo.svg b/test/command/SVG_logo.svg new file mode 100644 index 000000000..5333a5ddb --- /dev/null +++ b/test/command/SVG_logo.svg @@ -0,0 +1,33 @@ + + +SVG Logo + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/command/corrupt.svg b/test/command/corrupt.svg new file mode 100644 index 000000000..cfaa697f0 --- /dev/null +++ b/test/command/corrupt.svg @@ -0,0 +1,5 @@ +Lorem ipsum dolor sit amet etiam. A pede dolor neque pretium luctus pharetra vel rutrum. Orci nonummy ac. At eu est tempor +proin wisi. Nunc tincidunt proin. Suspendisse lorem commodo. Integer diam diam semper commodo dictum et tellus eu ultrices +nec erat pulvinar porttitor nulla nulla mauris orci libero eros elementum et possimus voluptate. Velit morbi et. Luctus diam +in. Lorem tincidunt sem dolor rerum mauris. Dis taciti posuere pellentesque sed rutrum. Lectus donec fusce in dictum pede. +In etiam congue. Aliquam aliquet elit arcu mauris enim. Risus at enim. diff --git a/test/command/inkscape-cube.svg b/test/command/inkscape-cube.svg new file mode 100644 index 000000000..995c3c734 --- /dev/null +++ b/test/command/inkscape-cube.svg @@ -0,0 +1,119 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/test/command/svg.md b/test/command/svg.md new file mode 100644 index 000000000..bcf00ddae --- /dev/null +++ b/test/command/svg.md @@ -0,0 +1,129 @@ +``` +% pandoc -f latex -t icml +\includegraphics{command/corrupt.svg} +^D + + + + + + + + + + + + + + + + + + + $ID/Embedded + + + + + + + +``` + +``` +% pandoc -f latex -t icml +\includegraphics{command/SVG_logo.svg} +^D + + + + + + + + + + + + + + + + + + + $ID/Embedded + + + + + + + +``` + +``` +% pandoc -f latex -t icml +\includegraphics{command/SVG_logo-without-xml-declaration.svg} +^D + + + + + + + + + + + + + + + + + + + $ID/Embedded + + + + + + + +``` + + +``` +% pandoc -f latex -t icml +\includegraphics{command/inkscape-cube.svg} +^D + + + + + + + + + + + + + + + + + + + $ID/Embedded + + + + + + + +``` + -- cgit v1.2.3