Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
be5invis committed Dec 26, 2020
2 parents 1f3ea22 + 38a85b2 commit 29c557e
Show file tree
Hide file tree
Showing 333 changed files with 181 additions and 189 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"codemetrics.basics.EnabledForJS": false,
"cSpell.enabled": false
"cSpell.enabled": false,
"search.useGlobalIgnoreFiles": true
}
5 changes: 4 additions & 1 deletion make/common/unicode-kind.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ exports.isKorean = c =>
(c >= 0xd7b0 && c <= 0xd7ff);

exports.isWS = function (c) {
return c >= 0x20a0 && c < 0x3000 && !(c >= 0x2e3a && c <= 0x2e3b);
return (
((c >= 0x2000 && c <= 0x200f) || (c >= 0x20a0 && c < 0x3000)) &&
!(c >= 0x2e3a && c <= 0x2e3b)
);
};

exports.isLongDash = function (c, isTerm) {
Expand Down
126 changes: 53 additions & 73 deletions make/punct/as.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,91 +2,38 @@

const introFont = require("../common/intro-font");
const buildFont = require("../common/build-font");
const {
isIdeograph,
isWestern,
isWS,
isKorean,
isLongDash,
filterUnicodeRange
} = require("../common/unicode-kind");
const { sanitizeSymbols, removeUnusedFeatures, toPWID, removeDashCcmp } = require("./common");
const { isWestern, isWS, isLongDash, filterUnicodeRange } = require("../common/unicode-kind");
const gc = require("../common/gc");
const createFinder = require("../common/glyph-finder");

const { sanitizeSymbols, toPWID } = require("./sanitize-symbols");
const { removeUnusedFeatures } = require("./remove-unused-features");
const { transferMonoGeometry, unlinkRefsOfSymbols, populatePwidOfMono } = require("./lgc-handler");

module.exports = async function makeFont(argv) {
const a = await introFont({ from: argv.main, prefix: "a", ignoreHints: true });
const b = await introFont({ from: argv.lgc, prefix: "b", ignoreHints: true });
a.cmap_uvs = null;
const main = await introFont({ from: argv.main, prefix: "a", ignoreHints: true });
const lgc = await introFont({ from: argv.lgc, prefix: "b", ignoreHints: true });
main.cmap_uvs = null;
filterUnicodeRange(
a,
c =>
!isIdeograph(c - 0) &&
!isWestern(c - 0) &&
!isKorean(c - 0) &&
!isLongDash(c - 0, argv.term) &&
!isWS(c - 0)
main,
c => !isWestern(c - 0) && !isLongDash(c - 0, argv.term) && !isWS(c - 0)
);

if (argv.pwid) toPWID(a);

if (argv.pwid) toPWID(main);
if (argv.mono) {
unlinkRefsOfSymbols(b, argv.term);
transferMonoGeometry(a, b);
populatePwidOfMono(a);
unlinkRefsOfSymbols(lgc, argv.term);
transferMonoGeometry(main, lgc);
populatePwidOfMono(main);
}
if (!argv.pwid) sanitizeSymbols(a, argv.goth, !argv.pwid && !argv.term);
if (argv.mono) removeDashCcmp(a, argv.mono);
if (!argv.pwid) sanitizeSymbols(main, argv.goth, !argv.pwid && !argv.term);
if (argv.mono) removeDashCcmp(main, argv.mono);

removeUnusedFeatures(a, "AS", argv.mono);
aliasFeatMap(a, "vert", [[0x2014, 0x2015]]);
gc(a);
removeUnusedFeatures(main, "AS", argv.mono);
aliasFeatMap(main, "vert", [[0x2014, 0x2015]]);
gc(main);

await buildFont(a, { to: argv.o, optimize: true });
await buildFont(main, { to: argv.o, optimize: true });
};

// Monospace punctuation transferring
function unlinkRefsOfSymbols(font, isTerm) {
const find = createFinder(font);
for (let u = 0x2000; u < 0x20a0; u++) {
let gn = find.gname.unicode(u);
if (!gn) continue;
let gnT = gn;
if (!isTerm) gnT = find.gname.subst("WWID", gn);
if (!gnT) continue;
const g = find.glyph(gn);
const g$ = find.glyph$(gnT);
HCopy(g, g$);
}
}
function transferMonoGeometry(main, lgc) {
for (let u = 0x2000; u < 0x20a0; u++) {
let gnSrc = main.cmap[u],
gnDst = lgc.cmap[u];
if (gnSrc && gnDst) {
HCopy(main.glyf[gnSrc], lgc.glyf[gnDst]);
}
}
}
function populatePwidOfMono(font) {
const find = createFinder(font);
for (let u = 0x2000; u < 0x20a0; u++) {
const gn = find.gname.unicode(u);
if (!gn) continue;
const gnPwid = find.gname.subst("pwid", gn);
if (!gnPwid) continue;
const g = find.glyph(gnPwid);
const g$ = find.glyph$(gn);
HCopy(g, g$);
}
}

function HCopy(g, g1) {
g.contours = g1.contours;
g.references = g1.references;
g.advanceWidth = g1.advanceWidth;
}

// Feature mapping
function aliasFeatMap(a, feat, aliases) {
if (!a.GSUB || !a.GSUB.features || !a.GSUB.lookups) return;
Expand All @@ -113,3 +60,36 @@ function aliasFeatMap(a, feat, aliases) {
}
}
}

// Dash CCMP removal
function removeDashCcmp(a) {
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;
}
}
47 changes: 47 additions & 0 deletions make/punct/lgc-handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"use strict";

const createFinder = require("../common/glyph-finder");

// LGC transferring
exports.unlinkRefsOfSymbols = function (font, isTerm) {
const find = createFinder(font);
for (let u = 0x2000; u < 0x20a0; u++) {
let gn = find.gname.unicode(u);
if (!gn) continue;
let gnT = gn;
if (!isTerm) gnT = find.gname.subst("WWID", gn);
if (!gnT) continue;
const g = find.glyph(gn);
const g$ = find.glyph$(gnT);
HCopy(g, g$);
}
};

exports.transferMonoGeometry = function (main, lgc) {
for (let u = 0x2000; u < 0x20a0; u++) {
let gnSrc = main.cmap[u],
gnDst = lgc.cmap[u];
if (gnSrc && gnDst) {
HCopy(main.glyf[gnSrc], lgc.glyf[gnDst]);
}
}
};

exports.populatePwidOfMono = function (font) {
const find = createFinder(font);
for (let u = 0x2000; u < 0x20a0; u++) {
const gn = find.gname.unicode(u);
if (!gn) continue;
const gnPwid = find.gname.subst("pwid", gn);
if (!gnPwid) continue;
const g = find.glyph(gnPwid);
const g$ = find.glyph$(gn);
HCopy(g, g$);
}
};

function HCopy(g, g1) {
g.contours = g1.contours;
g.references = g1.references;
g.advanceWidth = g1.advanceWidth;
}
31 changes: 31 additions & 0 deletions make/punct/remove-unused-features.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"use strict";

exports.removeUnusedFeatures = function (a, kind, mono) {
removeUnusedFeature(a.GSUB, "aalt");
removeUnusedFeature(a.GSUB, "pwid");
removeUnusedFeature(a.GSUB, "fwid");
removeUnusedFeature(a.GSUB, "hwid");
removeUnusedFeature(a.GSUB, "twid");
removeUnusedFeature(a.GSUB, "qwid");

if (mono) {
removeUnusedFeature(a.GSUB, "locl");
removeUnusedFeature(a.GPOS, "kern");
removeUnusedFeature(a.GPOS, "vkrn");
removeUnusedFeature(a.GPOS, "palt");
removeUnusedFeature(a.GPOS, "vpal");
}

if (mono && kind === "WS") {
removeUnusedFeature(a.GSUB, "ccmp");
}
};

