-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
base: text-overhaul
Are you sure you want to change the base?
Conversation
Note, fixing this would require updating 20 images (for very minimal changes), which I originally rolled into #29816, but it could be moved here. |
Since #29816 is now just the FreeType change, I've moved the kerning correction here. |
387a3c1
to
755eab1
Compare
cc4ede1
to
73bd5f5
Compare
There aren't too many test image changes here, so I'm debating whether to merge them in, but we've generally agreed not to until the whole feature branch is done. |
6a03850
to
1cbf39e
Compare
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.
1cbf39e
to
733cd7d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May have slightly preferred the actual output change to be separated from here, but not too fussed in total.
There are only 5 png changes here, the rest are svg, which I'm not concerned about as that is text changes rather than binary files.
Thus I'm good with the scale of change in a PR without needing to group these changes.
But the typing changes look good, are well reasoned, and look correct.
I can drop that and it'll be rolled into the final PR, so that should be fine. This is just for CI, really. |
Like I said, not too fussed, it was easy to see which lines actually changed, just slight preference. I don't think it is worth rolling back though. |
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 forchr
/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