forked from be5invis/Sarasa-Gothic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bddy.js
292 lines (269 loc) · 8.69 KB
/
bddy.js
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
"use strict";
const fs = require("fs-extra");
const path = require("path");
const os = require("os");
function objToArgs(o) {
let a = [];
for (let k in o) {
if (o[k] === false) continue;
if (k.length === 1) {
a.push("-" + k);
} else {
a.push("--" + k);
}
if (o[k] !== true) {
a.push("" + o[k]);
}
}
return a;
}
async function runBuildTask(recipe, args) {
return await this.run("node", "run", "--recipe", recipe, ...objToArgs(args));
}
async function sanitize(target, ttf) {
const tmpTTX = `${ttf}.ttx`;
const tmpTTF2 = `${ttf}.2.ttf`;
await this.run("ttx", "-o", tmpTTX, ttf);
await this.run("ttx", "-o", tmpTTF2, tmpTTX);
await this.run("ttfautohint", tmpTTF2, target);
await this.rm(ttf, tmpTTX, tmpTTF2);
}
/// config loader
const config = fs.readJsonSync(__dirname + "/config.json");
const PREFIX = config.prefix;
const CVT_PADDING = config.CVT_PADDING;
const FAMILIES = config.familyOrder;
const SUBFAMILIES = config.subfamilyOrder;
const STYLES = config.styleOrder;
const version = fs.readJsonSync(path.resolve(__dirname, "package.json")).version;
function deItalizedNameOf(set) {
return (set + "")
.split("-")
.map(w => (config.styles[w] ? config.styles[w].uprightStyleMap || w : w))
.join("-");
}
module.exports = function(ctx, the) {
the.file(`out/ttf/${PREFIX}-*-*-*.ttf`).def(async function(target) {
const { $1: family, $2: region, $3: style } = target;
const [_, $1, $2] = await this.need(
target.dir,
`build/pass1/${family}-${region}-${style}.ttf`,
`hint/out/${region}-${deItalizedNameOf(style)}.ttf`
);
const tmpOTD = `${target.dir}/${target.name}.otd`;
await runBuildTask.call(this, "make/pass2/build.js", {
main: $1,
kanji: $2,
o: tmpOTD,
italize: deItalizedNameOf(style) === style ? false : true
});
await this.run("otfccbuild", tmpOTD, "-o", target, "--keep-average-char-width", "-O3");
await this.rm(tmpOTD);
});
the.file(`build/pass1/*-*-*.ttf`).def(async function(target) {
const { $1: family, $2: region, $3: style } = target;
const latinFamily = config.families[family].latinGroup;
const [_, $1, $2, $3] = await this.need(
target.dir,
`sources/${latinFamily}/${latinFamily}-${style}.ttf`,
`build/as0/${family}-${region}-${deItalizedNameOf(style)}.ttf`,
`build/ws0/${family}-${region}-${deItalizedNameOf(style)}.ttf`
);
await runBuildTask.call(this, "make/pass1/build.js", {
main: $1,
asian: $2,
ws: $3,
o: target + ".tmp.ttf",
family: family,
subfamily: config.subfamilies[region].name,
style: style,
italize: deItalizedNameOf(target.name) === target.name ? false : true
});
await sanitize.call(this, target, target + ".tmp.ttf");
});
the.file(`build/as0/*-*-*.ttf`).def(async function(target) {
const { $1: family, $2: region, $3: style } = target;
const [_, $1] = await this.need(target.dir, `build/shs/${region}-${style}.otd`);
const tmpOTD = `${target.dir}/${target.name}.otd`;
await runBuildTask.call(this, "make/punct/as.js", {
main: $1,
o: tmpOTD,
mono: config.families[family].isMono || false,
type: config.families[family].isType || false,
pwid: config.families[family].isPWID || false,
term: config.families[family].isTerm || false
});
await this.run("otfccbuild", tmpOTD, "-o", target, "-q");
await this.rm(tmpOTD);
});
the.file(`build/ws0/*-*-*.ttf`).def(async function(target) {
const { $1: family, $2: region, $3: style } = target;
const [_, $1] = await this.need(target.dir, `build/shs/${region}-${style}.otd`);
const tmpOTD = `${target.dir}/${target.name}.otd`;
await runBuildTask.call(this, "make/punct/ws.js", {
main: $1,
o: tmpOTD,
mono: config.families[family].isMono || false,
type: config.families[family].isType || false,
pwid: config.families[family].isPWID || false,
term: config.families[family].isTerm || false
});
await this.run("otfccbuild", tmpOTD, "-o", target, "-q");
await this.rm(tmpOTD);
});
// kanji tasks
the.file(`hint/out/*.ttf`).def(async function(target) {
await this.need("hint-finish");
});
the.virt("hint-finish").def(async function(target) {
await this.need("hint-start");
await this.cd("hint").runInteractive("node", "top", "hint");
});
the.virt("hint-visual").def(async function(target) {
await this.need("hint-start");
await this.cd("hint").runInteractive("node", "top", "visual");
});
the.virt("hint-start").def(async function(target) {
let dependents = [];
const wSet = new Set();
for (let st of STYLES) {
wSet.add(deItalizedNameOf(st));
}
const config = {
settings: {
do_ttfautohint: false,
cvt_padding: CVT_PADDING,
use_externalIDH: false,
use_VTTShell: false
},
fonts: []
};
for (let st of wSet)
for (let sf of SUBFAMILIES) {
dependents.push(`hint/source/fonts/${sf}-${st}.ttf`);
config.fonts.push({
input: `source/fonts/${sf}-${st}.ttf`,
param: `source/parameters/${st}.toml`,
allchar: true
});
}
await this.need(...dependents);
await fs.writeFile("hint/source/fonts.json", JSON.stringify(config, null, 2));
});
the.file(`hint/source/fonts/*.ttf`).def(async function(target) {
const [$1] = await this.need(`build/kanji0/${target.name}.ttf`);
await this.cp($1, target);
});
the.file(`build/kanji0/*.ttf`).def(async function(target) {
const [_, $1] = await this.need(target.dir, `build/shs/${target.name}.otd`);
const tmpOTD = `${target.dir}/${target.name}.otd`;
await runBuildTask.call(this, "make/kanji/build.js", {
main: $1,
o: tmpOTD
});
await this.run("otfccbuild", tmpOTD, "-o", target, "-q");
await this.rm(tmpOTD);
});
// SHS dumps
the.file(`build/shs/*.otd`).def(async function(target) {
const name = target.$1;
const [_, $1] = await this.need(target.dir, `sources/shs/${name}.otf`);
await this.run(`otfccdump`, `-o`, target, $1);
});
the.virt("ttf").def(async function(target) {
let reqs = [];
for (let f of FAMILIES)
for (let sf of SUBFAMILIES)
for (let st of STYLES) {
reqs.push(`out/ttf/${PREFIX}-${f}-${sf}-${st}.ttf`);
}
await this.need(...reqs);
});
// buildint TTC files
the.virt(`out/ttc/${PREFIX}-*-parts`).def(async function(target) {
const style = target.$1;
let reqs = [];
for (let f of FAMILIES)
for (let sf of SUBFAMILIES) {
reqs.push(`out/ttf/${PREFIX}-${f}-${sf}-${style}.ttf`);
}
const [$$] = await this.need(reqs);
const ttcize = "node_modules/.bin/otfcc-ttcize" + (os.platform() === "win32" ? ".cmd" : "");
await this.run(ttcize, ...["--prefix", `out/ttc/${PREFIX}-${style}-parts`], ...$$, [
"-k",
"-h"
]);
});
the.file(`out/ttc/${PREFIX}-*-parts.*.otd`).def(async function(target) {
await this.need(`out/ttc/${PREFIX}-${target.$1}-parts`);
});
the.file(`out/ttc/${PREFIX}-*-parts.*.ttf`).def(async function(target) {
const [$1] = await this.need(`${target.dir}/${target.name}.otd`);
await this.run(
"otfccbuild",
$1,
["-o", target],
["-k", "--subroutinize", "--keep-average-char-width"]
);
});
the.file(`out/ttc/${PREFIX}-*.ttc`).def(async function(target) {
const style = target.$1;
await this.check(target.dir);
{
let reqs = [];
for (let f of FAMILIES)
for (let sf of SUBFAMILIES) {
reqs.push(`out/ttf/${PREFIX}-${f}-${sf}-${style}.ttf`);
}
await this.need(...reqs);
}
{
let reqs = [],
n = 0;
for (let f of FAMILIES)
for (let sf of SUBFAMILIES) {
reqs.push(`out/ttc/${PREFIX}-${style}-parts.${n}.ttf`);
n += 1;
}
const [_, $$] = await this.need(target.dir, reqs);
await this.run(`otf2otc`, ["-o", target], $$);
for (let r of $$) {
await this.rm(r, `${r.dir}/${r.name}.otd`);
}
}
});
// ttc virtual target
the.virt("ttc").def(async function(target) {
await this.need(...STYLES.map(st => `out/ttc/${PREFIX}-${st}.ttc`));
});
the.file(`out/sarasa-gothic-ttc-${version}.7z`).def(async function(target) {
await this.need(`ttc`);
await this.cd(`out/ttc`).run(
`7z`,
`a`,
`-t7z`,
`-mmt=on`,
`-m0=LZMA:a=0:d=1536m:fb=256`,
`../${target.name}.7z`,
`*.ttc`
);
});
the.file(`out/sarasa-gothic-ttf-${version}.7z`).def(async function(target) {
await this.need(`ttf`);
await this.cd(`out/ttf`).run(
`7z`,
`a`,
`-t7z`,
`-mmt=on`,
`-m0=LZMA:a=0:d=1536m:fb=256`,
`../${target.name}.7z`,
`*.ttf`
);
});
ctx.want(`out/sarasa-gothic-ttc-${version}.7z`);
ctx.want(`out/sarasa-gothic-ttf-${version}.7z`);
// cleanup
the.virt("clean").def(async function(target) {
await this.rm(`build`, `out`, `hint/source/fonts`, `hint/out`);
});
};