1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483 | 1×
1×
1×
85×
1×
1×
99×
1×
1×
182×
182×
4×
4×
1×
1×
1×
4×
1×
14×
14×
14×
14×
14×
14×
1×
1×
1×
14×
14×
7×
1×
1×
| class AATFeatureMap
# see https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html
# and /System/Library/Frameworks/CoreText.framework/Versions/A/Headers/SFNTLayoutTypes.h on a Mac
features =
allTypographicFeatures:
code: 0
exclusive: false
allTypeFeatures: 0
ligatures:
code: 1
exclusive: false
requiredLigatures: 0
commonLigatures: 2
rareLigatures: 4
# logos: 6
rebusPictures: 8
diphthongLigatures: 10
squaredLigatures: 12
abbrevSquaredLigatures: 14
symbolLigatures: 16
contextualLigatures: 18
historicalLigatures: 20
cursiveConnection:
code: 2
exclusive: true
unconnected: 0
partiallyConnected: 1
cursive: 2
letterCase:
code: 3
exclusive: true
# upperAndLowerCase: 0 # deprecated
# allCaps: 1 # deprecated
# allLowerCase: 2 # deprecated
# smallCaps: 3 # deprecated
# initialCaps: 4 # deprecated
# initialCapsAndSmallCaps: 5 # deprecated
verticalSubstitution:
code: 4
exclusive: false
substituteVerticalForms: 0
linguisticRearrangement:
code: 5
exclusive: false
linguisticRearrangement: 0
numberSpacing:
code: 6
exclusive: true
monospacedNumbers: 0
proportionalNumbers: 1
thirdWidthNumbers: 2
quarterWidthNumbers: 3
smartSwash:
code: 8
exclusive: false
wordInitialSwashes: 0
wordFinalSwashes: 2
# lineInitialSwashes: 4
# lineFinalSwashes: 6
nonFinalSwashes: 8
diacritics:
code: 9
exclusive: true
showDiacritics: 0
hideDiacritics: 1
decomposeDiacritics: 2
verticalPosition:
code: 10
exclusive: true
normalPosition: 0
superiors: 1
inferiors: 2
ordinals: 3
scientificInferiors: 4
fractions:
code: 11
exclusive: true
noFractions: 0
verticalFractions: 1
diagonalFractions: 2
overlappingCharacters:
code: 13
exclusive: false
preventOverlap: 0
typographicExtras:
code: 14
exclusive: false
# hyphensToEmDash: 0
# hyphenToEnDash: 2
slashedZero: 4
# formInterrobang: 6
# smartQuotes: 8
# periodsToEllipsis: 10
mathematicalExtras:
code: 15
exclusive: false
# hyphenToMinus: 0
# asteristoMultiply: 2
# slashToDivide: 4
# inequalityLigatures: 6
# exponents: 8
mathematicalGreek: 10
ornamentSets:
code: 16
exclusive: true
noOrnaments: 0
dingbats: 1
piCharacters: 2
fleurons: 3
decorativeBorders: 4
internationalSymbols: 5
mathSymbols: 6
characterAlternatives:
code: 17
exclusive: true
noAlternates: 0
# user defined options
designComplexity:
code: 18
exclusive: true
designLevel1: 0
designLevel2: 1
designLevel3: 2
designLevel4: 3
designLevel5: 4
styleOptions:
code: 19
exclusive: true
noStyleOptions: 0
displayText: 1
engravedText: 2
illuminatedCaps: 3
titlingCaps: 4
tallCaps: 5
characterShape:
code: 20
exclusive: true
traditionalCharacters: 0
simplifiedCharacters: 1
JIS1978Characters: 2
JIS1983Characters: 3
JIS1990Characters: 4
traditionalAltOne: 5
traditionalAltTwo: 6
traditionalAltThree: 7
traditionalAltFour: 8
traditionalAltFive: 9
expertCharacters: 10
JIS2004Characters: 11
hojoCharacters: 12
NLCCharacters: 13
traditionalNamesCharacters: 14
numberCase:
code: 21
exclusive: true
lowerCaseNumbers: 0
upperCaseNumbers: 1
textSpacing:
code: 22
exclusive: true
proportionalText: 0
monospacedText: 1
halfWidthText: 2
thirdWidthText: 3
quarterWidthText: 4
altProportionalText: 5
altHalfWidthText: 6
transliteration:
code: 23
exclusive: true
noTransliteration: 0
# hanjaToHangul: 1
# hiraganaToKatakana: 2
# katakanaToHiragana: 3
# kanaToRomanization: 4
# romanizationToHiragana: 5
# romanizationToKatakana: 6
# hanjaToHangulAltOne: 7
# hanjaToHangulAltTwo: 8
# hanjaToHangulAltThree: 9
annotation:
code: 24
exclusive: true
noAnnotation: 0
boxAnnotation: 1
roundedBoxAnnotation: 2
circleAnnotation: 3
invertedCircleAnnotation: 4
parenthesisAnnotation: 5
periodAnnotation: 6
romanNumeralAnnotation: 7
diamondAnnotation: 8
invertedBoxAnnotation: 9
invertedRoundedBoxAnnotation: 10
kanaSpacing:
code: 25
exclusive: true
fullWidthKana: 0
proportionalKana: 1
ideographicSpacing:
code: 26
exclusive: true
fullWidthIdeographs: 0
proportionalIdeographs: 1
halfWidthIdeographs: 2
unicodeDecomposition:
code: 27
exclusive: false
canonicalComposition: 0
compatibilityComposition: 2
transcodingComposition: 4
rubyKana:
code: 28
exclusive: false
# noRubyKana: 0 # deprecated - use rubyKanaOff instead
# rubyKana: 1 # deprecated - use rubyKanaOn instead
rubyKana: 2
CJKSymbolAlternatives:
code: 29
exclusive: true
noCJKSymbolAlternatives: 0
CJKSymbolAltOne: 1
CJKSymbolAltTwo: 2
CJKSymbolAltThree: 3
CJKSymbolAltFour: 4
CJKSymbolAltFive: 5
ideographicAlternatives:
code: 30
exclusive: true
noIdeographicAlternatives: 0
ideographicAltOne: 1
ideographicAltTwo: 2
ideographicAltThree: 3
ideographicAltFour: 4
ideographicAltFive: 5
CJKVerticalRomanPlacement:
code: 31
exclusive: true
CJKVerticalRomanCentered: 0
CJKVerticalRomanHBaseline: 1
italicCJKRoman:
code: 32
exclusive: false
# noCJKItalicRoman: 0 # deprecated - use CJKItalicRomanOff instead
# CJKItalicRoman: 1 # deprecated - use CJKItalicRomanOn instead
CJKItalicRoman: 2
caseSensitiveLayout:
code: 33
exclusive: false
caseSensitiveLayout: 0
caseSensitiveSpacing: 2
alternateKana:
code: 34
exclusive: false
alternateHorizKana: 0
alternateVertKana: 2
stylisticAlternatives:
code: 35
exclusive: false
noStylisticAlternates: 0
stylisticAltOne: 2
stylisticAltTwo: 4
stylisticAltThree: 6
stylisticAltFour: 8
stylisticAltFive: 10
stylisticAltSix: 12
stylisticAltSeven: 14
stylisticAltEight: 16
stylisticAltNine: 18
stylisticAltTen: 20
stylisticAltEleven: 22
stylisticAltTwelve: 24
stylisticAltThirteen: 26
stylisticAltFourteen: 28
stylisticAltFifteen: 30
stylisticAltSixteen: 32
stylisticAltSeventeen: 34
stylisticAltEighteen: 36
stylisticAltNineteen: 38
stylisticAltTwenty: 40
contextualAlternates:
code: 36
exclusive: false
contextualAlternates: 0
swashAlternates: 2
contextualSwashAlternates: 4
lowerCase:
code: 37
exclusive: true
defaultLowerCase: 0
lowerCaseSmallCaps: 1
lowerCasePetiteCaps: 2
upperCase:
code: 38
exclusive: true
defaultUpperCase: 0
upperCaseSmallCaps: 1
upperCasePetiteCaps: 2
languageTag: # indices into ltag table
code: 39
exclusive: true
CJKRomanSpacing:
code: 103
exclusive: true
halfWidthCJKRoman: 0
proportionalCJKRoman: 1
defaultCJKRoman: 2
fullWidthCJKRoman: 3
feature = (name, selector) ->
[features[name].code, features[name][selector]]
OTMapping =
rlig: feature 'ligatures', 'requiredLigatures'
clig: feature 'ligatures', 'contextualLigatures'
dlig: feature 'ligatures', 'rareLigatures'
hlig: feature 'ligatures', 'historicalLigatures'
liga: feature 'ligatures', 'commonLigatures'
hist: feature 'ligatures', 'historicalLigatures' # ??
smcp: feature 'lowerCase', 'lowerCaseSmallCaps'
pcap: feature 'lowerCase', 'lowerCasePetiteCaps'
frac: feature 'fractions', 'diagonalFractions'
dnom: feature 'fractions', 'diagonalFractions' # ??
numr: feature 'fractions', 'diagonalFractions' # ??
afrc: feature 'fractions', 'verticalFractions'
# aalt
# abvf, abvm, abvs, akhn, blwf, blwm, blws, cfar, cjct, cpsp, falt, isol, jalt, ljmo, mset?
# ltra, ltrm, nukt, pref, pres, pstf, psts, rand, rkrf, rphf, rtla, rtlm, size, tjmo, tnum?
# unic, vatu, vhal, vjmo, vpal, vrt2
# dist -> trak table?
# kern, vkrn -> kern table
# lfbd + opbd + rtbd -> opbd table?
# mark, mkmk -> acnt table?
# locl -> languageTag + ltag table
case: feature 'caseSensitiveLayout', 'caseSensitiveLayout' # also caseSensitiveSpacing
ccmp: feature 'unicodeDecomposition', 'canonicalComposition' # compatibilityComposition?
cpct: feature 'CJKVerticalRomanPlacement', 'CJKVerticalRomanCentered' # guess..., probably not given below
valt: feature 'CJKVerticalRomanPlacement', 'CJKVerticalRomanCentered'
swsh: feature 'contextualAlternates', 'swashAlternates'
cswh: feature 'contextualAlternates', 'contextualSwashAlternates'
curs: feature 'cursiveConnection', 'cursive' # ??
c2pc: feature 'upperCase', 'upperCasePetiteCaps'
c2sc: feature 'upperCase', 'upperCaseSmallCaps'
init: feature 'smartSwash', 'wordInitialSwashes' # ??
fin2: feature 'smartSwash', 'wordFinalSwashes' # ??
medi: feature 'smartSwash', 'nonFinalSwashes' # ??
med2: feature 'smartSwash', 'nonFinalSwashes' # ??
fin3: feature 'smartSwash', 'wordFinalSwashes' # ??
fina: feature 'smartSwash', 'wordFinalSwashes' # ??
fwid: feature 'kanaSpacing', 'fullWidthKana' # also ideographicSpacing: fullWidthIdeographs?
pkna: feature 'kanaSpacing', 'proportionalKana'
half: feature 'textSpacing', 'halfWidthText' # also HalfWidthCJKRoman, HalfWidthIdeographs?
halt: feature 'textSpacing', 'altHalfWidthText'
hwid: feature 'textSpacing', 'halfWidthText' # ?? what's the difference
hkna: feature 'alternateKana', 'alternateHorizKana'
vkna: feature 'alternateKana', 'alternateVertKana'
# hngl: feature 'transliteration', 'hanjaToHangulSelector' # deprecated
ital: feature 'italicCJKRoman', 'CJKItalicRoman'
lnum: feature 'numberCase', 'upperCaseNumbers'
onum: feature 'numberCase', 'lowerCaseNumbers'
mgrk: feature 'mathematicalExtras', 'mathematicalGreek'
# nalt: not enough info. what type of annotation?
# ornm: ditto, which ornament style?
calt: feature 'contextualAlternates', 'contextualAlternates' # or more?
vrt2: feature 'verticalSubstitution', 'substituteVerticalForms' # oh... below?
vert: feature 'verticalSubstitution', 'substituteVerticalForms'
tnum: feature 'numberSpacing', 'monospacedNumbers'
pnum: feature 'numberSpacing', 'proportionalNumbers'
sups: feature 'verticalPosition', 'superiors'
subs: feature 'verticalPosition', 'inferiors'
ordn: feature 'verticalPosition', 'ordinals'
pwid: feature 'textSpacing', 'proportionalText'
hwid: feature 'textSpacing', 'halfWidthText'
qwid: feature 'textSpacing', 'quarterWidthText' # also QuarterWidthNumbers?
twid: feature 'textSpacing', 'thirdWidthText' # also ThirdWidthNumbers?
fwid: feature 'textSpacing', 'proportionalText' #??
palt: feature 'textSpacing', 'altProportionalText'
trad: feature 'characterShape', 'traditionalCharacters'
smpl: feature 'characterShape', 'simplifiedCharacters'
jp78: feature 'characterShape', 'JIS1978Characters'
jp83: feature 'characterShape', 'JIS1983Characters'
jp90: feature 'characterShape', 'JIS1990Characters'
jp04: feature 'characterShape', 'JIS2004Characters'
expt: feature 'characterShape', 'expertCharacters'
hojo: feature 'characterShape', 'hojoCharacters'
nlck: feature 'characterShape', 'NLCCharacters'
tnam: feature 'characterShape', 'traditionalNamesCharacters'
ruby: feature 'rubyKana', 'rubyKana'
titl: feature 'styleOptions', 'titlingCaps'
zero: feature 'typographicExtras', 'slashedZero'
ss01: feature 'stylisticAlternatives', 'stylisticAltOne'
ss02: feature 'stylisticAlternatives', 'stylisticAltTwo'
ss03: feature 'stylisticAlternatives', 'stylisticAltThree'
ss04: feature 'stylisticAlternatives', 'stylisticAltFour'
ss05: feature 'stylisticAlternatives', 'stylisticAltFive'
ss06: feature 'stylisticAlternatives', 'stylisticAltSix'
ss07: feature 'stylisticAlternatives', 'stylisticAltSeven'
ss08: feature 'stylisticAlternatives', 'stylisticAltEight'
ss09: feature 'stylisticAlternatives', 'stylisticAltNine'
ss10: feature 'stylisticAlternatives', 'stylisticAltTen'
ss11: feature 'stylisticAlternatives', 'stylisticAltEleven'
ss12: feature 'stylisticAlternatives', 'stylisticAltTwelve'
ss13: feature 'stylisticAlternatives', 'stylisticAltThirteen'
ss14: feature 'stylisticAlternatives', 'stylisticAltFourteen'
ss15: feature 'stylisticAlternatives', 'stylisticAltFifteen'
ss16: feature 'stylisticAlternatives', 'stylisticAltSixteen'
ss17: feature 'stylisticAlternatives', 'stylisticAltSeventeen'
ss18: feature 'stylisticAlternatives', 'stylisticAltEighteen'
ss19: feature 'stylisticAlternatives', 'stylisticAltNineteen'
ss20: feature 'stylisticAlternatives', 'stylisticAltTwenty'
# salt: feature 'stylisticAlternatives', 'stylisticAltOne' # hmm, which one to choose
# Add cv01-cv99 features
for i in [1..99]
OTMapping['cv' + ('00' + i).slice(-2)] = [features.characterAlternatives.code, i]
# create inverse mapping
AATMapping = {}
for ot, aat of OTMapping
AATMapping[aat[0]] ?= {}
AATMapping[aat[0]][aat[1]] = ot
# Maps an array of OpenType features to AAT features
# in the form of {featureType:{featureSetting:true}}
@mapOTToAAT: (features) ->
res = {}
for feature in features
Eif r = OTMapping[feature]
res[r[0]] ?= {}
res[r[0]][r[1]] = true
return res
# Maps strings in a [featureType, featureSetting]
# to their equivalent number codes
mapFeatureStrings = (f) ->
[type, setting] = f
Iif isNaN(type)
typeCode = features[type]?.code
else
typeCode = type
Iif isNaN(setting)
settingCode = features[type]?[setting]
else
settingCode = setting
return [typeCode, settingCode]
# Maps AAT features to an array of OpenType features
# Supports both arrays in the form of [[featureType, featureSetting]]
# and objects in the form of {featureType:{featureSetting:true}}
# featureTypes and featureSettings can be either strings or number codes
@mapAATToOT: (features) ->
res = {}
Eif Array.isArray(features)
for feature in features
f = mapFeatureStrings feature
if r = AATMapping[f[0]]?[f[1]]
res[r] = true
else if typeof features is 'object'
for type, feature of features
for setting, v of feature
f = mapFeatureStrings [type, setting]
if v and (r = AATMapping[f[0]]?[f[1]])
res[r] = true
return Object.keys(res)
module.exports = AATFeatureMap
|