forked from yangheeryu/Gowun-Dodum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
84 lines (69 loc) · 2.09 KB
/
build.py
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from glyphsLib.cli import main
from fontTools.ttLib import TTFont, newTable
from pathlib import Path
import shutil, os, glob
import ufo2ft
import ufoLib2
import multiprocessing
import multiprocessing.pool
path = Path("sources")
#Converting from Glyphs to UFO
print ("[Gowun Dotum] Converting to UFO")
main(("glyphs2ufo", "sources/GowunDodum.glyphs", "--write-public-skip-export-glyphs", "--propagate-anchors"))
def DSIG_modification(font:TTFont):
font["DSIG"] = newTable("DSIG") #need that stub dsig
font["DSIG"].ulVersion = 1
font["DSIG"].usFlag = 0
font["DSIG"].usNumSigs = 0
font["DSIG"].signatureRecords = []
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}
def build(ufo:ufoLib2):
source = ufoLib2.Font.open(ufo)
source.lib['com.github.googlei18n.ufo2ft.filters'] = [
{
"name": "decomposeTransformedComponents",
"pre": 1,
},
{
"name": "flattenComponents",
"pre": 1,
},
]
style_name = source.info.styleName
family_name = str(source.info.familyName).replace(" ","")
static_ttf = ufo2ft.compileTTF(
source,
removeOverlaps=True,
overlapsBackend="pathops",
useProductionNames=True,
)
DSIG_modification(static_ttf)
GASP_set(static_ttf)
print ("[Dongle "+str(style_name).replace(" ","")+"] Saving")
output = "fonts/ttf/"+family_name+"-"+str(style_name).replace(" ","")+".ttf"
static_ttf.save(output)
pool = multiprocessing.pool.Pool(processes=multiprocessing.cpu_count())
processes = []
for source in path.glob("*.ufo"): # GOTTA GO FAST
processes.append(
pool.apply_async(
build,
(
source,
),
)
)
pool.close()
pool.join()
for process in processes:
process.get()
del processes, pool
# Cleanup
for ufo in path.glob("*.ufo"):
shutil.rmtree(ufo)
os.remove("sources/GowunDodum.designspace")