Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

ft2font: Split named instance count from style flags #29431

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

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions 13 galleries/examples/misc/ftface_props.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions 2 lib/matplotlib/ft2font.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down
3 changes: 3 additions & 0 deletions 3 lib/matplotlib/tests/test_ft2font.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion 10 src/ft2font_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,13 @@ PyFT2Font_face_flags(PyFT2Font *self)
static StyleFlags
PyFT2Font_style_flags(PyFT2Font *self)
{
return static_cast<StyleFlags>(self->x->get_face()->style_flags);
return static_cast<StyleFlags>(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
Expand Down Expand Up @@ -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,
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.