yWorks / svg2pdf.js

A javascript-only SVG to PDF conversion utility that runs in the browser. Brought to you by yWorks - the diagramming experts
MIT License
659 stars 101 forks source link

Nested tspans don't work #215

Closed edemaine closed 1 year ago

edemaine commented 2 years ago

Describe the bug Nested <tspan>s don't seem to respect the hierarchy, and dy sometimes gets skipped. In my case, I need a <tspan> to advance each line (via dy) and nested <tspan>s to change the font within a line.

To Reproduce See this playground.

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 150">
  <text fill="black" style="font-size:40px">HELLO
    <tspan x="0" dy="1.25em"><tspan class="code">WORLD</tspan></tspan>
  </text>
</svg>

Expected behavior I would have expected the PDF to render HELLO above WORLD, like in the SVG. This is in accordance to the following SVG spec. Instead HELLO and WORLD render on top of each other:

image

I believe the code is getting interpreted as if the first <tspan> was closed before the second one, so it doesn't render because it's empty.

Desktop (please complete the following information):