def diffenator(self, **kwargs): logger.info("Running Diffenator") dst = os.path.join(self._out, "Diffenator") mkdir(dst) for style in self._shared_instances: font_before = DFont(self._instances_before[style]) font_after = DFont(self._instances[style]) out = os.path.join(dst, style) if font_after.is_variable and not font_before.is_variable: font_after.set_variations_from_static(font_before) elif not font_after.is_variable and font_before.is_variable: font_before.set_variations_from_static(font_after) elif font_after.is_variable and font_before.is_variable: # TODO get wdth and slnt axis vals variations = {"wght": font_before.ttfont["OS/2"].usWeightClass} font_after.set_variations(variations) font_before.set_variations(variations) # TODO add settings diff = DiffFonts(font_before, font_after, {"render_diffs": True}) diff.to_gifs(dst=out) diff.to_txt(20, os.path.join(out, "report.txt")) diff.to_md(20, os.path.join(out, "report.md")) diff.to_html(20, os.path.join(out, "report.html"), image_dir=".")
def diffenator(self, **kwargs): logger.info("Running Diffenator") dst = os.path.join(self.out, "Diffenator") mkdir(dst) for style in self.matching_instances: font_before = DFont(self.instances_before[style]['filename']) font_after = DFont(self.instances[style]['filename']) out = os.path.join(dst, style) if font_after.is_variable and not font_before.is_variable: font_after.set_variations_from_static(font_before) elif not font_after.is_variable and font_before.is_variable: font_before.set_variations_from_static(font_after) elif font_after.is_variable and font_before.is_variable: coordinates = self.instances_before[style]['coordinates'] font_after.set_variations(coordinates) font_before.set_variations(coordinates) # TODO add settings diff = DiffFonts(font_before, font_after, {"render_diffs": True}) diff.to_gifs(dst=out) diff.to_txt(20, os.path.join(out, "report.txt")) diff.to_md(20, os.path.join(out, "report.md")) diff.to_html(20, os.path.join(out, "report.html"), image_dir=".")
def run_diffenator(logger, font_before, font_after, out, thresholds=DIFFENATOR_THRESHOLDS['normal']): logger.debug('run_diffenator with fonts before: %s after: %s', font_before, font_after) font_before = DFont(font_before) font_after = DFont(font_after) if font_after.is_variable and not font_before.is_variable: font_after.set_variations_from_static(font_before) elif not font_after.is_variable and font_before.is_variable: font_before.set_variations_from_static(font_after) elif font_after.is_variable and font_before.is_variable: # TODO get wdth and slnt axis vals variations = {"wght": font_before.ttfont["OS/2"].usWeightClass} font_after.set_variations(variations) font_before.set_variations(variations) diff = DiffFonts(font_before, font_after, settings=thresholds) diff.to_gifs(dst=out) diff.to_txt(20, os.path.join(out, "report.txt")) diff.to_md(20, os.path.join(out, "report.md")) diff.to_html(20, os.path.join(out, "report.html"), image_dir=".")
def main(): parser = argparse.ArgumentParser(description=__doc__, formatter_class=RawTextHelpFormatter) parser.add_argument('--version', action='version', version=__version__) parser.add_argument('font_before') parser.add_argument('font_after') parser.add_argument('-td', '--to_diff', nargs='+', choices=CHOICES, default='*', help="Categories to diff. '*' diffs everything") parser.add_argument('-ol', '--output-lines', type=int, default=50, help="Amout of rows to report for each diff table") formatter_group = parser.add_mutually_exclusive_group(required=False) formatter_group.add_argument('-txt', '--txt', action='store_true', default=True, help="Output report as txt.") formatter_group.add_argument('-md', '--markdown', action='store_true', default=False, help="Output report as markdown.") formatter_group.add_argument('-html', '--html', action='store_true', default=False, help="Output report as html.") parser.add_argument('-v', '--verbose', action='store_true', help='Output verbose reports') parser.add_argument('-l', '--log-level', choices=('INFO', 'DEBUG', 'WARN'), default='INFO') parser.add_argument('-i', '--vf-instance', default=None, help='Set vf variations e.g "wght=400"') parser.add_argument('--marks_thresh', type=int, default=0, help="Ignore modified marks under this value") parser.add_argument('--mkmks_thresh', type=int, default=0, help="Ignore modified mkmks under this value") parser.add_argument('--kerns_thresh', type=int, default=0, help="Ignore modified kerns under this value") parser.add_argument('--glyphs_thresh', type=float, default=0, help="Ignore modified glyphs under this value") parser.add_argument('--metrics_thresh', type=int, default=0, help="Ignore modified metrics under this value") parser.add_argument('--cbdt_thresh', type=float, default=0, help="Ignore modified CBDT glyphs under this value") parser.add_argument('-rd', '--render_diffs', action='store_true', help=("Render glyphs with hb-view and compare " "pixel diffs.")) parser.add_argument('-r', '--render-path', help="Path to generate before and after gifs to.") args = parser.parse_args() logger = logging.getLogger("fontdiffenator") logger.setLevel(args.log_level) diff_options = dict( marks_thresh=args.marks_thresh, mkmks_thresh=args.mkmks_thresh, kerns_thresh=args.kerns_thresh, glyphs_thresh=args.glyphs_thresh, metrics_thresh=args.metrics_thresh, cbdt_thresh=args.cbdt_thresh, to_diff=args.to_diff, render_diffs=args.render_diffs, render_path=args.render_path, html_output=args.html, ) font_before = DFont(args.font_before) font_after = DFont(args.font_after) font_matcher(font_before, font_after, args.vf_instance) diff = DiffFonts(font_before, font_after, diff_options) if args.render_path: diff.to_gifs(args.render_path, args.output_lines) if args.markdown: print(diff.to_md(args.output_lines)) elif args.html: print(diff.to_html(args.output_lines, image_dir=args.render_path)) else: print(diff.to_txt(args.output_lines))