Thanks to visit codestin.com
Credit goes to github.com

Skip to content

RuntimeError In FT2Font with NISC18030.ttf #7305

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

Closed
cdeil opened this issue Oct 19, 2016 · 6 comments
Closed

RuntimeError In FT2Font with NISC18030.ttf #7305

cdeil opened this issue Oct 19, 2016 · 6 comments
Labels
Difficulty: Hard https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues topic: text

Comments

@cdeil
Copy link
Contributor

cdeil commented Oct 19, 2016

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.

@tacaswell
Copy link
Member

tacaswell commented 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.0 and with a copy of dejavu for mpl =>2.0 which 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?

@tacaswell tacaswell added this to the 2.0.1 (next bug fix release) milestone Oct 19, 2016
@cdeil
Copy link
Contributor Author

cdeil commented Oct 22, 2016

@tacaswell - Thanks for the explanation!

This is the font that throws the error when calling get_name():

>>> matplotlib.font_manager.FontProperties(fname='/Library/Fonts/NISC18030.ttf').get_name()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/font_manager.py", line 737, in get_name
    return ft2font.FT2Font(findfont(self)).family_name
RuntimeError: In FT2Font: Could not set the fontsize

@tacaswell
Copy link
Member

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 tacaswell added topic: text Difficulty: Hard https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues labels Oct 27, 2016
@tacaswell tacaswell modified the milestones: unassigned, 2.0.1 (next bug fix release) Oct 27, 2016
@tacaswell
Copy link
Member

It looks like it is a font with a non-standard format, display from imagemagik also does not like it:

13:51 $ display ~/Downloads/NISC18030.ttf 
display: unable to read font `/home/tcaswell/Downloads/NISC18030.ttf' @ error/annotate.c/RenderFreetype/1389.
display: non-conforming drawing primitive definition `text' @ error/draw.c/DrawImage/3258.

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
Copy link
Contributor Author

cdeil commented 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
Copy link
Member

If you are happy going to close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Hard https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues topic: text
Projects
None yet
Development

No branches or pull requests

2 participants