def reset_fstype(fontpath): from bakery_cli.ttfont import Font try: font = Font(fontpath) except TTLibError as ex: print("ERROR: %s" % ex, file=sys.stderr) return font['OS/2'].fsType = 0 font.save(fontpath + '.fix')
def fix_style_names(fontpath): from bakery_cli.ttfont import Font try: font = Font(fontpath) except TTLibError as ex: print("ERROR: %s" % ex) return # font['name'].fsType = 0 font.save(fontpath + '.fix')
def metricfix(fonts): from bakery_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')
def fix_name_table(fontfile): try: font = Font(fontfile) except TTLibError: print("Unable to open {}".format(os.path.basename(fontfile)), file=sys.stderr) return for name in font['name'].names: title = Font.bin2unistring(name) title = normalizestr(title) if name.platformID == 3: name.string = title.encode('utf-16-be') else: name.string = title font.save(fontfile + '.fix')
# 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: from bakery_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: fixer = VmetFixer(None, f) fixer.apply(ymin, ymax)
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: vmet.metricfix(fonts) else: print(vmet.metricview(fonts))