2020import defcon
2121import drawBot as db
2222
23- from .verticalMetricsProof import MARGIN , PT_SIZE , FontInfo , finish_drawing
23+ from .verticalMetricsProof import (
24+ MARGIN , PT_SIZE , FontInfo , finish_drawing , report_metrics
25+ )
2426
2527from .proofing_helpers import fontSorter
2628from .proofing_helpers .files import get_font_paths , get_ufo_paths
2729from .proofing_helpers .formatter import RawDescriptionAndDefaultsFormatter
2830from .proofing_helpers .drawing import draw_glyph
2931from .proofing_helpers .globals import FONT_MONO
30- from .proofing_helpers .names import get_style_name
32+ from .proofing_helpers .names import get_style_name , get_ps_name
3133
3234
3335def get_args ():
@@ -218,18 +220,15 @@ def process_font_paths(font_paths, args):
218220 font_info_list = [FontInfo (font_path , args ) for font_path in font_list ]
219221 extension = font_list [0 ].suffix .upper ()
220222 family_name = font_info_list [0 ].familyName
223+ name_length = max ([len (fi .ps_name ) for fi in font_info_list ])
224+
221225 if args .output_file_name :
222226 doc_name = f'comparison { args .output_file_name } '
223227 else :
224228 doc_name = f'comparison { family_name } ({ extension [1 :]} )'
225229
226230 for f_info in font_info_list :
227- print ('{:20s} {:>3d} 0 {:>3d} {:>3d} {:>3d}' .format (
228- f_info .styleName ,
229- f_info .descender ,
230- f_info .xHeight ,
231- f_info .capHeight ,
232- f_info .ascender ))
231+ report_metrics (f_info , 0 , name_length )
233232
234233 for char in args .sample_string :
235234 draw_metrics_page_font (
@@ -238,9 +237,35 @@ def process_font_paths(font_paths, args):
238237 finish_drawing (doc_name )
239238
240239
240+ def report_ufo_metrics (fo , name_width = 20 ):
241+ '''
242+ report ps name, descender, baseline, x-height, cap height, ascender,
243+ '''
244+
245+ format_dict = {
246+ 'styleName' : fo .info .styleName ,
247+ 'ps_name' : (
248+ fo .info .postscriptFontName if fo .info .postscriptFontName else
249+ get_ps_name (fo .path )),
250+ 'descender' : fo .info .descender if fo .info .descender else 0 ,
251+ 'xHeight' : fo .info .xHeight if fo .info .xHeight else 0 ,
252+ 'capHeight' : fo .info .capHeight if fo .info .capHeight else 0 ,
253+ 'ascender' : fo .info .ascender if fo .info .ascender else 0 ,
254+ }
255+ print (
256+ f'{ format_dict .get ("ps_name" ):{name_width }s} '
257+ f'{ format_dict .get ("descender" ):>5d} 0 '
258+ f'{ format_dict .get ("xHeight" ):>4d} '
259+ f'{ format_dict .get ("capHeight" ):>4d} '
260+ f'{ format_dict .get ("ascender" ):>4d} '
261+ )
262+
263+
241264def process_ufo_paths (ufo_paths , args ):
242- font_list = fontSorter .sort_fonts (ufo_paths )
243- fo_list = [defcon .Font (f ) for f in font_list ]
265+ ufo_list = fontSorter .sort_fonts (ufo_paths )
266+ name_length = max ([len (get_ps_name (f )) for f in ufo_list ])
267+
268+ fo_list = [defcon .Font (f ) for f in ufo_list ]
244269 cmap_list = [{g .unicode : g .name for g in f if g .unicode } for f in fo_list ]
245270
246271 family_name = fo_list [0 ].info .familyName
@@ -250,21 +275,7 @@ def process_ufo_paths(ufo_paths, args):
250275 doc_name = f'comparison { family_name } (UFO)'
251276
252277 for fo in fo_list :
253- # terminal feedback
254- format_dict = {
255- 'styleName' : fo .info .styleName ,
256- 'descender' : fo .info .descender if fo .info .descender else 0 ,
257- 'xHeight' : fo .info .xHeight if fo .info .xHeight else 0 ,
258- 'capHeight' : fo .info .capHeight if fo .info .capHeight else 0 ,
259- 'ascender' : fo .info .ascender if fo .info .ascender else 0 ,
260- }
261-
262- print ('{:20s} {:>3d} 0 {:>3d} {:>3d} {:>3d}' .format (
263- format_dict .get ('styleName' ),
264- format_dict .get ('descender' ),
265- format_dict .get ('xHeight' ),
266- format_dict .get ('capHeight' ),
267- format_dict .get ('ascender' )))
278+ report_ufo_metrics (fo , name_length )
268279
269280 for char in args .sample_string :
270281 draw_metrics_page_ufo (
0 commit comments