Skip to content

add support for ttc font files#3912

Closed
luoq wants to merge 4 commits into
matplotlib:masterfrom
luoq:ttc
Closed

add support for ttc font files#3912
luoq wants to merge 4 commits into
matplotlib:masterfrom
luoq:ttc

Conversation

@luoq

@luoq luoq commented Dec 12, 2014

Copy link
Copy Markdown

solve #3135

I found this solution in various web posts.

You may need to clean the cache in ~/.cache/matplotlib.

@tacaswell

Copy link
Copy Markdown
Member

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)?

@tacaswell

Copy link
Copy Markdown
Member

It looks like freetype does indeed do this for us, it looks like for free! http://www.freetype.org/freetype2/

@luoq

luoq commented Dec 12, 2014

Copy link
Copy Markdown
Author

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.

@luoq

luoq commented Dec 12, 2014

Copy link
Copy Markdown
Author

matplotlib.rcParams['font.family'] = 'WenQuanYi Zen Hei'
is working for me for some months.

@tacaswell tacaswell added this to the v1.4.3 milestone Dec 12, 2014
@tacaswell

Copy link
Copy Markdown
Member

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?).

@luoq

luoq commented Dec 12, 2014

Copy link
Copy Markdown
Author

However test_font_priority failed in my system(cmmi10.ttf is available)

@tacaswell

Copy link
Copy Markdown
Member

Ah, your test is much better than what I had in mind 👍

@tacaswell

Copy link
Copy Markdown
Member

I think you will have to modify the .travis.yaml file to install which ever ubuntu package installs Zen Hei. The default vms are very bare bones.

@tacaswell

Copy link
Copy Markdown
Member

Specifically, just add the proper package to https://github.com/matplotlib/matplotlib/blob/master/.travis.yml#L27

@mdboom

mdboom commented Dec 12, 2014

Copy link
Copy Markdown
Member

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 ttconv library, which only supports regular TTF files.

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.

@mdboom

mdboom commented Dec 12, 2014

Copy link
Copy Markdown
Member

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 xfail.

Also, the test should actually do something with the font -- that would catch the brokenness on PDF.

@tacaswell

Copy link
Copy Markdown
Member

@mdboom What do you want to do about this?

@luoq Could you possibly extend the tests and add the guard logic to pdf/ps?

@luoq

luoq commented Dec 31, 2014

Copy link
Copy Markdown
Author

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.

@mdboom

mdboom commented Jan 5, 2015

Copy link
Copy Markdown
Member

@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 ttc file. So, even as ttc support, I'd say this is pretty limited. As much as it isn't great, I think the recommendation for users at this time should be to split the ttc file into separate ttf files, using a tool such as fontforge, and pull them into matplotlib that way.

@luoq: test_font_priority relies on a font that ships with cmmi10.ttf, so it's guaranteed to always be found. Not so with the ttc font in the new test.

@tacaswell tacaswell modified the milestones: v1.5.x, v1.4.3 Jan 8, 2015
@tacaswell tacaswell modified the milestones: proposed next point release, next point release Feb 19, 2015
@tacaswell tacaswell modified the milestones: proposed next point release, next point release Jun 22, 2015
@QuLogic QuLogic mentioned this pull request Dec 3, 2015
4 tasks
@tacaswell tacaswell mentioned this pull request May 12, 2017
@tacaswell tacaswell modified the milestone: 2.1 (next point release) Aug 29, 2017
@anntzer anntzer mentioned this pull request Nov 15, 2017
6 tasks
@jklymak

jklymak commented Oct 5, 2018

Copy link
Copy Markdown
Member

Superseded by #9787.. Thanks for getting the ball rolling...

@jklymak jklymak closed this Oct 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants