Skip to content

Commit

Permalink
Release 0.37.2
Browse files Browse the repository at this point in the history
  • Loading branch information
be5invis committed Sep 17, 2022
2 parents 5dbe085 + 4d0c976 commit 1687473
Show file tree
Hide file tree
Showing 329 changed files with 127 additions and 43 deletions.
89 changes: 82 additions & 7 deletions make/common/gc.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,90 @@
"use strict";

export default (function gcFont(font, cfg) {
simplifyFeatureMap(font.GSUB);
markSweepOtl(font.GSUB);
simplifyFeatureMap(font.GPOS);
markSweepOtl(font.GPOS);

const glyphSink = markGlyphs(font, cfg);
sweepGlyphs(font, glyphSink);
return [...glyphSink].sort((a, b) => a[1] - b[1]).map(x => x[0]);
});

///////////////////////////////////////////////////////////////////////////////////////////////////

function simplifyFeatureMap(table) {
if (!table || !table.features || !table.lookups) return;

const uniqueLookupListMap = new Map();

const mergedFeatures = {};
const knownLanguages = Object.keys(table.languages).sort();

for (let lid of knownLanguages) {
if (!table.languages[lid]) continue;
const lang = JSON.parse(JSON.stringify(table.languages[lid]));
table.languages[lid] = lang;

let flattenFeatureTagMap_Req = {};
let flattenFeatureTagMap = {};
if (lang.requiredFeature) {
addFeatureToTagMap(flattenFeatureTagMap_Req, lang.requiredFeature, table);
}
if (lang.features) {
for (let f of lang.features) addFeatureToTagMap(flattenFeatureTagMap, f, table);
}

lang.requiredFeature = null;
for (let tag in flattenFeatureTagMap_Req) {
const lookups = [...new Set(flattenFeatureTagMap_Req[tag])];
const fidNew = uniqFeature(uniqueLookupListMap, tag + "__R__" + lid, tag, lookups);
mergedFeatures[fidNew] = lookups;
lang.requiredFeature = fidNew;
}

lang.features = [];
for (let tag in flattenFeatureTagMap) {
const lookups = [...new Set(flattenFeatureTagMap[tag])];
const fidNew = uniqFeature(uniqueLookupListMap, tag + "__F__" + lid, tag, lookups);
mergedFeatures[fidNew] = lookups;
lang.features.push(fidNew);
}
}
table.features = mergedFeatures;
}

function addFeatureToTagMap(sink, fid, table) {
if (!table.features[fid]) return;
const tag = fid.slice(0, 4);
if (!sink[tag]) sink[tag] = [];
sink[tag] = [...sink[tag], ...table.features[fid]];
}

function uniqFeature(map, fid, tag, lookups) {
const key = tag + "|" + lookups.map(x => "{" + x + "}").join("|");

const existing = map.get(key);
if (existing) return existing;

map.set(key, fid);
return fid;
}

///////////////////////////////////////////////////////////////////////////////////////////////////

function markSweepOtl(table) {
if (!table || !table.features || !table.lookups) return;

const accessibleLookupsIds = new Set();
markLookups(table, accessibleLookupsIds);

let lookups1 = {};
for (const l in table.lookups) {
if (accessibleLookupsIds.has(l)) lookups1[l] = table.lookups[l];
}
table.lookups = lookups1;

let features1 = {};
for (let f in table.features) {
const feature = table.features[f];
Expand All @@ -19,6 +96,7 @@ function markSweepOtl(table) {
}
table.features = features1;
}

// eslint-disable-next-line complexity
function markLookups(gsub, lookupSet) {
if (!gsub || !gsub.features) return;
Expand Down Expand Up @@ -46,7 +124,9 @@ function markLookups(gsub, lookupSet) {
lookupSetChanged = sizeBefore !== lookupSet.size;
} while (loop < 0xff && lookupSetChanged);
}

///////////////////////////////////////////////////////////////////////////////////////////////////

const RANK_MOST = 0;
const RANK_UNICODE_PREFERRED = 0x1000000;
const RANK_UNICODE_ALIASED = 0x2000000;
Expand Down Expand Up @@ -163,7 +243,9 @@ function markSubtable(glyphSink, type, st, cfg) {
break;
}
}

///////////////////////////////////////////////////////////////////////////////////////////////////

