1pub const GENERIC_FILE_GLYPH: char = '\u{f15b}';
26
27pub const FOLDER_GLYPH: char = '\u{f07b}';
37
38pub const DEVICON_FONT_BYTES: &[u8] = include_bytes!("../assets/AilloliUIFileIcons-Regular.ttf");
52
53pub const SUPPORTED_GLYPHS: &[char] = &[
68 '\u{e21c}',
69 '\u{e271}',
70 '\u{e28b}',
71 '\u{e28c}',
72 '\u{e600}',
73 '\u{e603}',
74 '\u{e606}',
75 '\u{e607}',
76 '\u{e608}',
77 '\u{e609}',
78 '\u{e60a}',
79 '\u{e60b}',
80 '\u{e60c}',
81 '\u{e60d}',
82 '\u{e60e}',
83 '\u{e60f}',
84 '\u{e610}',
85 '\u{e611}',
86 '\u{e614}',
87 '\u{e615}',
88 '\u{e619}',
89 '\u{e61b}',
90 '\u{e61c}',
91 '\u{e61d}',
92 '\u{e61e}',
93 '\u{e61f}',
94 '\u{e620}',
95 '\u{e623}',
96 '\u{e624}',
97 '\u{e625}',
98 '\u{e627}',
99 '\u{e628}',
100 '\u{e62b}',
101 '\u{e62c}',
102 '\u{e62d}',
103 '\u{e62f}',
104 '\u{e631}',
105 '\u{e632}',
106 '\u{e633}',
107 '\u{e634}',
108 '\u{e639}',
109 '\u{e63a}',
110 '\u{e63b}',
111 '\u{e64a}',
112 '\u{e64b}',
113 '\u{e652}',
114 '\u{e655}',
115 '\u{e656}',
116 '\u{e65f}',
117 '\u{e660}',
118 '\u{e666}',
119 '\u{e667}',
120 '\u{e670}',
121 '\u{e672}',
122 '\u{e674}',
123 '\u{e677}',
124 '\u{e67a}',
125 '\u{e682}',
126 '\u{e684}',
127 '\u{e688}',
128 '\u{e68b}',
129 '\u{e691}',
130 '\u{e697}',
131 '\u{e69a}',
132 '\u{e69b}',
133 '\u{e69d}',
134 '\u{e69e}',
135 '\u{e69f}',
136 '\u{e6a0}',
137 '\u{e6a1}',
138 '\u{e6a9}',
139 '\u{e6ac}',
140 '\u{e6af}',
141 '\u{e6b2}',
142 '\u{e6b3}',
143 '\u{e6b4}',
144 '\u{e702}',
145 '\u{e706}',
146 '\u{e707}',
147 '\u{e70c}',
148 '\u{e70e}',
149 '\u{e718}',
150 '\u{e71e}',
151 '\u{e728}',
152 '\u{e736}',
153 '\u{e737}',
154 '\u{e738}',
155 '\u{e745}',
156 '\u{e749}',
157 '\u{e755}',
158 '\u{e768}',
159 '\u{e769}',
160 '\u{e76a}',
161 '\u{e772}',
162 '\u{e775}',
163 '\u{e779}',
164 '\u{e786}',
165 '\u{e791}',
166 '\u{e795}',
167 '\u{e798}',
168 '\u{e7a1}',
169 '\u{e7a7}',
170 '\u{e7a8}',
171 '\u{e7a9}',
172 '\u{e7aa}',
173 '\u{e7af}',
174 '\u{e7b1}',
175 '\u{e7b4}',
176 '\u{e7b8}',
177 '\u{e7ba}',
178 '\u{eac4}',
179 '\u{eae8}',
180 '\u{eaeb}',
181 '\u{eb9c}',
182 '\u{ebc8}',
183 '\u{ebe8}',
184 '\u{f001}',
185 '\u{f005}',
186 '\u{f019}',
187 '\u{f031}',
188 '\u{f06d}',
189 '\u{f073}',
190 '\u{f076}',
191 '\u{f07b}',
192 '\u{f0ad}',
193 '\u{f0c6}',
194 '\u{f0ec}',
195 '\u{f0fd}',
196 '\u{f108}',
197 '\u{f129}',
198 '\u{f15b}',
199 '\u{f179}',
200 '\u{f17c}',
201 '\u{f1ab}',
202 '\u{f1b2}',
203 '\u{f20e}',
204 '\u{f23e}',
205 '\u{f296}',
206 '\u{f2b8}',
207 '\u{f2d0}',
208 '\u{f2f7}',
209 '\u{f410}',
210 '\u{f462}',
211 '\u{f487}',
212 '\u{f489}',
213 '\u{f48a}',
214 '\u{f499}',
215 '\u{f49b}',
216 '\u{f4ae}',
217 '\u{f006f}',
218 '\u{f00ab}',
219 '\u{f019a}',
220 '\u{f01a7}',
221 '\u{f0219}',
222 '\u{f021b}',
223 '\u{f0227}',
224 '\u{f022c}',
225 '\u{f02a2}',
226 '\u{f031b}',
227 '\u{f032a}',
228 '\u{f0331}',
229 '\u{f035b}',
230 '\u{f042b}',
231 '\u{f0483}',
232 '\u{f04d9}',
233 '\u{f0509}',
234 '\u{f0565}',
235 '\u{f057c}',
236 '\u{f05c0}',
237 '\u{f05c6}',
238 '\u{f05ca}',
239 '\u{f0627}',
240 '\u{f0673}',
241 '\u{f06a9}',
242 '\u{f06d3}',
243 '\u{f0718}',
244 '\u{f0721}',
245 '\u{f072b}',
246 '\u{f07d4}',
247 '\u{f0858}',
248 '\u{f0868}',
249 '\u{f08c7}',
250 '\u{f099d}',
251 '\u{f0a0a}',
252 '\u{f0a16}',
253 '\u{f0aae}',
254 '\u{f0bc4}',
255 '\u{f0cb9}',
256 '\u{f0dd6}',
257 '\u{f0ebe}',
258 '\u{f0eeb}',
259 '\u{f1049}',
260 '\u{f1106}',
261 '\u{f121a}',
262 '\u{f125f}',
263 '\u{f13ff}',
264 '\u{f1997}',
265 '\u{f1998}',
266];
267
268pub fn supports_glyph(glyph: char) -> bool {
281 SUPPORTED_GLYPHS.binary_search(&glyph).is_ok()
282}
283
284pub fn glyph_or_fallback(glyph: char) -> char {
294 if supports_glyph(glyph) {
295 glyph
296 } else {
297 GENERIC_FILE_GLYPH
298 }
299}
300
301#[cfg(test)]
302mod tests {
303 use super::{
307 glyph_or_fallback, supports_glyph, DEVICON_FONT_BYTES, FOLDER_GLYPH, GENERIC_FILE_GLYPH,
308 SUPPORTED_GLYPHS,
309 };
310
311 #[test]
312 fn bundled_font_contains_exactly_the_audited_glyphs() {
313 let face = ttf_parser::Face::parse(DEVICON_FONT_BYTES, 0).expect("parse icon font");
314 assert_eq!(SUPPORTED_GLYPHS.len(), 198);
315 assert!(SUPPORTED_GLYPHS.windows(2).all(|pair| pair[0] < pair[1]));
316 for (label, ch) in [
317 ("rust", '\u{e68b}'),
318 ("toml", '\u{e6b2}'),
319 ("markdown", '\u{f48a}'),
320 ("json", '\u{e60b}'),
321 ("javascript", '\u{e60c}'),
322 ("typescript", '\u{e628}'),
323 ("html", '\u{e736}'),
324 ("css", '\u{e749}'),
325 ] {
326 assert!(
327 face.glyph_index(ch).is_some(),
328 "missing {label} glyph U+{:04X}",
329 ch as u32
330 );
331 }
332
333 for glyph in SUPPORTED_GLYPHS {
334 assert!(
335 face.glyph_index(*glyph).is_some(),
336 "missing audited glyph U+{:04X}",
337 *glyph as u32
338 );
339 }
340
341 let expected = SUPPORTED_GLYPHS
342 .iter()
343 .map(|glyph| *glyph as u32)
344 .collect::<std::collections::BTreeSet<_>>();
345 let mut actual = std::collections::BTreeSet::new();
346 let cmap = face.tables().cmap.expect("icon font has a cmap table");
347 for subtable in cmap
348 .subtables
349 .into_iter()
350 .filter(|table| table.is_unicode())
351 {
352 subtable.codepoints(|codepoint| {
353 if subtable.glyph_index(codepoint).is_some() {
354 actual.insert(codepoint);
355 }
356 });
357 }
358 assert_eq!(actual, expected);
359 }
360
361 #[test]
362 fn unlicensed_and_source_missing_glyphs_use_the_generic_fallback() {
363 assert!(supports_glyph(FOLDER_GLYPH));
364 assert!(supports_glyph(GENERIC_FILE_GLYPH));
365 assert_eq!(glyph_or_fallback('\u{f303}'), GENERIC_FILE_GLYPH);
366 assert_eq!(glyph_or_fallback('\u{f381}'), GENERIC_FILE_GLYPH);
367 assert_eq!(glyph_or_fallback('\u{25b2}'), GENERIC_FILE_GLYPH);
368
369 let face = ttf_parser::Face::parse(DEVICON_FONT_BYTES, 0).expect("parse icon font");
370 for codepoint in 0xf300..=0xf381 {
371 let glyph = char::from_u32(codepoint).expect("valid private-use codepoint");
372 assert!(
373 face.glyph_index(glyph).is_none(),
374 "unlicensed Font Logos glyph U+{codepoint:04X} is bundled"
375 );
376 }
377 }
378}