8000 Merge pull request #3630 from thisch/ftprop · matplotlib/matplotlib@0a96efb · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a96efb

Browse files
committed
Merge pull request #3630 from thisch/ftprop
refactor ftface_props example
2 parents 4aa6b7e + 8d5be56 commit 0a96efb

File tree

< 10000 span role="tooltip" aria-label="Collapse file tree" id="expand-button-file-tree-button" class="Tooltip__TooltipBase-sc-17tf59c-0 hWlpPn tooltipped-se">

2 files changed

+19
-30
lines changed

2 files changed

+19
-30
lines changed

examples/misc/ftface_props.py

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,14 @@
88
load_char
99
"""
1010
import matplotlib
11-
from matplotlib.ft2font import FT2Font
11+
import matplotlib.ft2font as ft
12+
1213

1314
#fname = '/usr/local/share/matplotlib/VeraIt.ttf'
1415
fname = matplotlib.get_data_path() + '/fonts/ttf/VeraIt.ttf'
1516
#fname = '/usr/local/share/matplotlib/cmr10.ttf'
1617

17-
font = FT2Font(fname)
18-
19-
# these constants are used to access the style_flags and face_flags
20-
FT_FACE_FLAG_SCALABLE = 1 << 0
21-
FT_FACE_FLAG_FIXED_SIZES = 1 << 1
22-
FT_FACE_FLAG_FIXED_WIDTH = 1 << 2
23-
FT_FACE_FLAG_SFNT = 1 << 3
24-
FT_FACE_FLAG_HORIZONTAL = 1 << 4
25-
FT_FACE_FLAG_VERTICAL = 1 << 5
26-
FT_FACE_FLAG_KERNING = 1 << 6
27-
FT_FACE_FLAG_FAST_GLYPHS = 1 << 7
28-
FT_FACE_FLAG_MULTIPLE_MASTERS = 1 << 8
29-
FT_FACE_FLAG_GLYPH_NAMES = 1 << 9
30-
FT_FACE_FLAG_EXTERNAL_STREAM = 1 << 10
31-
FT_STYLE_FLAG_ITALIC = 1 << 0
32-
FT_STYLE_FLAG_BOLD = 1 << 1
18+
font = ft.FT2Font(fname)
3319

3420
print('Num faces :', font.num_faces) # number of faces in file
3521
print('Num glyphs :', font.num_glyphs) # number of glyphs in the face
@@ -59,18 +45,21 @@
5945
# vertical thickness of the underline
6046
print('Underline thickness :', font.underline_thickness)
6147

62-
print('Italics :', font.style_flags & FT_STYLE_FLAG_ITALIC != 0)
63-
print('Bold :', font.style_flags & FT_STYLE_FLAG_BOLD != 0)
64-
print('Scalable :', font.style_flags & FT_FACE_FLAG_SCALABLE != 0)
65-
print('Fixed sizes :', font.style_flags & FT_FACE_FLAG_FIXED_SIZES != 0)
66-
print('Fixed width :', font.style_flags & FT_FACE_FLAG_FIXED_WIDTH != 0)
67-
print('SFNT :', font.style_flags & FT_FACE_FLAG_SFNT != 0)
68-
print('Horizontal :', font.style_flags & FT_FACE_FLAG_HORIZONTAL != 0)
69-
print('Vertical :', font.style_flags & FT_FACE_FLAG_VERTICAL != 0)
70-
print('Kerning :', font.style_flags & FT_FACE_FLAG_KERNING != 0)
71-
print('Fast glyphs :', font.style_flags & FT_FACE_FLAG_FAST_GLYPHS != 0)
72-
print('Mult. masters :', font.style_flags & FT_FACE_FLAG_MULTIPLE_MASTERS != 0)
73-
print('Glyph names :', font.style_flags & FT_FACE_FLAG_GLYPH_NAMES != 0)
48+
for style in ('Italic',
49+
'Bold',
50+
'Scalable',
51+
'Fixed sizes',
52+
'Fixed width',
53+
'SFNT',
54+
'Horizontal',
55+
'Vertical',
56+
'Kerning',
57+
'Fast glyphs',
58+
'Multiple masters',
59+
'Glyph names',
60+
'External stream'):
61+
bitpos = getattr(ft, style.replace(' ', '_').upper()) - 1
62+
print('%-17s:' % style, bool(font.style_flags & (1 << bitpos)))
7463

7564
print(dir(font))
7665

src/ft2font_wrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,7 @@ PyMODINIT_FUNC initft2font(void)
16711671
add_dict_int(d, "FIXED_WIDTH", FT_FACE_FLAG_FIXED_WIDTH) ||
16721672
add_dict_int(d, "SFNT", FT_FACE_FLAG_SFNT) ||
16731673
add_dict_int(d, "HORIZONTAL", FT_FACE_FLAG_HORIZONTAL) ||
1674-
add_dict_int(d, "VERTICAL", FT_FACE_FLAG_SCALABLE) ||
1674+
add_dict_int(d, "VERTICAL", FT_FACE_FLAG_VERTICAL) ||
16751675
add_dict_int(d, "KERNING", FT_FACE_FLAG_KERNING) ||
16761676
add_dict_int(d, "FAST_GLYPHS", FT_FACE_FLAG_FAST_GLYPHS) ||
16771677
add_dict_int(d, "MULTIPLE_MASTERS", FT_FACE_FLAG_MULTIPLE_MASTERS) ||

0 commit comments

Comments
 (0)
0