Gr simplify
This commit is contained in:
parent
aa23e2ec99
commit
b788212a64
4 changed files with 59 additions and 89 deletions
|
@ -8,17 +8,16 @@ extern Map
|
||||||
glyph-module
|
glyph-module
|
||||||
|
|
||||||
glyph-block Common-Derivatives : begin
|
glyph-block Common-Derivatives : begin
|
||||||
glyph-block-export ApplyCv
|
|
||||||
define [ApplyCv g shapeFrom follow para] : begin
|
define [ApplyCv g shapeFrom follow para] : begin
|
||||||
foreach { kPrime prime } para.variants.primes : foreach h [prime.variants.values] : begin
|
foreach { kPrime prime } para.variants.primes : foreach pv [prime.variants.values] : begin
|
||||||
local suffix : h.resolveFor para follow
|
local suffix : pv.resolveFor para follow
|
||||||
if suffix : begin
|
if (para.enableCvSs && pv.tag && pv.rank && suffix) : begin
|
||||||
local dstName : shapeFrom + '.' + suffix
|
local dstName : shapeFrom + '.' + suffix
|
||||||
local dst : glyphStore.queryByName dstName
|
local dst : glyphStore.queryByName dstName
|
||||||
if dst : g.dependsOn dst
|
if dst : g.dependsOn dst
|
||||||
if (para.enableCvSs && h.tag && h.rank) : begin
|
|
||||||
[Cv h.tag h.rank h.groupRank h.description].set g dstName
|
pv.set g dstName
|
||||||
if h.nonDeriving : [Cv h.tag h.rank].setPreventDeriving g
|
if pv.nonDeriving : pv.setPreventDeriving g
|
||||||
|
|
||||||
glyph-block-export select-variant
|
glyph-block-export select-variant
|
||||||
define [select-variant] : with-params [name unicode [shapeFrom name] [follow name] [reduction null]] : begin
|
define [select-variant] : with-params [name unicode [shapeFrom name] [follow name] [reduction null]] : begin
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
$$include '../meta/macros.ptl'
|
$$include '../meta/macros.ptl'
|
||||||
|
|
||||||
import [Cv AnyCv CvDecompose RightDependentLink RightDependentTrigger] from"../support/gr.mjs"
|
import [AnyCv CvDecompose] from"../support/gr.mjs"
|
||||||
|
|
||||||
extern Map
|
extern Map
|
||||||
extern Set
|
extern Set
|
||||||
|
@ -89,8 +89,8 @@ export : define [buildCVSS gsub para glyphStore] : begin
|
||||||
do "cvxx"
|
do "cvxx"
|
||||||
local cvGrs {}
|
local cvGrs {}
|
||||||
foreach {name prime} para.variants.primes : foreach {vn variant} prime.variants : begin
|
foreach {name prime} para.variants.primes : foreach {vn variant} prime.variants : begin
|
||||||
if (prime.tag && variant.rank) : cvGrs.push : Cv prime.tag variant.rank
|
if (variant.tag && variant.rank) : cvGrs.push variant
|
||||||
cvGrs.sort Cv.compare
|
cvGrs.sort AnyCv.compare
|
||||||
|
|
||||||
foreach gr [items-of cvGrs] : begin
|
foreach gr [items-of cvGrs] : begin
|
||||||
local cvAlt : [cvs.get gr.tag].createAlternateSubst
|
local cvAlt : [cvs.get gr.tag].createAlternateSubst
|
||||||
|
@ -106,10 +106,10 @@ export : define [buildCVSS gsub para glyphStore] : begin
|
||||||
define decomp : composition.decompose para para.variants.selectorTree
|
define decomp : composition.decompose para para.variants.selectorTree
|
||||||
local ssGrs {}
|
local ssGrs {}
|
||||||
foreach { prime pv } [items-of decomp] : if (pv.tag && pv.rank) : begin
|
foreach { prime pv } [items-of decomp] : if (pv.tag && pv.rank) : begin
|
||||||
ssGrs.push : Cv pv.tag pv.rank
|
ssGrs.push pv
|
||||||
local dl [cvs.get pv.tag].decompositionLookup
|
local dl [cvs.get pv.tag].decompositionLookup
|
||||||
if dl : feature.addLookup dl
|
if dl : feature.addLookup dl
|
||||||
ssGrs.sort Cv.compare
|
ssGrs.sort AnyCv.compare
|
||||||
|
|
||||||
foreach gr [items-of ssGrs] : begin
|
foreach gr [items-of ssGrs] : begin
|
||||||
local cvSingle : [cvs.get gr.tag].createSingleSubstFor gr.rank
|
local cvSingle : [cvs.get gr.tag].createSingleSubstFor gr.rank
|
||||||
|
|
|
@ -146,57 +146,6 @@ export const HintClass = {
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
const CvTagCache = new Map();
|
|
||||||
|
|
||||||
export function Cv(tag, rank, groupRank, description) {
|
|
||||||
const key = tag + "#" + rank;
|
|
||||||
if (CvTagCache.has(key)) return CvTagCache.get(key);
|
|
||||||
const rel = {
|
|
||||||
tag,
|
|
||||||
rank,
|
|
||||||
groupRank,
|
|
||||||
description,
|
|
||||||
get(glyph) {
|
|
||||||
if (glyph && glyph.related && glyph.related.cv) return glyph.related.cv[key];
|
|
||||||
else return null;
|
|
||||||
},
|
|
||||||
set(glyph, toGid) {
|
|
||||||
if (typeof toGid !== "string") throw new Error("Must supply a GID instead of a glyph");
|
|
||||||
if (!glyph.related) glyph.related = {};
|
|
||||||
if (!glyph.related.cv) glyph.related.cv = {};
|
|
||||||
glyph.related.cv[key] = toGid;
|
|
||||||
},
|
|
||||||
getPreventDeriving(glyph) {
|
|
||||||
return (
|
|
||||||
glyph.related &&
|
|
||||||
glyph.related.preventCvDeriving &&
|
|
||||||
!!glyph.related.preventCvDeriving[key]
|
|
||||||
);
|
|
||||||
},
|
|
||||||
setPreventDeriving(glyph) {
|
|
||||||
if (!glyph.related) glyph.related = {};
|
|
||||||
if (!glyph.related.preventCvDeriving) glyph.related.preventCvDeriving = {};
|
|
||||||
glyph.related.preventCvDeriving[key] = true;
|
|
||||||
},
|
|
||||||
amendName(name) {
|
|
||||||
return name + "." + key;
|
|
||||||
},
|
|
||||||
amendOtName(name) {
|
|
||||||
return name + "." + tag + "-" + rank;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
CvTagCache.set(key, rel);
|
|
||||||
return rel;
|
|
||||||
}
|
|
||||||
|
|
||||||
Cv.compare = function (a, b) {
|
|
||||||
if (a.tag < b.tag) return -1;
|
|
||||||
if (a.tag > b.tag) return 1;
|
|
||||||
if (a.rank < b.rank) return -1;
|
|
||||||
if (a.rank > b.rank) return 1;
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const DotlessOrNot = {
|
export const DotlessOrNot = {
|
||||||
query(glyph) {
|
query(glyph) {
|
||||||
if (Dotless.get(glyph)) return [Dotless];
|
if (Dotless.get(glyph)) return [Dotless];
|
||||||
|
@ -208,14 +157,18 @@ export const AnyCv = {
|
||||||
query(glyph) {
|
query(glyph) {
|
||||||
let ret = [];
|
let ret = [];
|
||||||
if (glyph && glyph.related && glyph.related.cv) {
|
if (glyph && glyph.related && glyph.related.cv) {
|
||||||
for (const key in glyph.related.cv) {
|
for (const [cv, dst] of glyph.related.cv) {
|
||||||
const [tag, rankStr] = key.split("#");
|
ret.push(cv);
|
||||||
const rank = parseInt(rankStr, 10);
|
|
||||||
const rel = Cv(tag, rank);
|
|
||||||
if (rel.get(glyph)) ret.push(rel);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
},
|
||||||
|
compare(a, b) {
|
||||||
|
const ua = a.tag.toUpperCase(),
|
||||||
|
ub = b.tag.toUpperCase();
|
||||||
|
if (ua < ub) return -1;
|
||||||
|
if (ua > ub) return 1;
|
||||||
|
return a.rank - b.rank;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -223,23 +176,17 @@ export const AnyDerivingCv = {
|
||||||
query(glyph) {
|
query(glyph) {
|
||||||
let ret = [];
|
let ret = [];
|
||||||
if (glyph && glyph.related && glyph.related.cv) {
|
if (glyph && glyph.related && glyph.related.cv) {
|
||||||
for (const key in glyph.related.cv) {
|
for (const [cv, dst] of glyph.related.cv) {
|
||||||
if (glyph.related.preventCvDeriving && glyph.related.preventCvDeriving[key])
|
if (glyph.related.preventCvDeriving && glyph.related.preventCvDeriving.has(cv))
|
||||||
continue;
|
continue;
|
||||||
const [tag, rankStr] = key.split("#");
|
ret.push(cv);
|
||||||
const rank = parseInt(rankStr, 10);
|
|
||||||
const rel = Cv(tag, rank);
|
|
||||||
if (rel.get(glyph)) ret.push(rel);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
},
|
},
|
||||||
hasNonDerivingVariants(glyph) {
|
hasNonDerivingVariants(glyph) {
|
||||||
if (glyph && glyph.related && glyph.related.cv) {
|
if (glyph && glyph.related && glyph.related.preventCvDeriving) {
|
||||||
for (const key in glyph.related.cv) {
|
return glyph.related.preventCvDeriving.size > 0;
|
||||||
if (glyph.related.preventCvDeriving && glyph.related.preventCvDeriving[key])
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -278,7 +225,7 @@ export function getGrMesh(gidList, grq, fnGidToGlyph) {
|
||||||
for (const g of gidList) {
|
for (const g of gidList) {
|
||||||
for (const gr of grq.query(fnGidToGlyph(g))) allGrSet.add(gr);
|
for (const gr of grq.query(fnGidToGlyph(g))) allGrSet.add(gr);
|
||||||
}
|
}
|
||||||
const allGrList = Array.from(allGrSet).sort(Cv.compare).reverse();
|
const allGrList = Array.from(allGrSet).sort(AnyCv.compare).reverse();
|
||||||
|
|
||||||
let ret = [];
|
let ret = [];
|
||||||
for (const gr of allGrList) {
|
for (const gr of allGrList) {
|
||||||
|
@ -399,15 +346,9 @@ function displayQuerySingleFeature(gs, gid, name, grCis, sink) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function byTagPreference(a, b) {
|
|
||||||
const ua = a.tag.toUpperCase(),
|
|
||||||
ub = b.tag.toUpperCase();
|
|
||||||
if (ua < ub) return -1;
|
|
||||||
if (ua > ub) return 1;
|
|
||||||
return a.rank - b.rank;
|
|
||||||
}
|
|
||||||
function queryCvFeatureTagsOf(sink, gid, glyph, tagSet) {
|
function queryCvFeatureTagsOf(sink, gid, glyph, tagSet) {
|
||||||
const cvs = AnyCv.query(glyph).sort(byTagPreference);
|
const cvs = AnyCv.query(glyph).sort(AnyCv.compare);
|
||||||
|
|
||||||
let existingFeatures = new Map();
|
let existingFeatures = new Map();
|
||||||
let existingTargets = new Set();
|
let existingTargets = new Set();
|
||||||
|
|
|
@ -181,7 +181,7 @@ class Prime {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PrimeVariant {
|
export class PrimeVariant {
|
||||||
constructor(key, tag, cfg) {
|
constructor(key, tag, cfg) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
|
@ -200,6 +200,36 @@ class PrimeVariant {
|
||||||
resolve(para, vs) {
|
resolve(para, vs) {
|
||||||
Object.assign(vs, this.selector);
|
Object.assign(vs, this.selector);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gr methods
|
||||||
|
get(glyph) {
|
||||||
|
if (glyph && glyph.related && glyph.related.cv) return glyph.related.cv.get(this);
|
||||||
|
else return null;
|
||||||
|
}
|
||||||
|
set(glyph, toGid) {
|
||||||
|
if (typeof toGid !== "string") throw new Error("Must supply a GID instead of a glyph");
|
||||||
|
if (!glyph.related) glyph.related = {};
|
||||||
|
if (!glyph.related.cv) glyph.related.cv = new Map();
|
||||||
|
glyph.related.cv.set(this, toGid);
|
||||||
|
}
|
||||||
|
getPreventDeriving(glyph) {
|
||||||
|
return (
|
||||||
|
glyph.related &&
|
||||||
|
glyph.related.preventCvDeriving &&
|
||||||
|
!!glyph.related.preventCvDeriving.has(this)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
setPreventDeriving(glyph) {
|
||||||
|
if (!glyph.related) glyph.related = {};
|
||||||
|
if (!glyph.related.preventCvDeriving) glyph.related.preventCvDeriving = new Set();
|
||||||
|
glyph.related.preventCvDeriving.add(this);
|
||||||
|
}
|
||||||
|
amendName(name) {
|
||||||
|
return name + "." + this.tag + "-" + this.rank;
|
||||||
|
}
|
||||||
|
amendOtName(name) {
|
||||||
|
return this.amendName(name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Composite {
|
class Composite {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue