Skip to content

Commit

Permalink
Merge branch 'master' into releases
Browse files Browse the repository at this point in the history
  • Loading branch information
be5invis committed Nov 2, 2019
2 parents 2eba95e + 8509372 commit de1eb20
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 14 deletions.
27 changes: 27 additions & 0 deletions make/non-kanji/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use strict";

const { introduce, build, gc } = require("megaminx");
const { isIdeograph, isKorean, filterUnicodeRange } = require("../common/unicode-kind");

async function pass(ctx, config, argv) {
const a = await ctx.run(introduce, "a", {
from: argv.main,
prefix: "a",
ignoreHints: true
});
filterUnicodeRange(a, c => !isIdeograph(c) && !isKorean(c));
a.cvt_ = [];
a.fpgm = [];
a.prep = [];
if (!config.loclFeature) {
a.GSUB = null;
a.GPOS = null;
}
await ctx.run(gc, "a");
await ctx.run(build, "a", { to: config.o, optimize: true });
ctx.remove("a");
}

module.exports = async function makeFont(ctx, config, argv) {
await pass(ctx, { o: argv.o }, argv);
};
10 changes: 9 additions & 1 deletion make/punct/as.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ const {
isKorean,
filterUnicodeRange
} = require("../common/unicode-kind");
const { sanitizeSymbols, removeUnusedFeatures, toPWID } = require("./common");
const {
sanitizeSymbols,
removeUnusedFeatures,
toPWID,
removeDashCcmp,
buildNexusDash
} = require("./common");

module.exports = async function makeFont(ctx, config, argv) {
const a = await ctx.run(introduce, "a", {
Expand All @@ -31,6 +37,8 @@ module.exports = async function makeFont(ctx, config, argv) {
}
if (argv.mono) {
await ctx.run(manip.glyph, "a", sanitizeSymbols, argv.type);
removeDashCcmp(ctx.items.a, argv.mono);
await ctx.run(manip.glyph, "a", buildNexusDash);
}
removeUnusedFeatures(ctx.items.a, argv.mono);
await ctx.run(gc, "a", { ignoreAltSub: true });
Expand Down
96 changes: 96 additions & 0 deletions make/punct/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,70 @@ exports.sanitizeSymbols = async function sanitizeSymbols(isType) {
}
};

exports.buildNexusDash = async function() {
let gidCovered = new Set();
for (const u of [0x2013, 0x2014, 0x2015]) {
const gn = this.find.gname.unicode(u);
if (gn) gidCovered.add(gn);
}

const nexusLookupName = "ccmp__nexusDash";
let nexusLookupSubst = {};
const nexusLookup = { type: "gsub_single", subtables: [nexusLookupSubst] };
const nexusChainingLookupName = "ccmp__nexusDash_chaining";
let nexusChainingRules = [];
const nexusChainingLookup = { type: "gsub_chaining", subtables: nexusChainingRules };

for (const originalGid of gidCovered) {
const glyph = createNexusGlyph(this.find.glyph$(originalGid));
const nexusGid = originalGid + ".nexus";
await this.save.to(nexusGid, null, glyph);
nexusLookupSubst[originalGid] = nexusGid;
nexusChainingRules.push({
match: [[originalGid, nexusGid], [originalGid]],
apply: [{ lookup: nexusLookupName, at: 1 }],
inputBegins: 1,
inputEnds: 2
});
}

if (this.font.GSUB) {
this.font.GSUB.lookups[nexusLookupName] = nexusLookup;
this.font.GSUB.lookups[nexusChainingLookupName] = nexusChainingLookup;

for (const fid in this.font.GSUB.features) {
if (fid.slice(0, 4) !== "ccmp") continue;
const feature = this.font.GSUB.features[fid];
if (!feature) continue;
feature.push(nexusChainingLookupName);
}
}
};

function createNexusGlyph(glyph) {
let xMax = -0xffff,
xMin = 0xffff;
if (glyph.contours) {
for (let c of glyph.contours) {
for (let z of c) {
if (z.x > xMax) xMax = z.x;
if (z.x < xMin) xMin = z.x;
}
}
}
const rsb = glyph.advanceWidth - xMax;
const negMin = rsb * 1.5;
const scaling = (xMax + rsb * 1.5) / (xMax - xMin);
if (glyph.contours) {
for (let c of glyph.contours) {
for (let z of c) {
z.x = (z.x - xMin) * scaling - negMin;
}
}
}
return glyph;
}

function removeUnusedFeature(table, tag) {
if (!table) return;
for (let f in table.features) {
Expand All @@ -124,6 +188,38 @@ exports.removeUnusedFeatures = function(a, mono) {
}
};

exports.removeDashCcmp = function(a, mono) {
if (!a.GSUB || !a.GSUB.features || !a.GSUB.lookups) return;

let affectedLookups = new Set();
for (const fid in a.GSUB.features) {
if (fid.slice(0, 4) === "ccmp") {
const feature = a.GSUB.features[fid];
if (!feature) continue;
for (const lid of feature) affectedLookups.add(lid);
}
}

for (const lid of affectedLookups) {
const lookup = a.GSUB.lookups[lid];
removeDashCcmpLookup(lookup, a.cmap);
}
};
function removeDashCcmpLookup(lookup, cmap) {
if (!lookup || lookup.type !== "gsub_ligature") return;
for (const st of lookup.subtables) {
let st1 = [];
for (const subst of st.substitutions) {
let valid = true;
for (const gid of subst.from) {
if (cmap[0x2014] === gid || cmap[0x2015] === gid) valid = false;
}
if (valid) st1.push(subst);
}
st.substitutions = st1;
}
}

exports.toPWID = async function() {
const font = this.font;
for (let c in font.cmap) {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "sarasa-gothic",
"version": "0.9.2",
"version": "0.10.1",
"main": "./run",
"dependencies": {
"@chlorophytum/cli": "^0.3.0",
"@chlorophytum/cli": "^0.3.5",
"@chlorophytum/final-hint-format-hltt": "^0.3.0",
"@chlorophytum/font-format-otd": "^0.3.0",
"@chlorophytum/hint-store-provider-file": "^0.3.0",
Expand All @@ -17,7 +17,7 @@
"yargs": "^9.0.0"
},
"engines": {
"node": ">=8.5.0"
"node": ">=12.0.0"
},
"scripts": {
"install": "node checkenv",
Expand Down
36 changes: 26 additions & 10 deletions verdafile.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const OTFCCDUMP = `otfccdump`;
const OTFCCBUILD = `otfccbuild`;
const OTF2TTF = `otf2ttf`;

const NPX_SUFFIX = os.platform() === "win32" ? ".cmd" : "";
const TTCIZE = "node_modules/.bin/otfcc-ttcize" + NPX_SUFFIX;
const Chlorophytum = [NODEJS, `./node_modules/@chlorophytum/cli/bin/_startup`];

///////////////////////////////////////////////////////////////////////////////////////////////////
// Entrypoint
const Start = phony("all", async t => {
Expand Down Expand Up @@ -106,11 +110,25 @@ const ShsOtd = file.make(
}
);

const NonKanji = file.make(
(region, style) => `${BUILD}/non-kanji0/${region}-${style}.ttf`,
async (t, { full, dir, name }, region, style) => {
await t.need(Config, Scripts);
const [$1] = await t.need(ShsOtd(region, style), de(dir));
const tmpOTD = `${dir}/${name}.otd`;
await RunFontBuildTask("make/non-kanji/build.js", {
main: $1.full,
o: tmpOTD
});
await OtfccBuildAsIs(tmpOTD, full);
}
);

const WS0 = file.make(
(family, region, style) => `${BUILD}/ws0/${family}-${region}-${style}.ttf`,
async (t, { full, dir, name }, family, region, style) => {
const [config] = await t.need(Config, Scripts);
const [, $1] = await t.need(de(dir), ShsOtd(region, style));
const [, $1] = await t.need(de(dir), NonKanji(region, style));
const tmpOTD = `${dir}/${name}.otd`;
await RunFontBuildTask("make/punct/ws.js", {
main: $1.full,
Expand All @@ -128,7 +146,7 @@ const AS0 = file.make(
(family, region, style) => `${BUILD}/as0/${family}-${region}-${style}.ttf`,
async (t, { full, dir, name }, family, region, style) => {
const [config] = await t.need(Config, Scripts);
const [, $1] = await t.need(de(dir), ShsOtd(region, style));
const [, $1] = await t.need(de(dir), NonKanji(region, style));
const tmpOTD = `${dir}/${name}.otd`;
await RunFontBuildTask("make/punct/as.js", {
main: $1.full,
Expand All @@ -142,6 +160,10 @@ const AS0 = file.make(
}
);

task("as-mono-sc-regular", async $ => {
await $.need(AS0("mono", "sc", "regular"));
});

const Pass1 = file.make(
(family, region, style) => `${BUILD}/pass1/${family}-${region}-${style}.ttf`,
async (t, { full, dir, name }, family, region, style) => {
Expand Down Expand Up @@ -220,12 +242,7 @@ const Prod = file.make(

///////////////////////////////////////////////////////////////////////////////////////////////////
// HINTING
const Chlorophytum = [
NODEJS,
`--experimental-worker`,
`--max-old-space-size=8192`,
`./node_modules/@chlorophytum/cli/lib/index.js`
];

const HintDirPrefix = `${BUILD}/hf`;
const HintDirOutPrefix = `${BUILD}/hfo`;

Expand Down Expand Up @@ -385,9 +402,8 @@ const TTCFile = file.make(
}

const [$$] = await t.need(requirements.map(t => t.from));
const ttcize = "node_modules/.bin/otfcc-ttcize" + (os.platform() === "win32" ? ".cmd" : "");
await run(
ttcize,
TTCIZE,
["-x", "--common-width", 1000, "--common-height", 1000],
["-o", full],
[...$$.map(t => t.full)]
Expand Down

0 comments on commit de1eb20

Please sign in to comment.