swash/feature/
util.rs

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
use super::internal::{raw_tag, RawTag};

#[derive(Copy, Clone)]
pub struct SeenFeatures {
    bits: [u32; 6],
}

impl SeenFeatures {
    pub fn new() -> Self {
        Self { bits: [0; 6] }
    }

    pub fn mark(&mut self, feature_index: usize) -> bool {
        let word = &mut self.bits[feature_index / 32];
        let bit = 1 << (feature_index % 32);
        if *word & bit == 0 {
            *word |= bit;
            true
        } else {
            false
        }
    }
}

/// Returns a feature description for the specified tag.
pub fn desc_from_at(tag: RawTag) -> Option<(usize, &'static str)> {
    Some(match FEATURES.binary_search_by(|e| e.0.cmp(&tag)) {
        Ok(index) => (index, FEATURES[index].1),
        _ => return None,
    })
}

/// Returns a feature tag and description from an AAT feature
/// and selector.
pub fn desc_from_aat(feature: u16, selector: u16) -> Option<(usize, RawTag, &'static str)> {
    let key = (feature << 8) | selector;
    Some(match AAT_TO_AT.binary_search_by(|pair| pair.0.cmp(&key)) {
        Ok(index) => {
            let (tag, desc) = FEATURES[AAT_TO_AT[index].1 as usize];
            (index, tag, desc)
        }
        _ => return None,
    })
}

