Skip to content

Commit

Permalink
Building: support custom optimization filter
Browse files Browse the repository at this point in the history
  • Loading branch information
be5invis committed Jun 21, 2020
1 parent 43431f8 commit fbd8700
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Expand Up @@ -13,7 +13,6 @@
},
"extends": ["eslint:recommended", "prettier"],
"rules": {
"indent": ["error", "tab", { "SwitchCase": 1 }],
"semi": ["error", "always"],
"no-var": "error",
"no-console": 0,
Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "iosevka",
"version": "3.2.0",
"version": "3.2.1",
"main": "./generate.js",
"scripts": {
"build": "verda -f verdafile.js",
Expand All @@ -11,7 +11,7 @@
"ejs": "^3.1.3",
"fs-extra": "^9.0.0",
"object-assign": "^4.1.1",
"otfcc-ttcize": "^0.10.1",
"otfcc-ttcize": "^0.10.2",
"patel": "^0.33.1",
"semver": "^7.1.3",
"spiro": "^2.0.0",
Expand Down
33 changes: 27 additions & 6 deletions verdafile.js
Expand Up @@ -92,6 +92,10 @@ const OptimizeWithTtx = computed("metadata:optimize-with-ttx", async target => {
const [hasTtx, rp] = await target.need(HasTtx, RawPlans);
return hasTtx && !!rp.buildOptions.optimizeWithTtx;
});
const OptimizeWithFilter = computed("metadata:optimize-with-filter", async target => {
const [rp] = await target.need(RawPlans);
return rp.buildOptions.optimizeWithFilter;
});
const RawCollectPlans = computed("metadata:raw-collect-plans", async target => {
const [rp] = await target.need(RawPlans);
return rp.collectPlans;
Expand Down Expand Up @@ -392,7 +396,12 @@ function fnStandardTtc(collectConfig, prefix, w, wd, s) {
const BuildRawTtf = file.make(
(gr, fn) => `${BUILD}/${gr}/${fn}.raw.ttf`,
async (target, output, gr, fn) => {
const [fi, useTtx] = await target.need(FontInfoOf(fn), OptimizeWithTtx, Version);
const [fi] = await target.need(
FontInfoOf(fn),
Version,
OptimizeWithFilter,
OptimizeWithTtx
);
const charmap = output.dir + "/" + fn + ".charmap";
await target.need(Scripts, Parameters, de`${output.dir}`);
const otdPath = `${output.dir}/${output.name}.otd`;
Expand All @@ -405,11 +414,18 @@ const BuildRawTtf = file.make(
const BuildTTF = file.make(
(gr, fn) => `${BUILD}/${gr}/${fn}.ttf`,
async (target, output, gr, fn) => {
const [useTtx] = await target.need(OptimizeWithTtx, de`${output.dir}`);
const [useFilter, useTtx] = await target.need(
OptimizeWithFilter,
OptimizeWithTtx,
de`${output.dir}`
);
await target.needed(FontInfoOf(fn), Version, Scripts, Parameters);

const [rawTtf] = await target.order(BuildRawTtf(gr, fn));
if (useTtx) {
if (useFilter) {
const filterArgs = useFilter.split(/ +/g);
await run(filterArgs, rawTtf.full, output.full);
await rm(rawTtf.full);
} else if (useTtx) {
const ttxPath = `${output.dir}/${output.name}.temp.ttx`;
await run(TTX, "-q", ["-o", ttxPath], rawTtf.full);
await rm(rawTtf.full);
Expand Down Expand Up @@ -531,11 +547,16 @@ async function buildCompositeTtc(out, inputs) {
);
}
async function buildGlyfTtc(target, parts, out) {
const [useTtx] = await target.need(OptimizeWithTtx, de`${out.dir}`);
const [useFilter, useTtx] = await target.need(
OptimizeWithFilter,
OptimizeWithTtx,
de`${out.dir}`
);
const [ttfInputs] = await target.need(parts.map(part => BuildTTF(part.dir, part.file)));
const tmpTtc = `${out.dir}/${out.name}.unhinted.ttc`;
const ttfInputPaths = ttfInputs.map(p => p.full);
await run(TTCIZE, ttfInputPaths, ["-o", tmpTtc], useTtx ? "--ttx-loop" : null);
const optimization = useFilter ? ["--filter-loop", useFilter] : useTtx ? ["--ttx-loop"] : [];
await run(TTCIZE, optimization, ["-o", tmpTtc], ttfInputPaths);
await run("ttfautohint", tmpTtc, out.full);
await rm(tmpTtc);
}
Expand Down

0 comments on commit fbd8700

Please sign in to comment.