74 lines
2.8 KiB
Text
74 lines
2.8 KiB
Text
import [add-lookup add-common-feature pick-feature add-feature-lookup pick-lookup BeginLookupBlock EndLookupBlock] from "./table-util"
|
|
import [Cv AnyCv CvDecompose] from "../support/gr"
|
|
extern Set
|
|
|
|
define [FeatureName tag] : tag + '_cvss'
|
|
define [CvLookupName tag] : 'lookup_cv_' + tag
|
|
define [SsLookupName tag] : 'lookup_ss_' + tag
|
|
|
|
export : define [buildCVSS sink para glyphStore] : begin
|
|
if [not para.enableCvSs] : return nothing
|
|
|
|
local rec : BeginLookupBlock sink
|
|
local cvLookupNameSet : new Set
|
|
local ssLookupNameSet : new Set
|
|
|
|
# Decomposition of enclosures
|
|
define decompositions {.}
|
|
foreach { gid g } [glyphStore.namedEntries] : begin
|
|
local parts : CvDecompose.get g
|
|
if (parts && parts.length) : set decompositions.(gid) parts
|
|
|
|
define lookupNameCvDecompose : add-lookup sink : object
|
|
.type 'gsub_multiple'
|
|
.substitutions decompositions
|
|
|
|
define [addFeatureAndLookup tag lookupName init] : begin
|
|
define feature : pick-feature sink [FeatureName tag]
|
|
add-common-feature sink feature
|
|
|
|
define lookup : pick-lookup sink lookupName init
|
|
add-feature-lookup feature lookupNameCvDecompose
|
|
add-feature-lookup feature lookupName
|
|
sink.lookupDep.push { lookupNameCvDecompose lookupName }
|
|
cvLookupNameSet.add lookupName
|
|
|
|
|
|
# cvxx
|
|
foreach {gn glyph} [glyphStore.namedEntries] : if [not : CvDecompose.get glyph] : do
|
|
foreach [gr : items-of : AnyCv.query glyph] : if gr.tag : begin
|
|
define lookupName : CvLookupName gr.tag
|
|
if [not : cvLookupNameSet.has lookupName] : begin
|
|
addFeatureAndLookup gr.tag lookupName {.type 'gsub_alternate' .substitutions {.}}
|
|
cvLookupNameSet.add lookupName
|
|
|
|
local st [pick-lookup sink lookupName].substitutions
|
|
if [not st.(gn)] : set st.(gn) { }
|
|
set st.(gn).(gr.rank - 1) : glyphStore.ensureExists : gr.get glyph
|
|
|
|
# ssxx
|
|
foreach {name composition} para.variants.composites : if composition.tag : do
|
|
define lookupName : SsLookupName composition.tag
|
|
if [not : ssLookupNameSet.has lookupName] : begin
|
|
addFeatureAndLookup composition.tag lookupName {.type 'gsub_single' .substitutions {.}}
|
|
cvLookupNameSet.add lookupName
|
|
|
|
define st [pick-lookup sink lookupName].substitutions
|
|
define decomp : composition.decompose para para.variants.selectorTree
|
|
foreach { prime pv } [items-of decomp] : if (pv.tag && pv.rank) : begin
|
|
local gr : Cv pv.tag pv.rank
|
|
foreach {gn glyph} [glyphStore.namedEntries] : if [not : CvDecompose.get glyph] : begin
|
|
local substituted : gr.get glyph
|
|
if substituted : set st.(gn) substituted
|
|
|
|
# If there are holes in the alternates list, fill them
|
|
foreach lutn cvLookupNameSet : begin
|
|
local st [pick-lookup sink lutn].substitutions
|
|
foreach { k v } [pairs-of st] : foreach idx [range 0 v.length] : if [not v.(idx)]
|
|
set v.(idx) k
|
|
|
|
# Lookup dependency
|
|
foreach lutnCv cvLookupNameSet : foreach lutnSS ssLookupNameSet : begin
|
|
sink.lookupDep.push { lutnCv lutnSS }
|
|
|
|
EndLookupBlock rec sink
|