2121import matplotlib .pyplot as plt
2222
2323
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+
2638 charmap = font .get_charmap ()
2739 max_indices_len = len (str (max (charmap .values ())))
2840
@@ -35,25 +47,19 @@ def print_glyphs(font):
3547 print (f"{ glyph_index :>{max_indices_len }} { char } { name } " )
3648
3749
38- def draw_font_table (path , print_all = False ):
50+ def draw_font_table (path ):
3951 """
4052 Draw a font table of the first 255 chars of the given font.
4153
4254 Parameters
4355 ----------
4456 path : str or None
4557 The path to the font file. If None, use Matplotlib's default font.
46- print_all : bool
47- Additionally print all chars to stdout.
4858 """
49-
5059 if path is None :
5160 path = fm .findfont (fm .FontProperties ()) # The default font.
5261
5362 font = FT2Font (path )
54- if print_all :
55- print_glyphs (font )
56-
5763 # A charmap is a mapping of "character codes" (in the sense of a character
5864 # encoding, e.g. latin-1) to glyph indices (i.e. the internal storage table
5965 # of the font face).
@@ -109,4 +115,6 @@ def draw_font_table(path, print_all=False):
109115 help = "Additionally, print all chars to stdout." )
110116 args = parser .parse_args ()
111117
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