def _autohint(self, otf, fmt): logger.info(f"Autohinting {self.name}.{fmt.value}") if fmt == Format.TTF: from io import BytesIO from ttfautohint import ttfautohint buf = BytesIO() otf.save(buf) otf.close() data = ttfautohint(in_buffer=buf.getvalue(), no_info=True) otf = TTFont(BytesIO(data)) elif fmt == Format.OTF: from tempfile import TemporaryDirectory from psautohint.__main__ import main as psautohint with TemporaryDirectory() as d: path = Path(d) / "tmp.otf" otf.save(path) with TemporaryLogLevel(logging.ERROR): psautohint([str(path)]) otf.close() otf = TTFont(path) return otf
def test_basic(path, tmpdir): # the input font is modified in-place, make a temp copy first pathSrc = py.path.local(path) pathDst = tmpdir / pathSrc.basename pathSrc.copy(pathDst) psautohint([str(pathDst)])
def _autohint(self, otf, fmt): logger.info(f"Autohinting {self.name}.{fmt.value}") if fmt == Format.TTF: from io import BytesIO from ttfautohint import ttfautohint buf = BytesIO() otf.save(buf) otf.close() data = ttfautohint(in_buffer=buf.getvalue(), no_info=True) otf = TTFont(BytesIO(data)) # Set bit 3 on head.flags # https://font-bakery.readthedocs.io/en/latest/fontbakery/profiles/googlefonts.html#com.google.fonts/check/integer_ppem_if_hinted head = otf["head"] head.flags |= 1 << 3 elif fmt == Format.OTF: from tempfile import TemporaryDirectory from psautohint.__main__ import main as psautohint with TemporaryDirectory() as d: path = Path(d) / "tmp.otf" otf.save(path) with TemporaryLogLevel(logging.ERROR): psautohint([str(path)]) otf.close() otf = TTFont(path) return otf
def test_missing_glyph_list(tmpdir): """Test that we raise if all glyph in the list do not exist.""" path = "%s/dummy/font.ufo" % DATA_DIR out = str(tmpdir / basename(path)) + ".out" with pytest.raises(ACFontError): psautohint([path, '-o', out, '-g', 'FOO,BAR'])
def test_option(path, option, argument, tmpdir): path = "%s/dummy/%s" % (DATA_DIR, path) out = str(tmpdir / basename(path)) + ".out" argument = "%s/dummy/%s" % (DATA_DIR, argument) psautohint([path, '-o', out, option, argument])
def test_outpath_multi(tmpdir): """Test handling multiple output paths.""" base = glob.glob("%s/dummy/mm0" % DATA_DIR)[0] paths = sorted(glob.glob(base + "/*.ufo")) # the reference font is modified in-place, make a temp copy first referenceSrc = py.path.local(paths[0]) referenceDst = tmpdir / referenceSrc.basename referenceSrc.copy(referenceDst) reference = str(referenceDst) inpaths = paths[1:] outpaths = [str(tmpdir / basename(p)) for p in inpaths] psautohint(inpaths + ['-o'] + outpaths + ['-r', reference])
def test_outpath_multi_unequal(tmpdir): """Test that we exit if output paths don't match number of input paths.""" base = glob.glob("%s/dummy/mm0" % DATA_DIR)[0] paths = sorted(glob.glob(base + "/*.ufo")) # the reference font is modified in-place, make a temp copy first referenceSrc = py.path.local(paths[0]) referenceDst = tmpdir / referenceSrc.basename referenceSrc.copy(referenceDst) reference = str(referenceDst) inpaths = paths[1:] outpaths = [str(tmpdir / basename(p)) for p in inpaths][1:] with pytest.raises(SystemExit): psautohint(inpaths + ['-o'] + outpaths + ['-r', reference])
def updateInstance(options, fontInstancePath): """ Run checkoutlinesufo and psautohint, unless explicitly suppressed. """ if options.doOverlapRemoval: logger.info("Doing overlap removal with checkoutlinesufo on %s ..." % fontInstancePath) co_args = ['-e', '-q', fontInstancePath] if options.no_round: co_args.insert(0, '-d') try: checkoutlinesUFO(co_args) except Exception: raise if options.doAutoHint: logger.info("Running psautohint on %s ..." % fontInstancePath) ah_args = ['--no-zones-stems', fontInstancePath] if options.no_round: ah_args.insert(0, '-d') try: psautohint(ah_args) except Exception: raise
def updateInstance(fontInstancePath, options): """ Run checkoutlinesufo and psautohint, unless explicitly suppressed. """ if options.doOverlapRemoval: logger.info("Doing overlap removal with checkoutlinesufo on %s ..." % fontInstancePath) co_args = ['-e', '-q', fontInstancePath] if options.no_round: co_args.insert(0, '-d') try: checkoutlinesUFO(co_args) except (Exception, SystemExit): raise if options.doAutoHint: logger.info("Running psautohint on %s ..." % fontInstancePath) ah_args = ['--no-zones-stems', fontInstancePath] if options.no_round: ah_args.insert(0, '-d') try: psautohint(ah_args) except (Exception, SystemExit): raise
def test_cid_glyph_range(tmpdir): path = "%s/source-code-pro/CID/font.otf" % DATA_DIR out = str(tmpdir / basename(path)) + ".out" psautohint([path, '-o', out, '-g', '/0-/10'])
def test_glyph_range(tmpdir): path = "%s/dummy/font.ufo" % DATA_DIR out = str(tmpdir / basename(path)) + ".out" psautohint([path, '-o', out, '-g', 'a-z'])
def test_type1(path, tmpdir): out = str(tmpdir / basename(path)) + ".out" with pytest.raises(SystemExit): psautohint([path, '-o', out])
def test_outpath(path, tmpdir): out = str(tmpdir / basename(path)) + ".out" psautohint([path, '-o', out])
def test_exclude_glyph_list(tmpdir): path = "%s/dummy/font.ufo" % DATA_DIR out = str(tmpdir / basename(path)) + ".out" psautohint([path, '-o', out, '-x', 'a,b,c'])
def autohint(args): return psautohint(["--all"] + args)
def test_missing_cff_table(tmpdir): path = "%s/dummy/nocff.otf" % DATA_DIR out = str(tmpdir / basename(path)) + ".out" with pytest.raises(ACFontError): psautohint([path, '-o', out])
def test_unsupported_format(path, tmpdir): with pytest.raises(SystemExit): psautohint([path])
def test_filter_glyph_list(tmpdir): """Test that we don't fail if some glyphs in the list do not exist.""" path = "%s/dummy/font.ufo" % DATA_DIR out = str(tmpdir / basename(path)) + ".out" psautohint([path, '-o', out, '-g', 'FOO,BAR,a'])
def test_doc_option(option, tmpdir): with pytest.raises(SystemExit) as e: psautohint([option]) assert e.type == SystemExit assert e.value.code == 0
def test_cid_prefixed_glyph_list(tmpdir): path = "%s/source-code-pro/CID/font.otf" % DATA_DIR out = str(tmpdir / basename(path)) + ".out" psautohint([path, '-o', out, '-g', 'cid0,cid1,cid2'])