import '../support/glyph' as Glyph import '../support/transform' as Transform define GDEF_SIMPLE 1 define GDEF_LIGATURE 2 define GDEF_MARK 3 # Compatibility ligatures define [interpretLookups gs lutns lookups] : begin foreach [lutn : items-of lutns] : begin local lut lookups.(lutn) if lut : interpretLookup gs lut lookups define [interpretLookup gs lut lookups] : match lut.type "gsub_chaining" : begin local j 0 while (j < gs.length) : begin local incN 1 do : foreach [subtable : items-of lut.subtables] : begin local matchT subtable.match local ib subtable.inputBegins local foundMatch true for [local k 0] (foundMatch && k < matchT.length) [inc k] : begin if [not gs.(j + k - ib)] : then : set foundMatch false : else : if ([matchT.(k).indexOf gs.(j + k - ib)] < 0) : set foundMatch false if foundMatch : begin foreach [app : items-of subtable.apply] : do local aj : j - ib + app.at local alut lookups.(app.lookup) interpretLookupAt gs aj alut set incN : incN + subtable.inputEnds - subtable.inputBegins break nothing set j : j + incN "gsub_reverse" : begin local j (gs.length - 1) while (j >= 0) : begin do : foreach [subtable : items-of lut.subtables] : begin local matchT subtable.match local ib subtable.inputIndex local foundMatch true for [local k 0] (foundMatch && k < matchT.length) [inc k] : begin if [not gs.(j + k - ib)] : then : set foundMatch false : else : if ([matchT.(k).indexOf gs.(j + k - ib)] < 0) : set foundMatch false if foundMatch : begin set gs.(j) : subtable.to.[matchT.(ib).indexOf gs.(j)] || gs.(j) set j : j - 1 "gsub_single" : begin for [local j 0] (j < gs.length) [inc j] : begin interpretLookupAt gs j lut define [interpretLookupAt gs j lut] : match lut.type "gsub_single" : foreach [subtable : items-of lut.subtables] : begin if subtable.(gs.(j)) : begin set gs.(j) subtable.(gs.(j)) export : define [BuildCompatLigatures glyphs glyphList unicodeGlyphs GSUB GDEF config] : begin foreach [cldef : items-of config] : do if [not cldef.unicode] : break nothing if [not cldef.featureTag] : break nothing if [not cldef.sequence] : break nothing local feature null foreach [fn : items-of GSUB.languages.'DFLT_DFLT'.features] if (cldef.featureTag === [fn.slice 0 4]) : set feature GSUB.features.(fn) if [not feature] : break nothing local gnames {} for [local j 0] [j < cldef.sequence.length] [inc j] : begin if [not unicodeGlyphs.[cldef.sequence.charCodeAt j]] : break nothing gnames.push unicodeGlyphs.[cldef.sequence.charCodeAt j].name interpretLookups gnames feature GSUB.lookups local g1 : new Glyph ('$clig.' + cldef.unicode) set g1.advanceWidth 0 set g1.autoRefPriority 1 set g1.unicode {cldef.unicode} foreach [gn : items-of gnames] : begin local g glyphs.(gn) g1.applyTransform : new Transform 1 0 0 1 (-g1.advanceWidth) 0 g1.includeGlyph g g1.applyTransform : new Transform 1 0 0 1 (g1.advanceWidth) 0 set g1.advanceWidth : g1.advanceWidth + g.advanceWidth set glyphs.(g1.name) g1 set unicodeGlyphs.(cldef.unicode) g1 glyphList.push g1 set GDEF.glyphClassDef.(g1.name) GDEF_LIGATURE