Better export char variants data

This commit is contained in:
Belleve Invis 2020-05-17 18:15:08 -07:00
parent 27b1888da6
commit da935d9e17
4 changed files with 98 additions and 40 deletions

View file

@ -2,17 +2,13 @@ const blockData = require("./block-data");
const ucdNames = require("unicode-13.0.0/Names");
const ugc = require("unicode-13.0.0/General_Category");
module.exports = function (rawCov) {
module.exports = function (covUpright, covItalic, covOblique) {
const result = [];
const glyphNameMap = new Map();
for (const [lchFont, [gn, tv, cv]] of rawCov) {
glyphNameMap.set(lchFont, [gn, tv, cv]);
}
for (const [[lchBlockStart, lchBlockEnd], block] of blockData) {
let blockResults = [];
let processed = new Set();
for (const [lchFont] of rawCov) {
for (const [lchFont] of covUpright) {
if (lchFont < 0x20 || lchFont < lchBlockStart || lchFont > lchBlockEnd) continue;
const lchStart = (lchFont >>> 4) << 4;
const lchEnd = lchStart + 0x10;
@ -20,25 +16,73 @@ module.exports = function (rawCov) {
if (processed.has(lch)) continue;
const chName = ucdNames.get(lch);
const gc = ugc.get(lch);
const inFont = glyphNameMap.get(lch);
blockResults.push({
lch,
gc,
charName: chName,
glyphName: inFont ? inFont[0] : undefined,
inFont: !!inFont,
typographicVariants: inFont && inFont[1].length ? inFont[1] : undefined,
charVariants: inFont && inFont[2].length ? inFont[2] : undefined,
});
const cdUpright = covUpright.get(lch);
const cdItalic = covItalic.get(lch);
const cdOblique = covOblique.get(lch);
if (cdUpright && cdItalic && cdOblique) {
const [glyphName, typographicVariants, charVariantsUpright] = cdUpright;
const [, , charVariantsItalic] = cdItalic;
const [, , charVariantsOblique] = cdOblique;
const interleaved = interleaveCharacterVariants(
new Set(charVariantsUpright),
new Set(charVariantsItalic),
new Set(charVariantsOblique)
);
blockResults.push({
lch,
gc,
charName: chName,
inFont: true,
glyphName: glyphName,
typographicVariants: typographicVariants,
charVariants: interleaved.common,
charVariantsUpright: interleaved.uprightSpecific,
charVariantsItalic: interleaved.italicSpecific,
charVariantsOblique: interleaved.obliqueSpecific
});
} else {
blockResults.push({
lch,
gc,
charName: chName,
inFont: false,
glyphName: undefined,
typographicVariants: undefined,
charVariants: undefined,
charVariantsUpright: undefined,
charVariantsItalic: undefined,
charVariantsOblique: undefined
});
}
processed.add(lch);
}
}
if (blockResults.length) {
result.push({
name: block,
characters: blockResults.sort((a, b) => a.lch - b.lch),
characters: blockResults.sort((a, b) => a.lch - b.lch)
});
}
}
return result;
};
function interleaveCharacterVariants(up, it, ob) {
const common = new Set();
for (const cv of up) {
if (it.has(cv) && ob.has(cv)) common.add(cv);
}
const upS = new Set(),
itS = new Set(),
obS = new Set();
for (const cv of up) if (!common.has(cv)) upS.add(cv);
for (const cv of it) if (!common.has(cv)) itS.add(cv);
for (const cv of ob) if (!common.has(cv)) obS.add(cv);
return {
common: [...common],
uprightSpecific: [...upS],
italicSpecific: [...itS],
obliqueSpecific: [...obS]
};
}