Fix bar variant preview's slopes
This commit is contained in:
parent
f0262ba5f8
commit
8b260c3c6b
7 changed files with 106 additions and 91 deletions
|
@ -66,6 +66,78 @@ class SelectorTree {
|
|||
}
|
||||
}
|
||||
|
||||
class Prime {
|
||||
constructor(key, cfg) {
|
||||
if (!cfg.variants) throw new Error(`Missing variants in ${key}`);
|
||||
this.key = key;
|
||||
this.sampler = cfg.sampler;
|
||||
this.ligatureSampler = / /.test(cfg.sampler || "");
|
||||
this.descSampleText = this.ligatureSampler
|
||||
? cfg.sampler.split(" ")
|
||||
: [...(cfg.sampler || "")];
|
||||
this.tag = cfg.tag;
|
||||
this.slopeDependent = !!cfg.slopeDependent;
|
||||
this.variants = new Map();
|
||||
for (const varKey in cfg.variants) {
|
||||
const variant = cfg.variants[varKey];
|
||||
this.variants.set(varKey, new PrimeVariant(varKey, cfg.tag, variant));
|
||||
}
|
||||
}
|
||||
register(tree) {
|
||||
for (const [k, v] of this.variants) tree.set(this.key, k, this, v);
|
||||
if (this.tag) {
|
||||
for (const v of this.variants.values()) if (v.rank) tree.set(this.tag, v.rank, this, v);
|
||||
}
|
||||
}
|
||||
|
||||
toJson() {
|
||||
const gr = {
|
||||
key: this.key,
|
||||
sampler: this.sampler,
|
||||
tag: this.tag,
|
||||
slopeDependent: this.slopeDependent,
|
||||
ligatureSampler: this.ligatureSampler,
|
||||
descSampleText: this.descSampleText,
|
||||
variants: []
|
||||
};
|
||||
for (const variant of this.variants.values()) {
|
||||
gr.variants.push({
|
||||
key: variant.key,
|
||||
fullKey: this.key + "#" + variant.key,
|
||||
rank: variant.rank,
|
||||
description: variant.description
|
||||
});
|
||||
}
|
||||
gr.variants.sort((a, b) => (a.rank || 0x7fffffff) - (b.rank || 0x7fffffff));
|
||||
return gr;
|
||||
}
|
||||
}
|
||||
|
||||
class PrimeVariant {
|
||||
constructor(key, tag, cfg) {
|
||||
this.key = key;
|
||||
this.tag = tag;
|
||||
this.description = cfg.description;
|
||||
this.rank = cfg.rank;
|
||||
this.selector = cfg.selector;
|
||||
this.selectorUpright = cfg.selectorUpright;
|
||||
this.selectorItalic = cfg.selectorItalic;
|
||||
}
|
||||
resolveFor(para, gn) {
|
||||
let vs = {};
|
||||
this.resolve(para, vs);
|
||||
return vs[gn];
|
||||
}
|
||||
resolve(para, vs) {
|
||||
Object.assign(vs, this.selector);
|
||||
if (para.isItalic) {
|
||||
Object.assign(vs, this.selectorItalic);
|
||||
} else {
|
||||
Object.assign(vs, this.selectorUpright);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Composite {
|
||||
constructor(key, cfg) {
|
||||
this.key = key;
|
||||
|
@ -104,48 +176,3 @@ class Composite {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Prime {
|
||||
constructor(key, cfg) {
|
||||
this.key = key;
|
||||
this.sampler = cfg.sampler;
|
||||
this.tag = cfg.tag;
|
||||
if (!cfg.variants) throw new Error(`Missing variants in ${key}`);
|
||||
this.variants = new Map();
|
||||
for (const varKey in cfg.variants) {
|
||||
const variant = cfg.variants[varKey];
|
||||
this.variants.set(varKey, new PrimeVariant(varKey, cfg.tag, variant));
|
||||
}
|
||||
}
|
||||
register(tree) {
|
||||
for (const [k, v] of this.variants) tree.set(this.key, k, this, v);
|
||||
if (this.tag) {
|
||||
for (const v of this.variants.values()) if (v.rank) tree.set(this.tag, v.rank, this, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PrimeVariant {
|
||||
constructor(key, tag, cfg) {
|
||||
this.key = key;
|
||||
this.tag = tag;
|
||||
this.description = cfg.description;
|
||||
this.rank = cfg.rank;
|
||||
this.selector = cfg.selector;
|
||||
this.selectorUpright = cfg.selectorUpright;
|
||||
this.selectorItalic = cfg.selectorItalic;
|
||||
}
|
||||
resolveFor(para, gn) {
|
||||
let vs = {};
|
||||
this.resolve(para, vs);
|
||||
return vs[gn];
|
||||
}
|
||||
resolve(para, vs) {
|
||||
Object.assign(vs, this.selector);
|
||||
if (para.isItalic) {
|
||||
Object.assign(vs, this.selectorItalic);
|
||||
} else {
|
||||
Object.assign(vs, this.selectorUpright);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1567,6 +1567,7 @@ selector.percent = "ringsConnected"
|
|||
[prime.bar]
|
||||
sampler = '|'
|
||||
tag = 'cv55'
|
||||
slopeDependent = true
|
||||
|
||||
[prime.bar.variants.natural-slope]
|
||||
rank = 1
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<section id="charvars" class="char-vars">
|
||||
<div class="hr">Character Variants</div>
|
||||
<ol class="narrow">
|
||||
<%_ for(const group of cvData) if(group.tag) { _%>
|
||||
<%_ for(const group of primes) if(group.tag) { _%>
|
||||
<li>
|
||||
<ol class="group header">
|
||||
<div class="desc-group <%= group.ligatureSampler ? 'ligature' : 'char' %>">
|
||||
|
@ -18,13 +18,13 @@
|
|||
<div class="triangle">▹</div>
|
||||
<ol class="group">
|
||||
<%_ for(const config of group.variants) if(config.rank) { _%>
|
||||
<li class="desc-group <%= group.ligatureSampler || config.slopeHetero ? 'ligature' : 'char' %>">
|
||||
<li class="desc-group <%= group.ligatureSampler || group.slopeDependent ? 'ligature' : 'char' %>">
|
||||
<div class="label tag"><%= config.rank %></div>
|
||||
<%_ if(group.ligatureSampler) { _%>
|
||||
<%_ for(const text of group.descSampleText) { _%>
|
||||
<div class="sample" style="font-feature-settings:'<%= group.tag %>' <%= config.rank %>"><%= text %></div>
|
||||
<%_ } _%>
|
||||
<%_ } else if(config.slopeHetero) { _%>
|
||||
<%_ } else if(group.slopeDependent) { _%>
|
||||
<div class="sample" style="font-feature-settings:'<%= group.tag %>' <%= config.rank %>"><%= group.descSampleText[0] %></div>
|
||||
<div class="sample italic" style="font-feature-settings:'<%= group.tag %>' <%= config.rank %>"><%= group.descSampleText[0] %></div>
|
||||
<%_ } else { _%>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<section id="stylesets" class="style-sets">
|
||||
<div class="hr">Stylistic Sets</div>
|
||||
<ol class="wide">
|
||||
<%_ for(const gr of ssData) { _%>
|
||||
<%_ for(const gr of composites) { _%>
|
||||
<li>
|
||||
<span class="tag"><%= gr.tag %></span><span class="description"><%= gr.description %></span>
|
||||
<span class="sample" style="font-feature-settings:'<%= gr.tag %>'"><%- buildSsHtml(`@real fox.quick(h){ *is_brown && it_jumps_over(dogs.lazy) } 0123456789 ABCKRWXYZ`, gr.hotCharSetUpright) -%></span>
|
||||
|
|
|
@ -31,7 +31,7 @@ async function processSs() {
|
|||
const md = new MdCol("Section-Stylistic-Sets");
|
||||
const headerPath = path.resolve(__dirname, "fragments/description-stylistic-sets.md");
|
||||
md.log(await fs.readFile(headerPath, "utf-8"));
|
||||
for (const gr of variantsData.ssData) {
|
||||
for (const gr of variantsData.composites) {
|
||||
if (!gr.effective) continue;
|
||||
md.log(` - \`${gr.tag}\`: Set character variant to “${gr.description}”.`);
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ async function processCv() {
|
|||
const headerPath = path.resolve(__dirname, "fragments/description-cheery-picking-styles.md");
|
||||
md.log(await fs.readFile(headerPath, "utf-8"));
|
||||
|
||||
for (const gr of variantsData.cvData) {
|
||||
for (const gr of variantsData.primes) {
|
||||
const sampleText = gr.descSampleText
|
||||
.map(c => (c === "`" ? "`` ` ``" : `\`${c}\``))
|
||||
.join(", ");
|
||||
|
|
|
@ -25,6 +25,17 @@ async function main() {
|
|||
charMapItalicPath,
|
||||
charMapObliquePath
|
||||
);
|
||||
await fs.writeJson(exportPathMeta, { version, variantsData, ligationData }, { spaces: 2 });
|
||||
await fs.writeJson(
|
||||
exportPathMeta,
|
||||
{
|
||||
version,
|
||||
variantsData,
|
||||
ligationData: {
|
||||
samplesNarrow: ligationData.samplesNarrow,
|
||||
nonMergeSets: ligationData.nonMergeSets
|
||||
}
|
||||
},
|
||||
{ spaces: 2 }
|
||||
);
|
||||
await fs.writeJson(exportPathCov, { version, ...cl }, { spaces: 2 });
|
||||
}
|
||||
|
|
|
@ -14,14 +14,14 @@ module.exports = async function () {
|
|||
const varDatRaw = toml.parse(variantsToml);
|
||||
const varDatParsed = VariantDataParser.parse(varDatRaw);
|
||||
|
||||
const cvData = getCvData(varDatParsed);
|
||||
const ssData = getSsData(varDatParsed);
|
||||
const defaultCompData = getDefaultCompData(varDatParsed);
|
||||
const primes = getCvData(varDatParsed);
|
||||
const defaults = getDefaultCompData(varDatParsed);
|
||||
const composites = getSsData(varDatParsed, defaults);
|
||||
|
||||
return {
|
||||
cvData,
|
||||
ssData,
|
||||
defaults: defaultCompData
|
||||
primes,
|
||||
composites,
|
||||
defaults: defaults
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -29,31 +29,8 @@ function getCvData(parsed) {
|
|||
const samplerGroups = new Map();
|
||||
for (const [_keyPrime, prime] of parsed.primes) {
|
||||
if (!prime.sampler) continue;
|
||||
let gr = samplerGroups.get(prime.key);
|
||||
if (!gr) {
|
||||
gr = {
|
||||
key: prime.key,
|
||||
sampler: prime.sampler,
|
||||
tag: prime.tag,
|
||||
ligatureSampler: isLigatureSampler(prime),
|
||||
descSampleText: isLigatureSampler(prime)
|
||||
? prime.sampler.split(" ")
|
||||
: [...prime.sampler],
|
||||
variants: []
|
||||
};
|
||||
samplerGroups.set(prime.key, gr);
|
||||
samplerGroups.set(prime.key, prime.toJson());
|
||||
}
|
||||
for (const variant of prime.variants.values()) {
|
||||
gr.variants.push({
|
||||
key: variant.key,
|
||||
fullKey: getSelectorKey(prime, variant),
|
||||
rank: variant.rank,
|
||||
description: variant.description
|
||||
});
|
||||
}
|
||||
gr.variants.sort((a, b) => (a.rank || 0x7fffffff) - (b.rank || 0x7fffffff));
|
||||
}
|
||||
|
||||
return Array.from(samplerGroups.values());
|
||||
}
|
||||
|
||||
|
@ -61,7 +38,7 @@ const UPRIGHT = {};
|
|||
const OBLIQUE = { isOblique: true };
|
||||
const ITALIC = { isItalic: true };
|
||||
|
||||
function getSsData(variants) {
|
||||
function getSsData(variants, defaultCompData) {
|
||||
const result = [
|
||||
{
|
||||
tag: "off",
|
||||
|
@ -75,9 +52,6 @@ function getSsData(variants) {
|
|||
hotCharSetOblique: []
|
||||
}
|
||||
];
|
||||
const defaultUpright = buildupComposite(variants, UPRIGHT, variants.defaultComposite);
|
||||
const defaultOblique = buildupComposite(variants, OBLIQUE, variants.defaultComposite);
|
||||
const defaultItalic = buildupComposite(variants, ITALIC, variants.defaultComposite);
|
||||
|
||||
for (const [key, composite] of variants.composites) {
|
||||
if (!composite.tag) continue;
|
||||
|
@ -92,9 +66,9 @@ function getSsData(variants) {
|
|||
uprightComposition: upright.composition,
|
||||
italicComposition: italic.composition,
|
||||
obliqueComposition: oblique.composition,
|
||||
hotCharSetUpright: Array.from(uniqueHotChars(defaultUpright, upright.hotChars)),
|
||||
hotCharSetItalic: Array.from(uniqueHotChars(defaultItalic, italic.hotChars)),
|
||||
hotCharSetOblique: Array.from(uniqueHotChars(defaultOblique, oblique.hotChars))
|
||||
hotCharSetUpright: uniqueHotChars(defaultCompData.sansUpright, upright.hotChars),
|
||||
hotCharSetItalic: uniqueHotChars(defaultCompData.sansItalic, italic.hotChars),
|
||||
hotCharSetOblique: uniqueHotChars(defaultCompData.sansOblique, oblique.hotChars)
|
||||
});
|
||||
}
|
||||
return result;
|
||||
|
@ -147,8 +121,10 @@ function buildupComposite(variants, para, ...composites) {
|
|||
}
|
||||
return { composition: Array.from(compositionMap.values()), hotChars };
|
||||
}
|
||||
function* uniqueHotChars(cfgDefault, cfgSS) {
|
||||
function uniqueHotChars(cfgDefault, cfgSS) {
|
||||
let s = new Set();
|
||||
for (const [hc, v] of cfgSS) {
|
||||
if (cfgDefault.hotChars.get(hc) !== v) yield hc;
|
||||
if (cfgDefault.hotChars.get(hc) !== v) s.add(hc);
|
||||
}
|
||||
return Array.from(s);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue