Godot version: 3.1.1
OS/device including version: Windows 10
Issue description: The dynamic font uses incorrect kerning values for a Google Font which renders correctly in Photoshop and in a browser.
Steps to reproduce: Open the demo project and observe the indicated visual problems, then compare with the included texture which shows the expected result.
Minimal reproduction project: https://github.com/sszigeti/godot-3.1.1-kerning-bug
It seems to be the problem of the font, I tried it in unity and it overlaps too. And I get the font graph of 'P' and 'l' and put them together, then I got an image like this:
You can see they overlaps. You can check font info use this: https://opentype.js.org/glyph-inspector.html
I think there are some intelligent mechanism when processing font in photoshop and Google fonts, so they don't overlap.
It is an aspect of the standard that FreeType does not handle. FT_HAS_KERNING
indeed returns 0 on this font. FreeType docs suggest other libraries like HarfBuzz for such cases.
For the curious: many recent fonts store the kerning information in GPOS
table and omit the good old kern
table. GPOS
contains far more information, often requiring more complex layout considerations, which is out of scope for FreeType as a font renderer 😝
It's possible to process the font before use.
Import the font into FontForge GUI, choose File → Generate Fonts, select the TrueType format, click Options, tick Old style 'kern' and generate.
The ttx
utility may as well come handy for inspecting font file contents.
Since this is something we can't solve on our end, we should probably add a quick note in the DynamicFont documentation about FreeType limitations and document the workaround given by @kawa-yoiko.
Having just seen the workaround suggested in the docs and recently discovering that currently DynamicFont
doesn't support kerning of any kind (see: #35730) I thought I'd mention that fact here to clarify that presently changing the kerning table included won't actually make the kerning work in Godot.
Most helpful comment
It's possible to process the font before use.
Import the font into FontForge GUI, choose File → Generate Fonts, select the TrueType format, click Options, tick Old style 'kern' and generate.
The
ttx
utility may as well come handy for inspecting font file contents.