Remove dupes in cv decomposition

This commit is contained in:
be5invis 2022-10-09 18:36:10 -07:00
parent dd69cf9c89
commit fa57b1a6f4
4 changed files with 49 additions and 32 deletions

View file

@ -23,9 +23,15 @@ function ConvertGsubGposImpl(handlers, T, table, glyphs) {
const ls = new LookupStore(handlers, glyphs); const ls = new LookupStore(handlers, glyphs);
if (table.lookups) { if (table.lookups) {
if (table.lookupOrder) { if (table.lookupOrder) {
for (const l of table.lookupOrder) ls.declare(l, table.lookups[l]); for (const l of table.lookupOrder) {
if (!table.lookups[l]) throw new Error("Cannot find lookup " + l);
ls.declare(l, table.lookups[l]);
}
}
for (const l in table.lookups) {
if (!table.lookups[l]) throw new Error("Cannot find lookup " + l);
ls.declare(l, table.lookups[l]);
} }
for (const l in table.lookups) ls.declare(l, table.lookups[l]);
for (const l in table.lookups) ls.fill(l, table.lookups[l]); for (const l in table.lookups) ls.fill(l, table.lookups[l]);
} }
const fs = new FeatureStore(ls); const fs = new FeatureStore(ls);

View file

@ -18,9 +18,37 @@ export : define [buildCVSS sink para glyphStore] : begin
local rec : BeginLookupBlock sink local rec : BeginLookupBlock sink
local cvLookupNameSet : new Set local cvLookupNameSet : new Set
local cvDecompositionLookupNameSet : new Set
local ssLookupNameSet : new Set local ssLookupNameSet : new Set
# Build decomposition lookups
local decompositions : new Map
local cvDecompositionLookupNameSet : new Set
local cvTagToDecompositionLookups : new Map
foreach { gn glyph } [glyphStore.namedEntries] : if [CvDecompose.get glyph] : do
local decomp : object
parts : CvDecompose.get glyph
influences : new Set
decompositions.set gn decomp
foreach part [items-of decomp.parts] : begin
local gPart : glyphStore.queryByName part
if gPart : foreach [gr : items-of : AnyCv.query gPart] : begin
if gr.tag : decomp.influences.add gr.tag
foreach { gn decomp } decompositions : if decomp.influences.size : do
define lookupName : CvDecomposeLookupName : [[Array.from decomp.influences].sort].join '/'
define lookup : PickLookup sink lookupName {.type 'gsub_multiple' .substitutions {.}}
cvDecompositionLookupNameSet.add lookupName
set lookup.substitutions.(gn) decomp.parts
foreach cvTag decomp.influences : begin
local s : cvTagToDecompositionLookups.get cvTag
if [not s] : begin
set s : new Set
cvTagToDecompositionLookups.set cvTag s
s.add lookupName
define [addCvMapping tag src dst rank] : begin define [addCvMapping tag src dst rank] : begin
define feature : PickCommonFeature sink [FeatureName tag] define feature : PickCommonFeature sink [FeatureName tag]
define lookupName : CvLookupName tag define lookupName : CvLookupName tag
@ -29,24 +57,12 @@ export : define [buildCVSS sink para glyphStore] : begin
if [not : cvLookupNameSet.has lookupName] : begin if [not : cvLookupNameSet.has lookupName] : begin
AddFeatureLookup feature lookupName AddFeatureLookup feature lookupName
cvLookupNameSet.add lookupName cvLookupNameSet.add lookupName
local decompLookups : cvTagToDecompositionLookups.get tag
if decompLookups : foreach d decompLookups : AddFeatureLookup feature d
if [not lookup.substitutions.(src)] : set lookup.substitutions.(src) { } if [not lookup.substitutions.(src)] : set lookup.substitutions.(src) { }
set lookup.substitutions.(src).(rank - 1) dst set lookup.substitutions.(src).(rank - 1) dst
define [addCvDecomposition tag gn parts] : begin
define feature : PickCommonFeature sink [FeatureName tag]
define lookupName : CvDecomposeLookupName tag
define lookup : PickLookup sink lookupName {.type 'gsub_multiple' .substitutions {.}}
if [not : cvDecompositionLookupNameSet.has lookupName] : begin
AddFeatureLookup feature lookupName
cvDecompositionLookupNameSet.add lookupName
define lookupNameCv : CvLookupName tag
sink.lookupDep.push { lookupName lookupNameCv }
set lookup.substitutions.(gn) parts
define [addSsSubstitution tag decomp src dst] : begin define [addSsSubstitution tag decomp src dst] : begin
define feature : PickCommonFeature sink [FeatureName tag] define feature : PickCommonFeature sink [FeatureName tag]
define lookupName : SsLookupName composition.tag define lookupName : SsLookupName composition.tag
@ -56,10 +72,8 @@ export : define [buildCVSS sink para glyphStore] : begin
AddFeatureLookup feature lookupName AddFeatureLookup feature lookupName
ssLookupNameSet.add lookupName ssLookupNameSet.add lookupName
foreach { prime pv } [items-of decomp] : if (pv.tag && pv.rank) : begin foreach { prime pv } [items-of decomp] : if (pv.tag && pv.rank) : begin
local pvDecomp : CvDecomposeLookupName pv.tag local decompLookups : cvTagToDecompositionLookups.get pv.tag
if [cvDecompositionLookupNameSet.has pvDecomp] : begin if decompLookups : foreach d decompLookups : AddFeatureLookup feature d
AddFeatureLookup feature pvDecomp
sink.lookupDep.push { pvDecomp lookupName }
set lookup.substitutions.(src) dst set lookup.substitutions.(src) dst
@ -68,13 +82,6 @@ export : define [buildCVSS sink para glyphStore] : begin
foreach [gr : items-of : AnyCv.query glyph] : if gr.tag : begin foreach [gr : items-of : AnyCv.query glyph] : if gr.tag : begin
addCvMapping gr.tag gn [glyphStore.ensureExists : gr.get glyph] gr.rank addCvMapping gr.tag gn [glyphStore.ensureExists : gr.get glyph] gr.rank
foreach {gn glyph} [glyphStore.namedEntries] : if [CvDecompose.get glyph] : do
local parts : CvDecompose.get glyph
foreach part [items-of parts] : begin
local gPart : glyphStore.queryByName part
if gPart : foreach [gr : items-of : AnyCv.query gPart] : if gr.tag : begin
addCvDecomposition gr.tag gn parts
# ssxx # ssxx
foreach {name composition} para.variants.composites : if composition.tag : do foreach {name composition} para.variants.composites : if composition.tag : do
define decomp : composition.decompose para para.variants.selectorTree define decomp : composition.decompose para para.variants.selectorTree
@ -91,8 +98,12 @@ export : define [buildCVSS sink para glyphStore] : begin
set v.(idx) k set v.(idx) k
# Lookup dependency # Lookup dependency
foreach lutnCv cvLookupNameSet : foreach lutnSS ssLookupNameSet : begin foreach lutnDe cvDecompositionLookupNameSet : foreach lutnCv cvLookupNameSet : begin
sink.lookupDep.push { lutnCv lutnSS } sink.lookupDep.push { lutnDe lutnCv }
foreach lutnDe cvDecompositionLookupNameSet : foreach lutnSs ssLookupNameSet : begin
sink.lookupDep.push { lutnDe lutnSs }
foreach lutnCv cvLookupNameSet : foreach lutnSs ssLookupNameSet : begin
sink.lookupDep.push { lutnCv lutnSs }
EndLookupBlock rec sink EndLookupBlock rec sink

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 328 KiB

After

Width:  |  Height:  |  Size: 328 KiB

Before After
Before After

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 328 KiB

After

Width:  |  Height:  |  Size: 328 KiB

Before After
Before After