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

Skip to content

TYP: Make glyph indices distinct from character codes #30143

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 Jun 4, 2025

PR summary

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.

This depends on #30134.

PR checklist

@QuLogic
Copy link
Member Author

QuLogic commented Jun 4, 2025

But this is still sufficient to catch errors such as the wrong call to FT2Font.get_kerning in _mathtext.py.

Note, fixing this would require updating 20 images (for very minimal changes), which I originally rolled into #29816, but it could be moved here.

@QuLogic QuLogic moved this to Waiting for other PR in Font and text overhaul Jun 5, 2025
@QuLogic QuLogic added this to the v3.11.0 milestone Jun 5, 2025
@QuLogic
Copy link
Member Author

QuLogic commented Jun 6, 2025

Since #29816 is now just the FreeType change, I've moved the kerning correction here.

@QuLogic QuLogic changed the base branch from main to text-overhaul June 11, 2025 02:57
QuLogic added 3 commits June 19, 2025 18:16
Also, check some expected conditions at parse time instead of somewhere
during use of the data.
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.
@QuLogic QuLogic force-pushed the character-glyph-types branch from 387a3c1 to 755eab1 Compare June 19, 2025 22:17
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