| """ |
| =============== |
| Font properties |
| =============== |
| |
| This example lists the attributes of an `.FT2Font` object, which describe |
| global font properties. For individual character metrics, use the `.Glyph` |
| object, as returned by `.load_char`. |
| """ |
|
|
| import os |
|
|
| import matplotlib |
| import matplotlib.ft2font as ft |
|
|
| font = ft.FT2Font( |
| |
| os.path.join(matplotlib.get_data_path(), |
| 'fonts/ttf/DejaVuSans-Oblique.ttf')) |
|
|
| print('Num faces: ', font.num_faces) |
| print('Num glyphs: ', font.num_glyphs) |
| print('Family name:', font.family_name) |
| print('Style name: ', font.style_name) |
| print('PS name: ', font.postscript_name) |
| print('Num fixed: ', font.num_fixed_sizes) |
|
|
| |
| if font.scalable: |
| |
| print('Bbox: ', font.bbox) |
| |
| print('EM: ', font.units_per_EM) |
| |
| print('Ascender: ', font.ascender) |
| |
| print('Descender: ', font.descender) |
| |
| print('Height: ', font.height) |
| |
| print('Max adv width: ', font.max_advance_width) |
| |
| print('Max adv height: ', font.max_advance_height) |
| |
| print('Underline pos: ', font.underline_position) |
| |
| print('Underline thickness:', font.underline_thickness) |
|
|
| 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(f"{style+':':17}", bool(font.style_flags & (1 << bitpos))) |
|
|