-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Support (first font of) TTC files. #9787
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
|
77c0e34
to
b67da2b
Compare
Could one use something like |
I'd rather just do it properly and switch everything to (pathname, index) (which is the standard representation FreeType uses, see https://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#FT_New_Face (pathname, face_index)). But that's out of scope for this PR. |
3ea2f9a
to
d653bc1
Compare
What's blocking? May I help here? |
We need a second positive review from one of the matplotlib reviewers before the PR can be merged. @anntzer Travis Python 3.7 now fails with:
This has to be investigated before merging. Is the font missing there? |
That's because I need to temporarily force the use of new font caches. Added a second commit that does so; then we can later revert that commit. |
72d25de
to
ccd00ac
Compare
Some of the metadata seems to end up wrong when using this. FT2Font.get_sfnt() gives back garbage on most (with a few odd exceptions) .TTC fonts. This makes certain fonts inaccessible - in my specific case, I'm asking for Microsoft YaHei and ending up with Microsoft YaHei light, and there's no way to specifically get the normal weight version. |
I guess that may be because YaHei has the light font at index 0 and the regular one at index 1? (I don't have access to it.) |
No, light and normal are separate TTCs (the whole point of .ttc is that it efficiently stores fonts that have many of the same glyphs; packing completely different versions of the same font doesn't do you any good.) The problem is that MatPlotLib can't load their metadata aside from the font family and sees them as identical. YaHei should come preinstalled on every Windows machine with 8 or later. I see similar issues with most .ttcs on my system, though maybe it's something unique Microsoft is doing. I only saw it work correctly with non-CJK fonts though I imagine that's coincidence. |
Oh, I see. I think it's basically the same issue as #8550? (in which case once again it's orthogonal to ttc support) |
No; it's the same end result, but in that case the issue was failure to correctly interpret the metadata, whereas here the metadata comes back as junk. The font is named "YaHei Light;" if it could read the name it would assign it the correct weight, it just can't read the name. With a conditional breakpoint on font_manager.py:342 with the condition set to |
No, the family name (as loaded by FreeType into the family_name field of FT_FaceRec) is 'Microsoft YaHei'. |
Ah, I get it now. Okay, this is a Microsoft being weird issue, not a .ttc issue. Weird how it worked before the .ttc switch, but it's not your problem. Thanks for the info. |
TTC is a TrueType Collection file (a collection of TTFs). Currently, ft2font only supports getting the first font from the collection, and neither the pdf nor ps backends are able to use them (due to limitations of ttconv). Still, it seems better than nothing to support them for Agg and SVG (that comes for free via FreeType).
@anntzer Looks like you need to do a commit/revert dance on this PR because of the cache? If so, I think you can self-merge, and then do the revert commit soon after? (not sure how big a deal it is to leave master in an uncahched state) |
I'll open a PR to restore the cache (that's what tests that the cache actually works...) immediately after this is merged (e.g. by you? :)). |
Sure, I just wanted to make sure you were around to do it. If now is good, here it goes... |
TTC is a TrueType Collection file (a collection of TTFs). Currently,
ft2font only supports getting the first font from the collection, and
neither the pdf nor ps backends are able to use them (due to limitations
of ttconv). Still, it seems better than nothing to support them for Agg
and SVG (that comes for free via FreeType).
xref #3135, #3912.
PR Summary
PR Checklist