Skip to content

Commit 5e75ba7

Browse files
committed
make terminal output more sophisticated
1 parent 3b534c0 commit 5e75ba7

3 files changed

Lines changed: 54 additions & 37 deletions

File tree

drawbot_proofing/proofing_helpers/names.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111

1212
def get_fi_dict(ufo_file):
13+
'''
14+
return fontinfo.plist as a dictionary
15+
'''
1316
fontinfo_path = ufo_file.joinpath('fontinfo.plist')
1417
with open(fontinfo_path, 'rb') as fi_blob:
1518
fi_dict = plistlib.load(fi_blob)
@@ -25,8 +28,8 @@ def get_ps_name(input_file):
2528
fi_dict = get_fi_dict(input_file)
2629
ps_name = fi_dict.get('postscriptFontName', None)
2730
if not ps_name:
28-
family_name = fi_dict.get('familyName', 'Family Name')
29-
style_name = fi_dict.get('styleName', 'Style Name')
31+
family_name = fi_dict.get('familyName', 'No Family Name')
32+
style_name = fi_dict.get('styleName', 'No Style Name')
3033
joined_name = f'{family_name}-{style_name}'
3134
ps_name = joined_name.replace(' ', '')
3235

drawbot_proofing/verticalMetricsComparisonProof.py

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@
2020
import defcon
2121
import 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

2527
from .proofing_helpers import fontSorter
2628
from .proofing_helpers.files import get_font_paths, get_ufo_paths
2729
from .proofing_helpers.formatter import RawDescriptionAndDefaultsFormatter
2830
from .proofing_helpers.drawing import draw_glyph
2931
from .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

3335
def 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+
241264
def 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(

drawbot_proofing/verticalMetricsProof.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ def parse_cmap(self):
169169
gname: chr(c_index) for c_index, gname in self.char_map.items()
170170
}
171171

172+
172173
def get_glyph_names(font_info):
173174
'''
174175
Collect some standard glyphs defining basic metrics,
@@ -308,16 +309,16 @@ def draw_metrics_page(
308309
db.text(f_info.ps_name, (MARGIN_L, 0 - line_height), align='left')
309310

310311

311-
def report_metrics(fi, args):
312-
313-
print('{:20s} {:>3d} 0 {:>3d} {:>3d} {:>3d}'.format(
314-
fi.styleName,
315-
fi.descender,
316-
fi.xHeight,
317-
fi.capHeight,
318-
fi.ascender))
312+
def report_metrics(fi, extremes, name_length=20):
313+
'''
314+
report ps name, descender, baseline, x-height, cap height, ascender,
315+
and potentially the most extreme glyphs on each end
316+
'''
317+
print(
318+
f'{fi.ps_name:{name_length}s} {fi.descender:>5d} 0 '
319+
f'{fi.xHeight:>4d} {fi.capHeight:>4d} {fi.ascender:>4d} '
320+
)
319321

320-
extremes = args.extremes
321322
if extremes > 1:
322323
print(f'{"":20s} lo {extremes}: {" ".join(fi.g_ymin)}')
323324
print(f'{"":20s} hi {extremes}: {" ".join(fi.g_ymax)}')
@@ -383,9 +384,11 @@ def main():
383384

384385
if font_paths:
385386
fi_objects = [FontInfo(fp, args) for fp in font_paths]
387+
name_length = max([len(fi.ps_name) for fi in fi_objects])
388+
386389
page_width, page_height, descender_gl = get_global_metrics(fi_objects)
387390
for fi in fi_objects:
388-
report_metrics(fi, args)
391+
report_metrics(fi, args.extremes, name_length)
389392
draw_metrics_page(
390393
fi, page_width, page_height, descender_gl, args.normalize_upm)
391394

0 commit comments

Comments
 (0)