21
21
import matplotlib .pyplot as plt
22
22
23
23
24
- def print_glyphs (font ):
25
- """Print the all the glyphs in the given FT2Font font to stdout."""
24
+ def print_glyphs (path ):
25
+ """
26
+ Print the all glyphs in the given font file to stdout.
27
+
28
+ Parameters
29
+ ----------
30
+ path : str or None
31
+ The path to the font file. If None, use Matplotlib's default font.
32
+ """
33
+ if path is None :
34
+ path = fm .findfont (fm .FontProperties ()) # The default font.
35
+
36
+ font = FT2Font (path )
37
+
26
38
charmap = font .get_charmap ()
27
39
max_indices_len = len (str (max (charmap .values ())))
28
40
@@ -35,25 +47,19 @@ def print_glyphs(font):
35
47
print (f"{ glyph_index :>{max_indices_len }} { char } { name } " )
36
48
37
49
38
- def draw_font_table (path , print_all = False ):
50
+ def draw_font_table (path ):
39
51
"""
40
52
Draw a font table of the first 255 chars of the given font.
41
53
42
54
Parameters
43
55
----------
44
56
path : str or None
45
57
The path to the font file. If None, use Matplotlib's default font.
46
- print_all : bool
47
- Additionally print all chars to stdout.
48
58
"""
49
-
50
59
if path is None :
51
60
path = fm .findfont (fm .FontProperties ()) # The default font.
52
61
53
62
font = FT2Font (path )
54
- if print_all :
55
- print_glyphs (font )
56
-
57
63
# A charmap is a mapping of "character codes" (in the sense of a character
58
64
# encoding, e.g. latin-1) to glyph indices (i.e. the internal storage table
59
65
# of the font face).
@@ -109,4 +115,6 @@ def draw_font_table(path, print_all=False):
109
115
help = "Additionally, print all chars to stdout." )
110
116
args = parser .parse_args ()
111
117
112
- draw_font_table (args .path , args .print_all )
118
+ if args .print_all :
119
+ print_glyphs (args .path )
120
+ draw_font_table (args .path )
0 commit comments