Repository navigation
Closed
Labels
Difficulty: Hardhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issueshttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuestopic: text
Milestone
Description
We're trying to fix the font in our MPL scripts to avoid PNG and PDF images changing depending on who produced it (Linux / Mac machines, different MPL versions).
So our idea was to find one font that everyone has and set that font.
How can I find out if I have 'Bitstream Vera Sans' (or some other font) available in my MPL install?
I tried this and got a RunTimeError.
Is this a bug or am I doing it wrong?
In [1]: %paste
import matplotlib.font_manager
flist = matplotlib.font_manager.get_fontconfig_fonts()
names = [matplotlib.font_manager.FontProperties(fname=fname).get_name() for fname in flist]
print('Bitstream Vera Sans' in names)
## -- End pasted text --
/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-1-d6f6752cbc94> in <module>()
1 import matplotlib.font_manager
2 flist = matplotlib.font_manager.get_fontconfig_fonts()
----> 3 names = [matplotlib.font_manager.FontProperties(fname=fname).get_name() for fname in flist]
4 print('Bitstream Vera Sans' in names)
<ipython-input-1-d6f6752cbc94> in <listcomp>(.0)
1 import matplotlib.font_manager
2 flist = matplotlib.font_manager.get_fontconfig_fonts()
----> 3 names = [matplotlib.font_manager.FontProperties(fname=fname).get_name() for fname in flist]
4 print('Bitstream Vera Sans' in names)
/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/font_manager.py in get_name(self)
735 properties.
736 """
--> 737 return ft2font.FT2Font(findfont(self)).family_name
738
739 def get_style(self):
RuntimeError: In FT2Font: Could not set the fontsize
Python 3.5 and MPL 1.5.3 from Macports on macOS.
Reacted by Dmitriy Shashkin
Metadata
Metadata
Assignees
Labels
Difficulty: Hardhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issueshttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuestopic: text
Type
Projects
- StatusShow more project fieldsDone
Activity
tacaswell commentedon Oct 19, 2016
mpl ships with a copy of Vera (https://github.com/matplotlib/matplotlib/tree/v1.5.3-doc/lib/matplotlib/mpl-data/fonts/ttf ) for
<v2.0and with a copy of dejavu for mpl=>2.0which is a strict super-set of vera. If mpl has been properly installed (some of the linux packagers package the fonts separately) you should be able to count on one of those two fonts being there (and being equivalent).Unfortunately, the changes to the text likely fall back to the version of freetype installed on the system. For the tests we pin to a specific version of freetype (https://github.com/matplotlib/matplotlib/blob/master/setupext.py#L67 2.6.1) when building the tests. With this pinned, we get (and test) pixel identical results on mac, linux and windows (mostly).
You are looping over all of the fonts found on a your system which makes me think you have a specific font that we are parsing badly. Can you sort out exactly which font is causing trouble?
cdeil commentedon Oct 22, 2016
@tacaswell - Thanks for the explanation!
This is the font that throws the error when calling
get_name():tacaswell commentedon Oct 27, 2016
Using a copy of the font from https://github.com/justrajdeep/fonts I can reproduce this.
Surprised we do not see this more as it seems to be a stock font on mac https://support.apple.com/en-us/HT201344
tacaswell commentedon Oct 27, 2016
It looks like it is a font with a non-standard format,
displayfrom imagemagik also does not like it:This seems to be a long-standing issue as https://sourceforge.net/p/matplotlib/mailman/message/9332845/
Not clear to me if this file is mal-formed or we (and imagemagik and corelDraw) do not implement the full ttf spec.
@cdeil The best thing here would be for you to handle the exceptions at the application error as mpl should not snarf exceptions from mal-formed (ie we can not read them) fonts.
cdeil commentedon Oct 27, 2016
@tacaswell - For me, it's OK to just close this issue. Unless it's useful to keep for MPL as a reminder of the issue.
I just thought I'd report it in case it's an MPL issue, and because I had a related question (which you answered).
tacaswell commentedon Oct 27, 2016
If you are happy going to close this issue.
[-]RuntimeError In FT2Font[/-][+]RuntimeError In FT2Font with NISC18030.ttf[/+]QuLogic commentedon Oct 29, 2025
This is a bitmap font, and you can't set an arbitrary size on it. So this error is fixed by #30319:
Note though that you can't actually do anything with the font, yet.