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

Open
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 QuLogic force-pushed the character-glyph-types branch from 387a3c1 to 755eab1 Compare June 19, 2025 22:17
@QuLogic QuLogic force-pushed the character-glyph-types branch 2 times, most recently from cc4ede1 to 73bd5f5 Compare July 9, 2025 06:13
@QuLogic QuLogic marked this pull request as ready for review July 9, 2025 06:14
@QuLogic QuLogic moved this from Waiting for other PR to Ready for Review in Font and text overhaul Jul 9, 2025
@QuLogic
Copy link
Member Author

QuLogic commented Jul 9, 2025

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.

@QuLogic QuLogic force-pushed the character-glyph-types branch 2 times, most recently from 6a03850 to 1cbf39e Compare July 19, 2025 07:32
QuLogic added 3 commits July 24, 2025 15:37
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 1cbf39e to 733cd7d Compare July 24, 2025 19:46
Copy link
Member

@ksunden ksunden left a 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.

@QuLogic
Copy link
Member Author

QuLogic commented Jul 24, 2025

May have slightly preferred the actual output change to be separated from here, but not too fussed in total.

I can drop that and it'll be rolled into the final PR, so that should be fine. This is just for CI, really.

@ksunden
Copy link
Member

ksunden commented Jul 25, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Ready for Review
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy