Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use glyph indices for font tracking in vector formats #30335

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

Draft
wants to merge 3 commits into
base: text-overhaul
Choose a base branch
from

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented Jul 19, 2025

PR summary

With libraqm, string layout produces glyph indices, not character codes, and font features may even produce different glyphs for the same character code (e.g., by picking a different Stylistic Set). Thus we cannot rely on character codes as unique items within a font, and must move toward glyph indices everywhere.

The only thing I don't quite like is that PDF uses character codes for its lookup, and I have to map glyph indices back through an inverse charmap. I think I may have to send everything through CharacterTracker and produce my own limited charmap, but still need to test out what's required.

This is based on #30143.

PR checklist

QuLogic added 3 commits July 19, 2025 03:27
Previously, these were both typed as `int`, which means you could mix
and match them erroneously. While the character code can't be made a
distinct type (because it's used for `chr`/`ord`), typing glyph indices
as a distinct type means these can't be fully swapped.

Unfortunately, you can still go back to the base type, so glyph indices
still work as character codes. But this is still sufficient to catch
errors such as the wrong call to `FT2Font.get_kerning` in
`_mathtext.py`.
The `FontInfo.num` value returned by `TruetypeFonts._get_info` is a
character code, but `FT2Font.get_kerning` takes *glyph indices*, meaning
that kerning was likely off in most cases.
With libraqm, string layout produces glyph indices, not character codes,
and font features may even produce different glyphs for the same
character code (e.g., by picking a different Stylistic Set). Thus we
cannot rely on character codes as unique items within a font, and must
move toward glyph indices everywhere.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Waiting for other PR
Development

Successfully merging this pull request may close these issues.

1 participant