Add double-struck digits

This commit is contained in:
be5invis 2020-11-07 12:58:18 -08:00
parent e85254c93c
commit a6ae67a433
3 changed files with 281 additions and 88 deletions

View file

@ -2,25 +2,14 @@ const blockData = require("./block-data");
const ucdNames = require("@unicode/unicode-13.0.0/Names");
const ugc = require("@unicode/unicode-13.0.0/General_Category");
// eslint-disable-next-line complexity
module.exports = function (covUpright, covItalic, covOblique) {
const result = [];
for (const [[lchBlockStart, lchBlockEnd], block] of blockData) {
let blockResults = [];
let lchFirst = 0,
lchLast = 0;
for (const [lchFont] of covUpright) {
if (lchFont < 0x20 || lchFont < lchBlockStart || lchFont > lchBlockEnd) continue;
if (!lchFirst || lchFont < lchFirst) lchFirst = lchFont;
if (!lchLast || lchFont > lchLast) lchLast = lchFont;
}
if (!lchFirst || !lchLast) continue;
if (lchBlockEnd - lchBlockStart <= 0x100 && lchBlockStart > 0xff) {
(lchFirst = lchBlockStart), (lchLast = lchBlockEnd);
}
const lchStart = (lchFirst >>> 4) << 4;
const lchEnd = ((lchLast >>> 4) << 4) + 0x10;
const [lchStart, lchEnd] = findFirstLastChar(lchBlockStart, lchBlockEnd, covUpright);
if (!lchStart || !lchEnd) continue;
for (let lch = lchStart; lch < lchEnd; lch++) {
const chName = ucdNames.get(lch);
@ -63,3 +52,21 @@ module.exports = function (covUpright, covItalic, covOblique) {
}
return result;
};
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];
}