Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kerning table does not get loaded, Font.horizontal_kern is always None #161

Open
tadeohepperle opened this issue Jan 24, 2025 · 0 comments

Comments

@tadeohepperle
Copy link

tadeohepperle commented Jan 24, 2025

Hello! I have noticed that for various ttf fonts the kerning table does not seem to get populated (example: https://fonts.google.com/specimen/Luxurious+Roman).
When I load the font with the stb_truetype library I get non-zero kerning values for character pairs such as ('A', 'V'), but if I load the same ttf file with fontdue, Font::horizontal_kern returns None for all glyph pairs.

Example:

let bytes = std::fs::read("LuxuriousRoman-Regular.ttf").unwrap();
let font = fontdue::Font::from_bytes(&bytes[..], FontSettings::default()).unwrap();
dbg!( font.horizontal_kern('A', 'V', 40.0)); // is None, but shouldn't be! 

No kerning as visible here:
Image
How is should look like:

Image

Edit: I think the issue is with how the kerning is loaded:
face.raw_face().table(Tag::from_bytes(&b"kern"))?;
This just looks at the kern table, but a lot of fonts omit this table and put the kerning information into the gpos table instead, which contains records such as:

TagRecord {
       tag: Tag(kern),
       offset: Offset16(38),
},

For example stb_truetype is doing this:

if (info->gpos)
      xAdvance += stbtt__GetGlyphGPOSInfoAdvance(info, g1, g2);
   else if (info->kern)
      xAdvance += stbtt__GetGlyphKernInfoAdvance(info, g1, g2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant