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 5, 2020
2 parents af7135f + e96db79 commit 0fc1f04
Show file tree
Hide file tree
Showing 331 changed files with 120 additions and 73 deletions.
10 changes: 4 additions & 6 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"familyOrder": ["gothic", "ui", "mono", "mono-slab", "term", "term-slab", "fixed", "fixed-slab"],
"families": {
"gothic": {
"isMono": false,
"isTNUM": true,
"isGothic": true,
"latinGroup": "Inter",
"naming": {
"en_US": "Sarasa Gothic",
Expand All @@ -16,9 +16,8 @@
}
},
"ui": {
"isPWID": true,
"isTNUM": true,
"isMono": false,
"isPWID": true,
"latinGroup": "Inter",
"naming": {
"en_US": "Sarasa UI",
Expand All @@ -31,7 +30,6 @@
},
"mono": {
"isMono": true,
"isType": true,
"latinGroup": "iosevka",
"naming": {
"en_US": "Sarasa Mono",
Expand All @@ -44,8 +42,8 @@
},
"term": {
"isMono": true,
"latinGroup": "iosevka-term",
"isTerm": true,
"latinGroup": "iosevka-term",
"naming": {
"en_US": "Sarasa Term",
"zh_CN": "Sarasa Term",
Expand All @@ -57,8 +55,8 @@
},
"fixed": {
"isMono": true,
"latinGroup": "iosevka-fixed",
"isTerm": true,
"latinGroup": "iosevka-fixed",
"naming": {
"en_US": "Sarasa Fixed",
"zh_CN": "Sarasa Fixed",
Expand Down
4 changes: 2 additions & 2 deletions make/common/unicode-kind.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ exports.isKorean = c =>
(c >= 0xa960 && c <= 0xa97f) ||
(c >= 0xd7b0 && c <= 0xd7ff);

exports.isWS = function (c, _isType = false, isTerm = false) {
return c >= (isTerm ? 0x2000 : 0x20a0) && c < 0x3000 && !(c >= 0x2e3a && c <= 0x2e3b);
exports.isWS = function (c) {
return c >= 0x20a0 && c < 0x3000 && !(c >= 0x2e3a && c <= 0x2e3b);
};

exports.isLongDash = function (c, isTerm) {
Expand Down
93 changes: 79 additions & 14 deletions make/punct/as.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,12 @@ const {
isLongDash,
filterUnicodeRange
} = require("../common/unicode-kind");
const {
sanitizeSymbols,
removeUnusedFeatures,
toPWID,
removeDashCcmp,
aliasFeatMap
} = require("./common");
const { sanitizeSymbols, removeUnusedFeatures, toPWID, removeDashCcmp } = require("./common");
const gc = require("../common/gc");

module.exports = async function makeFont(ctx, config, argv) {
const a = await ctx.run(introduce, "a", {
from: argv.main,
prefix: "a",
ignoreHints: true
});
const a = await ctx.run(introduce, "a", { from: argv.main, prefix: "a", ignoreHints: true });
const b = await ctx.run(introduce, "b", { from: argv.lgc, prefix: "b", ignoreHints: true });
a.cmap_uvs = null;
filterUnicodeRange(
a,
Expand All @@ -32,14 +23,21 @@ module.exports = async function makeFont(ctx, config, argv) {
!isWestern(c - 0) &&
!isKorean(c - 0) &&
!isLongDash(c - 0, argv.term) &&
!isWS(c - 0, argv.type, argv.term)
!isWS(c - 0)
);

if (argv.pwid) {
await ctx.run(manip.glyph, "a", toPWID);
}
if (argv.mono) {
await ctx.run(manip.glyph, "a", sanitizeSymbols, argv.type);
await ctx.run(manip.glyph, "b", unlinkRefsOfSymbols, argv.term);
transferMonoGeometry(ctx.items.a, ctx.items.b);
await ctx.run(manip.glyph, "a", populatePwidOfMono);
}
if (!argv.pwid) {
await ctx.run(manip.glyph, "a", sanitizeSymbols, argv.goth, !argv.pwid && !argv.term);
}
if (argv.mono) {
removeDashCcmp(ctx.items.a, argv.mono);
}
removeUnusedFeatures(ctx.items.a, "AS", argv.mono);
Expand All @@ -49,3 +47,70 @@ module.exports = async function makeFont(ctx, config, argv) {
await ctx.run(build, "a", { to: argv.o, optimize: true });
ctx.remove("a");
};

// Monospace punctuation transferring
function unlinkRefsOfSymbols(isTerm) {
for (let u = 0x2000; u < 0x20a0; u++) {
let gn = this.find.gname.unicode(u);
if (!gn) continue;
let gnT = gn;
if (!isTerm) gnT = this.find.gname.subst("WWID", gn);
if (!gnT) continue;
const g = this.find.glyph(gn);
const g$ = this.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() {
for (let u = 0x2000; u < 0x20a0; u++) {
const gn = this.find.gname.unicode(u);
if (!gn) continue;
const gnPwid = this.find.gname.subst("pwid", gn);
if (!gnPwid) continue;
const g = this.find.glyph(gnPwid);
const g$ = this.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;
for (const [uFrom, uTo] of aliases) {
const gidFrom = a.cmap[uFrom],
gidTo = a.cmap[uTo];
if (!gidFrom || !gidTo) continue;

let affectedLookups = new Set();
for (const fid in a.GSUB.features) {
if (fid.slice(0, 4) === feat) {
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];
if (lookup.type !== "gsub_single") continue;
for (const subtable of lookup.subtables) {
subtable[gidFrom] = subtable[gidTo];
}
}
}
}
44 changes: 12 additions & 32 deletions make/punct/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,33 @@ sanitizers.half = function (glyph) {
glyph.advanceWidth = targetW;
return glyph;
};
sanitizers.halfLeft = function (glyph, gid) {
sanitizers.halfLeft = function (glyph, gid, isGothic) {
const g1 = sanitizers.half.call(this, this.find.glyph$(this.find.gname.subst("pwid", gid)));
Object.assign(glyph, g1);
deleteGPOS(this.font, gid);
if (isGothic) glyph.advanceWidth = this.em;
return glyph;
};
sanitizers.halfRight = function (glyph, gid) {
sanitizers.halfRight = function (glyph, gid, isGothic) {
const g1 = sanitizers.half.call(this, this.find.glyph$(this.find.gname.subst("pwid", gid)));
Object.assign(glyph, g1);
deleteGPOS(this.font, gid);
if (isGothic) {
glyph.advanceWidth = this.em;
for (let c of glyph.contours) for (let z of c) z.x += this.em / 2;
}
return glyph;
};

function HalfCompN(n, forceFullWidth, forceHalfWidth) {
return function (glyph, gid, isType = false) {
return function (glyph, gid, isGothic, isType) {
const g1 = this.find.glyph$(this.find.gname.subst("fwid", gid));
Object.assign(glyph, g1);
const targetW = Math.min(
this.em * n,
Math.ceil(glyph.advanceWidth / this.em) *
(this.em * (forceHalfWidth ? 1 / 2 : isType || forceFullWidth ? 1 : 1 / 2))
(this.em *
(forceHalfWidth ? 1 / 2 : isGothic || isType || forceFullWidth ? 1 : 1 / 2))
);
if (glyph.contours) {
for (let c of glyph.contours) for (let z of c) z.x *= targetW / glyph.advanceWidth;
Expand Down Expand Up @@ -83,7 +89,7 @@ const sanitizerTypes = {
"\u2e3b": "halfComp3"
};

exports.sanitizeSymbols = async function sanitizeSymbols(isType) {
exports.sanitizeSymbols = async function sanitizeSymbols(isGothic, isType) {
let san = new Map();
for (let c in this.font.cmap) {
if (!this.font.cmap[c]) continue;
Expand All @@ -94,7 +100,7 @@ exports.sanitizeSymbols = async function sanitizeSymbols(isType) {
let sanitizer = sanitizers[san.has(g) ? san.get(g) : "auto"];
const glyph = this.font.glyf[g];
if (!glyph) continue;
sanitizer.call(this, glyph, g, isType);
sanitizer.call(this, glyph, g, isGothic, isType);
}
};

Expand Down Expand Up @@ -168,29 +174,3 @@ exports.toPWID = async function () {
font.cmap[c] = this.find.gname.subst("pwid", font.cmap[c]);
}
};

exports.aliasFeatMap = function (a, feat, aliases) {
if (!a.GSUB || !a.GSUB.features || !a.GSUB.lookups) return;
for (const [uFrom, uTo] of aliases) {
const gidFrom = a.cmap[uFrom],
gidTo = a.cmap[uTo];
if (!gidFrom || !gidTo) continue;

let affectedLookups = new Set();
for (const fid in a.GSUB.features) {
if (fid.slice(0, 4) === feat) {
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];
if (lookup.type !== "gsub_single") continue;
for (const subtable of lookup.subtables) {
subtable[gidFrom] = subtable[gidTo];
}
}
}
};
4 changes: 2 additions & 2 deletions make/punct/ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ module.exports = async function makeFont(ctx, config, argv) {
!isWestern(c - 0) &&
!isKorean(c - 0) &&
!isLongDash(c - 0, argv.term) &&
isWS(c - 0, argv.type, argv.term)
isWS(c - 0)
);

if (argv.pwid) {
await ctx.run(manip.glyph, "a", toPWID);
}
if (argv.mono) {
await ctx.run(manip.glyph, "a", sanitizeSymbols, argv.type);
await ctx.run(manip.glyph, "a", sanitizeSymbols, argv.goth, !argv.pwid && !argv.term);
}
removeUnusedFeatures(ctx.items.a, "WS", argv.mono);
gc(ctx.items.a);
Expand Down
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.15.3",
"version": "0.15.4",
"main": "./run",
"dependencies": {
"@chlorophytum/cli": "^0.20.0",
Expand Down
Loading

0 comments on commit 0fc1f04

Please sign in to comment.