Optimize building speed of GPOS
This commit is contained in:
parent
81905b1276
commit
d3991a85e5
2 changed files with 58 additions and 44 deletions
|
@ -1,4 +1,6 @@
|
||||||
import [AddCommonFeature AddFeature AddLookup] from"./table-util.mjs"
|
import [AddCommonFeature AddFeature AddLookup] from"./table-util.mjs"
|
||||||
|
|
||||||
|
extern Map
|
||||||
extern Set
|
extern Set
|
||||||
|
|
||||||
define MarkClasses {
|
define MarkClasses {
|
||||||
|
@ -9,56 +11,67 @@ define MarkClasses {
|
||||||
}
|
}
|
||||||
|
|
||||||
export : define [buildMarkMkmk sink glyphStore] : begin
|
export : define [buildMarkMkmk sink glyphStore] : begin
|
||||||
define mark : AddFeature sink 'mark'
|
define validMarkClasses : new Set MarkClasses
|
||||||
define mkmk : AddFeature sink 'mkmk'
|
|
||||||
AddCommonFeature sink mark
|
|
||||||
AddCommonFeature sink mkmk
|
|
||||||
|
|
||||||
local markLookupNames {}
|
define mark : object
|
||||||
local mkmkLookupNames {}
|
feature : AddFeature sink 'mark'
|
||||||
|
lookupMap : new Map
|
||||||
|
lookupNames : new Set
|
||||||
|
createLookup : function [] {.type 'gpos_mark_to_base' .marks {.} .bases {.}}
|
||||||
|
define mkmk : object
|
||||||
|
feature : AddFeature sink 'mkmk'
|
||||||
|
lookupMap : new Map
|
||||||
|
lookupNames : new Set
|
||||||
|
createLookup : function [] {.type 'gpos_mark_to_mark' .marks {.} .bases {.}}
|
||||||
|
|
||||||
foreach markCls [items-of MarkClasses] : begin
|
AddCommonFeature sink mark.feature
|
||||||
local [object markLookup mkmkLookup] : createMTLookups glyphStore { markCls }
|
AddCommonFeature sink mkmk.feature
|
||||||
if ([objectIsNotEmpty markLookup.marks] && [objectIsNotEmpty markLookup.bases]) : begin
|
|
||||||
local lidMark : AddLookup sink markLookup
|
|
||||||
mark.lookups.push lidMark
|
|
||||||
markLookupNames.push lidMark
|
|
||||||
|
|
||||||
if ([objectIsNotEmpty mkmkLookup.marks] && [objectIsNotEmpty mkmkLookup.bases]) : begin
|
foreach cls [items-of MarkClasses] : begin
|
||||||
local lidMkmk : AddLookup sink mkmkLookup
|
local markLookup : ensureLookup sink mark cls
|
||||||
mkmk.lookups.push lidMkmk
|
local mkmkLookup : ensureLookup sink mkmk cls
|
||||||
mkmkLookupNames.push lidMkmk
|
|
||||||
|
|
||||||
foreach lidMark [items-of markLookupNames] : foreach lidMkmk [items-of mkmkLookupNames]
|
foreach { gn glyph } [glyphStore.namedEntries] : begin
|
||||||
|
local glyphIsMark false
|
||||||
|
if glyph.markAnchors.(cls) : begin
|
||||||
|
set glyphIsMark true
|
||||||
|
addMarkAnchor markLookup gn cls glyph.markAnchors.(cls)
|
||||||
|
addMarkAnchor mkmkLookup gn cls glyph.markAnchors.(cls)
|
||||||
|
|
||||||
|
if glyph.baseAnchors.(cls) : begin
|
||||||
|
local anchor : object
|
||||||
|
x glyph.baseAnchors.(cls).x
|
||||||
|
y glyph.baseAnchors.(cls).y
|
||||||
|
if glyphIsMark
|
||||||
|
: then : addBaseAnchor mkmkLookup gn cls glyph.baseAnchors.(cls)
|
||||||
|
: else : addBaseAnchor markLookup gn cls glyph.baseAnchors.(cls)
|
||||||
|
|
||||||
|
foreach lidMark mark.lookupNames : foreach lidMkmk mkmk.lookupNames
|
||||||
sink.lookupDep.push { lidMark lidMkmk }
|
sink.lookupDep.push { lidMark lidMkmk }
|
||||||
|
|
||||||
define [createMTLookups glyphStore markClasses] : begin
|
|
||||||
local markLookup {.type 'gpos_mark_to_base' .marks {.} .bases {.}}
|
|
||||||
local mkmkLookup {.type 'gpos_mark_to_mark' .marks {.} .bases {.}}
|
|
||||||
local allowMarkClsSet : new Set markClasses
|
|
||||||
foreach { gn glyph } [glyphStore.namedEntries] : begin
|
|
||||||
createMarkInfo markLookup.marks gn glyph allowMarkClsSet
|
|
||||||
createMarkInfo mkmkLookup.marks gn glyph allowMarkClsSet
|
|
||||||
local isMark : objectIsNotEmpty glyph.markAnchors
|
|
||||||
if isMark
|
|
||||||
createBaseInfo mkmkLookup.bases gn glyph allowMarkClsSet
|
|
||||||
createBaseInfo markLookup.bases gn glyph allowMarkClsSet
|
|
||||||
return : object markLookup mkmkLookup
|
|
||||||
|
|
||||||
define [createBaseInfo sink gn glyph allowMarkClsSet] : begin
|
define [ensureLookup sink feat cls] : begin
|
||||||
local res {.}
|
local existing : feat.lookupMap.get cls
|
||||||
local pushed false
|
if existing : return existing
|
||||||
foreach { markCls anchor } [pairs-of glyph.baseAnchors] : if [allowMarkClsSet.has markCls] : begin
|
|
||||||
set pushed true
|
|
||||||
set res.(markCls) {.x anchor.x .y anchor.y}
|
|
||||||
if pushed : set sink.(gn) res
|
|
||||||
return pushed
|
|
||||||
|
|
||||||
define [createMarkInfo sink gn glyph allowMarkClsSet] : begin
|
local novel : feat.createLookup
|
||||||
local m null
|
local lid : AddLookup sink novel
|
||||||
foreach { markCls anchor } [pairs-of glyph.markAnchors] : if [allowMarkClsSet.has markCls] : begin
|
feat.feature.lookups.push lid
|
||||||
set m {.class markCls .x anchor.x .y anchor.y}
|
feat.lookupNames.add lid
|
||||||
if m : set sink.(gn) m
|
feat.lookupMap.set cls novel
|
||||||
return m
|
|
||||||
|
|
||||||
define [objectIsNotEmpty obj] : obj && [Object.keys obj].length
|
return novel
|
||||||
|
|
||||||
|
define [addMarkAnchor lookup gn cls anchor] : begin
|
||||||
|
local a : object
|
||||||
|
class cls
|
||||||
|
x anchor.x
|
||||||
|
y anchor.y
|
||||||
|
set lookup.marks.(gn) a
|
||||||
|
|
||||||
|
define [addBaseAnchor lookup gn cls anchor] : begin
|
||||||
|
local a : object
|
||||||
|
x anchor.x
|
||||||
|
y anchor.y
|
||||||
|
if [not lookup.bases.(gn)] : set lookup.bases.(gn) {.}
|
||||||
|
set lookup.bases.(gn).(cls) a
|
||||||
|
|
1
sample-text/tie-marks.txt
Normal file
1
sample-text/tie-marks.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
u\u0303\u0361\u034f\u030ei\u030a u\u030e u\u034f\u030e u\u0303\u035f\u034f\u0348i\u030a u\u0348 u\u034f\u0348
|
Loading…
Add table
Add a link
Reference in a new issue