8000 use identifiers from ft2font module in ftface props example · matplotlib/matplotlib@33e2dd4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 33e2dd4

Browse files
committed
use identifiers from ft2font module in ftface props example
Signed-off-by: Thomas Hisch <t.hisch@gmail.com>
1 parent c184a8e commit 33e2dd4

File tree

1 file changed

+18
-27
lines changed

1 file changed

+18
-27
lines changed

examples/misc/ftface_props.py

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +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 globals are used to access the style_flags and face_flags
20-
FT_STYLE_FLAGS = (
21-
('Italics', 0),
22-
('Bold', 1)
23-
)
24-
25-
FT_FACE_FLAGS = (
26-
('Scalable', 0),
27-
('Fixed sizes', 1),
28-
('Fixed width', 2),
29-
('SFNT', 3),
30-
('Horizontal', 4),
31-
('Vertical', 5),
32-
('Kerning', 6),
33-
('Fast glyphs', 7),
34-
('Mult. masters', 8),
35 10000 -
('Glyph names', 9),
36-
('External stream', 10)
37-
)
38-
18+
font = ft.FT2Font(fname)
3919

4020
print('Num faces :', font.num_faces) # number of faces in file
4121
print('Num glyphs :', font.num_glyphs) # number of glyphs in the face
@@ -65,10 +45,21 @@
6545
# vertical thickness of the underline
6646
print('Underline thickness :', font.underline_thickness)
6747

68-
for desc, val in FT_STYLE_FLAGS:
69-
print('%-16s:' % desc, bool(font.style_flags & (1 << val)))
70-
for desc, val in FT_FACE_FLAGS:
71-
print('%-16s:' % desc, bool(font.style_flags & (1 << val)))
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)))
7263

7364
print(dir(font))
7465

0 commit comments

Comments
 (0)
0