File tree Expand file tree Collapse file tree 2 files changed +23
-30
lines changed
Filter options
Expand file tree Collapse file tree 2 files changed +23
-30
lines changed
Original file line number Diff line number Diff line change 1
1
"""
2
2
=============
3
- Font Indexing
3
+ Font indexing
4
4
=============
5
5
6
- A little example that shows how the various indexing into the font
7
- tables relate to one another. Mainly for mpl developers....
8
-
6
+ This example shows how the font tables relate to one another.
9
7
"""
8
+
9
+ import os
10
+
10
11
import matplotlib
11
- from matplotlib .ft2font import FT2Font , KERNING_DEFAULT , KERNING_UNFITTED , KERNING_UNSCALED
12
+ from matplotlib .ft2font import (
13
+ FT2Font , KERNING_DEFAULT , KERNING_UNFITTED , KERNING_UNSCALED )
12
14
13
15
14
- fname = matplotlib . get_data_path () + '/fonts/ttf/DejaVuSans.ttf'
15
- font = FT2Font ( fname )
16
+ font = FT2Font (
17
+ os . path . join ( matplotlib . get_data_path (), 'fonts/ttf/DejaVuSans.ttf' ) )
16
18
font .set_charmap (0 )
17
19
18
20
codes = font .get_charmap ().items ()
19
- #dsu = [(ccode, glyphind) for ccode, glyphind in codes]
20
- #dsu.sort()
21
- #for ccode, glyphind in dsu:
22
- # try: name = font.get_glyph_name(glyphind)
23
- # except RuntimeError: pass
24
- # else: print('% 4d % 4d %s %s' % (glyphind, ccode, hex(int(ccode)), name))
25
-
26
21
27
22
# make a charname to charcode and glyphind dictionary
28
23
coded = {}
31
26
name = font .get_glyph_name (glyphind )
32
27
coded [name ] = ccode
33
28
glyphd [name ] = glyphind
29
+ # print(glyphind, ccode, hex(int(ccode)), name)
34
30
35
31
code = coded ['A' ]
36
32
glyph = font .load_char (code )
Original file line number Diff line number Diff line change 1
1
"""
2
- ============
3
- Ftface Props
4
- ============
2
+ ===============
3
+ Font properties
4
+ ===============
5
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
6
+ This example lists the attributes of an `FT2Font` object, which describe global
7
+ font properties. For individual character metrics, use the `Glyph` object, as
8
+ returned by `load_char`.
10
9
"""
10
+
11
+ import os
12
+
11
13
import matplotlib
12
14
import matplotlib .ft2font as ft
13
15
14
16
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 )
17
+ font = ft .FT2Font (
18
+ # Use a font shipped with Matplotlib.
19
+ os .path .join (matplotlib .get_data_path (),
20
+ 'fonts/ttf/DejaVuSans-Oblique.ttf' ))
20
21
21
22
print ('Num faces :' , font .num_faces ) # number of faces in file
22
23
print ('Num glyphs :' , font .num_glyphs ) # number of glyphs in the face
61
62
'External stream' ):
62
63
bitpos = getattr (ft , style .replace (' ' , '_' ).upper ()) - 1
63
64
print ('%-17s:' % style , bool (font .style_flags & (1 << bitpos )))
64
-
65
- print (dir (font ))
66
-
67
- print (font .get_kerning )
You can’t perform that action at this time.
0 commit comments