1
1
import [AddCommonFeature AddFeature AddLookup] from"./table-util.mjs"
2
+
3
+ extern Map
2
4
extern Set
3
5
4
6
define MarkClasses {
@@ -9,56 +11,67 @@ define MarkClasses {
9
11
}
10
12
11
13
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
16
29
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
19
33
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)
26
40
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)
31
48
32
- foreach lidMark [items-of markLookupNames] : foreach lidMkmk [items-of mkmkLookupNames]
49
+ foreach lidMark mark.lookupNames : foreach lidMkmk mkmk.lookupNames
33
50
sink.lookupDep.push { lidMark lidMkmk }
34
51
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
47
52
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
56
64
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
63
71
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
0 commit comments