Initial work of ESM transformation
This commit is contained in:
parent
2472c9cff2
commit
b8205a63aa
303 changed files with 1959 additions and 2450 deletions
66
utility/export-data/coverage-export/gather-coverage-data.mjs
Normal file
66
utility/export-data/coverage-export/gather-coverage-data.mjs
Normal file
|
@ -0,0 +1,66 @@
|
|||
import { BlockData } from "./block-data.mjs";
|
||||
import ucdNames from "@unicode/unicode-14.0.0/Names";
|
||||
import ugc from "@unicode/unicode-14.0.0/General_Category";
|
||||
function findFirstLastChar(lchBlockStart, lchBlockEnd, cov) {
|
||||
let lchFirst = 0,
|
||||
lchLast = 0;
|
||||
for (const [lchFont] of cov) {
|
||||
if (lchFont < 0x20 || lchFont < lchBlockStart || lchFont > lchBlockEnd) continue;
|
||||
if (!lchFirst || lchFont < lchFirst) lchFirst = lchFont;
|
||||
if (!lchLast || lchFont > lchLast) lchLast = lchFont;
|
||||
}
|
||||
if (!lchFirst || !lchLast) return [0, 0];
|
||||
if (lchBlockEnd - lchBlockStart <= 0x100 && lchBlockStart > 0xff) {
|
||||
lchFirst = lchBlockStart;
|
||||
lchLast = lchBlockEnd;
|
||||
}
|
||||
const lchStart = (lchFirst >>> 4) << 4;
|
||||
const lchEnd = ((lchLast >>> 4) << 4) + 0x10;
|
||||
return [lchStart, lchEnd];
|
||||
}
|
||||
export const gatherCoverageData = function (covUpright, covItalic, covOblique) {
|
||||
const result = [];
|
||||
for (const [[lchBlockStart, lchBlockEnd], block] of BlockData) {
|
||||
let blockResults = [];
|
||||
const [lchStart, lchEnd] = findFirstLastChar(lchBlockStart, lchBlockEnd, covUpright);
|
||||
if (!lchStart || !lchEnd) continue;
|
||||
for (let lch = lchStart; lch < lchEnd; lch++) {
|
||||
const chName = ucdNames.get(lch);
|
||||
const gc = ugc.get(lch);
|
||||
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;
|
||||
blockResults.push({
|
||||
lch,
|
||||
gc,
|
||||
charName: chName,
|
||||
inFont: true,
|
||||
glyphName: glyphName,
|
||||
typographicVariants: typographicVariants,
|
||||
charVariantsUpright,
|
||||
charVariantsItalic,
|
||||
charVariantsOblique
|
||||
});
|
||||
} else {
|
||||
blockResults.push({
|
||||
lch,
|
||||
gc,
|
||||
charName: chName,
|
||||
inFont: false,
|
||||
glyphName: undefined
|
||||
});
|
||||
}
|
||||
}
|
||||
if (blockResults.length) {
|
||||
result.push({
|
||||
name: block,
|
||||
characters: blockResults.sort((a, b) => a.lch - b.lch)
|
||||
});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue