RazrFalcon / resvg

An SVG rendering library.
Mozilla Public License 2.0
2.63k stars 216 forks source link

Letters overlap each other on specific font and combination of letters #635

Open antmelnyk opened 1 year ago

antmelnyk commented 1 year ago

Hey @RazrFalcon, I hope you're doing OK.

There is a weird issue with text resolving that was caught for one particular font and a combination of letters. Not sure exactly on which level that happens - either usvg-text-layout or rustybuzz. Maybe you have an idea?

SVG:

<svg width='100' height='100' viewBox='0 -201.7578125 100 251.3671875'
    xml:space='preserve'
    xmlns='http://www.w3.org/2000/svg'
    xmlns:xlink='http://www.w3.org/1999/xlink'>
    <text x='0' y='0' font-size='200' font-family='Fjalla One' fill='#000000'>fit</text>
</svg>

Font Fjalla One (https://fonts.google.com/specimen/Fjalla+One?noto.query=Roboto&preview.text=fit&preview.text_type=custom&query=fjalla)

Result of running minimal.rs example with added fontdb.load_font_file("./examples/Fjalla One-regular.ttf").unwrap();

Expected (rsvg-convert): rsvg

Actual (ReSVG): resvg

RazrFalcon commented 1 year ago

This is a ligature handling bug. Similar to #614, but this time it doesn't fail immediately. Seems like usvg-text-layout bug. rustybuzz produces the same output as harfbuzz.

It basically thinks that fi is a single character, which is not. Kinda...

antmelnyk commented 1 year ago

Yeah, that makes sense. I thought that it was about ligature handling.

For this font, the ligatures are classic ff, fi, fl, ffi, ffl. And it fails to render fi and fl if there are more characters after these.

I checked 350 other Google Fonts, and quite a lot of them have these 2 ligatures (fi and fl). It fails to render only for this particular font, Fjalla One. Maybe that can help you to understand the difference and core of the issue.