-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Please add support for ttc font files (PDF/PS output) #3135
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
Comments
Hi, This issue has been inactive for a while. Does this continue to represent a useful enhancement? I believe the PR associated with this has stalled a little. Thanks! |
A lot of the fonts I want to use on Mac (principally Gill Sans) are also TTC, so I would love to see #9787 merged. |
Friendly ping. I ran into this issue when testing various sans-serif fonts. Who would have the expertise to address this? |
#9897 is in Matplotlib 3.1. Does it not go far enough? I take it there are some issues with pdf/ps. |
I have matplotlib 3.1.1, issue is still present. In [1]: import matplotlib
In [2]: matplotlib.__version__
Out[2]: '3.1.1' This is an issue specifically with the PDF backend (not sure about PS). The title should probably be changed to reflect this. |
Also, I am on macOS, not windows. |
In the meantime here is a working example for macOS: import matplotlib.font_manager as fm
import matplotlib.pyplot as plt
props = fm.FontProperties(fname='/System/Library/Fonts/Helvetica.ttc')
f, ax = plt.subplots()
ax.set_title('Title', fontproperties=props)
f.savefig('tmp.pdf') Note that |
I have Catalina, and I don't have anything in EDIT:... oops, as I guess you realize... |
Haha yep, I discovered this by restoring the default system fonts. |
Basically one would need to extend https://github.com/matplotlib/matplotlib/blob/master/src/_ttconv.cpp and https://github.com/matplotlib/matplotlib/tree/master/extern/ttconv to support ttc files. Probably not actually that hard (likely by first porting the thing to pure python and using the ft2font interface) -- my guess is that it's at most a couple of days' work -- but not particularly fun either. Edit: hum, perhaps not so easy; adapting #5414 may be a better place to start. |
Perhaps a better idea: fonttools (https://github.com/fonttools/fonttools) is a pure-python lib that can -- in particular -- convert individual ttc subfaces to ttf (and do plenty of other things with fonts) -- it's a straightforward However, we also need to add more machinery on mpl's side, namely to handle all subfaces in ttcs (a ttc is a collection of multiple ttfs). In mplcairo (which fully supports ttcs) I hacked that by specifying the nth font in a ttc as Now I think this is actually doable... just a lot of work. If someone is interested in doing this, I can try to write up a more detailed todo, but you'll need to get yourself familiar with matplotlib.ft2font and matplotlib.font_manager first. |
So many years passing by, and I'm facing that again for using Currently, my solution is to extract An example snippet (hope it could help others): import os
import matplotlib.font_manager
from matplotlib import rc
dirname = os.path.dirname(__file__)
for style in ['normal', 'italic', 'bold', 'bold_italic']:
file_path = os.path.normpath(os.path.join(dirname, f'palatino_{style}.ttf'))
matplotlib.font_manager.fontManager.addfont(file_path)
rc('font', family='serif', serif='Palatino', weight='bold') |
Having a problem reading "Noto Serif CJK SC" font in matplotlib version 3.5.2 |
Missing fonts in ttc EXCEPT the first one. Install font by : >>> f = matplotlib.font_manager.get_font("/usr/share/fonts/opentype/noto/NotoSerifCJK-Regular.ttc")
>>> f.family_name
'Noto Serif CJK JP' But in fact:
|
That's their current implementation. So you better use ttf rather than ttc. You may use this snippet to extract ttf from ttc collection file: |
@ain-soph , thanks for solution! I know I can solve it with a lot of hack ways, but use only the first font in ttc file is clearly a bug. |
It's a known issue for over 5 years (and perhaps another 5 years lol). There seems to be some technical challenge. I'm not familiar with those stuff though. |
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help! |
Emojis! |
Emojis in PDF might need to wait, since the color formats are also an issue beyond just TTC. I heard that Clerk Ma is doing something to XeTeX to allow them -- maybe we can use his work if the license and stuff works. The current PR works, but converting by splitting is, at the end of the day, less than perfect -- especially if you have something like a 35-in-one Source Han Sans SuperOTC installed (I used to have that. I probably still do, but I'm too lazy to check.). The ideal is to find an alternative to _ttconv somewhere -- the TeX people might have the answer, I don't know. |
The code posted below will return the following: RuntimeError: TrueType font is missing table . It looks like TTC files have replaced TTF files for many fonts in Windows 8. Please consider adding support. Thanks so much,
MJ
The text was updated successfully, but these errors were encountered: