GNOME Bugzilla – Bug 767481
very serious text rendering bug: wrong kerning
Last modified: 2017-01-05 21:56:00 UTC
Created attachment 329528 [details] Rendering of string `Te' with rsvg-view-3 [e68ec178] This simple SVG file ``` <?xml version="1.0"?> <svg xmlns="http://www.w3.org/2000/svg" height="100" width="100"> <g style="font-family:DejaVu Sans; font-size:32px"> <text y="30" x="30"> <tspan y="30" x="30"> Te </tspan> </text> </g> </svg> ``` renders as shown in the attached image with `rsvg-view-3` after pressing the zoom up button eight times. I guess that the kerning value gets scaled incorrectly; looking into `DejavuSans.ttf` using the `ttx` tool, I see the line ``` <pair l="T" r="e" v="-348"/> ``` in its 'kern' table. This is an *extremely* serious bug! In particular, uploading any SVG files to Wikipedia that contains text yields very ugly PNG files.
Thanks for noticing this and making a minimal test case! I suspect that librsvg is not at fault here. By tracing the code, it's just setting the letter_spacing to 0, and from there on Pango handles things. But now that you mention this, I've been printing maps with text that is scaled up, and I've seen weird spacing issues - I thought the fonts weren't handling those scales correctly or something. But it may be the same problem after all. I'll investigate.
Created attachment 330967 [details] font-scaling.c Indeed, not an librsvg problem. This program uses Pango directly and shows the same problem. Run it and look at the letter-spacing.png file it creates.
Ah. The bug is present with Pango 1.36.8 (openSUSE 13.2), but does not happen with Pango 1.40.1 (openSUSE Tumbleweed).
This bug is similar to bug #341481, but that one is older... maybe Harfbuzz got fixed since then? In any case, make sure to update your Pango/Cairo/Harfbuzz stack. I think Wikipedia has some old libraries laying around ;)
Thanks a lot for your analysis! I'll file a bug report to the Wikipedia people.
Downstream bug: https://phabricator.wikimedia.org/T36947