svg-net / SVG

Fork of the ms svg library
http://svg-net.github.io/SVG/
Microsoft Public License
1.13k stars 471 forks source link

Multiple tspan not rendering correctly #938

Open TommyN opened 2 years ago

TommyN commented 2 years ago

Description

A SVG with multiple tspan elements below a text-node doesn't render correctly when converted to PNG. Below is a simple reproduction SVG using text-anchor "middle", <none> and "end" each with two child tspan elements.

Example data

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1080" height="1080">

  <g transform="translate(200 400)">
      <rect x="-150" y ="-50" width="300" height="100" rx="15" />
      <text text-anchor="middle" fill="#ffffff" font-size="26" font-family="Rubik-Regular, Rubik" letter-spacing="0em">
        <tspan style="font-weight: bold;fill: #ff0000">15</tspan>
        <tspan>Apples</tspan>
      </text>
  </g>

  <g transform="translate(200 600)">
      <rect x="-150" y ="-50" width="300" height="100" rx="15" />
      <text fill="#ffffff" font-size="26" font-family="Rubik-Regular, Rubik" letter-spacing="0em">
        <tspan style="font-weight: bold;fill: #ff0000">15</tspan>
        <tspan>Apples</tspan>
      </text>
  </g>

  <g transform="translate(200 800)">
      <rect x="-150" y ="-50" width="300" height="100" rx="15" />
      <text text-anchor="end" fill="#ffffff" font-size="26" font-family="Rubik-Regular, Rubik" letter-spacing="0em">
        <tspan style="font-weight: bold;fill: #ff0000">15</tspan>
        <tspan>Apples</tspan>
      </text>
  </g>

</svg>

image

It seems @Stoffelche found an issue that he commented on here: https://github.com/svg-net/SVG/issues/769#issuecomment-757167913

Related issue:

Used Versions

Svg 3.3.0 .NET Framework 4.7

jonthysell commented 2 years ago

I recently updated Chordious to .NET 6 and SVG 3.4.0, and am now seeing this regression.

Downgrading to SVG 3.1.1 seems to resolve the issue for me (though I'm not sure at what other cost).

H1Gdev commented 2 years ago

PR #782 will change rendering result. However, if revert this commit, everything will not be correct.

output