pub const FEATURES: [(u32, &'static str); 142] = [
    (raw_tag(b"aalt"), "Access All Alternates"),
    (raw_tag(b"abvf"), "Above-base Forms"),
    (raw_tag(b"abvm"), "Above-base Mark Positioning"),
    (raw_tag(b"abvs"), "Above-base Substitutions"),
    (raw_tag(b"afrc"), "Alternative Fractions"),
    (raw_tag(b"akhn"), "Akhands"),
    (raw_tag(b"blwf"), "Below-base Forms"),
    (raw_tag(b"blwm"), "Below-base Mark Positioning"),
    (raw_tag(b"blws"), "Below-base Substitutions"),
    (raw_tag(b"c2pc"), "Petite Capitals From Capitals"),
    (raw_tag(b"c2sc"), "Small Capitals From Capitals"),
    (raw_tag(b"calt"), "Contextual Alternates"),
    (raw_tag(b"case"), "Case-Sensitive Forms"),
    (raw_tag(b"ccmp"), "Glyph Composition / Decomposition"),
    (raw_tag(b"cfar"), "Conjunct Form After Ro"),
    (raw_tag(b"chws"), "Contextual Half-width Spacing"),
    (raw_tag(b"cjct"), "Conjunct Forms"),
    (raw_tag(b"clig"), "Contextual Ligatures"),
    (raw_tag(b"cpct"), "Centered CJK Punctuation"),
    (raw_tag(b"cpsp"), "Capital Spacing"),
    (raw_tag(b"cswh"), "Contextual Swash"),
    (raw_tag(b"curs"), "Cursive Positioning"),
    (raw_tag(b"dist"), "Distances"),
    (raw_tag(b"dlig"), "Discretionary Ligatures"),
    (raw_tag(b"dnom"), "Denominators"),
    (raw_tag(b"dtls"), "Dotless Forms"),
    (raw_tag(b"expt"), "Expert Forms"),
    (raw_tag(b"falt"), "Final Glyph on Line Alternates"),
    (raw_tag(b"fin2"), "Terminal Forms #2"),
    (raw_tag(b"fin3"), "Terminal Forms #3"),
    (raw_tag(b"fina"), "Terminal Forms"),
    (raw_tag(b"flac"), "Flattened accent forms"),
    (raw_tag(b"frac"), "Fractions"),
    (raw_tag(b"fwid"), "Full Widths"),
    (raw_tag(b"half"), "Half Forms"),
    (raw_tag(b"haln"), "Halant Forms"),
    (raw_tag(b"halt"), "Alternate Half Widths"),
    (raw_tag(b"hist"), "Historical Forms"),
    (raw_tag(b"hkna"), "Horizontal Kana Alternates"),
    (raw_tag(b"hlig"), "Historical Ligatures"),
    (raw_tag(b"hngl"), "Hangul"),
    (raw_tag(b"hojo"), "Hojo Kanji Forms"),
    (raw_tag(b"hwid"), "Half Widths"),
    (raw_tag(b"init"), "Initial Forms"),
    (raw_tag(b"isol"), "Isolated Forms"),
    (raw_tag(b"ital"), "Italics"),
    (raw_tag(b"jalt"), "Justification Alternates"),
    (raw_tag(b"jp78"), "JIS78 Forms"),
    (raw_tag(b"jp83"), "JIS83 Forms"),
    (raw_tag(b"jp90"), "JIS90 Forms"),
    (raw_tag(b"jp04"), "JIS2004 Forms"),
    (raw_tag(b"kern"), "Kerning"),
    (raw_tag(b"lfbd"), "Left Bounds"),
    (raw_tag(b"liga"), "Standard Ligatures"),
    (raw_tag(b"ljmo"), "Leading Jamo Forms"),
    (raw_tag(b"lnum"), "Lining Figures"),
    (raw_tag(b"locl"), "Localized Forms"),
    (raw_tag(b"ltra"), "Left-to-right alternates"),
    (raw_tag(b"ltrm"), "Left-to-right mirrored forms"),
    (raw_tag(b"mark"), "Mark Positioning"),
    (raw_tag(b"med2"), "Medial Forms #2"),
    (raw_tag(b"medi"), "Medial Forms"),
    (raw_tag(b"mgrk"), "Mathematical Greek"),
    (raw_tag(b"mkmk"), "Mark to Mark Positioning"),
    (raw_tag(b"mset"), "Mark Positioning via Substitution"),
    (raw_tag(b"nalt"), "Alternate Annotation Forms"),
    (raw_tag(b"nlck"), "NLC Kanji Forms"),
    (raw_tag(b"nukt"), "Nukta Forms"),
    (raw_tag(b"numr"), "Numerators"),
    (raw_tag(b"onum"), "Oldstyle Figures"),
    (raw_tag(b"opbd"), "Optical Bounds"),
    (raw_tag(b"ordn"), "Ordinals"),
    (raw_tag(b"ornm"), "Ornaments"),
    (raw_tag(b"palt"), "Proportional Alternate Widths"),
    (raw_tag(b"pcap"), "Petite Capitals"),
    (raw_tag(b"pkna"), "Proportional Kana"),
    (raw_tag(b"pnum"), "Proportional Figures"),
    (raw_tag(b"pref"), "Pre-Base Forms"),
    (raw_tag(b"pres"), "Pre-base Substitutions"),
    (raw_tag(b"pstf"), "Post-base Forms"),
    (raw_tag(b"psts"), "Post-base Substitutions"),
    (raw_tag(b"pwid"), "Proportional Widths"),
    (raw_tag(b"qwid"), "Quarter Widths"),
    (raw_tag(b"rand"), "Randomize"),
    (raw_tag(b"rclt"), "Required Contextual Alternates"),
    (raw_tag(b"rkrf"), "Rakar Forms"),
    (raw_tag(b"rlig"), "Required Ligatures"),
    (raw_tag(b"rphf"), "Reph Forms"),
    (raw_tag(b"rtbd"), "Right Bounds"),
    (raw_tag(b"rtla"), "Right-to-left alternates"),
    (raw_tag(b"rtlm"), "Right-to-left mirrored forms"),
    (raw_tag(b"ruby"), "Ruby Notation Forms"),
    (raw_tag(b"rvrn"), "Required Variation Alternates"),
    (raw_tag(b"salt"), "Stylistic Alternates"),
    (raw_tag(b"sinf"), "Scientific Inferiors"),
    (raw_tag(b"size"), "Optical size"),
    (raw_tag(b"smcp"), "Small Capitals"),
    (raw_tag(b"smpl"), "Simplified Forms"),
    (raw_tag(b"ss01"), "Stylistic Set 1"),
    (raw_tag(b"ss02"), "Stylistic Set 2"),
    (raw_tag(b"ss03"), "Stylistic Set 3"),
    (raw_tag(b"ss04"), "Stylistic Set 4"),
    (raw_tag(b"ss05"), "Stylistic Set 5"),
    (raw_tag(b"ss06"), "Stylistic Set 6"),
    (raw_tag(b"ss07"), "Stylistic Set 7"),
    (raw_tag(b"ss08"), "Stylistic Set 8"),
    (raw_tag(b"ss09"), "Stylistic Set 9"),
    (raw_tag(b"ss10"), "Stylistic Set 10"),
    (raw_tag(b"ss11"), "Stylistic Set 11"),
    (raw_tag(b"ss12"), "Stylistic Set 12"),
    (raw_tag(b"ss13"), "Stylistic Set 13"),
    (raw_tag(b"ss14"), "Stylistic Set 14"),
    (raw_tag(b"ss15"), "Stylistic Set 15"),
    (raw_tag(b"ss16"), "Stylistic Set 16"),
    (raw_tag(b"ss17"), "Stylistic Set 17"),
    (raw_tag(b"ss18"), "Stylistic Set 18"),
    (raw_tag(b"ss19"), "Stylistic Set 19"),
    (raw_tag(b"ss20"), "Stylistic Set 20"),
    (raw_tag(b"ssty"), "Math script style alternates"),
    (raw_tag(b"stch"), "Stretching Glyph Decomposition"),
    (raw_tag(b"subs"), "Subscript"),
    (raw_tag(b"sups"), "Superscript"),
    (raw_tag(b"swsh"), "Swash"),
    (raw_tag(b"titl"), "Titling"),
    (raw_tag(b"tjmo"), "Trailing Jamo Forms"),
    (raw_tag(b"tnam"), "Traditional Name Forms"),
    (raw_tag(b"tnum"), "Tabular Figures"),
    (raw_tag(b"trad"), "Traditional Forms"),
    (raw_tag(b"twid"), "Third Widths"),
    (raw_tag(b"unic"), "Unicase"),
    (raw_tag(b"valt"), "Alternate Vertical Metrics"),
    (raw_tag(b"vatu"), "Vattu Variants"),
    (raw_tag(b"vchw"), "Vertical Contextual Half-width Spacing"),
    (raw_tag(b"vert"), "Vertical Writing"),
    (raw_tag(b"vhal"), "Alternate Vertical Half Metrics"),
    (raw_tag(b"vjmo"), "Vowel Jamo Forms"),
    (raw_tag(b"vkna"), "Vertical Kana Alternates"),
    (raw_tag(b"vkrn"), "Vertical Kerning"),
    (raw_tag(b"vpal"), "Proportional Alternate Vertical Metrics"),
    (raw_tag(b"vrt2"), "Vertical Alternates and Rotation"),
    (raw_tag(b"vrtr"), "Vertical Alternates for Rotation"),
    (raw_tag(b"zero"), "Slashed Zero"),
];

pub const AAT_TO_AT: [(u16, u16); 77] = [
    (256, 86),
    (258, 53),
    (260, 23),
    (274, 15),
    (276, 37),
    (276, 39),
    (782, 129),
    (1024, 133),
    (1024, 139),
    (1536, 126),
    (1537, 76),
    (2561, 121),
    (2562, 120),
    (2563, 71),
    (2564, 94),
    (2817, 4),
    (2818, 32),
    (3588, 141),
    (3850, 62),
    (4868, 123),
    (5120, 127),
    (5121, 97),
    (5122, 47),
    (5123, 48),
    (5124, 49),
    (5130, 26),
    (5131, 50),
    (5132, 41),
    (5133, 66),
    (5134, 125),
    (5376, 69),
    (5377, 55),
    (5632, 81),
    (5632, 75),
    (5633, 33),
    (5634, 42),
    (5635, 128),
    (5636, 82),
    (5637, 73),
    (5637, 130),
    (5637, 138),
    (5638, 36),
    (5638, 134),
    (5889, 40),
    (7170, 91),
    (8194, 45),
    (8448, 10),
    (8450, 17),
    (8704, 38),
    (8706, 136),
    (8962, 98),
    (8964, 99),
    (8966, 100),
    (8968, 101),
    (8970, 102),
    (8972, 103),
    (8974, 104),
    (8976, 105),
    (8978, 106),
    (8980, 107),
    (8982, 108),
    (8984, 109),
    (8986, 110),
    (8988, 111),
    (8990, 112),
    (8992, 113),
    (8994, 114),
    (8996, 115),
    (8998, 116),
    (9000, 117),
    (9216, 9),
    (9218, 122),
    (9220, 18),
    (9473, 96),
    (9474, 74),
    (9729, 21),
    (9730, 20),
];