-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathot_aat_layout.go
1477 lines (1280 loc) · 55.2 KB
/
ot_aat_layout.go
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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package harfbuzz
import (
"fmt"
"github.com/benoitkugler/textlayout/fonts"
tt "github.com/benoitkugler/textlayout/fonts/truetype"
)
// ported from harfbuzz/src/hb-aat-layout.h Copyright © 2018 Ebrahim Byagowi, Behdad Esfahbod
// The possible feature types defined for AAT shaping,
// from https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html
type aatLayoutFeatureType = uint16
const (
// Initial, unset feature type
// aatLayoutFeatureTypeInvalid = 0xFFFF
// [All Typographic Features](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type0)
// aatLayoutFeatureTypeAllTypographic = 0
// [Ligatures](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type1)
aatLayoutFeatureTypeLigatures = 1
// [Cursive Connection](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type2)
// aatLayoutFeatureTypeCurisveConnection = 2
// [Letter Case](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type3)
aatLayoutFeatureTypeLetterCase = 3
// [Vertical Substitution](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type4)
aatLayoutFeatureTypeVerticalSubstitution = 4
// [Linguistic Rearrangement](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type5)
// aatLayoutFeatureTypeLinguisticRearrangement = 5
// [Number Spacing](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type6)
aatLayoutFeatureTypeNumberSpacing = 6
// [Smart Swash](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type8)
// aatLayoutFeatureTypeSmartSwashType = 8
// [Diacritics](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type9)
// aatLayoutFeatureTypeDiacriticsType = 9
// [Vertical Position](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type10)
aatLayoutFeatureTypeVerticalPosition = 10
// [Fractions](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type11)
aatLayoutFeatureTypeFractions = 11
// [Overlapping Characters](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type13)
// aatLayoutFeatureTypeOverlappingCharactersType = 13
// [Typographic Extras](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type14)
aatLayoutFeatureTypeTypographicExtras = 14
// [Mathematical Extras](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type15)
aatLayoutFeatureTypeMathematicalExtras = 15
// [Ornament Sets](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type16)
// aatLayoutFeatureTypeOrnamentSetsType = 16
// [Character Alternatives](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type17)
aatLayoutFeatureTypeCharacterAlternatives = 17
// [Design Complexity](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type18)
aatLayoutFeatureTypeDesignComplexityType = 18
// [Style Options](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type19)
aatLayoutFeatureTypeStyleOptions = 19
// [Character Shape](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type20)
aatLayoutFeatureTypeCharacterShape = 20
// [Number Case](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type21)
aatLayoutFeatureTypeNumberCase = 21
// [Text Spacing](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type22)
aatLayoutFeatureTypeTextSpacing = 22
// [Transliteration](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type23)
aatLayoutFeatureTypeTransliteration = 23
// [Ruby Kana](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type28)
aatLayoutFeatureTypeRubyKana = 28
// [Italic CJK Roman](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type32)
aatLayoutFeatureTypeItalicCjkRoman = 32
// [Case Sensitive Layout](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type33)
aatLayoutFeatureTypeCaseSensitiveLayout = 33
// [Alternate Kana](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type34)
aatLayoutFeatureTypeAlternateKana = 34
// [Stylistic Alternatives](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type35)
aatLayoutFeatureTypeStylisticAlternatives = 35
// [Contextual Alternatives](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type36)
aatLayoutFeatureTypeContextualAlternatives = 36
// [Lower Case](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type37)
aatLayoutFeatureTypeLowerCase = 37
// [Upper Case](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type38)
aatLayoutFeatureTypeUpperCase = 38
)
// The selectors defined for specifying AAT feature settings.
type aatLayoutFeatureSelector = uint16
const (
/* Selectors for #aatLayoutFeatureTypeLigatures */
// for #aatLayoutFeatureTypeLigatures
aatLayoutFeatureSelectorCommonLigaturesOn = 2
// for #aatLayoutFeatureTypeLigatures
aatLayoutFeatureSelectorCommonLigaturesOff = 3
// for #aatLayoutFeatureTypeLigatures
aatLayoutFeatureSelectorRareLigaturesOn = 4
// for #aatLayoutFeatureTypeLigatures
aatLayoutFeatureSelectorRareLigaturesOff = 5
// for #aatLayoutFeatureTypeLigatures
aatLayoutFeatureSelectorContextualLigaturesOn = 18
// for #aatLayoutFeatureTypeLigatures
aatLayoutFeatureSelectorContextualLigaturesOff = 19
// for #aatLayoutFeatureTypeLigatures
aatLayoutFeatureSelectorHistoricalLigaturesOn = 20
// for #aatLayoutFeatureTypeLigatures
aatLayoutFeatureSelectorHistoricalLigaturesOff = 21
/* Selectors for #aatLayoutFeatureTypeLetterCase */
// Deprecated
aatLayoutFeatureSelectorSmallCaps = 3 /* deprecated */
/* Selectors for #aatLayoutFeatureTypeVerticalSubstitution */
// for #aatLayoutFeatureTypeVerticalSubstitution
aatLayoutFeatureSelectorSubstituteVerticalFormsOn = 0
// for #aatLayoutFeatureTypeVerticalSubstitution
aatLayoutFeatureSelectorSubstituteVerticalFormsOff = 1
/* Selectors for #aatLayoutFeatureTypeNumberSpacing */
// for #aatLayoutFeatureTypeNumberSpacing
aatLayoutFeatureSelectorMonospacedNumbers = 0
// for #aatLayoutFeatureTypeNumberSpacing
aatLayoutFeatureSelectorProportionalNumbers = 1
/* Selectors for #aatLayoutFeatureTypeVerticalPosition */
// for #aatLayoutFeatureTypeVerticalPosition
aatLayoutFeatureSelectorNormalPosition = 0
// for #aatLayoutFeatureTypeVerticalPosition
aatLayoutFeatureSelectorSuperiors = 1
// for #aatLayoutFeatureTypeVerticalPosition
aatLayoutFeatureSelectorInferiors = 2
// for #aatLayoutFeatureTypeVerticalPosition
aatLayoutFeatureSelectorOrdinals = 3
// for #aatLayoutFeatureTypeVerticalPosition
aatLayoutFeatureSelectorScientificInferiors = 4
/* Selectors for #aatLayoutFeatureTypeFractions */
// for #aatLayoutFeatureTypeFractions
aatLayoutFeatureSelectorNoFractions = 0
// for #aatLayoutFeatureTypeFractions
aatLayoutFeatureSelectorVerticalFractions = 1
// for #aatLayoutFeatureTypeFractions
aatLayoutFeatureSelectorDiagonalFractions = 2
// for #aatLayoutFeatureTypeTypographicExtras
aatLayoutFeatureSelectorSlashedZeroOn = 4
// for #aatLayoutFeatureTypeTypographicExtras
aatLayoutFeatureSelectorSlashedZeroOff = 5
/* Selectors for #aatLayoutFeatureTypeMathematicalExtras */
// for #aatLayoutFeatureTypeMathematicalExtras
aatLayoutFeatureSelectorMathematicalGreekOn = 10
// for #aatLayoutFeatureTypeMathematicalExtras
aatLayoutFeatureSelectorMathematicalGreekOff = 11
/* Selectors for #aatLayoutFeatureTypeStyleOptions */
// for #aatLayoutFeatureTypeStyleOptions
aatLayoutFeatureSelectorNoStyleOptions = 0
// for #aatLayoutFeatureTypeStyleOptions
aatLayoutFeatureSelectorTitlingCaps = 4
/* Selectors for #aatLayoutFeatureTypeCharacterShape */
// for #aatLayoutFeatureTypeCharacterShape
aatLayoutFeatureSelectorTraditionalCharacters = 0
// for #aatLayoutFeatureTypeCharacterShape
aatLayoutFeatureSelectorSimplifiedCharacters = 1
// for #aatLayoutFeatureTypeCharacterShape
aatLayoutFeatureSelectorJis1978Characters = 2
// for #aatLayoutFeatureTypeCharacterShape
aatLayoutFeatureSelectorJis1983Characters = 3
// for #aatLayoutFeatureTypeCharacterShape
aatLayoutFeatureSelectorJis1990Characters = 4
// for #aatLayoutFeatureTypeCharacterShape
aatLayoutFeatureSelectorExpertCharacters = 10
// for #aatLayoutFeatureTypeCharacterShape
aatLayoutFeatureSelectorJis2004Characters = 11
// for #aatLayoutFeatureTypeCharacterShape
aatLayoutFeatureSelectorHojoCharacters = 12
// for #aatLayoutFeatureTypeCharacterShape
aatLayoutFeatureSelectorNlccharacters = 13
// for #aatLayoutFeatureTypeCharacterShape
aatLayoutFeatureSelectorTraditionalNamesCharacters = 14
/* Selectors for #aatLayoutFeatureTypeNumberCase */
// for #aatLayoutFeatureTypeNumberCase
aatLayoutFeatureSelectorLowerCaseNumbers = 0
// for #aatLayoutFeatureTypeNumberCase
aatLayoutFeatureSelectorUpperCaseNumbers = 1
/* Selectors for #aatLayoutFeatureTypeTextSpacing */
// for #aatLayoutFeatureTypeTextSpacing
aatLayoutFeatureSelectorProportionalText = 0
// for #aatLayoutFeatureTypeTextSpacing
aatLayoutFeatureSelectorMonospacedText = 1
// for #aatLayoutFeatureTypeTextSpacing
aatLayoutFeatureSelectorHalfWidthText = 2
// for #aatLayoutFeatureTypeTextSpacing
aatLayoutFeatureSelectorThirdWidthText = 3
// for #aatLayoutFeatureTypeTextSpacing
aatLayoutFeatureSelectorQuarterWidthText = 4
// for #aatLayoutFeatureTypeTextSpacing
aatLayoutFeatureSelectorAltProportionalText = 5
// for #aatLayoutFeatureTypeTextSpacing
aatLayoutFeatureSelectorAltHalfWidthText = 6
/* Selectors for #aatLayoutFeatureTypeTransliteration */
// for #aatLayoutFeatureTypeTransliteration
aatLayoutFeatureSelectorNoTransliteration = 0
// for #aatLayoutFeatureTypeTransliteration
aatLayoutFeatureSelectorHanjaToHangul = 1
/* Selectors for #aatLayoutFeatureTypeRubyKana */
// for #aatLayoutFeatureTypeRubyKana
aatLayoutFeatureSelectorRubyKanaOn = 2
// for #aatLayoutFeatureTypeRubyKana
aatLayoutFeatureSelectorRubyKanaOff = 3
/* Selectors for #aatLayoutFeatureTypeItalicCjkRoman */
// for #aatLayoutFeatureTypeItalicCjkRoman
aatLayoutFeatureSelectorCjkItalicRomanOn = 2
// for #aatLayoutFeatureTypeItalicCjkRoman
aatLayoutFeatureSelectorCjkItalicRomanOff = 3
/* Selectors for #aatLayoutFeatureTypeCaseSensitiveLayout */
// for #aatLayoutFeatureTypeCaseSensitiveLayout
aatLayoutFeatureSelectorCaseSensitiveLayoutOn = 0
// for #aatLayoutFeatureTypeCaseSensitiveLayout
aatLayoutFeatureSelectorCaseSensitiveLayoutOff = 1
// for #aatLayoutFeatureTypeCaseSensitiveLayout
aatLayoutFeatureSelectorCaseSensitiveSpacingOn = 2
// for #aatLayoutFeatureTypeCaseSensitiveLayout
aatLayoutFeatureSelectorCaseSensitiveSpacingOff = 3
/* Selectors for #aatLayoutFeatureTypeAlternateKana */
// for #aatLayoutFeatureTypeAlternateKana
aatLayoutFeatureSelectorAlternateHorizKanaOn = 0
// for #aatLayoutFeatureTypeAlternateKana
aatLayoutFeatureSelectorAlternateHorizKanaOff = 1
// for #aatLayoutFeatureTypeAlternateKana
aatLayoutFeatureSelectorAlternateVertKanaOn = 2
// for #aatLayoutFeatureTypeAlternateKana
aatLayoutFeatureSelectorAlternateVertKanaOff = 3
/* Selectors for #aatLayoutFeatureTypeStylisticAlternatives */
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltOneOn = 2
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltOneOff = 3
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltTwoOn = 4
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltTwoOff = 5
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltThreeOn = 6
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltThreeOff = 7
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltFourOn = 8
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltFourOff = 9
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltFiveOn = 10
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltFiveOff = 11
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltSixOn = 12
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltSixOff = 13
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltSevenOn = 14
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltSevenOff = 15
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltEightOn = 16
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltEightOff = 17
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltNineOn = 18
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltNineOff = 19
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltTenOn = 20
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltTenOff = 21
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltElevenOn = 22
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltElevenOff = 23
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltTwelveOn = 24
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltTwelveOff = 25
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltThirteenOn = 26
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltThirteenOff = 27
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltFourteenOn = 28
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltFourteenOff = 29
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltFifteenOn = 30
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltFifteenOff = 31
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltSixteenOn = 32
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltSixteenOff = 33
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltSeventeenOn = 34
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltSeventeenOff = 35
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltEighteenOn = 36
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltEighteenOff = 37
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltNineteenOn = 38
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltNineteenOff = 39
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltTwentyOn = 40
// for #aatLayoutFeatureTypeStylisticAlternatives
aatLayoutFeatureSelectorStylisticAltTwentyOff = 41
/* Selectors for #aatLayoutFeatureTypeContextualAlternatives */
// for #aatLayoutFeatureTypeContextualAlternatives
aatLayoutFeatureSelectorContextualAlternatesOn = 0
// for #aatLayoutFeatureTypeContextualAlternatives
aatLayoutFeatureSelectorContextualAlternatesOff = 1
// for #aatLayoutFeatureTypeContextualAlternatives
aatLayoutFeatureSelectorSwashAlternatesOn = 2
// for #aatLayoutFeatureTypeContextualAlternatives
aatLayoutFeatureSelectorSwashAlternatesOff = 3
// for #aatLayoutFeatureTypeContextualAlternatives
aatLayoutFeatureSelectorContextualSwashAlternatesOn = 4
// for #aatLayoutFeatureTypeContextualAlternatives
aatLayoutFeatureSelectorContextualSwashAlternatesOff = 5
/* Selectors for #aatLayoutFeatureTypeLowerCase */
// for #aatLayoutFeatureTypeLowerCase
aatLayoutFeatureSelectorDefaultLowerCase = 0
// for #aatLayoutFeatureTypeLowerCase
aatLayoutFeatureSelectorLowerCaseSmallCaps = 1
// for #aatLayoutFeatureTypeLowerCase
aatLayoutFeatureSelectorLowerCasePetiteCaps = 2
/* Selectors for #aatLayoutFeatureTypeUpperCase */
// for #aatLayoutFeatureTypeUpperCase
aatLayoutFeatureSelectorDefaultUpperCase = 0
// for #aatLayoutFeatureTypeUpperCase
aatLayoutFeatureSelectorUpperCaseSmallCaps = 1
// for #aatLayoutFeatureTypeUpperCase
aatLayoutFeatureSelectorUpperCasePetiteCaps = 2
)
/* Mapping from OpenType feature tags to AAT feature names and selectors.
*
* Table data courtesy of Apple. Converted from mnemonics to integers
* when moving to this file. */
var featureMappings = [...]aatFeatureMapping{
{tt.NewTag('a', 'f', 'r', 'c'), aatLayoutFeatureTypeFractions, aatLayoutFeatureSelectorVerticalFractions, aatLayoutFeatureSelectorNoFractions},
{tt.NewTag('c', '2', 'p', 'c'), aatLayoutFeatureTypeUpperCase, aatLayoutFeatureSelectorUpperCasePetiteCaps, aatLayoutFeatureSelectorDefaultUpperCase},
{tt.NewTag('c', '2', 's', 'c'), aatLayoutFeatureTypeUpperCase, aatLayoutFeatureSelectorUpperCaseSmallCaps, aatLayoutFeatureSelectorDefaultUpperCase},
{tt.NewTag('c', 'a', 'l', 't'), aatLayoutFeatureTypeContextualAlternatives, aatLayoutFeatureSelectorContextualAlternatesOn, aatLayoutFeatureSelectorContextualAlternatesOff},
{tt.NewTag('c', 'a', 's', 'e'), aatLayoutFeatureTypeCaseSensitiveLayout, aatLayoutFeatureSelectorCaseSensitiveLayoutOn, aatLayoutFeatureSelectorCaseSensitiveLayoutOff},
{tt.NewTag('c', 'l', 'i', 'g'), aatLayoutFeatureTypeLigatures, aatLayoutFeatureSelectorContextualLigaturesOn, aatLayoutFeatureSelectorContextualLigaturesOff},
{tt.NewTag('c', 'p', 's', 'p'), aatLayoutFeatureTypeCaseSensitiveLayout, aatLayoutFeatureSelectorCaseSensitiveSpacingOn, aatLayoutFeatureSelectorCaseSensitiveSpacingOff},
{tt.NewTag('c', 's', 'w', 'h'), aatLayoutFeatureTypeContextualAlternatives, aatLayoutFeatureSelectorContextualSwashAlternatesOn, aatLayoutFeatureSelectorContextualSwashAlternatesOff},
{tt.NewTag('d', 'l', 'i', 'g'), aatLayoutFeatureTypeLigatures, aatLayoutFeatureSelectorRareLigaturesOn, aatLayoutFeatureSelectorRareLigaturesOff},
{tt.NewTag('e', 'x', 'p', 't'), aatLayoutFeatureTypeCharacterShape, aatLayoutFeatureSelectorExpertCharacters, 16},
{tt.NewTag('f', 'r', 'a', 'c'), aatLayoutFeatureTypeFractions, aatLayoutFeatureSelectorDiagonalFractions, aatLayoutFeatureSelectorNoFractions},
{tt.NewTag('f', 'w', 'i', 'd'), aatLayoutFeatureTypeTextSpacing, aatLayoutFeatureSelectorMonospacedText, 7},
{tt.NewTag('h', 'a', 'l', 't'), aatLayoutFeatureTypeTextSpacing, aatLayoutFeatureSelectorAltHalfWidthText, 7},
{tt.NewTag('h', 'i', 's', 't'), aatLayoutFeatureTypeLigatures, aatLayoutFeatureSelectorHistoricalLigaturesOn, aatLayoutFeatureSelectorHistoricalLigaturesOff},
{tt.NewTag('h', 'k', 'n', 'a'), aatLayoutFeatureTypeAlternateKana, aatLayoutFeatureSelectorAlternateHorizKanaOn, aatLayoutFeatureSelectorAlternateHorizKanaOff},
{tt.NewTag('h', 'l', 'i', 'g'), aatLayoutFeatureTypeLigatures, aatLayoutFeatureSelectorHistoricalLigaturesOn, aatLayoutFeatureSelectorHistoricalLigaturesOff},
{tt.NewTag('h', 'n', 'g', 'l'), aatLayoutFeatureTypeTransliteration, aatLayoutFeatureSelectorHanjaToHangul, aatLayoutFeatureSelectorNoTransliteration},
{tt.NewTag('h', 'o', 'j', 'o'), aatLayoutFeatureTypeCharacterShape, aatLayoutFeatureSelectorHojoCharacters, 16},
{tt.NewTag('h', 'w', 'i', 'd'), aatLayoutFeatureTypeTextSpacing, aatLayoutFeatureSelectorHalfWidthText, 7},
{tt.NewTag('i', 't', 'a', 'l'), aatLayoutFeatureTypeItalicCjkRoman, aatLayoutFeatureSelectorCjkItalicRomanOn, aatLayoutFeatureSelectorCjkItalicRomanOff},
{tt.NewTag('j', 'p', '0', '4'), aatLayoutFeatureTypeCharacterShape, aatLayoutFeatureSelectorJis2004Characters, 16},
{tt.NewTag('j', 'p', '7', '8'), aatLayoutFeatureTypeCharacterShape, aatLayoutFeatureSelectorJis1978Characters, 16},
{tt.NewTag('j', 'p', '8', '3'), aatLayoutFeatureTypeCharacterShape, aatLayoutFeatureSelectorJis1983Characters, 16},
{tt.NewTag('j', 'p', '9', '0'), aatLayoutFeatureTypeCharacterShape, aatLayoutFeatureSelectorJis1990Characters, 16},
{tt.NewTag('l', 'i', 'g', 'a'), aatLayoutFeatureTypeLigatures, aatLayoutFeatureSelectorCommonLigaturesOn, aatLayoutFeatureSelectorCommonLigaturesOff},
{tt.NewTag('l', 'n', 'u', 'm'), aatLayoutFeatureTypeNumberCase, aatLayoutFeatureSelectorUpperCaseNumbers, 2},
{tt.NewTag('m', 'g', 'r', 'k'), aatLayoutFeatureTypeMathematicalExtras, aatLayoutFeatureSelectorMathematicalGreekOn, aatLayoutFeatureSelectorMathematicalGreekOff},
{tt.NewTag('n', 'l', 'c', 'k'), aatLayoutFeatureTypeCharacterShape, aatLayoutFeatureSelectorNlccharacters, 16},
{tt.NewTag('o', 'n', 'u', 'm'), aatLayoutFeatureTypeNumberCase, aatLayoutFeatureSelectorLowerCaseNumbers, 2},
{tt.NewTag('o', 'r', 'd', 'n'), aatLayoutFeatureTypeVerticalPosition, aatLayoutFeatureSelectorOrdinals, aatLayoutFeatureSelectorNormalPosition},
{tt.NewTag('p', 'a', 'l', 't'), aatLayoutFeatureTypeTextSpacing, aatLayoutFeatureSelectorAltProportionalText, 7},
{tt.NewTag('p', 'c', 'a', 'p'), aatLayoutFeatureTypeLowerCase, aatLayoutFeatureSelectorLowerCasePetiteCaps, aatLayoutFeatureSelectorDefaultLowerCase},
{tt.NewTag('p', 'k', 'n', 'a'), aatLayoutFeatureTypeTextSpacing, aatLayoutFeatureSelectorProportionalText, 7},
{tt.NewTag('p', 'n', 'u', 'm'), aatLayoutFeatureTypeNumberSpacing, aatLayoutFeatureSelectorProportionalNumbers, 4},
{tt.NewTag('p', 'w', 'i', 'd'), aatLayoutFeatureTypeTextSpacing, aatLayoutFeatureSelectorProportionalText, 7},
{tt.NewTag('q', 'w', 'i', 'd'), aatLayoutFeatureTypeTextSpacing, aatLayoutFeatureSelectorQuarterWidthText, 7},
{tt.NewTag('r', 'u', 'b', 'y'), aatLayoutFeatureTypeRubyKana, aatLayoutFeatureSelectorRubyKanaOn, aatLayoutFeatureSelectorRubyKanaOff},
{tt.NewTag('s', 'i', 'n', 'f'), aatLayoutFeatureTypeVerticalPosition, aatLayoutFeatureSelectorScientificInferiors, aatLayoutFeatureSelectorNormalPosition},
{tt.NewTag('s', 'm', 'c', 'p'), aatLayoutFeatureTypeLowerCase, aatLayoutFeatureSelectorLowerCaseSmallCaps, aatLayoutFeatureSelectorDefaultLowerCase},
{tt.NewTag('s', 'm', 'p', 'l'), aatLayoutFeatureTypeCharacterShape, aatLayoutFeatureSelectorSimplifiedCharacters, 16},
{tt.NewTag('s', 's', '0', '1'), aatLayoutFeatureTypeStylisticAlternatives, aatLayoutFeatureSelectorStylisticAltOneOn, aatLayoutFeatureSelectorStylisticAltOneOff},
{tt.NewTag('s', 's', '0', '2'), aatLayoutFeatureTypeStylisticAlternatives, aatLayoutFeatureSelectorStylisticAltTwoOn, aatLayoutFeatureSelectorStylisticAltTwoOff},
{tt.NewTag('s', 's', '0', '3'), aatLayoutFeatureTypeStylisticAlternatives, aatLayoutFeatureSelectorStylisticAltThreeOn, aatLayoutFeatureSelectorStylisticAltThreeOff},
{tt.NewTag('s', 's', '0', '4'), aatLayoutFeatureTypeStylisticAlternatives, aatLayoutFeatureSelectorStylisticAltFourOn, aatLayoutFeatureSelectorStylisticAltFourOff},
{tt.NewTag('s', 's', '0', '5'), aatLayoutFeatureTypeStylisticAlternatives, aatLayoutFeatureSelectorStylisticAltFiveOn, aatLayoutFeatureSelectorStylisticAltFiveOff},
{tt.NewTag('s', 's', '0', '6'), aatLayoutFeatureTypeStylisticAlternatives, aatLayoutFeatureSelectorStylisticAltSixOn, aatLayoutFeatureSelectorStylisticAltSixOff},
{tt.NewTag('s', 's', '0', '7'), aatLayoutFeatureTypeStylisticAlternatives, aatLayoutFeatureSelectorStylisticAltSevenOn, aatLayoutFeatureSelectorStylisticAltSevenOff},
{tt.NewTag('s', 's', '0', '8'), aatLayoutFeatureTypeStylisticAlternatives, aatLayoutFeatureSelectorStylisticAltEightOn, aatLayoutFeatureSelectorStylisticAltEightOff},
{tt.NewTag('s', 's', '0', '9'), aatLayoutFeatureTypeStylisticAlternatives, aatLayoutFeatureSelectorStylisticAltNineOn, aatLayoutFeatureSelectorStylisticAltNineOff},
{tt.NewTag('s', 's', '1', '0'), aatLayoutFeatureTypeStylisticAlternatives, aatLayoutFeatureSelectorStylisticAltTenOn, aatLayoutFeatureSelectorStylisticAltTenOff},
{tt.NewTag('s', 's', '1', '1'), aatLayoutFeatureTypeStylisticAlternatives, aatLayoutFeatureSelectorStylisticAltElevenOn, aatLayoutFeatureSelectorStylisticAltElevenOff},
{tt.NewTag('s', 's', '1', '2'), aatLayoutFeatureTypeStylisticAlternatives, aatLayoutFeatureSelectorStylisticAltTwelveOn, aatLayoutFeatureSelectorStylisticAltTwelveOff},
{tt.NewTag('s', 's', '1', '3'), aatLayoutFeatureTypeStylisticAlternatives, aatLayoutFeatureSelectorStylisticAltThirteenOn, aatLayoutFeatureSelectorStylisticAltThirteenOff},
{tt.NewTag('s', 's', '1', '4'), aatLayoutFeatureTypeStylisticAlternatives, aatLayoutFeatureSelectorStylisticAltFourteenOn, aatLayoutFeatureSelectorStylisticAltFourteenOff},
{tt.NewTag('s', 's', '1', '5'), aatLayoutFeatureTypeStylisticAlternatives, aatLayoutFeatureSelectorStylisticAltFifteenOn, aatLayoutFeatureSelectorStylisticAltFifteenOff},
{tt.NewTag('s', 's', '1', '6'), aatLayoutFeatureTypeStylisticAlternatives, aatLayoutFeatureSelectorStylisticAltSixteenOn, aatLayoutFeatureSelectorStylisticAltSixteenOff},
{tt.NewTag('s', 's', '1', '7'), aatLayoutFeatureTypeStylisticAlternatives, aatLayoutFeatureSelectorStylisticAltSeventeenOn, aatLayoutFeatureSelectorStylisticAltSeventeenOff},
{tt.NewTag('s', 's', '1', '8'), aatLayoutFeatureTypeStylisticAlternatives, aatLayoutFeatureSelectorStylisticAltEighteenOn, aatLayoutFeatureSelectorStylisticAltEighteenOff},
{tt.NewTag('s', 's', '1', '9'), aatLayoutFeatureTypeStylisticAlternatives, aatLayoutFeatureSelectorStylisticAltNineteenOn, aatLayoutFeatureSelectorStylisticAltNineteenOff},
{tt.NewTag('s', 's', '2', '0'), aatLayoutFeatureTypeStylisticAlternatives, aatLayoutFeatureSelectorStylisticAltTwentyOn, aatLayoutFeatureSelectorStylisticAltTwentyOff},
{tt.NewTag('s', 'u', 'b', 's'), aatLayoutFeatureTypeVerticalPosition, aatLayoutFeatureSelectorInferiors, aatLayoutFeatureSelectorNormalPosition},
{tt.NewTag('s', 'u', 'p', 's'), aatLayoutFeatureTypeVerticalPosition, aatLayoutFeatureSelectorSuperiors, aatLayoutFeatureSelectorNormalPosition},
{tt.NewTag('s', 'w', 's', 'h'), aatLayoutFeatureTypeContextualAlternatives, aatLayoutFeatureSelectorSwashAlternatesOn, aatLayoutFeatureSelectorSwashAlternatesOff},
{tt.NewTag('t', 'i', 't', 'l'), aatLayoutFeatureTypeStyleOptions, aatLayoutFeatureSelectorTitlingCaps, aatLayoutFeatureSelectorNoStyleOptions},
{tt.NewTag('t', 'n', 'a', 'm'), aatLayoutFeatureTypeCharacterShape, aatLayoutFeatureSelectorTraditionalNamesCharacters, 16},
{tt.NewTag('t', 'n', 'u', 'm'), aatLayoutFeatureTypeNumberSpacing, aatLayoutFeatureSelectorMonospacedNumbers, 4},
{tt.NewTag('t', 'r', 'a', 'd'), aatLayoutFeatureTypeCharacterShape, aatLayoutFeatureSelectorTraditionalCharacters, 16},
{tt.NewTag('t', 'w', 'i', 'd'), aatLayoutFeatureTypeTextSpacing, aatLayoutFeatureSelectorThirdWidthText, 7},
{tt.NewTag('u', 'n', 'i', 'c'), aatLayoutFeatureTypeLetterCase, 14, 15},
{tt.NewTag('v', 'a', 'l', 't'), aatLayoutFeatureTypeTextSpacing, aatLayoutFeatureSelectorAltProportionalText, 7},
{tt.NewTag('v', 'e', 'r', 't'), aatLayoutFeatureTypeVerticalSubstitution, aatLayoutFeatureSelectorSubstituteVerticalFormsOn, aatLayoutFeatureSelectorSubstituteVerticalFormsOff},
{tt.NewTag('v', 'h', 'a', 'l'), aatLayoutFeatureTypeTextSpacing, aatLayoutFeatureSelectorAltHalfWidthText, 7},
{tt.NewTag('v', 'k', 'n', 'a'), aatLayoutFeatureTypeAlternateKana, aatLayoutFeatureSelectorAlternateVertKanaOn, aatLayoutFeatureSelectorAlternateVertKanaOff},
{tt.NewTag('v', 'p', 'a', 'l'), aatLayoutFeatureTypeTextSpacing, aatLayoutFeatureSelectorAltProportionalText, 7},
{tt.NewTag('v', 'r', 't', '2'), aatLayoutFeatureTypeVerticalSubstitution, aatLayoutFeatureSelectorSubstituteVerticalFormsOn, aatLayoutFeatureSelectorSubstituteVerticalFormsOff},
{tt.NewTag('z', 'e', 'r', 'o'), aatLayoutFeatureTypeTypographicExtras, aatLayoutFeatureSelectorSlashedZeroOn, aatLayoutFeatureSelectorSlashedZeroOff},
}
// Used when getting or setting AAT feature selectors. Indicates that
// there is no selector index corresponding to the selector of interest.
const aatLayoutNoSelectorIndex = 0xFFFF
/* Note: This context is used for kerning, even without AAT, hence the condition. */
/**
* SECTION:hb-aat-layout
* @title: hb-aat-layout
* @short_description: Apple Advanced Typography Layout
* @include: hb-aat.h
*
* Functions for querying AAT Layout features in the font face.
*
* HarfBuzz supports all of the AAT tables (in their modern version) used to implement shaping. Other
* AAT tables and their associated features are not supported.
**/
// execute the state machine in AAT tables
type stateTableDriver struct {
buffer *Buffer
machine tt.AATStateTable
}
func newStateTableDriver(machine tt.AATStateTable, buffer *Buffer, face fonts.FaceMetrics) stateTableDriver {
return stateTableDriver{
machine: machine,
buffer: buffer,
}
}
// implemented by the subtables
type driverContext interface {
inPlace() bool
isActionable(s stateTableDriver, entry tt.AATStateEntry) bool
transition(s stateTableDriver, entry tt.AATStateEntry)
}
func (s stateTableDriver) drive(c driverContext) {
const (
stateStartOfText = uint16(0)
classEndOfText = uint16(0)
DontAdvance = 0x4000
)
if !c.inPlace() {
s.buffer.clearOutput()
}
state := stateStartOfText
for s.buffer.idx = 0; ; {
class := classEndOfText
if s.buffer.idx < len(s.buffer.Info) {
class = s.machine.GetClass(s.buffer.Info[s.buffer.idx].Glyph)
}
if debugMode >= 2 {
fmt.Printf("\t\tState machine - state %d, class %d at index %d\n", state, class, s.buffer.idx)
}
entry := s.machine.GetEntry(state, class)
nextState := entry.NewState // we only supported extended table
/* Conditions under which it's guaranteed safe-to-break before current glyph:
*
* 1. There was no action in this transition; and
*
* 2. If we break before current glyph, the results will be the same. That
* is guaranteed if:
*
* 2a. We were already in start-of-text state; or
*
* 2b. We are epsilon-transitioning to start-of-text state; or
*
* 2c. Starting from start-of-text state seeing current glyph:
*
* 2c'. There won't be any actions; and
*
* 2c". We would end up in the same state that we were going to end up
* in now, including whether epsilon-transitioning.
*
* and
*
* 3. If we break before current glyph, there won't be any end-of-text action
* after previous glyph.
*
* This triples the transitions we need to look up, but is worth returning
* granular unsafe-to-break results. See eg.:
*
* https://github.com/harfbuzz/harfbuzz/issues/2860
*/
wouldbeEntry := s.machine.GetEntry(stateStartOfText, class)
safeToBreak := /* 1. */ !c.isActionable(s, entry) &&
/* 2. */
(
/* 2a. */
state == stateStartOfText ||
/* 2b. */
((entry.Flags&DontAdvance != 0) && nextState == stateStartOfText) ||
/* 2c. */
(
/* 2c'. */
!c.isActionable(s, wouldbeEntry) &&
/* 2c". */
(nextState == wouldbeEntry.NewState) &&
(entry.Flags&DontAdvance) == (wouldbeEntry.Flags&DontAdvance))) &&
/* 3. */
!c.isActionable(s, s.machine.GetEntry(state, classEndOfText))
if !safeToBreak && s.buffer.backtrackLen() != 0 && s.buffer.idx < len(s.buffer.Info) {
s.buffer.unsafeToBreakFromOutbuffer(s.buffer.backtrackLen()-1, s.buffer.idx+1)
}
c.transition(s, entry)
state = nextState
if debugMode >= 2 {
fmt.Printf("\t\tState machine - new state %d\n", state)
}
if s.buffer.idx == len(s.buffer.Info) {
break
}
if entry.Flags&DontAdvance == 0 {
s.buffer.nextGlyph()
} else {
if s.buffer.maxOps <= 0 {
s.buffer.maxOps--
s.buffer.nextGlyph()
}
s.buffer.maxOps--
}
}
if !c.inPlace() {
s.buffer.swapBuffers()
}
}
type aatApplyContext struct {
plan *otShapePlan
font *Font
face fonts.FaceMetrics
buffer *Buffer
gdefTable *tt.TableGDEF
ankrTable tt.TableAnkr
}
func newAatApplyContext(plan *otShapePlan, font *Font, buffer *Buffer) *aatApplyContext {
var out aatApplyContext
out.plan = plan
out.font = font
out.face = font.face
out.buffer = buffer
out.gdefTable = &font.otTables.GDEF
return &out
}
func (c *aatApplyContext) applyMorx(chain tt.MorxChain, flags GlyphMask) {
// Coverage, see https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6morx.html
const (
Vertical = 0x80
Backwards = 0x40
AllDirections = 0x20
Logical = 0x10
)
for i, subtable := range chain.Subtables {
if subtable.Flags&flags == 0 {
continue
}
if subtable.Coverage&AllDirections == 0 && c.buffer.Props.Direction.isVertical() !=
(subtable.Coverage&Vertical != 0) {
continue
}
/* Buffer contents is always in logical direction. Determine if
we need to reverse before applying this subtable. We reverse
back after if we did reverse indeed.
Quoting the spec:
"""
Bits 28 and 30 of the coverage field control the order in which
glyphs are processed when the subtable is run by the layout engine.
Bit 28 is used to indicate if the glyph processing direction is
the same as logical order or layout order. Bit 30 is used to
indicate whether glyphs are processed forwards or backwards within
that order.
Bit 30 Bit 28 Interpretation for Horizontal Text
0 0 The subtable is processed in layout order (the same order as the glyphs, which is
always left-to-right).
1 0 The subtable is processed in reverse layout order (the order opposite that of the glyphs, which is
always right-to-left).
0 1 The subtable is processed in logical order (the same order as the characters, which may be
left-to-right or right-to-left).
1 1 The subtable is processed in reverse logical order (the order opposite that of the characters, which
may be right-to-left or left-to-right).
"""
*/
var reverse bool
if subtable.Coverage&Logical != 0 {
reverse = subtable.Coverage&Backwards != 0
} else {
reverse = subtable.Coverage&Backwards != 0 != c.buffer.Props.Direction.isBackward()
}
if debugMode >= 2 {
fmt.Printf("MORX - start chainsubtable %d\n", i)
}
if reverse {
reverseGraphemes(c.buffer)
}
c.applyMorxSubtable(subtable)
if reverse {
reverseGraphemes(c.buffer)
}
if debugMode >= 2 {
fmt.Printf("MORX - end chainsubtable %d\n", i)
fmt.Println(c.buffer.Info)
}
}
}
func (c *aatApplyContext) applyMorxSubtable(subtable tt.MortxSubtable) bool {
if debugMode >= 2 {
fmt.Printf("\tMORX subtable %T\n", subtable.Data)
}
switch data := subtable.Data.(type) {
case tt.MorxRearrangementSubtable:
var dc driverContextRearrangement
driver := newStateTableDriver(tt.AATStateTable(data), c.buffer, c.face)
driver.drive(&dc)
case tt.MorxContextualSubtable:
dc := driverContextContextual{table: data, gdef: c.gdefTable, hasGlyphClass: c.gdefTable.Class != nil}
driver := newStateTableDriver(data.Machine, c.buffer, c.face)
driver.drive(&dc)
return dc.ret
case tt.MorxLigatureSubtable:
dc := driverContextLigature{table: data}
driver := newStateTableDriver(data.Machine, c.buffer, c.face)
driver.drive(&dc)
case tt.MorxInsertionSubtable:
dc := driverContextInsertion{insertionAction: data.Insertions}
driver := newStateTableDriver(data.Machine, c.buffer, c.face)
driver.drive(&dc)
case tt.MorxNonContextualSubtable:
var ret bool
gdef := c.gdefTable
hasGlyphClass := gdef.Class != nil
info := c.buffer.Info
for i := range c.buffer.Info {
replacement, has := data.ClassID(info[i].Glyph)
if has {
info[i].Glyph = fonts.GID(replacement)
if hasGlyphClass {
info[i].glyphProps = gdef.GetGlyphProps(fonts.GID(replacement))
}
ret = true
}
}
return ret
}
return false
}
type driverContextRearrangement struct {
start int
end int
}
func (driverContextRearrangement) inPlace() bool { return true }
func (d driverContextRearrangement) isActionable(_ stateTableDriver, entry tt.AATStateEntry) bool {
return (entry.Flags&tt.MRVerb) != 0 && d.start < d.end
}
/* The following map has two nibbles, for start-side
* and end-side. Values of 0,1,2 mean move that many
* to the other side. Value of 3 means move 2 and
* flip them. */
var mapRearrangement = [16]int{
0x00, /* 0 no change */
0x10, /* 1 Ax => xA */
0x01, /* 2 xD => Dx */
0x11, /* 3 AxD => DxA */
0x20, /* 4 ABx => xAB */
0x30, /* 5 ABx => xBA */
0x02, /* 6 xCD => CDx */
0x03, /* 7 xCD => DCx */
0x12, /* 8 AxCD => CDxA */
0x13, /* 9 AxCD => DCxA */
0x21, /* 10 ABxD => DxAB */
0x31, /* 11 ABxD => DxBA */
0x22, /* 12 ABxCD => CDxAB */
0x32, /* 13 ABxCD => CDxBA */
0x23, /* 14 ABxCD => DCxAB */
0x33, /* 15 ABxCD => DCxBA */
}
func (d *driverContextRearrangement) transition(driver stateTableDriver, entry tt.AATStateEntry) {
buffer := driver.buffer
flags := entry.Flags
if flags&tt.MRMarkFirst != 0 {
d.start = buffer.idx
}
if flags&tt.MRMarkLast != 0 {
d.end = min(buffer.idx+1, len(buffer.Info))
}
if (flags&tt.MRVerb) != 0 && d.start < d.end {
m := mapRearrangement[flags&tt.MRVerb]
l := min(2, m>>4)
r := min(2, m&0x0F)
reverseL := m>>4 == 3
reverseR := m&0x0F == 3
if d.end-d.start >= l+r {
buffer.mergeClusters(d.start, min(buffer.idx+1, len(buffer.Info)))
buffer.mergeClusters(d.start, d.end)
info := buffer.Info
var buf [4]GlyphInfo
copy(buf[:], info[d.start:d.start+l])
copy(buf[2:], info[d.end-r:d.end])
if l != r {
copy(info[d.start+r:], info[d.start+l:d.end-r])
}
copy(info[d.start:d.start+r], buf[2:])
copy(info[d.end-l:d.end], buf[:])
if reverseL {
buf[0] = info[d.end-1]
info[d.end-1] = info[d.end-2]
info[d.end-2] = buf[0]
}
if reverseR {
buf[0] = info[d.start]
info[d.start] = info[d.start+1]
info[d.start+1] = buf[0]
}
}
}
}
type driverContextContextual struct {
gdef *tt.TableGDEF
table tt.MorxContextualSubtable
mark int
markSet bool
ret bool
hasGlyphClass bool // cached version from gdef
}
func (driverContextContextual) inPlace() bool { return true }
func (dc driverContextContextual) isActionable(driver stateTableDriver, entry tt.AATStateEntry) bool {
buffer := driver.buffer
if buffer.idx == len(buffer.Info) && !dc.markSet {
return false
}
markIndex, currentIndex := entry.AsMorxContextual()
return markIndex != 0xFFFF || currentIndex != 0xFFFF
}
func (dc *driverContextContextual) transition(driver stateTableDriver, entry tt.AATStateEntry) {
buffer := driver.buffer
/* Looks like CoreText applies neither mark nor current substitution for
* end-of-text if mark was not explicitly set. */
if buffer.idx == len(buffer.Info) && !dc.markSet {
return
}
var (
replacement uint32 // intepreted as GlyphIndex
hasRep bool
markIndex, currentIndex = entry.AsMorxContextual()
)
if markIndex != 0xFFFF {
lookup := dc.table.Substitutions[markIndex]
replacement, hasRep = lookup.ClassID(buffer.Info[dc.mark].Glyph)
}
if hasRep {
buffer.unsafeToBreak(dc.mark, min(buffer.idx+1, len(buffer.Info)))
buffer.Info[dc.mark].Glyph = fonts.GID(replacement)
if dc.hasGlyphClass {
buffer.Info[dc.mark].glyphProps = dc.gdef.GetGlyphProps(fonts.GID(replacement))
}
dc.ret = true
}
hasRep = false
idx := min(buffer.idx, len(buffer.Info)-1)
if currentIndex != 0xFFFF {
lookup := dc.table.Substitutions[currentIndex]
replacement, hasRep = lookup.ClassID(buffer.Info[idx].Glyph)
}
if hasRep {
buffer.Info[idx].Glyph = fonts.GID(replacement)
if dc.hasGlyphClass {
buffer.Info[idx].glyphProps = dc.gdef.GetGlyphProps(fonts.GID(replacement))
}
dc.ret = true
}
if entry.Flags&tt.MCSetMark != 0 {
dc.markSet = true
dc.mark = buffer.idx
}
}
type driverContextLigature struct {
table tt.MorxLigatureSubtable
matchLength int
matchPositions [maxContextLength]int
}
func (driverContextLigature) inPlace() bool { return false }
func (driverContextLigature) isActionable(_ stateTableDriver, entry tt.AATStateEntry) bool {
return entry.Flags&tt.MLOffset != 0
}
func (dc *driverContextLigature) transition(driver stateTableDriver, entry tt.AATStateEntry) {
buffer := driver.buffer
if debugMode >= 2 {
fmt.Printf("\tLigature - Ligature transition at %d\n", buffer.idx)
}
if entry.Flags&tt.MLSetComponent != 0 {
/* Never mark same index twice, in case DontAdvance was used... */
if dc.matchLength != 0 && dc.matchPositions[(dc.matchLength-1)%len(dc.matchPositions)] == len(buffer.outInfo) {
dc.matchLength--
}
dc.matchPositions[dc.matchLength%len(dc.matchPositions)] = len(buffer.outInfo)
dc.matchLength++
if debugMode >= 2 {
fmt.Printf("\tLigature - Set component at %d\n", len(buffer.outInfo))
}
}
if dc.isActionable(driver, entry) {
if debugMode >= 2 {
fmt.Printf("\tLigature - Perform action with %d\n", dc.matchLength)
}
end := len(buffer.outInfo)
if dc.matchLength == 0 {
return
}
if buffer.idx >= len(buffer.Info) {
return
}
cursor := dc.matchLength
actionIdx := entry.AsMorxLigature()
actionData := dc.table.LigatureAction[actionIdx:]
ligatureIdx := 0
var action uint32
for do := true; do; do = action&tt.MLActionLast == 0 {
if cursor == 0 {
/* Stack underflow. Clear the stack. */
if debugMode >= 2 {
fmt.Println("\tLigature - Stack underflow")
}
dc.matchLength = 0
break
}
if debugMode >= 2 {
fmt.Printf("\tLigature - Moving to stack position %d\n", cursor-1)
}
cursor--
buffer.moveTo(dc.matchPositions[cursor%len(dc.matchPositions)])
if len(actionData) == 0 {
break
}
action = actionData[0]
uoffset := action & tt.MLActionOffset
if uoffset&0x20000000 != 0 {
uoffset |= 0xC0000000 /* Sign-extend. */
}
offset := int32(uoffset)
componentIdx := int32(buffer.cur(0).Glyph) + offset
if int(componentIdx) >= len(dc.table.Component) {
break
}
componentData := dc.table.Component[componentIdx]
ligatureIdx += int(componentData)
if debugMode >= 2 {
fmt.Printf("\tLigature - Action store %d last %d\n", action&tt.MLActionStore, action&tt.MLActionLast)
}
if action&(tt.MLActionStore|tt.MLActionLast) != 0 {
if ligatureIdx >= len(dc.table.Ligatures) {
break
}
lig := dc.table.Ligatures[ligatureIdx]
if debugMode >= 2 {
fmt.Printf("\tLigature - Produced ligature %d\n", lig)
}
buffer.replaceGlyphIndex(lig)
ligEnd := dc.matchPositions[(dc.matchLength-1)%len(dc.matchPositions)] + 1
/* Now go and delete all subsequent components. */
for dc.matchLength-1 > cursor {
if debugMode >= 2 {
fmt.Println("\tLigature - Skipping ligature component")
}
dc.matchLength--
buffer.moveTo(dc.matchPositions[dc.matchLength%len(dc.matchPositions)])
buffer.replaceGlyphIndex(0xFFFF)
}
buffer.moveTo(ligEnd)
buffer.mergeOutClusters(dc.matchPositions[cursor%len(dc.matchPositions)], len(buffer.outInfo))
}
actionData = actionData[1:]
}
buffer.moveTo(end)
}
}
type driverContextInsertion struct {