示例#1
0
    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
示例#2
0
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)])
示例#3
0
    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
示例#4
0
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'])
示例#5
0
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])
示例#6
0
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])
示例#7
0
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
示例#10
0
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'])
示例#11
0
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'])
示例#12
0
def test_type1(path, tmpdir):
    out = str(tmpdir / basename(path)) + ".out"

    with pytest.raises(SystemExit):
        psautohint([path, '-o', out])
示例#13
0
def test_outpath(path, tmpdir):
    out = str(tmpdir / basename(path)) + ".out"

    psautohint([path, '-o', out])
示例#14
0
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'])
示例#15
0
def autohint(args):
    return psautohint(["--all"] + args)
示例#16
0
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])
示例#17
0
def test_unsupported_format(path, tmpdir):
    with pytest.raises(SystemExit):
        psautohint([path])
示例#18
0
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'])
示例#19
0
def test_doc_option(option, tmpdir):
    with pytest.raises(SystemExit) as e:
        psautohint([option])
    assert e.type == SystemExit
    assert e.value.code == 0
示例#20
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'])