You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi. There seems to be a bug in how CairoSVG renders a tspan contained inside text that is not left-anchored. Here's an example svg:
<?xmlversion="1.0"encoding="utf-8"standalone="no"?>
<!DOCTYPEsvg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svgheight="200"width="800"version="1.1"xmlns="http://www.w3.org/2000/svg"xmlns:xlink="http://www.w3.org/1999/xlink">
<rectwidth="100%"height="100%"fill="white"/>
<linex1="400"y1="0"x2="400"y2="200"style="stroke:red; stroke-width:1" />
<textstyle="font-family:Times; font-size:20;"x="400"y="40"text-anchor="middle">This is center-anchored regular text</text>
<textstyle="font-family:Times; font-size:20;"x="400"y="80"text-anchor="start">This is left-anchored <tspanfont-style="italic">italic</tspan> text</text>
<textstyle="font-family:Times; font-size:20;"x="400"y="120"text-anchor="middle">This is center-anchored <tspanfont-style="italic">italic</tspan> text</text>
<textstyle="font-family:Times; font-size:20;"x="400"y="160"text-anchor="end">This is right-anchored <tspanfont-style="italic">italic</tspan> text</text>
</svg>
Here's the expected output:
Here's CairoSVG's actual output:
Is this a known bug? I couldn't find a previous report of this.
I've had a look through the code, and it seems like a difficult thing to fix. In this case, it seems that the sentence is rendered as three separate chunks (it's treated as three nodes): "This is center-anchored", "italic", and "text". When the first chunk is positioned, it needs to account for the width of the subsequent two chunks, and then some kind of offset needs to be passed to the subsequent chunks to position them correctly. My hunch is that, in order to do this properly, you need a kind of "pre-rendering" stage, where you figure out the width of the full text element before handling each node separately. Or do you think there could be some simpler ways to fix this?
The text was updated successfully, but these errors were encountered:
Hi. There seems to be a bug in how CairoSVG renders a tspan contained inside text that is not left-anchored. Here's an example svg:
Here's the expected output:
Here's CairoSVG's actual output:
Is this a known bug? I couldn't find a previous report of this.
I've had a look through the code, and it seems like a difficult thing to fix. In this case, it seems that the sentence is rendered as three separate chunks (it's treated as three nodes): "This is center-anchored", "italic", and "text". When the first chunk is positioned, it needs to account for the width of the subsequent two chunks, and then some kind of offset needs to be passed to the subsequent chunks to position them correctly. My hunch is that, in order to do this properly, you need a kind of "pre-rendering" stage, where you figure out the width of the full text element before handling each node separately. Or do you think there could be some simpler ways to fix this?
The text was updated successfully, but these errors were encountered: