ftface_props.py
来自「非原创。很好的python例子」· Python 代码 · 共 77 行
PY
77 行
#!/usr/bin/env python"""This is a demo script to show you how to use all the properties of anFT2Font object. These describe global font properties. Forindividual character metrices, use the Glyp object, as returned byload_char"""import matplotlibfrom matplotlib.ft2font import FT2Font#fname = '/usr/local/share/matplotlib/VeraIt.ttf'fname = matplotlib.get_data_path() + '/VeraIt.ttf'#fname = '/usr/local/share/matplotlib/cmr10.ttf'font = FT2Font(fname)# these constants are used to access the style_flags and face_flagsFT_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 print 'Num faces :', font.num_faces # number of faces in fileprint 'Num glyphs :', font.num_glyphs # number of glyphs in the faceprint 'Family name :', font.family_name # face family nameprint 'Syle name :', font.style_name # face syle nameprint 'PS name :', font.postscript_name # the postscript nameprint 'Num fixed :', font.num_fixed_sizes # number of embedded bitmap in face# the following are only available if face.scalableif font.scalable: # the face global bounding box (xmin, ymin, xmax, ymax) print 'Bbox :', font.bbox # number of font units covered by the EM print 'EM :', font.units_per_EM # the ascender in 26.6 units print 'Ascender :', font.ascender # the descender in 26.6 units print 'Descender :', font.descender # the height in 26.6 units print 'Height :', font.height # maximum horizontal cursor advance print 'Max adv width :', font.max_advance_width # same for vertical layout print 'Max adv height :', font.max_advance_height # vertical position of the underline bar print 'Underline pos :', font.underline_position # vertical thickness of the underline print 'Underline thickness :', font.underline_thickness print 'Italics :', font.style_flags & FT_STYLE_FLAG_ITALIC != 0print 'Bold :', font.style_flags & FT_STYLE_FLAG_BOLD != 0print 'Scalable :', font.style_flags & FT_FACE_FLAG_SCALABLE != 0print 'Fixed sizes :', font.style_flags & FT_FACE_FLAG_FIXED_SIZES != 0 print 'Fixed width :', font.style_flags & FT_FACE_FLAG_FIXED_WIDTH != 0print 'SFNT :', font.style_flags & FT_FACE_FLAG_SFNT != 0print 'Horizontal :', font.style_flags & FT_FACE_FLAG_HORIZONTAL != 0print 'Vertical :', font.style_flags & FT_FACE_FLAG_VERTICAL != 0print 'Kerning :', font.style_flags & FT_FACE_FLAG_KERNING != 0print 'Fast glyphs :', font.style_flags & FT_FACE_FLAG_FAST_GLYPHS != 0print 'Mult. masters :', font.style_flags & FT_FACE_FLAG_MULTIPLE_MASTERS != 0print 'Glyph names :', font.style_flags & FT_FACE_FLAG_GLYPH_NAMES != 0print dir(font)cmap = font.get_charmap()print font.get_kerning
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?