Thanks to visit codestin.com
Credit goes to github.com

Skip to content

refactor ftface_props example #3630

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 3 commits into from
Oct 20, 2014
Merged
Changes from 1 commit
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
Prev Previous commit
use identifiers from ft2font module in ftface props example
Signed-off-by: Thomas Hisch <[email protected]>
  • Loading branch information
twmr committed Oct 19, 2014
commit 8d5be560e07a28d96924eb1e02ee1b449de1a4a9
45 changes: 18 additions & 27 deletions examples/misc/ftface_props.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down