Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MD-to-ODT-conversion: SVG images not supported properly #3462

Closed
nicodecker opened this issue Feb 21, 2017 · 4 comments · Fixed by #3464
Closed

MD-to-ODT-conversion: SVG images not supported properly #3462

nicodecker opened this issue Feb 21, 2017 · 4 comments · Fixed by #3464

Comments

@nicodecker
Copy link

Problem

A simple markdown document referencing an SVG image can be
converted to ODT. However, the following warnings appear:

[pandoc.exe warning] Could not determine image size in `test1.svg': could not determine image type

The ODT file is created and the image appears, but the dimensions of the image
are wrong: width and height are always equal (as it can be seen below)

output

Call

pandoc was called like this:

pandoc -f markdown -t odt -o test.odt test.md

Version Information

C:\>pandoc --version
pandoc.exe 1.19.2.1
Compiled with pandoc-types 1.17.0.4, texmath 0.9, skylighting 0.1.1.4
Default user data directory: C:\Users\nico\AppData\Roaming\pandoc
Copyright (C) 2006-2016 John MacFarlane
Web:  http://pandoc.org
This is free software; see the source for copying conditions.
There is no warranty, not even for merchantability or fitness
for a particular purpose.

Resources

  • Markdown is also very simple and short.
Test
=====

A small test image.

![Test1](test1.svg)

End of markdown file.
  • The SVG is a very simple test file containing two paths and some text.
    This is an inkscape file, however, the pure SVG version did not work either.

test1

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->

<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:xlink="http://www.w3.org/1999/xlink"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   width="353.07678"
   height="214.60573"
   id="svg2"
   version="1.1"
   inkscape:version="0.91 r13725"
   sodipodi:docname="test1.svg">
  <defs
     id="defs4">
    <linearGradient
       id="linearGradient3765">
      <stop
         style="stop-color:#ff5555;stop-opacity:1;"
         offset="0"
         id="stop3767" />
      <stop
         style="stop-color:#690551;stop-opacity:0.90555555;"
         offset="1"
         id="stop3769" />
    </linearGradient>
    <radialGradient
       inkscape:collect="always"
       xlink:href="#linearGradient3765"
       id="radialGradient3771"
       cx="238.90109"
       cy="165.44824"
       fx="238.90109"
       fy="165.44824"
       r="66.164993"
       gradientTransform="matrix(1,0,0,0.21374045,19.994277,130.50302)"
       gradientUnits="userSpaceOnUse" />
  </defs>
  <sodipodi:namedview
     id="base"
     pagecolor="#ffffff"
     bordercolor="#666666"
     borderopacity="1.0"
     inkscape:pageopacity="0.0"
     inkscape:pageshadow="2"
     inkscape:zoom="0.98994949"
     inkscape:cx="-81.01726"
     inkscape:cy="-89.392653"
     inkscape:document-units="px"
     inkscape:current-layer="layer1"
     showgrid="false"
     fit-margin-top="1"
     fit-margin-left="1"
     fit-margin-right="1"
     fit-margin-bottom="1"
     units="cm"
     inkscape:window-width="1920"
     inkscape:window-height="1057"
     inkscape:window-x="1358"
     inkscape:window-y="-8"
     inkscape:window-maximized="1" />
  <metadata
     id="metadata7">
    <rdf:RDF>
      <cc:Work
         rdf:about="">
        <dc:format>image/svg+xml</dc:format>
        <dc:type
           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
        <dc:title />
      </cc:Work>
    </rdf:RDF>
  </metadata>
  <g
     inkscape:label="Ebene 1"
     inkscape:groupmode="layer"
     id="layer1"
     transform="translate(-19.99428,-0.41771923)">
    <path
       sodipodi:type="star"
       style="color:#000000;fill:#ffff00;stroke:#ff0000;stroke-width:9.89999962;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
       id="path2985"
       sodipodi:sides="9"
       sodipodi:cx="197.9899"
       sodipodi:cy="188.68176"
       sodipodi:r1="64.206299"
       sodipodi:r2="32.103149"
       sodipodi:arg1="1.1493771"
       sodipodi:arg2="1.498443"
       inkscape:flatsided="false"
       inkscape:rounded="0"
       inkscape:randomized="0"
       d="m 224.25387,247.27061 -23.94323,-26.56969 -19.86156,29.74465 -1.26291,-35.74397 -34.33433,10.01897 22.00834,-28.19325 -32.74169,-14.39472 34.98163,-7.45059 -15.82884,-32.07295 31.58664,16.77828 8.49049,-34.74389 13.4119,33.15641 28.83703,-21.15778 -11.03841,34.02028 35.69041,2.32829 -30.32374,18.96569 25.84385,24.72493 -35.42024,-4.96316 z"
       inkscape:transform-center-x="13.131983"
       inkscape:transform-center-y="3.2745809"
       transform="translate(-73.741136,-83.842661)" />
    <text
       xml:space="preserve"
       style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:27.5px;line-height:125%;font-family:Arial;-inkscape-font-specification:Arial;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;letter-spacing:0px;word-spacing:0px;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;baseline-shift:baseline;text-anchor:start;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:9.89999962;marker:none;enable-background:accumulate"
       x="211.12189"
       y="64.432991"
       id="text2987"
       sodipodi:linespacing="125%"><tspan
         sodipodi:role="line"
         x="211.12189"
         y="64.432991"
         id="tspan2993">Test Text</tspan><tspan
         sodipodi:role="line"
         x="211.12189"
         y="98.807991"
         id="tspan4148">Text Text</tspan><tspan
         sodipodi:role="line"
         x="211.12189"
         y="133.18298"
         id="tspan4150">tt AA BB</tspan></text>
    <rect
       style="color:#000000;fill:url(#radialGradient3771);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:9.89999961999999910;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
       id="rect2995"
       width="132.32999"
       height="28.284271"
       x="200.01021"
       y="151.30611" />
  </g>
</svg>
@mb21
Copy link
Collaborator

mb21 commented Feb 21, 2017

Image sizes are determined in Text/Pandoc/ImageSize.hs.

Unfortunately, there are a gazillion ways for an SVG to end up with a specific size, see https://css-tricks.com/scale-svg/ I guess we could support some of the (like the width, height attributes on the svg root element)...

In the meantime, try e.g. ![Test1](test1.svg){width=4cm height=3cm}

@nicodecker
Copy link
Author

Of course I use the workaround to live with it for now. Since I did not find any topic on the problem I thought it would be wise to file an issue report...

I assumed that SVG would be somehow standardized. Anyway. Actually, the size itself is not bothering me. The ratio is bothering me. As you can see above the tag svg (first main tag) contains the attributes width and height. The ratio could easily be calculated. It would help a lot to simply say width=20% and to receive a related height. However, pandoc sets width and height always to the same value (wrong ratio).

Maybe I can find some spare time to provide a fix/improvement myself and to file a merge request.

@jgm
Copy link
Owner

jgm commented Feb 21, 2017

Are the units for the width and height attributes on the svg root element in pixels, or what?

@nicodecker
Copy link
Author

I do not know the "standard", but yes, this is what I assume. I quickly made a new SVG, where the dimensions of the document are in mm-units. The related SVG attributes are then:

   width="68.120636mm"
   height="58.444443mm"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants