parent
53a20618e1
commit
e19645da03
2 changed files with 11 additions and 26 deletions
|
@ -2,10 +2,8 @@
|
||||||
|
|
||||||
const fs = require("fs-extra");
|
const fs = require("fs-extra");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const child_process = require("child_process");
|
|
||||||
|
|
||||||
const Toml = require("@iarna/toml");
|
const Toml = require("@iarna/toml");
|
||||||
const which = require("which");
|
|
||||||
|
|
||||||
const BuildFont = require("./gen/build-font.js");
|
const BuildFont = require("./gen/build-font.js");
|
||||||
const Parameters = require("./support/parameters");
|
const Parameters = require("./support/parameters");
|
||||||
|
@ -17,7 +15,7 @@ module.exports = async function main(argv) {
|
||||||
const para = await getParameters(argv);
|
const para = await getParameters(argv);
|
||||||
const { font, glyphStore } = BuildFont(para);
|
const { font, glyphStore } = BuildFont(para);
|
||||||
if (argv.oCharMap) await saveCharMap(argv, glyphStore);
|
if (argv.oCharMap) await saveCharMap(argv, glyphStore);
|
||||||
if (argv.o) await saveTTF(argv, font);
|
if (argv.o) await saveOTD(argv, font);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parameter preparation
|
// Parameter preparation
|
||||||
|
@ -83,28 +81,9 @@ async function tryParseToml(str) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save TTF
|
// Save OTD
|
||||||
async function saveTTF(argv, font) {
|
async function saveOTD(argv, font) {
|
||||||
await otfccBuild(argv.o, JSON.stringify(font));
|
await fs.writeJSON(argv.o, 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
|
// Save character map file
|
||||||
|
|
|
@ -422,9 +422,15 @@ const BuildRawTtf = file.make(
|
||||||
const [fi] = await target.need(FontInfoOf(fn), Version);
|
const [fi] = await target.need(FontInfoOf(fn), Version);
|
||||||
const charmap = output.dir + "/" + fn + ".charmap";
|
const charmap = output.dir + "/" + fn + ".charmap";
|
||||||
await target.need(Scripts, Parameters, de`${output.dir}`);
|
await target.need(Scripts, Parameters, de`${output.dir}`);
|
||||||
await node("font-src/index", { o: output.full, oCharMap: charmap, ...fi });
|
const otdPath = `${output.dir}/${output.name}.otd`;
|
||||||
|
await node("font-src/index", { o: otdPath, oCharMap: charmap, ...fi });
|
||||||
|
await optimizedOtfcc(otdPath, output.full);
|
||||||
|
await rm(otdPath);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
function optimizedOtfcc(from, to) {
|
||||||
|
return run(OTFCC_BUILD, from, ["-o", `${to}`], ["-O3", "--keep-average-char-width", "-q"]);
|
||||||
|
}
|
||||||
|
|
||||||
const BuildTTF = file.make(
|
const BuildTTF = file.make(
|
||||||
(gr, fn) => `${BUILD}/ttf/${gr}/${fn}.ttf`,
|
(gr, fn) => `${BUILD}/ttf/${gr}/${fn}.ttf`,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue