deeplook / svglib

Read SVG files and convert them to other formats.
GNU Lesser General Public License v3.0
311 stars 80 forks source link

Rendering issue with <tspan> and <style> #343

Open jspobst opened 2 years ago

jspobst commented 2 years ago

A plotly figure I made isn't rendering correctly. The part that's failing involves a <tspan>, so I went and grabbed the simplest tspan example I could find from here to test further.

<svg viewBox="0 0 240 40" xmlns="http://www.w3.org/2000/svg">
  <style>
    text  { font: italic 12px serif; }
    tspan { font: bold 10px sans-serif; fill: red; }
  </style>

  <text x="10" y="30" class="small">
    You are
    <tspan>not</tspan>
    a banana!
  </text>
</svg>

That should produce

image

But when putting it through

drawing = svglib.svg2rlg(io.StringIO(textwrap.dedent(svg_string)))
renderPDF.draw(drawing, c, 50, 50)

I get this in the produced pdf

image

svglib: 1.3.0 reportlab: 3.6.9 python: 3.97 MacOS: 12.3.1

Thank you.

github-actions[bot] commented 2 years ago

Thank you for raising your first issue! Your help to improve svglib is much appreciated!

jspobst commented 2 years ago

Given that no text after not shows, it almost seems as though the </tspan> is somehow closing the <text>.

claudep commented 2 years ago

In #344, I tried to solve the issue of the trailing part of text nodes. The rendering of the sample above is not yet optimal, but at least it seems all text appear.

jspobst commented 2 years ago

Hi @claudep, I see that this isn't optimal just yet, but I wanted to say thanks for the work you've already put into it so quickly. It really is appreciated!