1use super::internal::{raw_tag, RawTag};
2
3#[derive(Copy, Clone)]
4pub struct SeenFeatures {
5 bits: [u32; 6],
6}
7
8impl SeenFeatures {
9 pub fn new() -> Self {
10 Self { bits: [0; 6] }
11 }
12
13 pub fn mark(&mut self, feature_index: usize) -> bool {
14 let word = &mut self.bits[feature_index / 32];
15 let bit = 1 << (feature_index % 32);
16 if *word & bit == 0 {
17 *word |= bit;
18 true
19 } else {
20 false
21 }
22 }
23}
24
25pub fn desc_from_at(tag: RawTag) -> Option<(usize, &'static str)> {
27 Some(match FEATURES.binary_search_by(|e| e.0.cmp(&tag)) {
28 Ok(index) => (index, FEATURES[index].1),
29 _ => return None,
30 })
31}
32
33pub fn desc_from_aat(feature: u16, selector: u16) -> Option<(usize, RawTag, &'static str)> {
36 let key = (feature << 8) | selector;
37 Some(match AAT_TO_AT.binary_search_by(|pair| pair.0.cmp(&key)) {
38 Ok(index) => {
39 let (tag, desc) = FEATURES[AAT_TO_AT[index].1 as usize];
40 (index, tag, desc)
41 }
42 _ => return None,
43 })
44}
45
46pub const FEATURES: [(u32, &'static str); 142] = [
47 (raw_tag(b"aalt"), "Access All Alternates"),
48 (raw_tag(b"abvf"), "Above-base Forms"),
49 (raw_tag(b"abvm"), "Above-base Mark Positioning"),
50 (raw_tag(b"abvs"), "Above-base Substitutions"),
51 (raw_tag(b"afrc"), "Alternative Fractions"),
52 (raw_tag(b"akhn"), "Akhands"),
53 (raw_tag(b"blwf"), "Below-base Forms"),
54 (raw_tag(b"blwm"), "Below-base Mark Positioning"),
55 (raw_tag(b"blws"), "Below-base Substitutions"),
56 (raw_tag(b"c2pc"), "Petite Capitals From Capitals"),
57 (raw_tag(b"c2sc"), "Small Capitals From Capitals"),
58 (raw_tag(b"calt"), "Contextual Alternates"),
59 (raw_tag(b"case"), "Case-Sensitive Forms"),
60 (raw_tag(b"ccmp"), "Glyph Composition / Decomposition"),
61 (raw_tag(b"cfar"), "Conjunct Form After Ro"),
62 (raw_tag(b"chws"), "Contextual Half-width Spacing"),
63 (raw_tag(b"cjct"), "Conjunct Forms"),
64 (raw_tag(b"clig"), "Contextual Ligatures"),
65 (raw_tag(b"cpct"), "Centered CJK Punctuation"),
66 (raw_tag(b"cpsp"), "Capital Spacing"),
67 (raw_tag(b"cswh"), "Contextual Swash"),
68 (raw_tag(b"curs"), "Cursive Positioning"),
69 (raw_tag(b"dist"), "Distances"),
70 (raw_tag(b"dlig"), "Discretionary Ligatures"),
71 (raw_tag(b"dnom"), "Denominators"),
72 (raw_tag(b"dtls"), "Dotless Forms"),
73 (raw_tag(b"expt"), "Expert Forms"),
74 (raw_tag(b"falt"), "Final Glyph on Line Alternates"),
75 (raw_tag(b"fin2"), "Terminal Forms #2"),
76 (raw_tag(b"fin3"), "Terminal Forms #3"),
77 (raw_tag(b"fina"), "Terminal Forms"),
78 (raw_tag(b"flac"), "Flattened accent forms"),
79 (raw_tag(b"frac"), "Fractions"),
80 (raw_tag(b"fwid"), "Full Widths"),
81 (raw_tag(b"half"), "Half Forms"),
82 (raw_tag(b"haln"), "Halant Forms"),
83 (raw_tag(b"halt"), "Alternate Half Widths"),
84 (raw_tag(b"hist"), "Historical Forms"),
85 (raw_tag(b"hkna"), "Horizontal Kana Alternates"),
86 (raw_tag(b"hlig"), "Historical Ligatures"),
87 (raw_tag(b"hngl"), "Hangul"),
88 (raw_tag(b"hojo"), "Hojo Kanji Forms"),
89 (raw_tag(b"hwid"), "Half Widths"),
90 (raw_tag(b"init"), "Initial Forms"),
91 (raw_tag(b"isol"), "Isolated Forms"),
92 (raw_tag(b"ital"), "Italics"),
93 (raw_tag(b"jalt"), "Justification Alternates"),
94 (raw_tag(b"jp78"), "JIS78 Forms"),
95 (raw_tag(b"jp83"), "JIS83 Forms"),
96 (raw_tag(b"jp90"), "JIS90 Forms"),
97 (raw_tag(b"jp04"), "JIS2004 Forms"),
98 (raw_tag(b"kern"), "Kerning"),
99 (raw_tag(b"lfbd"), "Left Bounds"),
100 (raw_tag(b"liga"), "Standard Ligatures"),
101 (raw_tag(b"ljmo"), "Leading Jamo Forms"),
102 (raw_tag(b"lnum"), "Lining Figures"),
103 (raw_tag(b"locl"), "Localized Forms"),
104 (raw_tag(b"ltra"), "Left-to-right alternates"),
105 (raw_tag(b"ltrm"), "Left-to-right mirrored forms"),
106 (raw_tag(b"mark"), "Mark Positioning"),
107 (raw_tag(b"med2"), "Medial Forms #2"),
108 (raw_tag(b"medi"), "Medial Forms"),
109 (raw_tag(b"mgrk"), "Mathematical Greek"),
110 (raw_tag(b"mkmk"), "Mark to Mark Positioning"),
111 (raw_tag(b"mset"), "Mark Positioning via Substitution"),
112 (raw_tag(b"nalt"), "Alternate Annotation Forms"),
113 (raw_tag(b"nlck"), "NLC Kanji Forms"),
114 (raw_tag(b"nukt"), "Nukta Forms"),
115 (raw_tag(b"numr"), "Numerators"),
116 (raw_tag(b"onum"), "Oldstyle Figures"),
117 (raw_tag(b"opbd"), "Optical Bounds"),
118 (raw_tag(b"ordn"), "Ordinals"),
119 (raw_tag(b"ornm"), "Ornaments"),
120 (raw_tag(b"palt"), "Proportional Alternate Widths"),
121 (raw_tag(b"pcap"), "Petite Capitals"),
122 (raw_tag(b"pkna"), "Proportional Kana"),
123 (raw_tag(b"pnum"), "Proportional Figures"),
124 (raw_tag(b"pref"), "Pre-Base Forms"),
125 (raw_tag(b"pres"), "Pre-base Substitutions"),
126 (raw_tag(b"pstf"), "Post-base Forms"),
127 (raw_tag(b"psts"), "Post-base Substitutions"),
128 (raw_tag(b"pwid"), "Proportional Widths"),
129 (raw_tag(b"qwid"), "Quarter Widths"),
130 (raw_tag(b"rand"), "Randomize"),
131 (raw_tag(b"rclt"), "Required Contextual Alternates"),
132 (raw_tag(b"rkrf"), "Rakar Forms"),
133 (raw_tag(b"rlig"), "Required Ligatures"),
134 (raw_tag(b"rphf"), "Reph Forms"),
135 (raw_tag(b"rtbd"), "Right Bounds"),
136 (raw_tag(b"rtla"), "Right-to-left alternates"),
137 (raw_tag(b"rtlm"), "Right-to-left mirrored forms"),
138 (raw_tag(b"ruby"), "Ruby Notation Forms"),
139 (raw_tag(b"rvrn"), "Required Variation Alternates"),
140 (raw_tag(b"salt"), "Stylistic Alternates"),
141 (raw_tag(b"sinf"), "Scientific Inferiors"),
142 (raw_tag(b"size"), "Optical size"),
143 (raw_tag(b"smcp"), "Small Capitals"),
144 (raw_tag(b"smpl"), "Simplified Forms"),
145 (raw_tag(b"ss01"), "Stylistic Set 1"),
146 (raw_tag(b"ss02"), "Stylistic Set 2"),
147 (raw_tag(b"ss03"), "Stylistic Set 3"),
148 (raw_tag(b"ss04"), "Stylistic Set 4"),
149 (raw_tag(b"ss05"), "Stylistic Set 5"),
150 (raw_tag(b"ss06"), "Stylistic Set 6"),
151 (raw_tag(b"ss07"), "Stylistic Set 7"),
152 (raw_tag(b"ss08"), "Stylistic Set 8"),
153 (raw_tag(b"ss09"), "Stylistic Set 9"),
154 (raw_tag(b"ss10"), "Stylistic Set 10"),
155 (raw_tag(b"ss11"), "Stylistic Set 11"),
156 (raw_tag(b"ss12"), "Stylistic Set 12"),
157 (raw_tag(b"ss13"), "Stylistic Set 13"),
158 (raw_tag(b"ss14"), "Stylistic Set 14"),
159 (raw_tag(b"ss15"), "Stylistic Set 15"),
160 (raw_tag(b"ss16"), "Stylistic Set 16"),
161 (raw_tag(b"ss17"), "Stylistic Set 17"),
162 (raw_tag(b"ss18"), "Stylistic Set 18"),
163 (raw_tag(b"ss19"), "Stylistic Set 19"),
164 (raw_tag(b"ss20"), "Stylistic Set 20"),
165 (raw_tag(b"ssty"), "Math script style alternates"),
166 (raw_tag(b"stch"), "Stretching Glyph Decomposition"),
167 (raw_tag(b"subs"), "Subscript"),
168 (raw_tag(b"sups"), "Superscript"),
169 (raw_tag(b"swsh"), "Swash"),
170 (raw_tag(b"titl"), "Titling"),
171 (raw_tag(b"tjmo"), "Trailing Jamo Forms"),
172 (raw_tag(b"tnam"), "Traditional Name Forms"),
173 (raw_tag(b"tnum"), "Tabular Figures"),
174 (raw_tag(b"trad"), "Traditional Forms"),
175 (raw_tag(b"twid"), "Third Widths"),
176 (raw_tag(b"unic"), "Unicase"),
177 (raw_tag(b"valt"), "Alternate Vertical Metrics"),
178 (raw_tag(b"vatu"), "Vattu Variants"),
179 (raw_tag(b"vchw"), "Vertical Contextual Half-width Spacing"),
180 (raw_tag(b"vert"), "Vertical Writing"),
181 (raw_tag(b"vhal"), "Alternate Vertical Half Metrics"),
182 (raw_tag(b"vjmo"), "Vowel Jamo Forms"),
183 (raw_tag(b"vkna"), "Vertical Kana Alternates"),
184 (raw_tag(b"vkrn"), "Vertical Kerning"),
185 (raw_tag(b"vpal"), "Proportional Alternate Vertical Metrics"),
186 (raw_tag(b"vrt2"), "Vertical Alternates and Rotation"),
187 (raw_tag(b"vrtr"), "Vertical Alternates for Rotation"),
188 (raw_tag(b"zero"), "Slashed Zero"),
189];
190
191pub const AAT_TO_AT: [(u16, u16); 77] = [
192 (256, 86),
193 (258, 53),
194 (260, 23),
195 (274, 15),
196 (276, 37),
197 (276, 39),
198 (782, 129),
199 (1024, 133),
200 (1024, 139),
201 (1536, 126),
202 (1537, 76),
203 (2561, 121),
204 (2562, 120),
205 (2563, 71),
206 (2564, 94),
207 (2817, 4),
208 (2818, 32),
209 (3588, 141),
210 (3850, 62),
211 (4868, 123),
212 (5120, 127),
213 (5121, 97),
214 (5122, 47),
215 (5123, 48),
216 (5124, 49),
217 (5130, 26),
218 (5131, 50),
219 (5132, 41),
220 (5133, 66),
221 (5134, 125),
222 (5376, 69),
223 (5377, 55),
224 (5632, 81),
225 (5632, 75),
226 (5633, 33),
227 (5634, 42),
228 (5635, 128),
229 (5636, 82),
230 (5637, 73),
231 (5637, 130),
232 (5637, 138),
233 (5638, 36),
234 (5638, 134),
235 (5889, 40),
236 (7170, 91),
237 (8194, 45),
238 (8448, 10),
239 (8450, 17),
240 (8704, 38),
241 (8706, 136),
242 (8962, 98),
243 (8964, 99),
244 (8966, 100),
245 (8968, 101),
246 (8970, 102),
247 (8972, 103),
248 (8974, 104),
249 (8976, 105),
250 (8978, 106),
251 (8980, 107),
252 (8982, 108),
253 (8984, 109),
254 (8986, 110),
255 (8988, 111),
256 (8990, 112),
257 (8992, 113),
258 (8994, 114),
259 (8996, 115),
260 (8998, 116),
261 (9000, 117),
262 (9216, 9),
263 (9218, 122),
264 (9220, 18),
265 (9473, 96),
266 (9474, 74),
267 (9729, 21),
268 (9730, 20),
269];