-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpatch.py
executable file
·121 lines (105 loc) · 3.19 KB
/
patch.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env python
import fontforge
import sys
import os
target = sys.argv[1]
target_base = os.path.basename(target)
bold_target = sys.argv[2]
bold_target_base = os.path.basename(bold_target)
olddir = sys.argv[3] + "/"
f = fontforge.open(target)
# boldf = fontforge.open(bold_target)
oldf = fontforge.open(olddir + target_base)
oldboldf = fontforge.open(olddir + bold_target_base)
fnv = f.fontname.split("-");
if (len(fnv) != 2):
raise Exception("Unexpeced fontname")
style = fnv[1]
# alternate symbols
CV = [
['zero', 'zero.zero'],
['five', 'five.cv20'],
# ['five.dnom', 'five.dnom.cv20'],
# ['five.numr', 'five.numr.cv20'],
# ['f', 'f.cv09.ss20'],
['g', 'g.cv03'],
['uni01F5', 'uni01F5.cv03'],
['gbreve', 'gbreve.cv03'],
['gcaron', 'gcaron.cv03'],
['gcircumflex', 'gcircumflex.cv03'],
['uni0123', 'uni0123.cv03'],
['gdotaccent', 'gdotaccent.cv03'],
# u and friends
['u', 'u.cv12'],
['uacute', 'uacute.cv12'],
['ubreve', 'ubreve.cv12'],
['ucircumflex', 'ucircumflex.cv12'],
['udieresis', 'udieresis.cv12'],
['uni1EE5', 'uni1EE5.cv12'],
['ugrave', 'ugrave.cv12'],
['uni1EE7', 'uni1EE7.cv12'],
['uhorn', 'uhorn.cv12'],
['uni1EE9', 'uni1EE9.cv12'],
['uni1EF1', 'uni1EF1.cv12'],
['uni1EEB', 'uni1EEB.cv12'],
['uni1EED', 'uni1EED.cv12'],
['uni1EEF', 'uni1EEF.cv12'],
['uhungarumlaut', 'uhungarumlaut.cv12'],
['umacron', 'umacron.cv12'],
['uogonek', 'uogonek.cv12'],
['uring', 'uring.cv12'],
['utilde', 'utilde.cv12'],
]
for [find, replace] in CV:
f.removeGlyph(find)
f.selection.select(replace)
f.copy()
f.selection.select(find)
f.paste()
# old J
f.removeGlyph('J')
oldf.selection.select('J')
oldf.copy()
f.selection.select('J')
f.paste()
# Bold stuff
BV = [
"exclam", "quotedbl", "numbersign",
"dollar", "percent", "ampersand",
"quotesingle", "parenleft", "parenright",
"asterisk", "plus", "comma", "hyphen",
"period", "slash", "colon", "semicolon",
"less", "equal", "greater", "question",
"at", "bracketleft", "backslash",
"bracketright", "asciicircum",
"underscore", "grave", "braceleft",
"bar", "braceright", "asciitilde",
]
for g in BV:
f.removeGlyph(g)
oldboldf.selection.select(g);
oldboldf.copy()
f.selection.select(g);
f.paste()
# fixup: https://github.com/JetBrains/JetBrainsMono/issues/334
# following values were taken from v2.001
f.os2_winascent = 1085
f.os2_windescent = 270
f.os2_typoascent = 970
f.os2_typodescent = -270
f.hhea_ascent = 970
f.hhea_descent = -270
# change font names and shit
fn = "NRK Mono"
f.fontname = fn.replace(" ", "") + "-" + style
f.familyname = fn
f.fullname = fn + " " + style
ver = f.version.split(";")[0]
uniq_id = ver + ";NM;" + fn.replace(" ", "") + "-" + style
f.appendSFNTName('English (US)', 'UniqueID', uniq_id);
# f.appendSFNTName('English (US)', 'Preffered Family', "NRK Mono");
outdir = "./"
if len(sys.argv) > 4:
outdir = sys.argv[4] + "/"
o = outdir + fn + " " + style + ".ttf"
f.generate(o.replace(" ", "-"))