function removeUnusedFeature(table, tag) {
if (!table) return;
for (let f in table.features) {
if (f.slice(0, 4) === tag) {
table.features[f] = null;
}
}
}
62 changes: 0 additions & 62 deletions make/punct/common.js → make/punct/sanitize-symbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,68 +109,6 @@ exports.sanitizeSymbols = function sanitizeSymbols(font, isGothic, isType) {
}
};

function removeUnusedFeature(table, tag) {
if (!table) return;
for (let f in table.features) {
if (f.slice(0, 4) === tag) {
table.features[f] = null;
}
}
}

exports.removeUnusedFeatures = function (a, kind, mono) {
removeUnusedFeature(a.GSUB, "aalt");
removeUnusedFeature(a.GSUB, "pwid");
removeUnusedFeature(a.GSUB, "fwid");
removeUnusedFeature(a.GSUB, "hwid");
removeUnusedFeature(a.GSUB, "twid");
removeUnusedFeature(a.GSUB, "qwid");

if (mono) {
removeUnusedFeature(a.GSUB, "locl");
removeUnusedFeature(a.GPOS, "kern");
removeUnusedFeature(a.GPOS, "vkrn");
removeUnusedFeature(a.GPOS, "palt");
removeUnusedFeature(a.GPOS, "vpal");
}

if (mono && kind === "WS") {
removeUnusedFeature(a.GSUB, "ccmp");
}
};

exports.removeDashCcmp = function (a) {
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 = function (font) {
const find = createFinder(font);
for (let c in font.cmap) {
Expand Down
46 changes: 23 additions & 23 deletions make/punct/ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@

const introFont = require("../common/intro-font");
const buildFont = require("../common/build-font");
const {
isIdeograph,
isWestern,
isWS,
isKorean,
isLongDash,
filterUnicodeRange
} = require("../common/unicode-kind");
const { sanitizeSymbols, removeUnusedFeatures, toPWID } = require("./common");
const { isWestern, isWS, isLongDash, filterUnicodeRange } = require("../common/unicode-kind");
const gc = require("../common/gc");

const { sanitizeSymbols, toPWID } = require("./sanitize-symbols");
const { removeUnusedFeatures } = require("./remove-unused-features");
const { transferMonoGeometry, unlinkRefsOfSymbols, populatePwidOfMono } = require("./lgc-handler");

module.exports = async function makeFont(argv) {
const a = await introFont({ from: argv.main, prefix: "a", ignoreHints: true });
a.cmap_uvs = null;
const main = await introFont({ from: argv.main, prefix: "a", ignoreHints: true });
const lgc = await introFont({ from: argv.lgc, prefix: "b", ignoreHints: true });

main.cmap_uvs = null;
filterUnicodeRange(
a,
c =>
!isIdeograph(c - 0) &&
!isWestern(c - 0) &&
!isKorean(c - 0) &&
!isLongDash(c - 0, argv.term) &&
isWS(c - 0)
main,
c => !isWestern(c - 0) && !isLongDash(c - 0, argv.term) && isWS(c - 0)
);

if (argv.pwid) toPWID(a);
if (argv.mono) sanitizeSymbols(a, argv.goth, !argv.pwid && !argv.term);
if (argv.pwid) toPWID(main);
if (argv.mono) {
unlinkRefsOfSymbols(lgc, argv.term);
transferMonoGeometry(main, lgc);
populatePwidOfMono(main);
}
if (!argv.pwid) {
sanitizeSymbols(main, argv.goth, !argv.pwid && !argv.term);
}

removeUnusedFeatures(a, "WS", argv.mono);
gc(a);
removeUnusedFeatures(main, "WS", argv.mono);
gc(main);

await buildFont(a, { to: argv.o, optimize: true });
await buildFont(main, { to: argv.o, optimize: true });
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sarasa-gothic",
"version": "0.16.2",
"version": "0.16.3",
"main": "./run",
"scripts": {
"build": "verda -f verdafile.js",
Expand Down
Loading

0 comments on commit 29c557e

Please sign in to comment.