-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.py
41 lines (33 loc) · 894 Bytes
/
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
import fontforge
import sys
import unicodedata
FLAGS = ("opentype", "omit-instructions", "no-mac-names") # , 'short-post')
font = fontforge.open(sys.argv[1])
font.selection.all()
font.correctReferences()
font.selection.none()
allA = set()
for glyph in font.glyphs():
if glyph.unicode > 0:
ct = unicodedata.category(chr(glyph.unicode))
if ct[0] not in {"L", "M", "N"}:
continue
allA.add(glyph.glyphname)
allE = allA - {
"uni0627",
"uni0622",
"uni0671",
"uni0627.fina",
"uni0671.fina",
"uni0648",
}
with open(sys.argv[3]) as f:
classes = f"""
@All = [{' '.join(sorted(allA))}];
@AllExceptWawAndAlef = [{' '.join(sorted(allE))}];
"""
fea = f.read().replace("%CLASSES%", classes)
with open(sys.argv[1].replace(".sfd", ".fea"), "w") as f:
f.write(fea)
font.mergeFeature(f.name)
font.generate(sys.argv[2], flags=FLAGS)