RazrFalcon / resvg

An SVG rendering library.
Mozilla Public License 2.0
2.73k stars 220 forks source link

usvg panics on text with diacritics #732

Open zignis opened 5 months ago

zignis commented 5 months ago

usvg@0.41.0 panics here when rendering a text having diacritics using a custom font:

removal index (is 2) should be < len (is 2)

https://github.com/RazrFalcon/resvg/blob/fb7e28513f561ed847acbf4a6fb8b743474837a0/crates/usvg/src/text/layout.rs#L823

I'm using a non-system font that does not include diacritics. Relevant SVG:

<svg width="500" height="500" viewBox="0 0 500 500" fill="none" xmlns="http://www.w3.org/2000/svg">
    <text font-family="Font without diacritics, Some fallback font" x="50%" y="50%">
        <tspan>y̆</tspan>
    </text>
</svg>

Perhaps we can check if the glyph exists at the index before removing it, but I'm not certain if it's the right way to handle this.

RazrFalcon commented 5 months ago

Do you have fonts with which I can reproduce it?

zignis commented 5 months ago

@RazrFalcon try this: https://www.dropbox.com/scl/fi/6wiosp1bwtkysx77foqhx/CabinetGrotesk-Regular.ttf?rlkey=pen3lkx3ers0sic03z2sxmhfn&dl=0