Better export char variants data
This commit is contained in:
parent
27b1888da6
commit
da935d9e17
4 changed files with 98 additions and 40 deletions
|
@ -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]
|
||||
};
|
||||
}
|
||||
|
|
|
@ -6,7 +6,9 @@ const getCharMapAndSupportedLanguageList = require("./supported-languages");
|
|||
const version = require("../../package.json").version;
|
||||
|
||||
const charMapPath = process.argv[2];
|
||||
const exportPath = process.argv[3];
|
||||
const charMapItalicPath = process.argv[3];
|
||||
const charMapObliquePath = process.argv[4];
|
||||
const exportPath = process.argv[5];
|
||||
main().catch(e => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
|
@ -16,6 +18,10 @@ main().catch(e => {
|
|||
async function main() {
|
||||
const variantsData = await parseVariantsData();
|
||||
const ligationData = await parseLigationData();
|
||||
const cl = await getCharMapAndSupportedLanguageList(charMapPath);
|
||||
const cl = await getCharMapAndSupportedLanguageList(
|
||||
charMapPath,
|
||||
charMapItalicPath,
|
||||
charMapObliquePath
|
||||
);
|
||||
await fs.writeJson(exportPath, { version, variantsData, ligationData, ...cl }, { spaces: 2 });
|
||||
}
|
||||
|
|
|
@ -5,12 +5,27 @@ const gatherCov = require("./coverage-export/gather-coverage-data");
|
|||
// List all the languages that Iosevka supports, but cannot inferred from CLDR data.
|
||||
const overrideSupportedLanguages = [];
|
||||
|
||||
module.exports = async function (charMapPath) {
|
||||
module.exports = async function (charMapPath, charMapItalicPath, charMapObliquePath) {
|
||||
const charMap = await fs.readJson(charMapPath);
|
||||
const charMapItalic = await fs.readJson(charMapItalicPath);
|
||||
const charMapOblique = await fs.readJson(charMapObliquePath);
|
||||
|
||||
const rawCoverage = getRawCoverage(charMap);
|
||||
const rawCoverageItalic = getRawCoverage(charMapItalic);
|
||||
const rawCoverageOblique = getRawCoverage(charMapOblique);
|
||||
|
||||
return {
|
||||
stats: {
|
||||
glyphCount: charMap.length,
|
||||
codePointCount: rawCoverage.size
|
||||
},
|
||||
unicodeCoverage: gatherCov(rawCoverage, rawCoverageItalic, rawCoverageOblique),
|
||||
languages: Array.from(getSupportedLanguageSet(rawCoverage)).sort()
|
||||
};
|
||||
};
|
||||
|
||||
function getSupportedLanguageSet(rawCoverage) {
|
||||
const supportLocaleSet = new Set();
|
||||
const codePointSet = new Set();
|
||||
for (const ch of charMap) for (const unicode of ch[1]) codePointSet.add(unicode);
|
||||
|
||||
for (const locale of cldr.localeIds) {
|
||||
const exemplar = cldr.extractCharacters(locale).exemplar;
|
||||
|
@ -27,10 +42,10 @@ module.exports = async function (charMapPath) {
|
|||
let fullSupport = true;
|
||||
let basicSupport = true;
|
||||
for (const ch of basicChars) {
|
||||
if (!codePointSet.has(ch.codePointAt(0))) basicSupport = false;
|
||||
if (!rawCoverage.has(ch.codePointAt(0))) basicSupport = false;
|
||||
}
|
||||
for (const ch of fullChars) {
|
||||
if (!codePointSet.has(ch.codePointAt(0))) fullSupport = false;
|
||||
if (!rawCoverage.has(ch.codePointAt(0))) fullSupport = false;
|
||||
}
|
||||
|
||||
if (basicSupport) {
|
||||
|
@ -60,16 +75,12 @@ module.exports = async function (charMapPath) {
|
|||
if (displayName) supportLangSet.add(displayName);
|
||||
}
|
||||
|
||||
return supportLangSet;
|
||||
}
|
||||
|
||||
function getRawCoverage(charMap) {
|
||||
const rawCoverage = new Map();
|
||||
for (const [gn, codes, tv, cv] of charMap)
|
||||
for (const u of codes) rawCoverage.set(u, [gn, tv, cv]);
|
||||
|
||||
return {
|
||||
stats: {
|
||||
glyphCount: charMap.length,
|
||||
codePointCount: rawCoverage.size
|
||||
},
|
||||
unicodeCoverage: gatherCov(rawCoverage),
|
||||
languages: Array.from(supportLangSet).sort()
|
||||
};
|
||||
};
|
||||
return rawCoverage;
|
||||
}
|
||||
|
|
|
@ -547,17 +547,14 @@ const PagesDataExport = task(`pages:data-export`, async target => {
|
|||
await target.need(sfu`variants.toml`, sfu`ligation-set.toml`, UtilScripts);
|
||||
const [cm] = await target.need(BuildCM("iosevka", "iosevka-regular"));
|
||||
const [cmi] = await target.need(BuildCM("iosevka", "iosevka-italic"));
|
||||
const [cmo] = await target.need(BuildCM("iosevka", "iosevka-oblique"));
|
||||
await run(
|
||||
`node`,
|
||||
`utility/export-data/index`,
|
||||
cm.full,
|
||||
path.resolve(pagesDir, "shared/data-import/iosevka.json")
|
||||
);
|
||||
await run(
|
||||
`node`,
|
||||
`utility/export-data/index`,
|
||||
cmi.full,
|
||||
path.resolve(pagesDir, "shared/data-import/iosevka-italic.json")
|
||||
cmo.full,
|
||||
path.resolve(pagesDir, "shared/data-import/iosevka.json")
|
||||
);
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue