10000 Merge pull request #29431 from QuLogic/ft2font-instances · matplotlib/matplotlib@a61e118 · GitHub
[go: up one dir, main page]

Skip to content

Commit a61e118

Browse files
authored
Merge pull request #29431 from QuLogic/ft2font-instances
ft2font: Split named instance count from style flags
2 parents 419b661 + 4d87371 commit a61e118

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

galleries/examples/misc/ftface_props.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
os.path.join(matplotlib.get_data_path(),
1919
'fonts/ttf/DejaVuSans-Oblique.ttf'))
2020

21-
print('Num faces: ', font.num_faces) # number of faces in file
22-
print('Num glyphs: ', font.num_glyphs) # number of glyphs in the face
23-
print('Family name:', font.family_name) # face family name
24-
print('Style name: ', font.style_name) # face style name
25-
print('PS name: ', font.postscript_name) # the postscript name
26-
print('Num fixed: ', font.num_fixed_sizes) # number of embedded bitmaps
21+
print('Num instances: ', font.num_named_instances) # number of named instances in file
22+
print('Num faces: ', font.num_faces) # number of faces in file
23+
print('Num glyphs: ', font.num_glyphs) # number of glyphs in the face
24+
print('Family name: ', font.family_name) # face family name
25+
print('Style name: ', font.style_name) # face style name
26+
print('PS name: ', font.postscript_name) # the postscript name
27+
print('Num fixed: ', font.num_fixed_sizes) # number of embedded bitmaps
2728

2829
# the following are only available if face.scalable
2930
if font.scalable:

lib/matplotlib/ft2font.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ class FT2Font(Buffer):
265265
@property
266266
def num_glyphs(self) -> int: ...
267267
@property
268+
def num_named_instances(self) -> int: ...
269+
@property
268270
def postscript_name(self) -> str: ...
269271
@property
270272
def scalable(self) -> bool: ...

lib/matplotlib/tests/test_ft2font.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def test_ft2font_dejavu_attrs():
4040
assert font.family_name == 'DejaVu Sans'
4141
assert font.style_name == 'Book'
4242
assert font.num_faces == 1 # Single TTF.
43+
assert font.num_named_instances == 0 # Not a variable font.
4344
assert font.num_glyphs == 6241 # From compact encoding view in FontForge.
4445
assert font.num_fixed_sizes == 0 # All glyphs are scalable.
4546
assert font.num_charmaps == 5
@@ -73,6 +74,7 @@ def test_ft2font_cm_attrs():
7374
assert font.family_name == 'cmtt10'
7475
assert font.style_name == 'Regular'
7576
assert font.num_faces == 1 # Single TTF.
77+
assert font.num_named_instances == 0 # Not a variable font.
7678
assert font.num_glyphs == 133 # From compact encoding view in FontForge.
7779
assert font.num_fixed_sizes == 0 # All glyphs are scalable.
7880
assert font.num_charmaps == 2
@@ -105,6 +107,7 @@ def test_ft2font_stix_bold_attrs():
105107
assert font.family_name == 'STIXSizeTwoSym'
106108
assert font.style_name == 'Bold'
107109
assert font.num_faces == 1 # Single TTF.
110+
assert font.num_named_instances == 0 # Not a variable font.
108111
assert font.num_glyphs == 20 # From compact encoding view in FontForge.
109112
assert font.num_fixed_sizes == 0 # All glyphs are scalable.
110113
assert font.num_charmaps == 3

src/ft2font_wrapper.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,13 @@ PyFT2Font_face_flags(PyFT2Font *self)
14751475
static StyleFlags
14761476
PyFT2Font_style_flags(PyFT2Font *self)
14771477
{
1478-
return static_cast<StyleFlags>(self->x->get_face()->style_flags);
1478+
return static_cast<StyleFlags>(self->x->get_face()->style_flags & 0xffff);
1479+
}
1480+
1481+
static FT_Long
1482+
PyFT2Font_num_named_instances(PyFT2Font *self)
1483+
{
1484+
return (self->x->get_face()->style_flags & 0x7fff0000) >> 16;
14791485
}
14801486

14811487
static FT_Long
@@ -1766,6 +1772,8 @@ PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
17661772
"Face flags; see `.FaceFlags`.")
17671773
.def_property_readonly("style_flags", &PyFT2Font_style_flags,
17681774
"Style flags; see `.StyleFlags`.")
1775+
.def_property_readonly("num_named_instances", &PyFT2Font_num_named_instances,
1776+
"Number of named instances in the face.")
17691777
.def_property_readonly("num_glyphs", &PyFT2Font_num_glyphs,
17701778
"Number of glyphs in the face.")
17711779
.def_property_readonly("num_fixed_sizes", &PyFT2Font_num_fixed_sizes,

0 commit comments

Comments
 (0)
0