-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
add support for ttc font files #3912
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
This seems too simple to be true... Do you know of an open ttc font we can install on travis (either by 'hand' or through apt-get)? |
It looks like freetype does indeed do this for us, it looks like for free! http://www.freetype.org/freetype2/ |
There are some widely used free chinese fonts: package 'ttf-wqy-zenhei' and 'ttf-wqy-microhei' in ubuntu repo. They are located in /usr/share/fonts/truetype/wqy after installation. |
matplotlib.rcParams['font.family'] = 'WenQuanYi Zen Hei' |
Can you put together an image test with Chinese labels? Please don't spend too much time on it until feedback from @mdboom (is this a bad idea?). |
However test_font_priority failed in my system(cmmi10.ttf is available) |
Ah, your test is much better than what I had in mind 👍 |
I think you will have to modify the |
Specifically, just add the proper package to https://github.com/matplotlib/matplotlib/blob/master/.travis.yml#L27 |
This does work for Agg and SVG, but it doesn't work for PDF or PS. (Didn't check macosx, but it has a completely different code path for fonts, so we'd need to check that, too). There are two ways fonts are handled in PDF and PS in matplotlib. One, is we just shove the whole font file in the output. This works only for "standard" ttf fonts, not ttc (which is a TrueType collection -- really just a packaging of multiple ttf fonts). The other way is that we subset the font and convert it to a Type 3 font and save that in the file. For this, we use the So, we can commit this now, but we'd, at a minimum, need to add checks to not use these fonts when outputting PDF or PS. The long term plan is to move the font subsetting to a new implementation similar to what SVG does, where it just gets the curves from FreeType (and thus would support any font that FreeType supports, which is very comprehensive). That would let us put any kind of font in PDF and SVG. Just haven't found the resources to do that yet. |
I should also add a couple of things about the test: This test will fail if this special font isn't installed. That's fine for Travis, but for end-user-developers, there will always be a failing test. The test should instead check for the presence of the file, and not finding it, mark as Also, the test should actually do something with the font -- that would catch the brokenness on PDF. |
I don't know how to achieve this right now. It will take me some time to be more familiar with matplotlib codebase. Or we can merge this pull request for now( the font is loaded but #3135 with pdf issue unsolved) , and let some one more familiar to add this logic. @mdboom test_font_priority will also fail if a special font ('cmmi10.ttf') is not installed. |
@tacaswell: I don't think we should merge this without fixing the pdf/ps issues. I might be able to find some time in the near future to add this. Having looked at this problem even more, it seems this fix only allows one to access the first font in a @luoq: |
Superseded by #9787.. Thanks for getting the ball rolling... |
solve #3135
I found this solution in various web posts.
You may need to clean the cache in ~/.cache/matplotlib.