Skip to content

Commit d3991a8

Browse files
committed
Optimize building speed of GPOS
1 parent 81905b1 commit d3991a8

File tree

2 files changed

+58
-44
lines changed

2 files changed

+58
-44
lines changed

font-src/otl/gpos-mark-mkmk.ptl

+57-44
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import [AddCommonFeature AddFeature AddLookup] from"./table-util.mjs"
2+
3+
extern Map
24
extern Set
35

46
define MarkClasses {
@@ -9,56 +11,67 @@ define MarkClasses {
911
}
1012

1113
export : define [buildMarkMkmk sink glyphStore] : begin
12-
define mark : AddFeature sink 'mark'
13-
define mkmk : AddFeature sink 'mkmk'
14-
AddCommonFeature sink mark
15-
AddCommonFeature sink mkmk
14+
define validMarkClasses : new Set MarkClasses
15+
16+
define mark : object
17+
feature : AddFeature sink 'mark'
18+
lookupMap : new Map
19+
lookupNames : new Set
20+
createLookup : function [] {.type 'gpos_mark_to_base' .marks {.} .bases {.}}
21+
define mkmk : object
22+
feature : AddFeature sink 'mkmk'
23+
lookupMap : new Map
24+
lookupNames : new Set
25+
createLookup : function [] {.type 'gpos_mark_to_mark' .marks {.} .bases {.}}
26+
27+
AddCommonFeature sink mark.feature
28+
AddCommonFeature sink mkmk.feature
1629

17-
local markLookupNames {}
18-
local mkmkLookupNames {}
30+
foreach cls [items-of MarkClasses] : begin
31+
local markLookup : ensureLookup sink mark cls
32+
local mkmkLookup : ensureLookup sink mkmk cls
1933

20-
foreach markCls [items-of MarkClasses] : begin
21-
local [object markLookup mkmkLookup] : createMTLookups glyphStore { markCls }
22-
if ([objectIsNotEmpty markLookup.marks] && [objectIsNotEmpty markLookup.bases]) : begin
23-
local lidMark : AddLookup sink markLookup
24-
mark.lookups.push lidMark
25-
markLookupNames.push lidMark
34+
foreach { gn glyph } [glyphStore.namedEntries] : begin
35+
local glyphIsMark false
36+
if glyph.markAnchors.(cls) : begin
37+
set glyphIsMark true
38+
addMarkAnchor markLookup gn cls glyph.markAnchors.(cls)
39+
addMarkAnchor mkmkLookup gn cls glyph.markAnchors.(cls)
2640

27-
if ([objectIsNotEmpty mkmkLookup.marks] && [objectIsNotEmpty mkmkLookup.bases]) : begin
28-
local lidMkmk : AddLookup sink mkmkLookup
29-
mkmk.lookups.push lidMkmk
30-
mkmkLookupNames.push lidMkmk
41+
if glyph.baseAnchors.(cls) : begin
42+
local anchor : object
43+
x glyph.baseAnchors.(cls).x
44+
y glyph.baseAnchors.(cls).y
45+
if glyphIsMark
46+
: then : addBaseAnchor mkmkLookup gn cls glyph.baseAnchors.(cls)
47+
: else : addBaseAnchor markLookup gn cls glyph.baseAnchors.(cls)
3148

32-
foreach lidMark [items-of markLookupNames] : foreach lidMkmk [items-of mkmkLookupNames]
49+
foreach lidMark mark.lookupNames : foreach lidMkmk mkmk.lookupNames
3350
sink.lookupDep.push { lidMark lidMkmk }
3451

35-
define [createMTLookups glyphStore markClasses] : begin
36-
local markLookup {.type 'gpos_mark_to_base' .marks {.} .bases {.}}
37-
local mkmkLookup {.type 'gpos_mark_to_mark' .marks {.} .bases {.}}
38-
local allowMarkClsSet : new Set markClasses
39-
foreach { gn glyph } [glyphStore.namedEntries] : begin
40-
createMarkInfo markLookup.marks gn glyph allowMarkClsSet
41-
createMarkInfo mkmkLookup.marks gn glyph allowMarkClsSet
42-
local isMark : objectIsNotEmpty glyph.markAnchors
43-
if isMark
44-
createBaseInfo mkmkLookup.bases gn glyph allowMarkClsSet
45-
createBaseInfo markLookup.bases gn glyph allowMarkClsSet
46-
return : object markLookup mkmkLookup
4752

48-
define [createBaseInfo sink gn glyph allowMarkClsSet] : begin
49-
local res {.}
50-
local pushed false
51-
foreach { markCls anchor } [pairs-of glyph.baseAnchors] : if [allowMarkClsSet.has markCls] : begin
52-
set pushed true
53-
set res.(markCls) {.x anchor.x .y anchor.y}
54-
if pushed : set sink.(gn) res
55-
return pushed
53+
define [ensureLookup sink feat cls] : begin
54+
local existing : feat.lookupMap.get cls
55+
if existing : return existing
56+
57+
local novel : feat.createLookup
58+
local lid : AddLookup sink novel
59+
feat.feature.lookups.push lid
60+
feat.lookupNames.add lid
61+
feat.lookupMap.set cls novel
62+
63+
return novel
5664

57-
define [createMarkInfo sink gn glyph allowMarkClsSet] : begin
58-
local m null
59-
foreach { markCls anchor } [pairs-of glyph.markAnchors] : if [allowMarkClsSet.has markCls] : begin
60-
set m {.class markCls .x anchor.x .y anchor.y}
61-
if m : set sink.(gn) m
62-
return m
65+
define [addMarkAnchor lookup gn cls anchor] : begin
66+
local a : object
67+
class cls
68+
x anchor.x
69+
y anchor.y
70+
set lookup.marks.(gn) a
6371

64-
define [objectIsNotEmpty obj] : obj && [Object.keys obj].length
72+
define [addBaseAnchor lookup gn cls anchor] : begin
73+
local a : object
74+
x anchor.x
75+
y anchor.y
76+
if [not lookup.bases.(gn)] : set lookup.bases.(gn) {.}
77+
set lookup.bases.(gn).(cls) a

sample-text/tie-marks.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
u\u0303\u0361\u034f\u030ei\u030a u\u030e u\u034f\u030e u\u0303\u035f\u034f\u0348i\u030a u\u0348 u\u034f\u0348

0 commit comments

Comments
 (0)