-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: Style flag errors trying to save figures as PDF with font Inter #29396
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
Comments
Note for repro: to trigger the bug it may be necessary to use the explicit path to the "bad" (actually, variable) font, i.e. something like from pylab import *; from pathlib import Path
figtext(.5, .5, "foo", font=Path("/path/to/InterVariable.ttf")) # or font="Inter Variable" also seems to "work" here
savefig("/tmp/test.pdf") but the bug is valid. It basically arises because of the conversion of FT_STYLE_FLAG_XXX to enum.Flag (regression in #28842), which means that any unknown value in style_flags raises the error seen above. Note that such values are explicitly allowed by the FreeType docs (https://freetype.org/freetype2/docs/reference/ft2-face_creation.html#ft_facerec): "[Since 2.6.1] Bits 16-30 hold the number of named instances available for the current face if we have a GX or OpenType variation (sub)font. Bit 31 is always zero (that is, style_flags is always a positive value). Note that a variation font has always at least one named instance, namely the default instance." There's a few fixes possible there:
Note that face_flags likely suffers from the same issue; at least, the commented out FaceFlag values in ft2font_wrapper.cpp's |
These can't be |
Good catch. The following appears to work, though: #ifdef FT_FACE_FLAG_VARIATION
#define FACE_FLAG_VARIATION {"VARIATION", FaceFlags::VARIATION},
#else
#define FACE_FLAG_VARIATION
#endif
P11X_DECLARE_ENUM(
"FaceFlags", "Flag",
{"SCALABLE", FaceFlags::SCALABLE},
{"FIXED_SIZES", FaceFlags::FIXED_SIZES},
{"FIXED_WIDTH", FaceFlags::FIXED_WIDTH},
{"SFNT", FaceFlags::SFNT},
{"HORIZONTAL", FaceFlags::HORIZONTAL},
{"VERTICAL", FaceFlags::VERTICAL},
{"KERNING", FaceFlags::KERNING},
{"FAST_GLYPHS", FaceFlags::FAST_GLYPHS},
{"MULTIPLE_MASTERS", FaceFlags::MULTIPLE_MASTERS},
{"GLYPH_NAMES", FaceFlags::GLYPH_NAMES},
{"EXTERNAL_STREAM", FaceFlags::EXTERNAL_STREAM},
{"HINTER", FaceFlags::HINTER},
{"CID_KEYED", FaceFlags::CID_KEYED},
{"TRICKY", FaceFlags::TRICKY},
{"COLOR", FaceFlags::COLOR},
FACE_FLAG_VARIATION // backcompat: ft 2.9.0.
// ditto for the others
); |
Uh oh!
There was an error while loading. Please reload this page.
Bug summary
I have installed the font Inter with
brew install font-inter
and successfully imported it into matplotlib such that the figure from the plot below displays correctly with the Inter font as specified; however, when it comes to saving, I get the error below in "actual outcome".Code for reproduction
Actual outcome
Expected outcome
The figure is saved as a PDF with the Inter font.
Additional information
This only occurs on my macOS installation of Python 3.13.1 with matplotlib 3.10.0.
Operating system
macOS Sequoia 15.2
Matplotlib Version
3.10.0
Matplotlib Backend
QtAgg, cairo, macosx
Python version
3.13.1
Jupyter version
No response
Installation
pip
The text was updated successfully, but these errors were encountered: