import as toposort from 'toposort' import as Gr from"../support/gr.mjs" import [CreateEmptyTable FinalizeTable MoveBackUtilityLookups] from"./table-util.mjs" import [buildLigations] from"./gsub-ligation.mjs" import [buildCCMP buildCCMPPostCvSs] from"./gsub-ccmp.mjs" import [buildGrFeature] from"./gsub-gr.mjs" import [buildFrac] from"./gsub-frac.mjs" import [buildCVSS] from"./gsub-cv-ss.mjs" import [buildLOCL] from"./gsub-locl.mjs" import [buildGsubThousands] from"./gsub-thousands.mjs" import [buildMarkMkmk] from"./gpos-mark-mkmk.mjs" import [BuildCompatLigatures] from"./compat-ligature.mjs" define GDEF_SIMPLE 1 define GDEF_LIGATURE 2 define GDEF_MARK 3 # GSUB define [buildGSUB para glyphStore markGlyphs] : begin define gsub : CreateEmptyTable # NWID / WWID if para.enableNwidWwid : begin buildGrFeature gsub glyphStore Gr.Nwid buildGrFeature gsub glyphStore Gr.Wwid # lnum / onum buildGrFeature gsub glyphStore Gr.Lnum buildGrFeature gsub glyphStore Gr.Onum # APLF if para.enableCvSs : begin buildGrFeature gsub glyphStore Gr.AplForm # numr / dnom buildGrFeature gsub glyphStore Gr.NumeratorForm buildGrFeature gsub glyphStore Gr.DenominatorForm # ccmp local ccmp : buildCCMP gsub glyphStore markGlyphs # frac buildFrac gsub glyphStore # Ligation if para.enableLigation : do define plm : Object.assign {.} para.ligation.defaultBuildup if (para.ligation.caltBuildup && para.ligation.caltBuildup.length) : begin set plm.calt para.ligation.caltBuildup buildLigations gsub para plm # THND buildGsubThousands gsub para glyphStore # cv##, ss## if para.enableCvSs : begin buildCVSS gsub para glyphStore # ccmp post cv/ss (for Ogonek shape transform) buildCCMPPostCvSs gsub ccmp glyphStore markGlyphs # locl # Builds last, but the lookups are added into the beginning of the lookup list buildLOCL gsub para glyphStore MoveBackUtilityLookups gsub FinalizeTable gsub return gsub # GPOS define [buildGPOS para glyphStore markGlyphs] : begin define gpos : CreateEmptyTable buildMarkMkmk gpos glyphStore FinalizeTable gpos return gpos # GDEF define [buildGDEF para glyphStore markGlyphs] : begin local GDEF {.glyphClassDef {.}} foreach { gn glyph } [glyphStore.namedEntries] : begin set GDEF.glyphClassDef.(gn) : if [[regex '_'].test gn] GDEF_LIGATURE GDEF_SIMPLE if (glyph.markAnchors && [begin [local anchorKeys : Object.keys glyph.markAnchors] anchorKeys.length]) : begin foreach key [items-of anchorKeys] : begin if [not markGlyphs.(key)] : set markGlyphs.(key) {} markGlyphs.(key).push gn markGlyphs.all.push gn set GDEF.glyphClassDef.(gn) GDEF_MARK return GDEF export : define [buildOtl para glyphStore] : begin local markGlyphs {.all {} } local GPOS : buildGPOS para glyphStore markGlyphs local GDEF : buildGDEF para glyphStore markGlyphs local GSUB : buildGSUB para glyphStore markGlyphs # Make all diacritics join-l (Kitty #3716) foreach gnMark [items-of markGlyphs.all] : begin Gr.Joining.or [glyphStore.queryByName gnMark] Gr.Joining.Classes.Left # Build compatibility ligatures if (para.enableLigation && para.compLig) : begin BuildCompatLigatures para glyphStore GSUB GDEF para.compLig return [object GSUB GPOS GDEF]