-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Remove ttconv and implement Type-42 embedding using fontTools #20866
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
Conversation
447fd1b to
a826065
Compare
8c44828 to
2535508
Compare
de16cf0 to
daee4e5
Compare
016713a to
7cea2d4
Compare
| if fontfile.endswith('ttc'): | ||
| # fix this once we support loading more fonts from a collection | ||
| # https://github.com/matplotlib/matplotlib/issues/3135#issuecomment-571085541 | ||
| options.font_number = 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.
I think we test a ttc in CI already, so it could be used to test this line?
| The Type-42 formatted font | ||
| """ | ||
| version, breakpoints = _version_and_breakpoints(font.get('loca'), fontdata) | ||
| post, name = font['post'], font['name'] |
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.
Are these tables guaranteed to exist?
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.
Both post and name are required: https://docs.fileformat.com/font/ttf/
| tuple | ||
| ((v1, v2), breakpoints) where v1 is the major version number, | ||
| v2 is the minor version number and breakpoints is a sorted list | ||
| of offsets into fontdata; if loca is not available, just the table | ||
| boundaries |
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.
For multiple return, you should list the entries separately, like Parameters.
|
Wow, I missed that this came in. 💯 on dropping an extension module! |
|
Dropping to draft until the comments and rebase are addressed. Anyone should feel free to move back to active... |
|
Ping @jkseppan? |
| Returns | ||
| ------- | ||
| fontTools.ttLib.ttFont.TTFont |
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.
Long term, it could make sense to link to the documentation? (Although fontTools is not in the intersphinx_mapping yet.)
|
We want to try and do mpl 3.7 feature freeze around Jan 1 so I think it is unlikely we will have the bandwidth to get this rebased and reviewed by then, pushing to 3.8. |
7cea2d4 to
a1b41fe
Compare
|
Do we have someone who can pick this up? |
7f2b2a2 to
1393702
Compare
|
FYI, I think I'm okay with this as it stands, but as I did some followup cleanup work, I'm not sure if I should approve it myself. |
oscargus
left a comment
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.
I am still open to the possibility to add fontTools to the intersphinx-stuff and provide a proper link, but I am also open to do that myself in another PR.
|
Btw, do we (i.e. someone with a Mac(?)) know if #20866 (comment) still holds? |
Maybe @greglucas or @ksunden can have a look at it? |
|
Using the example from the linked issue: # this needs the patch above
import matplotlib
from pathlib import Path
matplotlib.use('ps')
from matplotlib import pyplot as plt
# the following font is in CFF format on my Mac
font = Path('/System/Library/Fonts/AppleSDGothicNeo.ttc')
fig = plt.figure()
plt.axis((0,10,0,10))
plt.text(3,3,'Glib jocks quiz nymph to vex dwarf.', font=font)
matplotlib.rc('ps', fonttype=42)
plt.savefig('fmt42.ps')
matplotlib.rc('ps', fonttype=3)
plt.savefig('fmt3.ps')The type42 is completely blank for me (no axes either). The type3 shows up as expected. I don't get an error though 🤷 |
|
That example fails for me on main. Trying to open the and with this branch I get |
|
Okay, looks like the answer is that this has not fixed #20866 (comment), however that is broken on main anyway, so I'd lean towards not blocking for merging this if we are otherwise satisfied. |
|
The issue also appears to be font specific, dejavu being embedded as type42 works OK. |
Split _backend_pdf_ps.get_glyphs_subset into two functions: get_glyphs_subset returns the font object (which needs to be closed after using) and font_as_file serializes this object into a BytesIO file-like object.
Move the test in lib/matplotlib/tests/test_ttconv.py to lib/matplotlib/tests/test_backend_pdf.py. Actually it has not been a test of ttconv for a while, since type-3 conversion has not been using ttconv.
Fonttools cannot subset these and drops them; avoid the warning.
Also don't end up in an infinite loop if there is a larger gap between breakpoints than we would like.
FT2Font throws RuntimeError for some fonts
Not the subsetted one, since in some cases fontTools.subset does not produce a good name table.
De-wrap a few lines now that we allow longer lines.
1393702 to
45a1654
Compare
This was missed in matplotlib#20866
This was missed in matplotlib#20866
PR Summary
ttconv is now only being used for outputting fonts in Type-42 format in PostScript files, and with fontTools this turns out to be quite doable in pure Python.
PR Checklist
pytestpasses).flake8on changed files to check).flake8-docstringsand runflake8 --docstring-convention=all).doc/users/next_whats_new/(follow instructions in README.rst there).doc/api/next_api_changes/(follow instructions in README.rst there).