Add support of Unicode Variation Sequence for 0 that adds a slash (#1534).

This commit is contained in:
be5invis 2023-01-22 17:48:49 -08:00
parent d2faa3883b
commit 1c0fb8b0f3
5 changed files with 56 additions and 9 deletions

View file

@ -1,4 +1,11 @@
import { Radical } from "../../support/gr.mjs";
import { Radical, VS01 } from "../../support/gr.mjs";
export function gcFont(glyphStore, excludedChars, otl, cfg) {
markSweepOtlLookups(otl.GSUB);
markSweepOtlLookups(otl.GPOS);
const sink = markGlyphs(glyphStore, excludedChars, otl, cfg);
return sweepGlyphs(glyphStore, sink);
}
function markSweepOtlLookups(table) {
if (!table || !table.features || !table.lookups) return;
@ -56,6 +63,7 @@ function sweepFeatures(table, accessibleLookupsIds) {
}
table.features = features1;
}
function markGlyphs(glyphStore, excludedChars, otl, cfg) {
const sink = markGlyphsInitial(glyphStore, excludedChars);
while (markGlyphsStep(glyphStore, sink, otl, cfg));
@ -78,6 +86,9 @@ function markGlyphsInitial(glyphStore, excludedChars) {
}
function markGlyphsStep(glyphStore, sink, otl, cfg) {
const glyphCount = sink.size;
for (const g of glyphStore.glyphs()) {
markLinkedGlyph(sink, g, VS01);
}
if (otl.GSUB) {
for (const l in otl.GSUB.lookups) {
const lookup = otl.GSUB.lookups[l];
@ -88,6 +99,10 @@ function markGlyphsStep(glyphStore, sink, otl, cfg) {
const glyphCount1 = sink.size;
return glyphCount1 > glyphCount;
}
function markLinkedGlyph(sink, g, gr) {
const linked = gr.get(g);
if (linked) sink.add(linked);
}
function markGlyphsLookupImpl(sink, lookup, cfg) {
switch (lookup.type) {
case "gsub_single":
@ -136,12 +151,7 @@ function markGlyphsGsubReverse(sink, lookup, cfg) {
}
}
}
function sweep(glyphStore, gnSet) {
function sweepGlyphs(glyphStore, gnSet) {
return glyphStore.filterByName(gnSet);
}
export function gcFont(glyphStore, excludedChars, otl, cfg) {
markSweepOtlLookups(otl.GSUB);
markSweepOtlLookups(otl.GPOS);
const sink = markGlyphs(glyphStore, excludedChars, otl, cfg);
return sweep(glyphStore, sink);
}

View file

@ -122,10 +122,13 @@ class MappedGlyphStore {
g.geometry = cs;
}
}
export function convertGlyphs(gsOrig) {
const sortedEntries = Array.from(gsOrig.namedEntries(Gr.Nwid, Gr.Wwid)).sort(byRank);
const gs = new MappedGlyphStore();
const cmap = new Ot.Cmap.Table();
// initialize
for (const [name, gSrc] of sortedEntries) {
gs.declare(name, gSrc);
const us = gsOrig.queryUnicodeOf(gSrc);
@ -137,7 +140,36 @@ export function convertGlyphs(gsOrig) {
}
}
}
// fill geometry
for (const [name, gSrc] of sortedEntries) gs.fill(name, gSrc);
// fill VS
addVsLinks(gsOrig, gs, cmap, Gr.VS01, 0xfe00);
// fill glyph names
gs.fillOtGlyphNames();
return { glyphs: gs, cmap };
}
function addVsLinks(gsOrig, gs, cmap, gr, vs) {
for (const gSrc of gsOrig.glyphs()) {
const us = gsOrig.queryUnicodeOf(gSrc);
if (!us) continue;
const gnSrcLinked = gr.get(gSrc);
if (!gnSrcLinked) continue;
const gSrcLinked = gsOrig.queryByName(gnSrcLinked);
if (!gSrcLinked) continue;
const gDstLinked = gs.queryBySourceGlyph(gSrcLinked);
if (!gDstLinked) continue;
for (const u of us) {
if (!(isFinite(u - 0) && u)) continue;
cmap.vs.set(u, vs, gDstLinked);
}
}
}