Ftface属性

这是一个演示脚本,向您展示如何使用FT2Font对象的所有属性。这些描述了全局字体属性。对于单个字符度量标准,请使用load_char返回的Glyph对象

输出:

  1. Num faces : 1
  2. Num glyphs : 5343
  3. Family name : DejaVu Sans
  4. Style name : Oblique
  5. PS name : DejaVuSans-Oblique
  6. Num fixed : 0
  7. Bbox : (-2080, -717, 3398, 2187)
  8. EM : 2048
  9. Ascender : 1901
  10. Descender : -483
  11. Height : 2384
  12. Max adv width : 3461
  13. Max adv height : 2384
  14. Underline pos : -175
  15. Underline thickness : 90
  16. Italic : True
  17. Bold : False
  18. Scalable : True
  19. Fixed sizes : False
  20. Fixed width : False
  21. SFNT : False
  22. Horizontal : False
  23. Vertical : False
  24. Kerning : False
  25. Fast glyphs : False
  26. Multiple masters : False
  27. Glyph names : False
  28. External stream : False
  29. ['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'ascender', 'bbox', 'clear', 'descender', 'draw_glyph_to_bitmap', 'draw_glyphs_to_bitmap', 'face_flags', 'family_name', 'fname', 'get_bitmap_offset', 'get_char_index', 'get_charmap', 'get_descent', 'get_glyph_name', 'get_image', 'get_kerning', 'get_name_index', 'get_num_glyphs', 'get_path', 'get_ps_font_info', 'get_sfnt', 'get_sfnt_table', 'get_width_height', 'get_xys', 'height', 'load_char', 'load_glyph', 'max_advance_height', 'max_advance_width', 'num_charmaps', 'num_faces', 'num_fixed_sizes', 'num_glyphs', 'postscript_name', 'scalable', 'select_charmap', 'set_charmap', 'set_size', 'set_text', 'style_flags', 'style_name', 'underline_position', 'underline_thickness', 'units_per_EM']
  30. <built-in method get_kerning of matplotlib.ft2font.FT2Font object at 0x7f6451677ed0>
  1. import matplotlib
  2. import matplotlib.ft2font as ft
  3. #fname = '/usr/local/share/matplotlib/VeraIt.ttf'
  4. fname = matplotlib.get_data_path() + '/fonts/ttf/DejaVuSans-Oblique.ttf'
  5. #fname = '/usr/local/share/matplotlib/cmr10.ttf'
  6. font = ft.FT2Font(fname)
  7. print('Num faces :', font.num_faces) # number of faces in file
  8. print('Num glyphs :', font.num_glyphs) # number of glyphs in the face
  9. print('Family name :', font.family_name) # face family name
  10. print('Style name :', font.style_name) # face style name
  11. print('PS name :', font.postscript_name) # the postscript name
  12. print('Num fixed :', font.num_fixed_sizes) # number of embedded bitmap in face
  13. # the following are only available if face.scalable
  14. if font.scalable:
  15. # the face global bounding box (xmin, ymin, xmax, ymax)
  16. print('Bbox :', font.bbox)
  17. # number of font units covered by the EM
  18. print('EM :', font.units_per_EM)
  19. # the ascender in 26.6 units
  20. print('Ascender :', font.ascender)
  21. # the descender in 26.6 units
  22. print('Descender :', font.descender)
  23. # the height in 26.6 units
  24. print('Height :', font.height)
  25. # maximum horizontal cursor advance
  26. print('Max adv width :', font.max_advance_width)
  27. # same for vertical layout
  28. print('Max adv height :', font.max_advance_height)
  29. # vertical position of the underline bar
  30. print('Underline pos :', font.underline_position)
  31. # vertical thickness of the underline
  32. print('Underline thickness :', font.underline_thickness)
  33. for style in ('Italic',
  34. 'Bold',
  35. 'Scalable',
  36. 'Fixed sizes',
  37. 'Fixed width',
  38. 'SFNT',
  39. 'Horizontal',
  40. 'Vertical',
  41. 'Kerning',
  42. 'Fast glyphs',
  43. 'Multiple masters',
  44. 'Glyph names',
  45. 'External stream'):
  46. bitpos = getattr(ft, style.replace(' ', '_').upper()) - 1
  47. print('%-17s:' % style, bool(font.style_flags & (1 << bitpos)))
  48. print(dir(font))
  49. print(font.get_kerning)

下载这个示例