Make the build script directly output TTF
This commit is contained in:
parent
de804c206a
commit
54c5cc6be0
2 changed files with 30 additions and 24 deletions
|
@ -2,19 +2,22 @@
|
|||
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
const child_process = require("child_process");
|
||||
|
||||
const Toml = require("@iarna/toml");
|
||||
const which = require("which");
|
||||
|
||||
const BuildFont = require("./gen/build-font.js");
|
||||
const Parameters = require("./support/parameters");
|
||||
const FormVariantData = require("./support/variant-data");
|
||||
const FormLigationData = require("./support/ligation-data");
|
||||
const { createGrDisplaySheet } = require("./support/gr");
|
||||
const Toml = require("@iarna/toml");
|
||||
|
||||
module.exports = async function main(argv) {
|
||||
const para = await getParameters(argv);
|
||||
const { font, glyphStore } = BuildFont(para);
|
||||
if (argv.oCharMap) await saveCharMap(argv, glyphStore);
|
||||
if (argv.o) await saveOtd(argv, font);
|
||||
if (argv.o) await saveTTF(argv, font);
|
||||
};
|
||||
|
||||
// Parameter preparation
|
||||
|
@ -31,7 +34,7 @@ async function getParameters(argv) {
|
|||
await tryParseToml(PARAMETERS_TOML),
|
||||
await tryParseToml(WEIGHTS_TOML),
|
||||
await tryParseToml(WIDTHS_TOML),
|
||||
(await fs.exists(PRIVATE_TOML)) ? await tryParseToml(PRIVATE_TOML) : {}
|
||||
fs.existsSync(PRIVATE_TOML) ? await tryParseToml(PRIVATE_TOML) : {}
|
||||
);
|
||||
const rawVariantsData = await tryParseToml(VARIANTS_TOML);
|
||||
const rawLigationData = await tryParseToml(LIGATIONS_TOML);
|
||||
|
@ -80,22 +83,31 @@ async function tryParseToml(str) {
|
|||
}
|
||||
}
|
||||
|
||||
// Save OTD
|
||||
async function saveOtd(argv, font) {
|
||||
if (argv.o === "|") {
|
||||
process.stdout.write(JSON.stringify(font));
|
||||
} else {
|
||||
await fs.writeFile(argv.o, JSON.stringify(font, null, " "));
|
||||
}
|
||||
}
|
||||
|
||||
// Save char map
|
||||
function objHashNonEmpty(obj) {
|
||||
if (!obj) return false;
|
||||
for (let k in obj) if (obj[k]) return true;
|
||||
return false;
|
||||
// Save TTF
|
||||
async function saveTTF(argv, font) {
|
||||
await otfccBuild(argv.o, JSON.stringify(font));
|
||||
}
|
||||
function otfccBuild(argvO, fontJson) {
|
||||
const otfccOptions = ["-O3", "--keep-average-char-width", "-q"];
|
||||
return new Promise((resolve, reject) => {
|
||||
const otfccBuild = which.sync("otfccbuild");
|
||||
const cp = child_process.spawn(otfccBuild, ["-o", argvO, ...otfccOptions]);
|
||||
cp.stdout.on("data", data => {
|
||||
console.log(`stdout: ${data}`);
|
||||
});
|
||||
cp.stderr.on("data", data => {
|
||||
console.error(`stderr: ${data}`);
|
||||
});
|
||||
cp.on("close", code => {
|
||||
if (code) reject(new Error("OTFCC returned with: " + code));
|
||||
else resolve(0);
|
||||
});
|
||||
cp.stdin.write(fontJson);
|
||||
cp.stdin.end();
|
||||
});
|
||||
}
|
||||
|
||||
// Save character map file
|
||||
async function saveCharMap(argv, glyphStore) {
|
||||
let charMap = [];
|
||||
for (const [gn] of glyphStore.namedEntries()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue