-
-
Notifications
You must be signed in to change notification settings - Fork 8k
TST: Remove redundant font tests #30513
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
QuLogic
wants to merge
9
commits into
matplotlib:text-overhaul
Choose a base branch
from
QuLogic:redundant-font-tests
base: text-overhaul
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Currently, we split text into single byte chunks and multi-byte glyphs, then iterate through single byte chunks for output and multi-byte glyphs for output. Instead, output the single byte chunks as we finish them, then do the multi-byte glyphs at the end.
For a Type 3 font, its encoding is entirely defined by its `Encoding` dictionary (which we create), so there's no reason to use a specific encoding like `cp1252`. Instead, switch to Latin-1, which corresponds exactly to the first 256 character codes in Unicode, and can be mapped directly with `ord`.
By tracking both character codes and glyph indices, we can handle producing multiple font subsets if needed by a file format.
For character codes outside the embedded font limits (256 for type 3 and 65536 for type 42), we output them as XObjects instead of using text commands. But there is nothing in the PDF spec that requires any specific encoding like this. Since we now support subsetting all fonts before embedding, split each font into groups based on the maximum character code (e.g., 256-entry groups for type 3), then switch text strings to a different font subset and re-map character codes to it when necessary. This means all text is true text (albeit with some strange encoding), and we no longer need any XObjects for glyphs. For users of non-English text, this means it will become selectable and copyable again. Fixes matplotlib#21797
For Type 3 fonts, add a `ToUnicode` mapping (which was added in PDF 1.2), and for Type 42 fonts, correct the Unicode encoding, which should be UTF-16BE, not UCS2.
These characters are outside the BMP and should test subset splitting for type 42 output in PDF.
- `test_backend_ps::test_type3_font` is covered by `test_backend_ps::test_multi_font_type3` - `test_text::test_pdf_chars_beyond_bmp` is covered by `test_backend_pdf::test_multi_font_type3` and `test_backend_pdf::test_multi_font_type42` - `test_text::test_pdf_kerning` is covered by `test_backend_pdf::test_kerning` - `test_text::test_pdf_type42_kerning` is covered by `test_backend_pdf::test_kerning`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR summary
I extracted this out of #30512 because it was causing issues with the pre-loading of test images. I may update this as/when I find more redundant tests.
test_backend_ps::test_type3_font
is covered bytest_backend_ps::test_multi_font_type3
test_text::test_pdf_chars_beyond_bmp
is covered bytest_backend_pdf::test_multi_font_type3
andtest_backend_pdf::test_multi_font_type42
test_text::test_pdf_kerning
is covered bytest_backend_pdf::test_kerning
test_text::test_pdf_type42_kerning
is covered bytest_backend_pdf::test_kerning
PR checklist