def metricfix(fonts): from cli.ttfont import Font ymin = 0 ymax = 0 for f in fonts: metrics = Font(f) font_ymin, font_ymax = metrics.get_bounding() ymin = min(font_ymin, ymin) ymax = max(font_ymax, ymax) for f in fonts: metrics = Font(f) metrics.ascents.set(ymax) metrics.descents.set(ymin) metrics.linegaps.set(0) metrics.save(f + '.fix')
for f in fonts: try: metrics = Font(f) except TTLibError, ex: print('Error: %s' % ex) continue # set ascents, descents and linegaps. FontVerticalMetrics will # not set those values if None, and overwrite them if concrete # argument has been passed metrics.ascents.set(options.ascents) metrics.descents.set(options.descents) metrics.linegaps.set(options.linegaps) metrics.ascents.hhea = options.ascents_hhea metrics.ascents.os2typo = options.ascents_typo metrics.ascents.os2win = options.ascents_win metrics.descents.hhea = options.descents_hhea metrics.descents.os2typo = options.descents_typo metrics.descents.os2win = options.descents_win metrics.linegaps.hhea = options.linegaps_hhea metrics.linegaps.os2typo = options.linegaps_typo metrics.save(f + '.fix') elif options.autofix: metricfix(fonts) else: print(metricview(fonts))