function sweepGlyphs(font, glyphSink) {
// glyf
if (font.glyf) {
Expand Down Expand Up @@ -291,10 +373,3 @@ function sweep_gsubReverse(st, gs) {
st.to = newTo;
return true;
}
export default (function gcFont(font, cfg) {
markSweepOtl(font.GSUB);
markSweepOtl(font.GPOS);
const glyphSink = markGlyphs(font, cfg);
sweepGlyphs(font, glyphSink);
return [...glyphSink].sort((a, b) => a[1] - b[1]).map(x => x[0]);
});
27 changes: 14 additions & 13 deletions make/common/merge.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function mergeAbove(major, side, config) {
export function mergeAbove(major, side, config) {
config = config || {};
const gid0 = side.glyph_order[0];
for (const unicode in side.cmap) {
Expand All @@ -22,7 +22,8 @@ function mergeAbove(major, side, config) {
major.GDEF = mergeGDEF(major.GDEF || {}, side.GDEF || {});
}
}
function mergeBelow(major, side, config) {

export function mergeBelow(major, side, config) {
config = config || {};
for (const unicode in side.cmap) {
if (major.cmap[unicode]) continue;
Expand All @@ -44,35 +45,35 @@ function mergeBelow(major, side, config) {
major.GDEF = mergeGDEF(side.GDEF || {}, major.GDEF || {});
}
}

function mergeOTLTables(dst, src, priorizeSrc) {
if (!dst || !src) return;
for (const fid in src.features) {
dst.features[fid] = src.features[fid];
}
for (const lid in src.lookups) {
dst.lookups[lid] = src.lookups[lid];
}

for (const fid in src.features) dst.features[fid] = src.features[fid];
for (const lid in src.lookups) dst.lookups[lid] = src.lookups[lid];

for (const lid in src.languages) {
if (dst.languages[lid]) {
dst.languages[lid].features = dst.languages[lid].features.concat(
src.languages[lid].features
);
dst.languages[lid].features = [
...dst.languages[lid].features,
...src.languages[lid].features
];
} else {
dst.languages[lid] = src.languages[lid];
}
}

if (priorizeSrc) {
dst.lookupOrder = [src.lookupOrder || [], dst.lookupOrder || []];
} else {
dst.lookupOrder = [dst.lookupOrder || [], src.lookupOrder || []];
}
}

function mergeGDEF(first, second) {
return {
markAttachClassDef: Object.assign({}, first.markAttachClassDef, second.markAttachClassDef),
glyphClassDef: Object.assign({}, first.glyphClassDef, second.glyphClassDef),
ligCarets: Object.assign({}, first.ligCarets, second.ligCarets)
};
}
export { mergeAbove };
export { mergeBelow };
3 changes: 3 additions & 0 deletions make/common/support/font-io.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function getStream(sourcefile, options) {
return fs.createReadStream(sourcefile, { encoding: "utf8" });
}
}

function cpToPromise(cp) {
return new Promise(function (resolve, reject) {
cp.on("close", code => {
Expand All @@ -42,9 +43,11 @@ function cpToPromise(cp) {
});
});
}

export function loadFont(sourceFile, options) {
return JsonUtil.parseJsonObjectFromStream(getStream(sourceFile, options));
}

export const buildFont = async function builFont(font, destination, options) {
if (destination === "|") {
if (process.stdout.setEncoding instanceof Function) process.stdout.setEncoding("utf8");
Expand Down
49 changes: 27 additions & 22 deletions make/pass1/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,36 @@ const globalConfig = fs.readJsonSync(path.resolve(__dirname, "../../config.json"
const packageConfig = fs.readJsonSync(path.resolve(__dirname, "../../package.json"));
const ENCODINGS = globalConfig.os2encodings;
export default (async function (argv) {
const a = await introFont({ from: argv.main, prefix: "a", ignoreHints: true });
const b = await introFont({ from: argv.asian, prefix: "b", ignoreHints: true });
const c = await introFont({ from: argv.ws, prefix: "c", ignoreHints: true });
const d = await introFont({ from: argv.feMisc, prefix: "d", ignoreHints: true });
rebaseFont(a, { scale: 1000 / a.head.unitsPerEm });
const main = await introFont({ from: argv.main, prefix: "a", ignoreHints: true });
const as = await introFont({ from: argv.asian, prefix: "b", ignoreHints: true });
const ws = await introFont({ from: argv.ws, prefix: "c", ignoreHints: true });
const feMisc = await introFont({ from: argv.feMisc, prefix: "d", ignoreHints: true });

rebaseFont(main, { scale: 1000 / main.head.unitsPerEm });

// tnum
if (argv.tnum) toTNUM(a);
if (argv.tnum) toTNUM(main);
// vhea
a.vhea = b.vhea;
for (let g in a.glyf) {
a.glyf[g].verticalOrigin = a.head.unitsPerEm * 0.88;
a.glyf[g].advanceHeight = a.head.unitsPerEm;
main.vhea = as.vhea;
for (let g in main.glyf) {
main.glyf[g].verticalOrigin = main.head.unitsPerEm * 0.88;
main.glyf[g].advanceHeight = main.head.unitsPerEm;
}
if (argv.italize) italize(a, -9.4);
knockoutSymbols(a, { enclosedAlphaNumerics: !argv.mono, pua: !argv.mono });
crossTransfer(a, b, [0x2010, 0x2011, 0x2012, 0x2013, 0x2014, 0x2015]);

mergeBelow(a, c, { mergeOTL: true });
mergeAbove(a, b, { mergeOTL: true });
mergeAbove(a, d, { mergeOTL: true });
buildNexusDash(a);
setHintFlag(a);
if (argv.italize) italize(main, -9.4);

knockoutSymbols(main, { enclosedAlphaNumerics: !argv.mono, pua: !argv.mono });
crossTransfer(main, as, [0x2010, 0x2011, 0x2012, 0x2013, 0x2014, 0x2015]);

mergeBelow(main, ws, { mergeOTL: true });
mergeAbove(main, as, { mergeOTL: true });
mergeBelow(main, feMisc, { mergeOTL: true });

buildNexusDash(main);
setHintFlag(main);

nameFont(
a,
main,
!!argv.mono,
globalConfig.nameTupleSelector[argv.subfamily],
ENCODINGS[argv.subfamily],
Expand Down Expand Up @@ -76,8 +80,9 @@ export default (async function (argv) {
}
}
);
if (argv.italize) italize(a, +9.4);

a.glyph_order = gc(a);
await buildFont(a, { to: argv.o });
if (argv.italize) italize(main, +9.4);

main.glyph_order = gc(main);
await buildFont(main, { to: argv.o });
});
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.37.1",
"version": "0.37.2",
"main": "./run",
"scripts": {
"build": "verda -f verdafile.mjs",
Expand Down
Loading

0 comments on commit 1687473

Please sign in to comment.