35 lines
1.3 KiB
Text
35 lines
1.3 KiB
Text
import [add-common-feature add-feature add-lookup BeginLookupBlock EndLookupBlock] from "./table-util"
|
|
|
|
# Name-driven feature pairs
|
|
export : define [buildPairFeature sink tag1 tag2 glyphStore codedOnly] : begin
|
|
local rec : BeginLookupBlock sink
|
|
|
|
local mapTag2 {.}
|
|
local mapTag1 {.}
|
|
define reHidden : regex "^\\."
|
|
define reTag1 : new RegExp ("\\." + tag1 + "$")
|
|
foreach { glyphName glyph } [glyphStore.namedEntries] : begin
|
|
if ([reTag1.test glyphName] && ![reHidden.test glyphName]) : do
|
|
local gnTag2 : glyphName.replace reTag1 ('.' + tag2)
|
|
local glyphTag2 : glyphStore.queryByName gnTag2
|
|
if (glyphTag2) : begin
|
|
if(!codedOnly || [glyphStore.queryUnicodeOf glyph])
|
|
set mapTag2.(glyphName) gnTag2
|
|
if(!codedOnly || [glyphStore.queryUnicodeOf glyphTag2])
|
|
set mapTag1.(gnTag2) glyphName
|
|
|
|
if [objectIsNotEmpty mapTag1] : begin
|
|
define lookup1 : add-lookup sink {.type 'gsub_single' .substitutions mapTag1}
|
|
define feature1 : add-feature sink tag1
|
|
feature1.lookups.push lookup1
|
|
add-common-feature sink feature1
|
|
|
|
if [objectIsNotEmpty mapTag2] : begin
|
|
define lookup2 : add-lookup sink {.type 'gsub_single' .substitutions mapTag2}
|
|
define feature2 : add-feature sink tag2
|
|
feature2.lookups.push lookup2
|
|
add-common-feature sink feature2
|
|
|
|
EndLookupBlock rec sink
|
|
|
|
define [objectIsNotEmpty obj] : obj && [Object.keys obj].length
|