From 3eb865307d696d193afa04d213cee8acade318fe Mon Sep 17 00:00:00 2001 From: Thomas Hisch Date: Tue, 9 Sep 2014 17:10:56 +0200 Subject: [PATCH 1/3] refactor ftface_props example Signed-off-by: Thomas Hisch --- examples/misc/ftface_props.py | 50 +++++++++++++++++------------------ 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/examples/misc/ftface_props.py b/examples/misc/ftface_props.py index e64f2ecba574..7a48d0a2216e 100755 --- a/examples/misc/ftface_props.py +++ b/examples/misc/ftface_props.py @@ -16,20 +16,26 @@ font = FT2Font(fname) -# these constants are used to access the style_flags and face_flags -FT_FACE_FLAG_SCALABLE = 1 << 0 -FT_FACE_FLAG_FIXED_SIZES = 1 << 1 -FT_FACE_FLAG_FIXED_WIDTH = 1 << 2 -FT_FACE_FLAG_SFNT = 1 << 3 -FT_FACE_FLAG_HORIZONTAL = 1 << 4 -FT_FACE_FLAG_VERTICAL = 1 << 5 -FT_FACE_FLAG_KERNING = 1 << 6 -FT_FACE_FLAG_FAST_GLYPHS = 1 << 7 -FT_FACE_FLAG_MULTIPLE_MASTERS = 1 << 8 -FT_FACE_FLAG_GLYPH_NAMES = 1 << 9 -FT_FACE_FLAG_EXTERNAL_STREAM = 1 << 10 -FT_STYLE_FLAG_ITALIC = 1 << 0 -FT_STYLE_FLAG_BOLD = 1 << 1 +# these globals are used to access the style_flags and face_flags +FT_STYLE_FLAGS = ( + ('Italics', 0), + ('Bold', 1) +) + +FT_FACE_FLAGS = ( + ('Scalable', 0), + ('Fixed sizes', 1), + ('Fixed width', 2), + ('SFNT', 3), + ('Horizontal', 4), + ('Vertical', 5), + ('Kerning', 6), + ('Fast glyphs', 7), + ('Mult. masters', 8), + ('Glyph names', 9), + ('External stream', 10) +) + print('Num faces :', font.num_faces) # number of faces in file print('Num glyphs :', font.num_glyphs) # number of glyphs in the face @@ -59,18 +65,10 @@ # vertical thickness of the underline print('Underline thickness :', font.underline_thickness) -print('Italics :', font.style_flags & FT_STYLE_FLAG_ITALIC != 0) -print('Bold :', font.style_flags & FT_STYLE_FLAG_BOLD != 0) -print('Scalable :', font.style_flags & FT_FACE_FLAG_SCALABLE != 0) -print('Fixed sizes :', font.style_flags & FT_FACE_FLAG_FIXED_SIZES != 0) -print('Fixed width :', font.style_flags & FT_FACE_FLAG_FIXED_WIDTH != 0) -print('SFNT :', font.style_flags & FT_FACE_FLAG_SFNT != 0) -print('Horizontal :', font.style_flags & FT_FACE_FLAG_HORIZONTAL != 0) -print('Vertical :', font.style_flags & FT_FACE_FLAG_VERTICAL != 0) -print('Kerning :', font.style_flags & FT_FACE_FLAG_KERNING != 0) -print('Fast glyphs :', font.style_flags & FT_FACE_FLAG_FAST_GLYPHS != 0) -print('Mult. masters :', font.style_flags & FT_FACE_FLAG_MULTIPLE_MASTERS != 0) -print('Glyph names :', font.style_flags & FT_FACE_FLAG_GLYPH_NAMES != 0) +for desc, val in FT_STYLE_FLAGS: + print('%-16s:' % desc, bool(font.style_flags & (1 << val))) +for desc, val in FT_FACE_FLAGS: + print('%-16s:' % desc, bool(font.style_flags & (1 << val))) print(dir(font)) From b802d15a5501ec6783a56a19b582477d123e2ba1 Mon Sep 17 00:00:00 2001 From: Thomas Hisch Date: Fri, 10 Oct 2014 21:00:14 +0200 Subject: [PATCH 2/3] fix wrong numerical value for ft2font.VERTICAL Signed-off-by: Thomas Hisch --- src/ft2font_wrapper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ft2font_wrapper.cpp b/src/ft2font_wrapper.cpp index f8d9e44e74a4..024e2c5d6141 100644 --- a/src/ft2font_wrapper.cpp +++ b/src/ft2font_wrapper.cpp @@ -1665,7 +1665,7 @@ PyMODINIT_FUNC initft2font(void) add_dict_int(d, "FIXED_WIDTH", FT_FACE_FLAG_FIXED_WIDTH) || add_dict_int(d, "SFNT", FT_FACE_FLAG_SFNT) || add_dict_int(d, "HORIZONTAL", FT_FACE_FLAG_HORIZONTAL) || - add_dict_int(d, "VERTICAL", FT_FACE_FLAG_SCALABLE) || + add_dict_int(d, "VERTICAL", FT_FACE_FLAG_VERTICAL) || add_dict_int(d, "KERNING", FT_FACE_FLAG_KERNING) || add_dict_int(d, "FAST_GLYPHS", FT_FACE_FLAG_FAST_GLYPHS) || add_dict_int(d, "MULTIPLE_MASTERS", FT_FACE_FLAG_MULTIPLE_MASTERS) || From 8d5be560e07a28d96924eb1e02ee1b449de1a4a9 Mon Sep 17 00:00:00 2001 From: Thomas Hisch Date: Fri, 10 Oct 2014 21:03:07 +0200 Subject: [PATCH 3/3] use identifiers from ft2font module in ftface props example Signed-off-by: Thomas Hisch --- examples/misc/ftface_props.py | 45 ++++++++++++++--------------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/examples/misc/ftface_props.py b/examples/misc/ftface_props.py index 7a48d0a2216e..f01310948577 100755 --- a/examples/misc/ftface_props.py +++ b/examples/misc/ftface_props.py @@ -8,34 +8,14 @@ load_char """ import matplotlib -from matplotlib.ft2font import FT2Font +import matplotlib.ft2font as ft + #fname = '/usr/local/share/matplotlib/VeraIt.ttf' fname = matplotlib.get_data_path() + '/fonts/ttf/VeraIt.ttf' #fname = '/usr/local/share/matplotlib/cmr10.ttf' -font = FT2Font(fname) - -# these globals are used to access the style_flags and face_flags -FT_STYLE_FLAGS = ( - ('Italics', 0), - ('Bold', 1) -) - -FT_FACE_FLAGS = ( - ('Scalable', 0), - ('Fixed sizes', 1), - ('Fixed width', 2), - ('SFNT', 3), - ('Horizontal', 4), - ('Vertical', 5), - ('Kerning', 6), - ('Fast glyphs', 7), - ('Mult. masters', 8), - ('Glyph names', 9), - ('External stream', 10) -) - +font = ft.FT2Font(fname) print('Num faces :', font.num_faces) # number of faces in file print('Num glyphs :', font.num_glyphs) # number of glyphs in the face @@ -65,10 +45,21 @@ # vertical thickness of the underline print('Underline thickness :', font.underline_thickness) -for desc, val in FT_STYLE_FLAGS: - print('%-16s:' % desc, bool(font.style_flags & (1 << val))) -for desc, val in FT_FACE_FLAGS: - print('%-16s:' % desc, bool(font.style_flags & (1 << val))) +for style in ('Italic', + 'Bold', + 'Scalable', + 'Fixed sizes', + 'Fixed width', + 'SFNT', + 'Horizontal', + 'Vertical', + 'Kerning', + 'Fast glyphs', + 'Multiple masters', + 'Glyph names', + 'External stream'): + bitpos = getattr(ft, style.replace(' ', '_').upper()) - 1 + print('%-17s:' % style, bool(font.style_flags & (1 << bitpos))) print(dir(font))