@@ -1108,26 +1108,44 @@ def _fontfile(cls, suffix, texname):
1108
1108
from argparse import ArgumentParser
1109
1109
import itertools
1110
1110
1111
+ import fontTools .agl
1112
+
1113
+ from matplotlib .ft2font import FT2Font
1114
+ from matplotlib .textpath import TextToPath
1115
+
1111
1116
parser = ArgumentParser ()
1112
1117
parser .add_argument ("filename" )
1113
1118
parser .add_argument ("dpi" ,nargs = "?" ,type = float ,default = None )
1114
1119
args = parser .parse_args ()
1120
+
1121
+ def _print_fields (* args ):
1122
+ print (" " .join (map ("{:>11}" .format ,args )))
1123
+
1115
1124
with Dvi (args .filename ,args .dpi )as dvi :
1116
1125
fontmap = PsfontsMap (find_tex_file ('pdftex.map' ))
1117
1126
for page in dvi :
1118
- print (f"===new page === "
1127
+ print (f"===NEW PAGE === "
1119
1128
f"(w:{ page .width } , h:{ page .height } , d:{ page .descent } )" )
1129
+ print ("--- GLYPHS ---" )
1120
1130
for font ,group in itertools .groupby (
1121
1131
page .text ,lambda text :text .font ):
1122
- print (f"font:{ font .texname .decode ('latin-1' )!r} \t "
1123
- f"scale:{ font ._scale / 2 ** 20 } " )
1124
- print ("x" ,"y" ,"glyph" ,"chr" ,"w" ,"(glyphs)" ,sep = "\t " )
1132
+ psfont = fontmap [font .texname ]
1133
+ fontpath = psfont .filename
1134
+ print (f"font:{ font .texname .decode ('latin-1' )} "
1135
+ f"(scale:{ font ._scale / 2 ** 20 } ) at{ fontpath } " )
1136
+ face = FT2Font (fontpath )
1137
+ TextToPath ._select_native_charmap (face )
1138
+ _print_fields ("x" ,"y" ,"glyph" ,"chr" ,"w" )
1125
1139
for text in group :
1126
- print (text .x ,text .y ,text .glyph ,
1127
- chr (text .glyph )if chr (text .glyph ).isprintable ()
1128
- else "." ,
1129
- text .width ,sep = "\t " )
1140
+ if psfont .encoding :
1141
+ glyph_name = _parse_enc (psfont .encoding )[text .glyph ]
1142
+ else :
1143
+ glyph_name = face .get_glyph_name (
1144
+ face .get_char_index (text .glyph ))
1145
+ glyph_str = fontTools .agl .toUnicode (glyph_name )
1146
+ _print_fields (text .x ,text .y ,text .glyph ,glyph_str ,text .width )
1130
1147
if page .boxes :
1131
- print ("x" ,"y" ,"h" ,"w" ,"" ,"(boxes)" ,sep = "\t " )
1148
+ print ("--- BOXES ---" )
1149
+ _print_fields ("x" ,"y" ,"h" ,"w" )
1132
1150
for box in page .boxes :
1133
- print (box .x ,box .y ,box .height ,box .width , sep = " \t " )
1151
+ _print_fields (box .x ,box .y ,box .height ,box .width )