Skip to content

RuntimeError In FT2Font with NISC18030.ttf #7305

Closed

Description

@cdeil

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.

Activity

  1. tacaswell commented on Oct 19, 2016

    @tacaswell
    Member

    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?

  2. added this to the milestone on Oct 19, 2016
  3. cdeil commented on Oct 22, 2016

    @cdeil
    ContributorAuthor

    @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
    
  4. tacaswell commented on Oct 27, 2016

    @tacaswell
    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

  5. modified the milestones: , on Oct 27, 2016
  6. tacaswell commented on Oct 27, 2016

    @tacaswell
    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.

  7. cdeil commented on Oct 27, 2016

    @cdeil
    ContributorAuthor

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

  8. tacaswell commented on Oct 27, 2016

    @tacaswell
    Member

    If you are happy going to close this issue.

  9. changed the title [-]RuntimeError In FT2Font[/-] [+]RuntimeError In FT2Font with NISC18030.ttf[/+] on Oct 27, 2016
  10. QuLogic commented on Oct 29, 2025

    @QuLogic
    Member

    This is a bitmap font, and you can't set an arbitrary size on it. So this error is fixed by #30319:

    >>> import matplotlib.font_manager
    >>> matplotlib.font_manager.FontProperties(fname='/home/elliott/Downloads/NISC18030.ttf').get_name()
    'GB18030 Bitmap'

    Note though that you can't actually do anything with the font, yet.

  11. added this to the v3.11.0 milestone on Oct 29, 2025
  12. moved this from Waiting for other PR to Done in Font and text overhaulon Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Hardhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuestopic: text

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions