File: build.py

package info (click to toggle)
fonts-train 1.100-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 25,536 kB
  • sloc: python: 57; makefile: 4
file content (65 lines) | stat: -rw-r--r-- 2,168 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from fontTools.ttLib.ttFont import newTable
from fontmake import __main__
from fontTools.ttLib import TTFont, newTable
import shutil, subprocess, glob, sys
from pathlib import Path

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

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}

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

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

try:
    shutil.rmtree("instance_ufo")
except Exception as e:
    print(e)
try:
    shutil.rmtree("master_ufo")
except Exception as e:
    print(e)
try:
    shutil.rmtree("master_ttf")
except Exception as e:
    print(e)

try:
    if sys.argv[1] == "--autohinting":
        for font in Path("fonts/ttf/").glob("*.ttf"):
            print ("["+str(font).split("/")[2][:-4]+"] Autohinting")
            fontName = str(font)
            hintedName = fontName[:-4]+"-hinted.ttf"
            subprocess.check_call(
                [
                    "ttfautohint",
                    "--stem-width",
                    "nsn",
                    fontName,
                    hintedName,
                ]
            )

            shutil.move(hintedName, fontName)
except IndexError:
    pass