def fix_metrics(testcase): """ Fix vmet table with actual min and max values """ targetpath = os.path.dirname(testcase.operator.path) SCRIPTPATH = 'fontbakery-fix-vertical-metrics.py' directory = UpstreamDirectory(targetpath) paths = [] for f in directory.BIN: path = op.join(targetpath, f) paths.append(path) command = "$ {0} --autofix {1}" command = command.format(SCRIPTPATH, ' '.join(paths)) if hasattr(testcase, 'operator'): testcase.operator.debug(command) metricfix(paths) for path in paths: try: shutil.move(path + '.fix', path, log=testcase.operator.logger) except IOError: pass command = "$ {0} {1}".format(SCRIPTPATH, ' '.join(paths)) if hasattr(testcase, 'operator'): testcase.operator.debug(command) testcase.operator.debug(metricview(paths))
def apply(self, override_origin=False): from bakery_cli.ttfont import Font ymin = 0 ymax = 0 for f in self.fonts: metrics = Font(f) font_ymin, font_ymax = metrics.get_bounding() ymin = min(font_ymin, ymin) ymax = max(font_ymax, ymax) for f in self.fonts: fixer = VmetFixer(self.testcase, f) fixer.apply(ymin, ymax, override_origin=override_origin) command = "$ {0} {1}".format(Vmet.SCRIPTPATH, ' '.join(self.fonts)) logger.debug(command) import StringIO for l in StringIO.StringIO(metricview(self.fonts)): logger.debug(l)
def fix_metrics(path, log=None): """ Fix vmet table with actual min and max values """ SCRIPTPATH = 'bakery-vmet-fix.py' from bakery_lint.metadata import FamilyMetadata family_metadata = FamilyMetadata(json.load(open(path))) paths = [] for f in family_metadata.fonts: path = op.join(op.dirname(path), f.filename) paths.append(path) command = "{0} {1} --autofix {2}" command = command.format(PYPATH, SCRIPTPATH, ' '.join(paths)) logging(log, command) metricfix(paths) for font_path in paths: shutil.move(font_path + '.fix', font_path, log=log) command = "{0} {1} {2}".format(PYPATH, SCRIPTPATH, ' '.join(paths)) logging(log, command) log.write(metricview(paths))
def print_vertical_metrics(self, binfiles): from bakery_cli.scripts import vmet fonts = [op.join(self.builddir, x) for x in binfiles] self.bakery.logging_raw(vmet.metricview(fonts))
def print_vertical_metrics(self, binfiles): from bakery_cli.scripts import vmet SCRIPTPATH = 'fontbakery-fix-vertical-metrics.py' fonts = [op.join(self.builddir, x) for x in binfiles] command = ' '.join(fonts) self.bakery.logging_raw(vmet.metricview(fonts))
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) else: print(vmet.metricview(fonts))
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))