|
1 | 1 | """ |
2 | | -============ |
3 | | -Ftface Props |
4 | | -============ |
5 | | -
|
6 | | -This is a demo script to show you how to use all the properties of an |
7 | | -FT2Font object. These describe global font properties. For |
8 | | -individual character metrics, use the Glyph object, as returned by |
9 | | -load_char |
| 2 | +=============== |
| 3 | +Face properties |
| 4 | +=============== |
| 5 | +
|
| 6 | +This is a demo script to show you how to use all the properties of a Face |
| 7 | +object. These describe global font properties. For individual character |
| 8 | +metrics, use the Glyph object, as loaded from the glyph attribute after calling |
| 9 | +load_char. |
10 | 10 | """ |
11 | 11 | import matplotlib |
12 | | -import matplotlib.ft2font as ft |
13 | | - |
14 | | - |
15 | | -#fname = '/usr/local/share/matplotlib/VeraIt.ttf' |
16 | | -fname = matplotlib.get_data_path() + '/fonts/ttf/DejaVuSans-Oblique.ttf' |
17 | | -#fname = '/usr/local/share/matplotlib/cmr10.ttf' |
18 | | - |
19 | | -font = ft.FT2Font(fname) |
20 | | - |
21 | | -print('Num faces :', font.num_faces) # number of faces in file |
22 | | -print('Num glyphs :', font.num_glyphs) # number of glyphs in the face |
23 | | -print('Family name :', font.family_name) # face family name |
24 | | -print('Style name :', font.style_name) # face style name |
25 | | -print('PS name :', font.postscript_name) # the postscript name |
26 | | -print('Num fixed :', font.num_fixed_sizes) # number of embedded bitmap in face |
27 | | - |
28 | | -# the following are only available if face.scalable |
29 | | -if font.scalable: |
30 | | - # the face global bounding box (xmin, ymin, xmax, ymax) |
31 | | - print('Bbox :', font.bbox) |
32 | | - # number of font units covered by the EM |
33 | | - print('EM :', font.units_per_EM) |
34 | | - # the ascender in 26.6 units |
35 | | - print('Ascender :', font.ascender) |
36 | | - # the descender in 26.6 units |
37 | | - print('Descender :', font.descender) |
38 | | - # the height in 26.6 units |
39 | | - print('Height :', font.height) |
40 | | - # maximum horizontal cursor advance |
41 | | - print('Max adv width :', font.max_advance_width) |
42 | | - # same for vertical layout |
43 | | - print('Max adv height :', font.max_advance_height) |
44 | | - # vertical position of the underline bar |
45 | | - print('Underline pos :', font.underline_position) |
46 | | - # vertical thickness of the underline |
47 | | - print('Underline thickness :', font.underline_thickness) |
48 | | - |
49 | | -for style in ('Italic', |
50 | | - 'Bold', |
51 | | - 'Scalable', |
52 | | - 'Fixed sizes', |
53 | | - 'Fixed width', |
54 | | - 'SFNT', |
55 | | - 'Horizontal', |
56 | | - 'Vertical', |
57 | | - 'Kerning', |
58 | | - 'Fast glyphs', |
59 | | - 'Multiple masters', |
60 | | - 'Glyph names', |
61 | | - 'External stream'): |
62 | | - bitpos = getattr(ft, style.replace(' ', '_').upper()) - 1 |
63 | | - print('%-17s:' % style, bool(font.style_flags & (1 << bitpos))) |
64 | | - |
65 | | -print(dir(font)) |
66 | | - |
67 | | -print(font.get_kerning) |
| 12 | +from matplotlib import font_manager, _ft2 |
| 13 | + |
| 14 | + |
| 15 | +fname = matplotlib.get_data_path() + "/fonts/ttf/DejaVuSans-Oblique.ttf" |
| 16 | +font = font_manager.get_font(fname) |
| 17 | + |
| 18 | +print("Faces in file :", font.num_faces) |
| 19 | +print("Glyphs in face :", font.num_glyphs) |
| 20 | +print("Family name :", font.family_name) |
| 21 | +print("Style name :", font.style_name) |
| 22 | +print("Postscript name :", font.get_postscript_name()) |
| 23 | +print("Embedded bitmap strikes:", font.num_fixed_sizes) |
| 24 | + |
| 25 | +if font.face_flags & _ft2.FACE_FLAG_SCALABLE: |
| 26 | + print('Global bbox (xmin, ymin, xmax, ymax):', font.bbox) |
| 27 | + print('Font units per EM :', font.units_per_EM) |
| 28 | + print('Ascender (pixels) :', font.ascender) |
| 29 | + print('Descender (pixels) :', font.descender) |
| 30 | + print('Height (pixels) :', font.height) |
| 31 | + print('Max horizontal advance :', font.max_advance_width) |
| 32 | + print('Max vertical advance :', font.max_advance_height) |
| 33 | + print('Underline position :', font.underline_position) |
| 34 | + print('Underline thickness :', font.underline_thickness) |
| 35 | + |
| 36 | +for style in ['Style flag italic', |
| 37 | + 'Style flag bold']: |
| 38 | + flag = getattr(_ft2, style.replace(' ', '_').upper()) - 1 |
| 39 | + print('%-26s:' % style, bool(font.style_flags & flag)) |
| 40 | + |
| 41 | +for style in ['Face flag scalable', |
| 42 | + 'Face flag fixed sizes', |
| 43 | + 'Face flag fixed width', |
| 44 | + 'Face flag SFNT', |
| 45 | + 'Face flag horizontal', |
| 46 | + 'Face flag vertical', |
| 47 | + 'Face flag kerning', |
| 48 | + 'Face flag fast glyphs', |
| 49 | + 'Face flag multiple masters', |
| 50 | + 'Face flag glyph names', |
| 51 | + 'Face flag external stream']: |
| 52 | + flag = getattr(_ft2, style.replace(' ', '_').upper()) |
| 53 | + print('%-26s:' % style, bool(font.face_flags & flag)) |
0 commit comments