Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
PrepareCharacterTracker
for advanced font features#30608
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation
CharacterTracker.track
implementationCharacterTracker
for advanced font featuresNote, I think the original commit was small, and the remaining ended up small enough, that I just put them all in this PR. |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
print("%%BeginProlog",file=fh) | ||
ifnotmpl.rcParams['ps.useafm']: | ||
Ndict+=len(ps_renderer._character_tracker.used) | ||
Ndict+=sum(map(len,ps_renderer._character_tracker.used.values()),0) |
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.
The 0 at the end is unneeded.
Uh oh!
There was an error while loading.Please reload this page.
No need to repeat the calculation of subset blocks, but instead offloadit to `track_glyph`.
Instead of splitting fonts into `subset_size` blocks and writing text ascharacter code modulo `subset_size`, compress the blocks by doing twothings:1. Preserve the character code if it lies in the first block. This keeps ASCII (for Type 3) and the Basic Multilingual Plane (for Type 42) as their normal codes.2. Push everything else into the next spot in the next block, splitting by `subset_size` as necessary.This should reduce the number of additional font subsets to embed.
If mixing languages, sometimes a single character may use differentglyphs in one document. In that case, we need to give it a new charactercode in the next subset, since subset 0 is preserving character codes.
OK, I've handled all your comments, I think. I also fixed subsetting in the PostScript backend, noted above. There are 3 test image changes:
|
Uh oh!
There was an error while loading.Please reload this page.
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.
Just a minor point regarding a comment.
For ligatures or complex shapings, multiple characters may map to asingle glyph. In this case, we still want to output a single charactercode for the string using the font subset, but the `ToUnicode` mapshould give back all the characters.
Previously, this was supposed to "upgrade" type 3 to type 42 if thenumber of glyphs overflowed. However, as `CharacterTracker` can suggesta new subset for other reasons (i.e., multiple glyphs for the samecharacter or a glyph for multiple characters may go to a second subset),we do need proper subset handling here as well.Since that is now done, we can drop the "promotion" from type 3 to type42, as we don't get too many glyphs in each embedded font.
Removed the image changes (and moved them to the |
Linting issues are known (#30626), so merging over those. |
ed4ca6c
intomatplotlib:text-overhaulUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
PR summary
The original code split fonts into subsets based on the character modulo the subset size (determined by font type limits). This had some limitations:
ord
on a multi-char string.To fix this,
CharacterTracker
now tracks characters and glyphs more closely. Specifically,With these changes, the complex/font features/languages tests in#30607 produce correct results.
PR checklist