Further simplify data format
This commit is contained in:
parent
d1d25faf04
commit
13bfc1ccbf
3 changed files with 30 additions and 25 deletions
|
@ -103,7 +103,6 @@ class Prime {
|
||||||
for (const variant of this.variants.values()) {
|
for (const variant of this.variants.values()) {
|
||||||
gr.variants.push({
|
gr.variants.push({
|
||||||
key: variant.key,
|
key: variant.key,
|
||||||
fullKey: this.key + "#" + variant.key,
|
|
||||||
rank: variant.rank,
|
rank: variant.rank,
|
||||||
description: variant.description
|
description: variant.description
|
||||||
});
|
});
|
||||||
|
|
|
@ -120,32 +120,32 @@ function figureOutDefaults(variantsData, gr) {
|
||||||
desc: "Sans Upright",
|
desc: "Sans Upright",
|
||||||
mask: 1,
|
mask: 1,
|
||||||
result: null,
|
result: null,
|
||||||
keys: [...variantsData.defaults.sansUpright.composition]
|
composition: { ...variantsData.defaults.sansUpright }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Sans Italic",
|
desc: "Sans Italic",
|
||||||
mask: 2,
|
mask: 2,
|
||||||
result: null,
|
result: null,
|
||||||
keys: [...variantsData.defaults.sansItalic.composition]
|
composition: { ...variantsData.defaults.sansItalic }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Slab Upright",
|
desc: "Slab Upright",
|
||||||
mask: 4,
|
mask: 4,
|
||||||
result: null,
|
result: null,
|
||||||
keys: [...variantsData.defaults.slabUpright.composition]
|
composition: { ...variantsData.defaults.slabUpright }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Slab Italic",
|
desc: "Slab Italic",
|
||||||
mask: 8,
|
mask: 8,
|
||||||
result: null,
|
result: null,
|
||||||
keys: [...variantsData.defaults.slabItalic.composition]
|
composition: { ...variantsData.defaults.slabItalic }
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const variant of gr.variants) {
|
for (const variant of gr.variants) {
|
||||||
for (const dc of defaultConfigs)
|
for (const dc of defaultConfigs) {
|
||||||
for (const selector of dc.keys)
|
if (variant.key === dc.composition[gr.key]) dc.result = variant.key;
|
||||||
if (variant.fullKey === selector) dc.result = variant.key;
|
}
|
||||||
}
|
}
|
||||||
return defaultConfigs;
|
return defaultConfigs;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,8 @@ module.exports = async function () {
|
||||||
const varDatParsed = VariantDataParser.parse(varDatRaw);
|
const varDatParsed = VariantDataParser.parse(varDatRaw);
|
||||||
|
|
||||||
const primes = getCvData(varDatParsed);
|
const primes = getCvData(varDatParsed);
|
||||||
|
const composites = getSsData(varDatParsed);
|
||||||
const defaults = getDefaultCompData(varDatParsed);
|
const defaults = getDefaultCompData(varDatParsed);
|
||||||
const composites = getSsData(varDatParsed, defaults);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
primes,
|
primes,
|
||||||
|
@ -38,21 +38,26 @@ const UPRIGHT = {};
|
||||||
const OBLIQUE = { isOblique: true };
|
const OBLIQUE = { isOblique: true };
|
||||||
const ITALIC = { isItalic: true };
|
const ITALIC = { isItalic: true };
|
||||||
|
|
||||||
function getSsData(variants, defaultCompData) {
|
function getSsData(variants) {
|
||||||
const result = [
|
const result = [
|
||||||
{
|
{
|
||||||
|
key: "off",
|
||||||
tag: "off",
|
tag: "off",
|
||||||
effective: false,
|
effective: false,
|
||||||
description: "Default",
|
description: "Default",
|
||||||
uprightComposition: [],
|
uprightComposition: {},
|
||||||
italicComposition: [],
|
italicComposition: {},
|
||||||
obliqueComposition: [],
|
obliqueComposition: {},
|
||||||
hotCharSetUpright: [],
|
hotCharSetUpright: [],
|
||||||
hotCharSetItalic: [],
|
hotCharSetItalic: [],
|
||||||
hotCharSetOblique: []
|
hotCharSetOblique: []
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const hcSansUpright = buildupComposite(variants, UPRIGHT, variants.defaultComposite).hotChars;
|
||||||
|
const hcSansItalic = buildupComposite(variants, ITALIC, variants.defaultComposite).hotChars;
|
||||||
|
const hcSansOblique = buildupComposite(variants, OBLIQUE, variants.defaultComposite).hotChars;
|
||||||
|
|
||||||
for (const [key, composite] of variants.composites) {
|
for (const [key, composite] of variants.composites) {
|
||||||
if (!composite.tag) continue;
|
if (!composite.tag) continue;
|
||||||
const upright = buildupComposite(variants, UPRIGHT, composite);
|
const upright = buildupComposite(variants, UPRIGHT, composite);
|
||||||
|
@ -60,15 +65,16 @@ function getSsData(variants, defaultCompData) {
|
||||||
const italic = buildupComposite(variants, ITALIC, composite);
|
const italic = buildupComposite(variants, ITALIC, composite);
|
||||||
|
|
||||||
result.push({
|
result.push({
|
||||||
|
key,
|
||||||
tag: composite.tag,
|
tag: composite.tag,
|
||||||
effective: true,
|
effective: true,
|
||||||
description: composite.description,
|
description: composite.description,
|
||||||
uprightComposition: upright.composition,
|
uprightComposition: upright.composition,
|
||||||
italicComposition: italic.composition,
|
italicComposition: italic.composition,
|
||||||
obliqueComposition: oblique.composition,
|
obliqueComposition: oblique.composition,
|
||||||
hotCharSetUpright: uniqueHotChars(defaultCompData.sansUpright, upright.hotChars),
|
hotCharSetUpright: uniqueHotChars(hcSansUpright, upright.hotChars),
|
||||||
hotCharSetItalic: uniqueHotChars(defaultCompData.sansItalic, italic.hotChars),
|
hotCharSetItalic: uniqueHotChars(hcSansItalic, italic.hotChars),
|
||||||
hotCharSetOblique: uniqueHotChars(defaultCompData.sansOblique, oblique.hotChars)
|
hotCharSetOblique: uniqueHotChars(hcSansOblique, oblique.hotChars)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -76,27 +82,27 @@ function getSsData(variants, defaultCompData) {
|
||||||
|
|
||||||
function getDefaultCompData(variants) {
|
function getDefaultCompData(variants) {
|
||||||
return {
|
return {
|
||||||
sansUpright: buildupComposite(variants, UPRIGHT, variants.defaultComposite),
|
sansUpright: buildupComposite(variants, UPRIGHT, variants.defaultComposite).composition,
|
||||||
sansItalic: buildupComposite(variants, ITALIC, variants.defaultComposite),
|
sansItalic: buildupComposite(variants, ITALIC, variants.defaultComposite).composition,
|
||||||
sansOblique: buildupComposite(variants, OBLIQUE, variants.defaultComposite),
|
sansOblique: buildupComposite(variants, OBLIQUE, variants.defaultComposite).composition,
|
||||||
slabUpright: buildupComposite(
|
slabUpright: buildupComposite(
|
||||||
variants,
|
variants,
|
||||||
UPRIGHT,
|
UPRIGHT,
|
||||||
variants.defaultComposite,
|
variants.defaultComposite,
|
||||||
variants.composites.get("slab")
|
variants.composites.get("slab")
|
||||||
),
|
).composition,
|
||||||
slabItalic: buildupComposite(
|
slabItalic: buildupComposite(
|
||||||
variants,
|
variants,
|
||||||
ITALIC,
|
ITALIC,
|
||||||
variants.defaultComposite,
|
variants.defaultComposite,
|
||||||
variants.composites.get("slab")
|
variants.composites.get("slab")
|
||||||
),
|
).composition,
|
||||||
slabOblique: buildupComposite(
|
slabOblique: buildupComposite(
|
||||||
variants,
|
variants,
|
||||||
OBLIQUE,
|
OBLIQUE,
|
||||||
variants.defaultComposite,
|
variants.defaultComposite,
|
||||||
variants.composites.get("slab")
|
variants.composites.get("slab")
|
||||||
)
|
).composition
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,15 +122,15 @@ function buildupComposite(variants, para, ...composites) {
|
||||||
if (!prime.sampler || isLigatureSampler(prime)) continue;
|
if (!prime.sampler || isLigatureSampler(prime)) continue;
|
||||||
const key = getSelectorKey(prime, variant);
|
const key = getSelectorKey(prime, variant);
|
||||||
for (const ch of prime.sampler) hotChars.set(ch, key);
|
for (const ch of prime.sampler) hotChars.set(ch, key);
|
||||||
compositionMap.set(prime.key, key);
|
compositionMap.set(prime.key, variant.key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return { composition: Array.from(compositionMap.values()), hotChars };
|
return { composition: Object.fromEntries(compositionMap), hotChars };
|
||||||
}
|
}
|
||||||
function uniqueHotChars(cfgDefault, cfgSS) {
|
function uniqueHotChars(cfgDefault, cfgSS) {
|
||||||
let s = new Set();
|
let s = new Set();
|
||||||
for (const [hc, v] of cfgSS) {
|
for (const [hc, v] of cfgSS) {
|
||||||
if (cfgDefault.hotChars.get(hc) !== v) s.add(hc);
|
if (cfgDefault.get(hc) !== v) s.add(hc);
|
||||||
}
|
}
|
||||||
return Array.from(s);
|
return Array.from(s);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue