diff --git a/galleries/examples/misc/ftface_props.py b/galleries/examples/misc/ftface_props.py index 8306e142c144..ec26dff5bf6a 100644 --- a/galleries/examples/misc/ftface_props.py +++ b/galleries/examples/misc/ftface_props.py @@ -18,12 +18,13 @@ os.path.join(matplotlib.get_data_path(), 'fonts/ttf/DejaVuSans-Oblique.ttf')) -print('Num faces: ', font.num_faces) # number of faces in file -print('Num glyphs: ', font.num_glyphs) # number of glyphs in the face -print('Family name:', font.family_name) # face family name -print('Style name: ', font.style_name) # face style name -print('PS name: ', font.postscript_name) # the postscript name -print('Num fixed: ', font.num_fixed_sizes) # number of embedded bitmaps +print('Num instances: ', font.num_named_instances) # number of named instances in file +print('Num faces: ', font.num_faces) # number of faces in file +print('Num glyphs: ', font.num_glyphs) # number of glyphs in the face +print('Family name: ', font.family_name) # face family name +print('Style name: ', font.style_name) # face style name +print('PS name: ', font.postscript_name) # the postscript name +print('Num fixed: ', font.num_fixed_sizes) # number of embedded bitmaps # the following are only available if face.scalable if font.scalable: diff --git a/lib/matplotlib/ft2font.pyi b/lib/matplotlib/ft2font.pyi index 811f82f95963..37281afeaafa 100644 --- a/lib/matplotlib/ft2font.pyi +++ b/lib/matplotlib/ft2font.pyi @@ -265,6 +265,8 @@ class FT2Font(Buffer): @property def num_glyphs(self) -> int: ... @property + def num_named_instances(self) -> int: ... + @property def postscript_name(self) -> str: ... @property def scalable(self) -> bool: ... diff --git a/lib/matplotlib/tests/test_ft2font.py b/lib/matplotlib/tests/test_ft2font.py index 7dc851b2c9cf..6ba23bab347e 100644 --- a/lib/matplotlib/tests/test_ft2font.py +++ b/lib/matplotlib/tests/test_ft2font.py @@ -40,6 +40,7 @@ def test_ft2font_dejavu_attrs(): assert font.family_name == 'DejaVu Sans' assert font.style_name == 'Book' assert font.num_faces == 1 # Single TTF. + assert font.num_named_instances == 0 # Not a variable font. assert font.num_glyphs == 6241 # From compact encoding view in FontForge. assert font.num_fixed_sizes == 0 # All glyphs are scalable. assert font.num_charmaps == 5 @@ -73,6 +74,7 @@ def test_ft2font_cm_attrs(): assert font.family_name == 'cmtt10' assert font.style_name == 'Regular' assert font.num_faces == 1 # Single TTF. + assert font.num_named_instances == 0 # Not a variable font. assert font.num_glyphs == 133 # From compact encoding view in FontForge. assert font.num_fixed_sizes == 0 # All glyphs are scalable. assert font.num_charmaps == 2 @@ -105,6 +107,7 @@ def test_ft2font_stix_bold_attrs(): assert font.family_name == 'STIXSizeTwoSym' assert font.style_name == 'Bold' assert font.num_faces == 1 # Single TTF. + assert font.num_named_instances == 0 # Not a variable font. assert font.num_glyphs == 20 # From compact encoding view in FontForge. assert font.num_fixed_sizes == 0 # All glyphs are scalable. assert font.num_charmaps == 3 diff --git a/src/ft2font_wrapper.cpp b/src/ft2font_wrapper.cpp index 7e1b3948a00e..9b54721810d6 100644 --- a/src/ft2font_wrapper.cpp +++ b/src/ft2font_wrapper.cpp @@ -1475,7 +1475,13 @@ PyFT2Font_face_flags(PyFT2Font *self) static StyleFlags PyFT2Font_style_flags(PyFT2Font *self) { - return static_cast(self->x->get_face()->style_flags); + return static_cast(self->x->get_face()->style_flags & 0xffff); +} + +static FT_Long +PyFT2Font_num_named_instances(PyFT2Font *self) +{ + return (self->x->get_face()->style_flags & 0x7fff0000) >> 16; } static FT_Long @@ -1766,6 +1772,8 @@ PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used()) "Face flags; see `.FaceFlags`.") .def_property_readonly("style_flags", &PyFT2Font_style_flags, "Style flags; see `.StyleFlags`.") + .def_property_readonly("num_named_instances", &PyFT2Font_num_named_instances, + "Number of named instances in the face.") .def_property_readonly("num_glyphs", &PyFT2Font_num_glyphs, "Number of glyphs in the face.") .def_property_readonly("num_fixed_sizes", &PyFT2Font_num_fixed_sizes,