OTL codegen cleanup
This commit is contained in:
parent
d471e9d948
commit
c6dc8c370c
11 changed files with 120 additions and 123 deletions
|
|
@ -26,9 +26,9 @@ function markLookups(table, sink) {
|
|||
let sizeBefore = sink.size;
|
||||
for (const l of Array.from(sink)) {
|
||||
const lookup = table.lookups[l];
|
||||
if (!lookup || !lookup.subtables) continue;
|
||||
if (!lookup) continue;
|
||||
if (lookup.type === "gsub_chaining" || lookup.type === "gpos_chaining") {
|
||||
for (let st of lookup.subtables) {
|
||||
for (let st of lookup.rules) {
|
||||
if (!st || !st.apply) continue;
|
||||
for (const app of st.apply) sink.add(app.lookup);
|
||||
}
|
||||
|
|
@ -91,56 +91,60 @@ function markGlyphsStep(glyphStore, sink, restFont, cfg) {
|
|||
if (restFont.GSUB) {
|
||||
for (const l in restFont.GSUB.lookups) {
|
||||
const lookup = restFont.GSUB.lookups[l];
|
||||
if (!lookup || !lookup.subtables) continue;
|
||||
for (let st of lookup.subtables) {
|
||||
markGlyphsSubtable(sink, lookup.type, st, cfg);
|
||||
}
|
||||
if (!lookup) continue;
|
||||
markGlyphsLookupImpl(sink, lookup, cfg);
|
||||
}
|
||||
}
|
||||
const glyphCount1 = sink.size;
|
||||
return glyphCount1 > glyphCount;
|
||||
}
|
||||
|
||||
function markGlyphsSubtable(sink, type, st, cfg) {
|
||||
switch (type) {
|
||||
function markGlyphsLookupImpl(sink, lookup, cfg) {
|
||||
switch (lookup.type) {
|
||||
case "gsub_single":
|
||||
return markGlyphsGsubSingle(sink, st, cfg);
|
||||
return markGlyphsGsubSingle(sink, lookup, cfg);
|
||||
case "gsub_multiple":
|
||||
return markGlyphsGsubMultiple(sink, st, cfg);
|
||||
return markGlyphsGsubMultiple(sink, lookup, cfg);
|
||||
case "gsub_alternate":
|
||||
return markGlyphsGsubAlternate(sink, st, cfg);
|
||||
return markGlyphsGsubAlternate(sink, lookup, cfg);
|
||||
case "gsub_ligature":
|
||||
return markGlyphsGsubLigature(sink, st, cfg);
|
||||
return markGlyphsGsubLigature(sink, lookup, cfg);
|
||||
case "gsub_chaining":
|
||||
break;
|
||||
case "gsub_reverse":
|
||||
return markGlyphsGsubReverse(sink, st, cfg);
|
||||
return markGlyphsGsubReverse(sink, lookup, cfg);
|
||||
}
|
||||
}
|
||||
|
||||
function markGlyphsGsubSingle(sink, st, cfg) {
|
||||
function markGlyphsGsubSingle(sink, lookup, cfg) {
|
||||
const st = lookup.substitutions;
|
||||
for (const k in st) if (sink.has(k) && st[k]) sink.add(st[k]);
|
||||
}
|
||||
function markGlyphsGsubMultiple(sink, st, cfg) {
|
||||
function markGlyphsGsubMultiple(sink, lookup, cfg) {
|
||||
const st = lookup.substitutions;
|
||||
for (const k in st) if (sink.has(k) && st[k]) for (const g of st[k]) sink.add(g);
|
||||
}
|
||||
function markGlyphsGsubAlternate(sink, st, cfg) {
|
||||
function markGlyphsGsubAlternate(sink, lookup, cfg) {
|
||||
const st = lookup.substitutions;
|
||||
if (!cfg || !cfg.ignoreAltSub) {
|
||||
for (const k in st) if (sink.has(k) && st[k]) for (const g of st[k]) sink.add(g);
|
||||
}
|
||||
}
|
||||
function markGlyphsGsubLigature(sink, st, cfg) {
|
||||
for (const sub of st.substitutions) {
|
||||
function markGlyphsGsubLigature(sink, lookup, cfg) {
|
||||
const st = lookup.substitutions;
|
||||
for (const sub of st) {
|
||||
let check = true;
|
||||
for (const g of sub.from) if (!sink.has(g)) check = false;
|
||||
if (check && sub.to) sink.add(sub.to);
|
||||
}
|
||||
}
|
||||
function markGlyphsGsubReverse(sink, st, cfg) {
|
||||
if (st.match && st.to) {
|
||||
const matchCoverage = st.match[st.inputIndex];
|
||||
for (let j = 0; j < matchCoverage.length; j++) {
|
||||
if (sink.has(matchCoverage[j]) && st.to[j]) sink.add(st.to[j]);
|
||||
function markGlyphsGsubReverse(sink, lookup, cfg) {
|
||||
for (const rule of lookup.rules) {
|
||||
if (rule.match && rule.to) {
|
||||
const matchCoverage = rule.match[rule.inputIndex];
|
||||
for (let j = 0; j < matchCoverage.length; j++) {
|
||||
if (sink.has(matchCoverage[j]) && rule.to[j]) sink.add(rule.to[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class LookupStore {
|
|||
const dst = this.query(id);
|
||||
const handler = this.m_handlers[otdLookup.type];
|
||||
if (!dst || !handler) return;
|
||||
|
||||
if (otdLookup.subtables) throw new Error("Unreachable.");
|
||||
handler.fill(dst, otdLookup, this);
|
||||
}
|
||||
}
|
||||
|
|
@ -33,12 +33,11 @@ const GsubSingleHandler = {
|
|||
return new Ot.Gsub.Single();
|
||||
},
|
||||
fill(dst, src, store) {
|
||||
for (const st of src.subtables) {
|
||||
for (const k in st) {
|
||||
const from = store.glyphs.query(k);
|
||||
const to = store.glyphs.query(st[k]);
|
||||
if (from && to) dst.mapping.set(from, to);
|
||||
}
|
||||
const st = src.substitutions;
|
||||
for (const k in st) {
|
||||
const from = store.glyphs.query(k);
|
||||
const to = store.glyphs.query(st[k]);
|
||||
if (from && to) dst.mapping.set(from, to);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -47,13 +46,12 @@ const GsubMultipleHandler = {
|
|||
return new Ot.Gsub.Multiple();
|
||||
},
|
||||
fill(dst, src, store) {
|
||||
for (const st of src.subtables) {
|
||||
out: for (const k in st) {
|
||||
const from = store.glyphs.query(k);
|
||||
const to = mapGlyphListAll(st[k], store);
|
||||
if (!from || !to) continue out;
|
||||
dst.mapping.set(from, to);
|
||||
}
|
||||
const st = src.substitutions;
|
||||
for (const k in st) {
|
||||
const from = store.glyphs.query(k);
|
||||
const to = mapGlyphListAll(st[k], store);
|
||||
if (!from || !to) continue;
|
||||
dst.mapping.set(from, to);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -68,13 +66,12 @@ const GsubLigatureHandler = {
|
|||
return new Ot.Gsub.Ligature();
|
||||
},
|
||||
fill(dst, src, store) {
|
||||
for (const st of src.subtables) {
|
||||
for (const { from: _from, to: _to } of st.substitutions) {
|
||||
const to = store.glyphs.query(_to);
|
||||
const from = mapGlyphListAll(_from, store);
|
||||
if (!from || !to) continue;
|
||||
dst.mapping.push({ from, to });
|
||||
}
|
||||
const st = src.substitutions;
|
||||
for (const { from: _from, to: _to } of st) {
|
||||
const to = store.glyphs.query(_to);
|
||||
const from = mapGlyphListAll(_from, store);
|
||||
if (!from || !to) continue;
|
||||
dst.mapping.push({ from, to });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -84,7 +81,7 @@ const GsubChainingHandler = {
|
|||
return new Ot.Gsub.Chaining();
|
||||
},
|
||||
fill(dst, src, store) {
|
||||
out: for (const st of src.subtables) {
|
||||
out: for (const st of src.rules) {
|
||||
const match = [];
|
||||
for (const m of st.match) {
|
||||
const m1 = mapGlyphListSome(m, store);
|
||||
|
|
@ -109,7 +106,7 @@ const GsubReverseHandler = {
|
|||
return new Ot.Gsub.ReverseSub();
|
||||
},
|
||||
fill(dst, src, store) {
|
||||
out: for (const st of src.subtables) {
|
||||
out: for (const st of src.rules) {
|
||||
const match = [];
|
||||
const doSubAt = st.inputIndex;
|
||||
const replacement = new Map();
|
||||
|
|
@ -176,10 +173,9 @@ const GposMarkToBaseHandler = {
|
|||
return new Ot.Gpos.MarkToBase();
|
||||
},
|
||||
fill(dst, src, store) {
|
||||
const st = src.subtables[0];
|
||||
const mm = collectClassMap(st.marks);
|
||||
dst.marks = convertMarkRecords(st.marks, mm, store);
|
||||
dst.bases = convertBaseRecords(st.bases, mm, store);
|
||||
const mm = collectClassMap(src.marks);
|
||||
dst.marks = convertMarkRecords(src.marks, mm, store);
|
||||
dst.bases = convertBaseRecords(src.bases, mm, store);
|
||||
}
|
||||
};
|
||||
const GposMarkToMarkHandler = {
|
||||
|
|
@ -187,10 +183,9 @@ const GposMarkToMarkHandler = {
|
|||
return new Ot.Gpos.MarkToMark();
|
||||
},
|
||||
fill(dst, src, store) {
|
||||
const st = src.subtables[0];
|
||||
const mm = collectClassMap(st.marks);
|
||||
dst.marks = convertMarkRecords(st.marks, mm, store);
|
||||
dst.baseMarks = convertBaseRecords(st.bases, mm, store);
|
||||
const mm = collectClassMap(src.marks);
|
||||
dst.marks = convertMarkRecords(src.marks, mm, store);
|
||||
dst.baseMarks = convertBaseRecords(src.bases, mm, store);
|
||||
}
|
||||
};
|
||||
function collectClassMap(marks) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue