Esempio n. 1
0
def install_cvt(fo, cvs, base):
    """If base is greater than zero, we append CVs to an existing CVT table. If
    not, we generate a new table."""
    if base > 0:
        assert base == len(fo['cvt '].values)
        for c in cvs:
            fo['cvt '].values.append(c)
    else:
        fo['cvt '] = ttFont.newTable('cvt ')
        setattr(fo['cvt '], 'values', array.array('h', cvs))
Esempio n. 2
0
def install_functions(fo, fns, base):
    """If base greater than zero, we append our own functions to those already
    in the font. If not, generate a new fpgm table."""
    if base > 0:
        oldfpgm = "\n".join(fo['fpgm'].program.getAssembly())
        newfpgm = oldfpgm + "\n" + str(fns)
        fo['fpgm'].program.fromAssembly(newfpgm)
        fo['fpgm'].program.getBytecode()
    else:
        fo['fpgm'] = ttFont.newTable('fpgm')
        fo['fpgm'].program = tables.ttProgram.Program()
        fo['fpgm'].program.fromAssembly(str(fns))
Esempio n. 3
0
def install_prep(fo, pr, keepold, replace):
    """If keepold is True, we append our own prep table to the existing one.
    It is up to the Xgridfit programmer to make sure that no conflicts arise
    (though if there's a duplication--for example, instructions being disabled
    at a different ppem in the new code than in the old, the new code will
    take precedence.)"""
    if keepold and not replace:
        oldprep = "\n".join(fo['prep'].program.getAssembly())
        newprep = oldprep + "\n" + str(pr)
        fo['prep'].program.fromAssembly(newprep)
    else:
        fo['prep'] = ttFont.newTable('prep')
        fo['prep'].program = tables.ttProgram.Program()
        fo['prep'].program.fromAssembly(str(pr))
Esempio n. 4
0
def add_avar_table(ttFont):
    avar = newTable("avar")
    avar.segments = {
        "wght": {
            -1.0: -1.0,
            0: 0,
            1.0: 1.0
        },
        "ital": {
            -1.0: -1.0,
            0: 0,
            1.0: 1.0
        }
    }
    ttFont['avar'] = avar
Esempio n. 5
0
from fontTools.ttLib.ttFont import newTable
from fontmake import __main__
from fontTools.ttLib import TTFont, newTable
import shutil, subprocess, glob
from pathlib import Path

print ("[Train One] Generating TTFs")
__main__.main(("-g","sources/TrainOne.glyphs", "-o","ttf",))

for font in Path("master_ttf").glob("*.ttf"):
    modifiedFont = TTFont(font)
    print ("["+str(font).split("/")[1][:-4]+"] Adding stub DSIG")
    modifiedFont["DSIG"] = newTable("DSIG")     #need that stub dsig
    modifiedFont["DSIG"].ulVersion = 1
    modifiedFont["DSIG"].usFlag = 0
    modifiedFont["DSIG"].usNumSigs = 0
    modifiedFont["DSIG"].signatureRecords = []

    print ("["+str(font).split("/")[1][:-4]+"] Making other changes")
    modifiedFont["name"].addMultilingualName({'ja':'トレイン One'}, modifiedFont, nameID = 1, windows=True, mac=False)
    modifiedFont["name"].addMultilingualName({'ja':'Regular'}, modifiedFont, nameID = 2, windows=True, mac=False)
    modifiedFont["head"].flags |= 1 << 3        #sets flag to always round PPEM to integer

    modifiedFont.save("fonts/ttf/"+str(font).split("/")[1])

shutil.rmtree("instance_ufo")
shutil.rmtree("master_ufo")
shutil.rmtree("master_ttf")

for font in Path("fonts/ttf/").glob("*.ttf"):
    print ("["+str(font).split("/")[2][:-4]+"] Autohinting")
Esempio n. 6
0
def GASP_set(font:TTFont):
    if "gasp" not in font:
        font["gasp"] = newTable("gasp")
        font["gasp"].gaspRange = {}
    if font["gasp"].gaspRange != {65535: 0x000A}:
        font["gasp"].gaspRange = {65535: 0x000A}
Esempio n. 7
0
def install_cvar(fo, cvarstore, keepold, cvtbase):
    """If keepold is True, we append our own cvar data to the existing
    TupleVariation objects. If False, generate our own cvar table. Since
    The old cvar may not exactly match the new one, there are contingencies:
    If a tuple is missing in the old or the new cvar, pad the new one
    and issue a warning. If there is no cvar at all in the existing font (this
    can easily happen with VTT or the non-VF version of ttfautohint), pad all
    our tuples and issue a warning. In
    such cases it may be a good idea to manually edit the cvar table."""
    cvtlen = len(fo['cvt '].values)
    if keepold:
        complications = False
        needoldfontpadding = False
        try:
            oldcvarstore = fo['cvar'].variations
        except:
            if quietcount < 2:
                print(
                    "Warning: No cvar table in existing font. Making a dummy table."
                )
            # Create a dummy cvar table to merge the new one into.
            complications = True
            cvardummy = []
            for cvst in cvarstore:
                cvardummy.append(TupleVariation(cvst[0], [None] * cvtlen))
            fo['cvar'] = ttFont.newTable('cvar')
            fo['cvar'].variations = cvardummy
            oldcvarstore = fo['cvar'].variations
        try:
            # When you fiddle the size of the cvt, fonttools helpfully
            # extends the cvar coordinate lists to match. But test to make
            # sure it has been done (as it doesn't seem to be documented).
            assert cvtlen == len(oldcvarstore[0].coordinates)
        except:
            print("Size of cvt does not match size of cvar.")
            print("Size of cvt:  " + str(cvtlen))
            print("Size of cvar: " + str(len(oldcvarstore[0].coordinates)))
            sys.exit(1)
        oldcoordlen = len(oldcvarstore[0].coordinates)
        newcoordlen = len(cvarstore[0][1])
        new_tuple_found = [0] * len(cvarstore)
        for oldc in oldcvarstore:
            try:
                newc = None
                new_tuple_counter = 0
                for tc in cvarstore:
                    # if oldc.axes == tc[0]:
                    if _axes_match(oldc.axes, tc[0]):
                        newc = tc
                        break
                    new_tuple_counter += 1
                if newc:
                    new_tuple_found[new_tuple_counter] = 1
                    newcoordinates = newc[1]
                    i = 0
                    for val in newcoordinates:
                        if val != None and val != 0:
                            oldc.coordinates[i + cvtbase] = val
                        i += 1
                else:
                    # we've failed to find a match for one of the TupleVariations
                    # in the existing font. We don't need to do anything (the
                    # table is okay), but we'll warn.
                    complications = True
            except Exception as err:
                print(err)
                print("Here are the regions in the existing font:")
                for tup in oldcvarstore:
                    print(str(tup.axes))
                sys.exit(1)
        # If there are new TupleVariations unaccounted for:
        tt_index = 0
        for tt in new_tuple_found:
            if tt == 0:
                # In the absence of an old coordinate list, we'll pad
                # the beginning of the new list.
                newcoordlist = [None] * cvtbase
                newcoordlist.extend(cvarstore[tt_index][1])
                thistuple = TupleVariation(cvarstore[tt_index][0],
                                           newcoordlist)
                oldcvarstore.append(thistuple)
                # fo['cvar'].variations.append(thistuple)
            tt_index += 1
            complications = True
        if complications and quietcount < 2:
            print("Warning: The cvar table in the existing font and the one")
            print("in the Xgridfit program were not a perfect match. I have")
            print("done my best to combine them, but you should check over it")
            print("and make changes if necessary. Here is the new cvar table:")
            print(fo['cvar'].variations)
    else:
        ts = []
        for s in cvarstore:
            ts.append(TupleVariation(s[0], s[1]))
        fo['cvar'] = ttFont.newTable('cvar')
        fo['cvar'].variations = ts
Esempio n. 8
0
 def _write_math_table(self, style: str, input_path: str, output_path: str):
     with TTFont(input_path) as tt_font:
         tt_font['MATH'] = newTable('MATH')
         tt_font['MATH'].table = self.math_tables[style].encode()
         tt_font.save(output_path)