You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Version 2.0.0_1 breaks OpenType font character spacing on PDF save #8050
I know that Matplotlib does not officially support OpenType fonts, but I have successfully been using them for axis labels in version 1.5.3 and earlier. I just updated Matplotlib via Macports and the character spacing and alignment broke, especially with larger font sizes. For example, X axis titles that are centered begin at the same position, but have extra wide spacing. This is found with all OpenType fonts that I have tried.
Code for reproduction
This requires the free font Canter (not ideal for graphing, but it is available for testing), but can be reproduced with other fonts.
I have only included my setting of the fonts and saving the PDF, as this can be reproduced with any plot I've made.
Except the missing “-” glyph, nothing does really looks wrong with 1.5.1, and I get the same text rendering as with 2.0.0rc1. With a recent mpl version from master, the spacing between the glyphs is a bit smaller than with the former mpl versions
Oh I thought it would be difficult to get the Canter font, but actually it was not (freely available here). So the results are similar to the ones with ComicNeue, i.e. I cannot reproduce the bug :/. What I get is:
I have tried to delete the font cache and that was not successful. I have made a minimal example that continues to work in version 1.5.3 and fail in version 2.0.0. I was not using FontProperties, though.
NB: I am using FontProperties because Canter fonts are not installed on my OS (and they do not seem to be available in CentOS 7 repositories).
I tried @andermannlab 's example with FontProperties (else I fallback to DejaVu or Bitstream fonts…) and the results are the same as my previous trials. @andermannlab Could you test it using FontProperties please? Just to see if you still have the issue on your side.
Honestly I know almost nothing about how fonts are handled in matplotlib, so currently I would simply consider this as a workaround to your problem. Maybe one of the core devs will know more.
It is related to #7937, I've been solving this with a monkeypatch from the patch mentioned in that issue. I'm using otf fonts, and confirm that it works:
import matplotlib.font_manager as fm
from matplotlib.ft2font import FT2Font
def get_font(*args, **kwargs):
return FT2Font(*args, **kwargs)
fm.get_font = get_font
BUT, the whole darned font gets added to the pdf since subsetting is broken. I run the pdf through ghostscript afterwards, which properly subsets. I use an ipython shell command to do this for me:
Thanks @QuLogic and @jkseppan, this does appear to have solved the issue. Master branch works properly after the #7961 merge, no need for the workaround anymore.
I have a feeling it's a pretty deep rabbit hole, but I might start looking into the subsetting issue.
Activity
QuLogic commentedon Feb 8, 2017
Might be related to #7937?
afvincent commentedon Feb 9, 2017
FWIW, I tried to reproduce this bug (on CentOS 7) with ComicNeue_Light.otf (in the current directory) and the following script
What I get is:
with mpl 1.5.1:
mwe_1.5.1.pdf
with mpl 2.0.0rc1:
mwe_2.0.0rc1.pdf
with mpl from master (2.0.0.post3337+gc15694b):
mwe_2.0.0.post3337+gc15694b.pdf
Except the missing “-” glyph, nothing does really looks wrong with 1.5.1, and I get the same text rendering as with 2.0.0rc1. With a recent mpl version from master, the spacing between the glyphs is a bit smaller than with the former mpl versions
afvincent commentedon Feb 9, 2017
Oh I thought it would be difficult to get the Canter font, but actually it was not (freely available here). So the results are similar to the ones with ComicNeue, i.e. I cannot reproduce the bug :/. What I get is:
with mpl 1.5.1:
mwe_1.5.1.pdf
with mpl 2.0.0rc1:
mwe_2.0.0rc1.pdf
with mpl from master (2.0.0.post3337+gc15694b):
mwe_2.0.0.post3337+gc15694b.pdf
tacaswell commentedon Feb 9, 2017
Might need to delete the mpl font cache?
andermannlab commentedon Feb 9, 2017
I have tried to delete the font cache and that was not successful. I have made a minimal example that continues to work in version 1.5.3 and fail in version 2.0.0. I was not using FontProperties, though.
afvincent commentedon Feb 9, 2017
NB: I am using FontProperties because Canter fonts are not installed on my OS (and they do not seem to be available in CentOS 7 repositories).
I tried @andermannlab 's example with FontProperties (else I fallback to DejaVu or Bitstream fonts…) and the results are the same as my previous trials. @andermannlab Could you test it using FontProperties please? Just to see if you still have the issue on your side.
andermannlab commentedon Feb 9, 2017
I have just tried the FontProperties version and it works (with multiple OpenType fonts, including Canter). Thank you.
Is the long-term solution to transition legacy code to FontProperties?
afvincent commentedon Feb 9, 2017
Honestly I know almost nothing about how fonts are handled in matplotlib, so currently I would simply consider this as a workaround to your problem. Maybe one of the core devs will know more.
grahamrow commentedon Feb 10, 2017
It is related to #7937, I've been solving this with a monkeypatch from the patch mentioned in that issue. I'm using otf fonts, and confirm that it works:
BUT, the whole darned font gets added to the pdf since subsetting is broken. I run the pdf through ghostscript afterwards, which properly subsets. I use an ipython shell command to do this for me:
QuLogic commentedon Feb 10, 2017
Can you try with the fix in #7961 and not the workaround from #7937?
jkseppan commentedon Feb 11, 2017
Did subsetting ever work for otf fonts?
tacaswell commentedon Feb 11, 2017
That is a @mdboom question, but I think the answer is no.
QuLogic commentedon Feb 26, 2017
Ping @andermannlab and @grahamrow; please try with #7961 or I'm going to close this eventually.
grahamrow commentedon Feb 27, 2017
Thanks @QuLogic and @jkseppan, this does appear to have solved the issue. Master branch works properly after the #7961 merge, no need for the workaround anymore.
I have a feeling it's a pretty deep rabbit hole, but I might start looking into the subsetting issue.
jkseppan commentedon Feb 27, 2017
QuLogic commentedon Apr 15, 2017
I'm going to close this since at least one reporter has confirmed it's working.