Refine variant export for website

This commit is contained in:
Belleve Invis 2020-04-03 21:46:37 -07:00
parent efc93f5ee0
commit f18c366c16
8 changed files with 74 additions and 49 deletions

View file

@ -2,17 +2,17 @@ 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 (rawCov) {
const result = [];
const glyphNameMap = new Map();
for (const [lchFont, [gn, ck]] of rawCov) {
glyphNameMap.set(lchFont, gn);
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, [_gn, ck]] of rawCov) {
for (const [lchFont] of rawCov) {
if (lchFont < 0x20 || lchFont < lchBlockStart || lchFont > lchBlockEnd) continue;
const lchStart = (lchFont >>> 4) << 4;
const lchEnd = lchStart + 0x10;
@ -20,12 +20,15 @@ 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: glyphNameMap.get(lch),
inFont: glyphNameMap.has(lch)
glyphName: inFont ? inFont[0] : undefined,
inFont: !!inFont,
typographicVariants: inFont && inFont[1].length ? inFont[1] : undefined,
charVariants: inFont && inFont[2].length ? inFont[2] : undefined,
});
processed.add(lch);
}
@ -33,7 +36,7 @@ module.exports = function(rawCov) {
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),
});
}
}