Skip to content

Commit 36030da

Browse files
committed
refactor ftface_props example
Signed-off-by: Thomas Hisch <t.hisch@gmail.com>
1 parent d596f94 commit 36030da

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

examples/misc/ftface_props.py

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,26 @@
1616

1717
font = FT2Font(fname)
1818

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
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+
('Glyph names', 9),
36+
('External stream', 10)
37+
)
38+
3339

3440
print('Num faces :', font.num_faces) # number of faces in file
3541
print('Num glyphs :', font.num_glyphs) # number of glyphs in the face
@@ -60,18 +66,10 @@
6066
# vertical thickness of the underline
6167
print('Underline thickness :', font.underline_thickness)
6268

63-
print('Italics :', font.style_flags & FT_STYLE_FLAG_ITALIC != 0)
64-
print('Bold :', font.style_flags & FT_STYLE_FLAG_BOLD != 0)
65-
print('Scalable :', font.style_flags & FT_FACE_FLAG_SCALABLE != 0)
66-
print('Fixed sizes :', font.style_flags & FT_FACE_FLAG_FIXED_SIZES != 0)
67-
print('Fixed width :', font.style_flags & FT_FACE_FLAG_FIXED_WIDTH != 0)
68-
print('SFNT :', font.style_flags & FT_FACE_FLAG_SFNT != 0)
69-
print('Horizontal :', font.style_flags & FT_FACE_FLAG_HORIZONTAL != 0)
70-
print('Vertical :', font.style_flags & FT_FACE_FLAG_VERTICAL != 0)
71-
print('Kerning :', font.style_flags & FT_FACE_FLAG_KERNING != 0)
72-
print('Fast glyphs :', font.style_flags & FT_FACE_FLAG_FAST_GLYPHS != 0)
73-
print('Mult. masters :', font.style_flags & FT_FACE_FLAG_MULTIPLE_MASTERS != 0)
74-
print('Glyph names :', font.style_flags & FT_FACE_FLAG_GLYPH_NAMES != 0)
69+
for desc, val in FT_STYLE_FLAGS:
70+
print('%-16s:' % desc, bool(font.style_flags & (1 << val)))
71+
for desc, val in FT_FACE_FLAGS:
72+
print('%-16s:' % desc, bool(font.style_flags & (1 << val)))
7573

7674
print(dir(font))
7775

0 commit comments

Comments
 (0)