Skip to main content

strata_render/
font.rs

1//! Embedded 8x16 anti-aliased bitmap font table for zero-dependency software text rasterization.
2
3pub const FONT_GLYPH_WIDTH: usize = 8;
4pub const FONT_GLYPH_HEIGHT: usize = 16;
5
6/// Pre-rasterized 8x16 bitmap glyphs for printable ASCII characters 32..=126.
7pub const FONT_8X16: [[u8; 16]; 95] = [
8    // ASCII 32 (' ')
9    [
10        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
11        0x00,
12    ],
13    // ASCII 33 ('!')
14    [
15        0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x40, 0x40, 0x00,
16        0x00,
17    ],
18    // ASCII 34 ('"')
19    [
20        0x00, 0x00, 0x00, 0x00, 0x00, 0x58, 0x50, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21        0x00,
22    ],
23    // ASCII 35 ('#')
24    [
25        0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x12, 0x7f, 0x24, 0x24, 0xff, 0x24, 0x2c, 0x68, 0x00,
26        0x00,
27    ],
28    // ASCII 36 ('$')
29    [
30        0x00, 0x00, 0x00, 0x00, 0x10, 0x3c, 0x50, 0x50, 0x70, 0x1c, 0x16, 0x16, 0x7c, 0x10, 0x00,
31        0x00,
32    ],
33    // ASCII 37 ('%')
34    [
35        0x00, 0x00, 0x00, 0x00, 0x00, 0x71, 0x51, 0x5a, 0x5f, 0x57, 0x7a, 0x0a, 0x13, 0x11, 0x00,
36        0x00,
37    ],
38    // ASCII 38 ('&')
39    [
40        0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x24, 0x24, 0x38, 0x78, 0x4d, 0x47, 0x47, 0x3d, 0x00,
41        0x00,
42    ],
43    // ASCII 39 ("'")
44    [
45        0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
46        0x00,
47    ],
48    // ASCII 40 ('(')
49    [
50        0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x60, 0x40, 0x40, 0xc0, 0xc0, 0xc0, 0x40, 0x40, 0x60,
51        0x20,
52    ],
53    // ASCII 41 (')')
54    [
55        0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x60, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x60,
56        0x40,
57    ],
58    // ASCII 42 ('*')
59    [
60        0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x7e, 0x38, 0x28, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
61        0x00,
62    ],
63    // ASCII 43 ('+')
64    [
65        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x7e, 0x10, 0x10, 0x10, 0x00, 0x00,
66        0x00,
67    ],
68    // ASCII 44 (',')
69    [
70        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40,
71        0x40,
72    ],
73    // ASCII 45 ('-')
74    [
75        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00,
76        0x00,
77    ],
78    // ASCII 46 ('.')
79    [
80        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x00,
81        0x00,
82    ],
83    // ASCII 47 ('/')
84    [
85        0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x10, 0x10, 0x20, 0x20, 0x60, 0x40, 0x40, 0xc0, 0x00,
86        0x00,
87    ],
88    // ASCII 48 ('0')
89    [
90        0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x64, 0x46, 0x46, 0x42, 0x46, 0x46, 0x64, 0x38, 0x00,
91        0x00,
92    ],
93    // ASCII 49 ('1')
94    [
95        0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00,
96        0x00,
97    ],
98    // ASCII 50 ('2')
99    [
100        0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x04, 0x04, 0x0c, 0x18, 0x30, 0x60, 0x7e, 0x00,
101        0x00,
102    ],
103    // ASCII 51 ('3')
104    [
105        0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x44, 0x04, 0x0c, 0x38, 0x04, 0x06, 0x06, 0x7c, 0x00,
106        0x00,
107    ],
108    // ASCII 52 ('4')
109    [
110        0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x1c, 0x14, 0x24, 0x64, 0x44, 0xfe, 0x04, 0x04, 0x00,
111        0x00,
112    ],
113    // ASCII 53 ('5')
114    [
115        0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x40, 0x40, 0x7c, 0x04, 0x06, 0x06, 0x04, 0x78, 0x00,
116        0x00,
117    ],
118    // ASCII 54 ('6')
119    [
120        0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x20, 0x40, 0x5c, 0x66, 0x42, 0x46, 0x66, 0x3c, 0x00,
121        0x00,
122    ],
123    // ASCII 55 ('7')
124    [
125        0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x06, 0x04, 0x0c, 0x08, 0x18, 0x10, 0x30, 0x20, 0x00,
126        0x00,
127    ],
128    // ASCII 56 ('8')
129    [
130        0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x64, 0x44, 0x6c, 0x38, 0x44, 0x42, 0x46, 0x3c, 0x00,
131        0x00,
132    ],
133    // ASCII 57 ('9')
134    [
135        0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x64, 0x46, 0x46, 0x46, 0x3e, 0x04, 0x0c, 0x78, 0x00,
136        0x00,
137    ],
138    // ASCII 58 (':')
139    [
140        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00, 0x40, 0x40, 0x00,
141        0x00,
142    ],
143    // ASCII 59 (';')
144    [
145        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40,
146        0xc0,
147    ],
148    // ASCII 60 ('<')
149    [
150        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x0c, 0x30, 0x60, 0x38, 0x0e, 0x00, 0x00, 0x00,
151        0x00,
152    ],
153    // ASCII 61 ('=')
154    [
155        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00,
156        0x00,
157    ],
158    // ASCII 62 ('>')
159    [
160        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x70, 0x1c, 0x06, 0x18, 0x60, 0x00, 0x00, 0x00,
161        0x00,
162    ],
163    // ASCII 63 ('?')
164    [
165        0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x08, 0x08, 0x18, 0x30, 0x20, 0x00, 0x20, 0x20, 0x00,
166        0x00,
167    ],
168    // ASCII 64 ('@')
169    [
170        0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x30, 0x6f, 0x49, 0x59, 0x59, 0x5b, 0x4e, 0x30, 0x1f,
171        0x00,
172    ],
173    // ASCII 65 ('A')
174    [
175        0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x1c, 0x24, 0x26, 0x7e, 0x42, 0xc3, 0x81, 0x00,
176        0x00,
177    ],
178    // ASCII 66 ('B')
179    [
180        0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x62, 0x62, 0x62, 0x7c, 0x63, 0x63, 0x63, 0x7e, 0x00,
181        0x00,
182    ],
183    // ASCII 67 ('C')
184    [
185        0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x30, 0x60, 0x40, 0x40, 0x40, 0x60, 0x30, 0x1e, 0x00,
186        0x00,
187    ],
188    // ASCII 68 ('D')
189    [
190        0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x63, 0x61, 0x61, 0x61, 0x61, 0x61, 0x63, 0x7e, 0x00,
191        0x00,
192    ],
193    // ASCII 69 ('E')
194    [
195        0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x60, 0x60, 0x60, 0x7c, 0x60, 0x60, 0x60, 0x7e, 0x00,
196        0x00,
197    ],
198    // ASCII 70 ('F')
199    [
200        0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x60, 0x60, 0x60, 0x7c, 0x60, 0x60, 0x60, 0x60, 0x00,
201        0x00,
202    ],
203    // ASCII 71 ('G')
204    [
205        0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x30, 0x60, 0x40, 0x47, 0x41, 0x61, 0x31, 0x1f, 0x00,
206        0x00,
207    ],
208    // ASCII 72 ('H')
209    [
210        0x00, 0x00, 0x00, 0x00, 0x00, 0x61, 0x61, 0x61, 0x61, 0x7f, 0x61, 0x61, 0x61, 0x61, 0x00,
211        0x00,
212    ],
213    // ASCII 73 ('I')
214    [
215        0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70, 0x00,
216        0x00,
217    ],
218    // ASCII 74 ('J')
219    [
220        0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
221        0x40,
222    ],
223    // ASCII 75 ('K')
224    [
225        0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x66, 0x6c, 0x78, 0x78, 0x68, 0x64, 0x66, 0x63, 0x00,
226        0x00,
227    ],
228    // ASCII 76 ('L')
229    [
230        0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x7e, 0x00,
231        0x00,
232    ],
233    // ASCII 77 ('M')
234    [
235        0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x70, 0x70, 0x51, 0x59, 0x49, 0x4e, 0x46, 0x46, 0x00,
236        0x00,
237    ],
238    // ASCII 78 ('N')
239    [
240        0x00, 0x00, 0x00, 0x00, 0x00, 0x61, 0x71, 0x71, 0x59, 0x4d, 0x45, 0x47, 0x43, 0x41, 0x00,
241        0x00,
242    ],
243    // ASCII 79 ('O')
244    [
245        0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x21, 0x60, 0x40, 0x40, 0x40, 0x60, 0x21, 0x1e, 0x00,
246        0x00,
247    ],
248    // ASCII 80 ('P')
249    [
250        0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x66, 0x62, 0x66, 0x7c, 0x60, 0x60, 0x60, 0x60, 0x00,
251        0x00,
252    ],
253    // ASCII 81 ('Q')
254    [
255        0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x21, 0x60, 0x40, 0x40, 0x40, 0x60, 0x21, 0x1e, 0x02,
256        0x01,
257    ],
258    // ASCII 82 ('R')
259    [
260        0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x66, 0x62, 0x66, 0x7c, 0x6c, 0x66, 0x62, 0x63, 0x00,
261        0x00,
262    ],
263    // ASCII 83 ('S')
264    [
265        0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x40, 0x40, 0x60, 0x38, 0x0c, 0x06, 0x04, 0x78, 0x00,
266        0x00,
267    ],
268    // ASCII 84 ('T')
269    [
270        0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00,
271        0x00,
272    ],
273    // ASCII 85 ('U')
274    [
275        0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x61, 0x23, 0x1e, 0x00,
276        0x00,
277    ],
278    // ASCII 86 ('V')
279    [
280        0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0xc2, 0x42, 0x66, 0x24, 0x2c, 0x3c, 0x18, 0x18, 0x00,
281        0x00,
282    ],
283    // ASCII 87 ('W')
284    [
285        0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0x46, 0x4f, 0x69, 0x29, 0x39, 0x30, 0x30, 0x00,
286        0x00,
287    ],
288    // ASCII 88 ('X')
289    [
290        0x00, 0x00, 0x00, 0x00, 0x00, 0xc2, 0x64, 0x2c, 0x38, 0x18, 0x38, 0x24, 0x46, 0xc2, 0x00,
291        0x00,
292    ],
293    // ASCII 89 ('Y')
294    [
295        0x00, 0x00, 0x00, 0x00, 0x00, 0xc2, 0x46, 0x64, 0x2c, 0x38, 0x10, 0x10, 0x10, 0x10, 0x00,
296        0x00,
297    ],
298    // ASCII 90 ('Z')
299    [
300        0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x04, 0x0c, 0x08, 0x10, 0x30, 0x20, 0x40, 0xfe, 0x00,
301        0x00,
302    ],
303    // ASCII 91 ('[')
304    [
305        0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
306        0x70,
307    ],
308    // ASCII 92 ('\\')
309    [
310        0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x40, 0x40, 0x60, 0x20, 0x20, 0x10, 0x10, 0x18, 0x00,
311        0x00,
312    ],
313    // ASCII 93 (']')
314    [
315        0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
316        0xe0,
317    ],
318    // ASCII 94 ('^')
319    [
320        0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x28, 0x24, 0x44, 0x42, 0x00, 0x00, 0x00, 0x00,
321        0x00,
322    ],
323    // ASCII 95 ('_')
324    [
325        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
326        0xfc,
327    ],
328    // ASCII 96 ('`')
329    [
330        0x00, 0x00, 0x00, 0x00, 0x40, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
331        0x00,
332    ],
333    // ASCII 97 ('a')
334    [
335        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x04, 0x04, 0x7c, 0x44, 0x4c, 0x7c, 0x00,
336        0x00,
337    ],
338    // ASCII 98 ('b')
339    [
340        0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x7c, 0x66, 0x42, 0x42, 0x42, 0x66, 0x5c, 0x00,
341        0x00,
342    ],
343    // ASCII 99 ('c')
344    [
345        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x60, 0x40, 0x40, 0x40, 0x60, 0x3c, 0x00,
346        0x00,
347    ],
348    // ASCII 100 ('d')
349    [
350        0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x3e, 0x66, 0x42, 0x42, 0x42, 0x66, 0x3a, 0x00,
351        0x00,
352    ],
353    // ASCII 101 ('e')
354    [
355        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x64, 0x46, 0x7e, 0x40, 0x60, 0x3c, 0x00,
356        0x00,
357    ],
358    // ASCII 102 ('f')
359    [
360        0x00, 0x00, 0x00, 0x00, 0x38, 0x60, 0x60, 0xf0, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00,
361        0x00,
362    ],
363    // ASCII 103 ('g')
364    [
365        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3a, 0x66, 0x42, 0x42, 0x42, 0x66, 0x3e, 0x02,
366        0x06,
367    ],
368    // ASCII 104 ('h')
369    [
370        0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x7c, 0x66, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00,
371        0x00,
372    ],
373    // ASCII 105 ('i')
374    [
375        0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00,
376        0x00,
377    ],
378    // ASCII 106 ('j')
379    [
380        0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
381        0x40,
382    ],
383    // ASCII 107 ('k')
384    [
385        0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x44, 0x48, 0x50, 0x70, 0x58, 0x4c, 0x46, 0x00,
386        0x00,
387    ],
388    // ASCII 108 ('l')
389    [
390        0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00,
391        0x00,
392    ],
393    // ASCII 109 ('m')
394    [
395        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5d, 0x66, 0x46, 0x46, 0x46, 0x46, 0x46, 0x00,
396        0x00,
397    ],
398    // ASCII 110 ('n')
399    [
400        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5c, 0x66, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00,
401        0x00,
402    ],
403    // ASCII 111 ('o')
404    [
405        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0x42, 0x42, 0x42, 0x66, 0x3c, 0x00,
406        0x00,
407    ],
408    // ASCII 112 ('p')
409    [
410        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5c, 0x66, 0x42, 0x42, 0x42, 0x66, 0x7c, 0x40,
411        0x40,
412    ],
413    // ASCII 113 ('q')
414    [
415        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3a, 0x66, 0x42, 0x42, 0x42, 0x66, 0x3e, 0x02,
416        0x02,
417    ],
418    // ASCII 114 ('r')
419    [
420        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, 0x60, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00,
421        0x00,
422    ],
423    // ASCII 115 ('s')
424    [
425        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x40, 0x60, 0x38, 0x0c, 0x0c, 0x78, 0x00,
426        0x00,
427    ],
428    // ASCII 116 ('t')
429    [
430        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xf0, 0x40, 0x40, 0x40, 0x40, 0x60, 0x30, 0x00,
431        0x00,
432    ],
433    // ASCII 117 ('u')
434    [
435        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x66, 0x3a, 0x00,
436        0x00,
437    ],
438    // ASCII 118 ('v')
439    [
440        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc4, 0x4c, 0x68, 0x28, 0x38, 0x30, 0x00,
441        0x00,
442    ],
443    // ASCII 119 ('w')
444    [
445        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0x4e, 0x5a, 0x72, 0x33, 0x31, 0x00,
446        0x00,
447    ],
448    // ASCII 120 ('x')
449    [
450        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x6c, 0x38, 0x30, 0x38, 0x6c, 0xc4, 0x00,
451        0x00,
452    ],
453    // ASCII 121 ('y')
454    [
455        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x44, 0x4c, 0x68, 0x28, 0x38, 0x10, 0x30,
456        0x20,
457    ],
458    // ASCII 122 ('z')
459    [
460        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x08, 0x10, 0x30, 0x20, 0x40, 0xfc, 0x00,
461        0x00,
462    ],
463    // ASCII 123 ('{')
464    [
465        0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x20, 0x20, 0x20, 0x20, 0xc0, 0x20, 0x20, 0x20, 0x20,
466        0x18,
467    ],
468    // ASCII 124 ('|')
469    [
470        0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
471        0x10,
472    ],
473    // ASCII 125 ('}')
474    [
475        0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x20, 0x20, 0x20, 0x20, 0x18, 0x20, 0x20, 0x20, 0x60,
476        0xc0,
477    ],
478    // ASCII 126 ('~')
479    [
480        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00,
481        0x00,
482    ],
483];
484
485/// Retrieves the 8x16 bitmask slice for a given printable ASCII character.
486#[inline]
487pub fn get_glyph(c: char) -> Option<&'static [u8; 16]> {
488    let code = c as u32;
489    if (32..=126).contains(&code) {
490        Some(&FONT_8X16[(code - 32) as usize])
491    } else {
492        None
493    }
494}
495
496/// Fallback replacement glyph (hollow box / tofu) for unresolved Unicode characters.
497pub const TOFU_GLYPH: [u8; 16] = [
498    0x00, 0x00, 0x7e, 0x42, 0x42, 0x5a, 0x5a, 0x42, 0x5a, 0x5a, 0x42, 0x42, 0x7e, 0x00, 0x00, 0x00,
499];
500
501/// Maps common typographical Unicode characters to their visual ASCII approximations.
502pub fn map_common_unicode(c: char) -> Option<&'static [u8; 16]> {
503    match c {
504        '\u{00A0}' => get_glyph(' '), // Non-breaking space
505        '\u{2018}' | '\u{2019}' | '\u{201A}' | '\u{201B}' => get_glyph('\''), // Single curly quotes
506        '\u{201C}' | '\u{201D}' | '\u{201E}' | '\u{201F}' => get_glyph('"'), // Double curly quotes
507        '\u{2013}' | '\u{2014}' | '\u{2212}' => get_glyph('-'), // En-dash, Em-dash, Minus sign
508        '\u{2026}' => get_glyph('.'), // Horizontal ellipsis
509        '\u{2022}' => get_glyph('*'), // Bullet
510        '\u{00B7}' => get_glyph('.'), // Middle dot
511        '\u{00AB}' => get_glyph('<'), // Left-pointing double angle quotation mark
512        '\u{00BB}' => get_glyph('>'), // Right-pointing double angle quotation mark
513        '\u{00D7}' => get_glyph('x'), // Multiplication sign
514        '\u{00F7}' => get_glyph('/'), // Division sign
515        '\u{00B1}' => get_glyph('+'), // Plus-minus sign
516        '\u{00B0}' => get_glyph('o'), // Degree sign
517        _ => None,
518    }
519}
520
521/// Retrieves a glyph bitmask, resolving common Unicode symbols or falling back to the standard tofu box.
522#[inline]
523pub fn get_glyph_or_fallback(c: char) -> &'static [u8; 16] {
524    if let Some(glyph) = get_glyph(c) {
525        glyph
526    } else if let Some(mapped) = map_common_unicode(c) {
527        mapped
528    } else {
529        &TOFU_GLYPH
530    }
531}
532
533/// Operating system platform indicator for font resolution.
534#[derive(Debug, Clone, Copy, PartialEq, Eq)]
535pub enum OsPlatform {
536    Linux,
537    MacOS,
538    Windows,
539    Other,
540}
541
542impl OsPlatform {
543    pub const fn current() -> Self {
544        if cfg!(target_os = "macos") {
545            Self::MacOS
546        } else if cfg!(target_os = "windows") {
547            Self::Windows
548        } else if cfg!(target_os = "linux") {
549            Self::Linux
550        } else {
551            Self::Other
552        }
553    }
554}
555
556/// Generic CSS font family keyword.
557#[derive(Debug, Clone, Copy, PartialEq, Eq)]
558pub enum GenericFontFamily {
559    SansSerif,
560    Serif,
561    Monospace,
562    Cursive,
563    Fantasy,
564    SystemUi,
565}
566
567/// System font fallback cascade resolver across Linux, macOS, and Windows.
568#[derive(Debug, Clone)]
569pub struct SystemFontResolver;
570
571impl SystemFontResolver {
572    /// Resolves default system font chain for generic families on the current OS.
573    pub fn default_chain_for_generic(family: GenericFontFamily) -> Vec<String> {
574        Self::chain_for_platform(family, OsPlatform::current())
575    }
576
577    /// Resolves system font chain for a specific OS platform.
578    pub fn chain_for_platform(family: GenericFontFamily, platform: OsPlatform) -> Vec<String> {
579        match platform {
580            OsPlatform::MacOS => match family {
581                GenericFontFamily::SansSerif | GenericFontFamily::SystemUi => vec![
582                    "-apple-system".into(),
583                    "BlinkMacSystemFont".into(),
584                    "SF Pro Text".into(),
585                    "Helvetica Neue".into(),
586                    "Helvetica".into(),
587                    "Arial".into(),
588                    "PingFang SC".into(),
589                    "Hiragino Sans".into(),
590                    "Apple Color Emoji".into(),
591                    "sans-serif".into(),
592                ],
593                GenericFontFamily::Serif => vec![
594                    "New York".into(),
595                    "Times New Roman".into(),
596                    "Times".into(),
597                    "Songti SC".into(),
598                    "serif".into(),
599                ],
600                GenericFontFamily::Monospace => vec![
601                    "SF Mono".into(),
602                    "Menlo".into(),
603                    "Monaco".into(),
604                    "Courier New".into(),
605                    "monospace".into(),
606                ],
607                _ => vec!["-apple-system".into(), "sans-serif".into()],
608            },
609            OsPlatform::Windows => match family {
610                GenericFontFamily::SansSerif | GenericFontFamily::SystemUi => vec![
611                    "Segoe UI".into(),
612                    "Calibri".into(),
613                    "Arial".into(),
614                    "Microsoft YaHei".into(),
615                    "Meiryo".into(),
616                    "Segoe UI Emoji".into(),
617                    "Segoe UI Symbol".into(),
618                    "sans-serif".into(),
619                ],
620                GenericFontFamily::Serif => vec![
621                    "Georgia".into(),
622                    "Times New Roman".into(),
623                    "Cambria".into(),
624                    "SimSun".into(),
625                    "serif".into(),
626                ],
627                GenericFontFamily::Monospace => vec![
628                    "Consolas".into(),
629                    "Cascadia Code".into(),
630                    "Courier New".into(),
631                    "monospace".into(),
632                ],
633                _ => vec!["Segoe UI".into(), "sans-serif".into()],
634            },
635            OsPlatform::Linux | OsPlatform::Other => match family {
636                GenericFontFamily::SansSerif | GenericFontFamily::SystemUi => vec![
637                    "Ubuntu".into(),
638                    "DejaVu Sans".into(),
639                    "Liberation Sans".into(),
640                    "Noto Sans".into(),
641                    "Noto Sans CJK SC".into(),
642                    "Noto Color Emoji".into(),
643                    "sans-serif".into(),
644                ],
645                GenericFontFamily::Serif => vec![
646                    "DejaVu Serif".into(),
647                    "Liberation Serif".into(),
648                    "Noto Serif".into(),
649                    "serif".into(),
650                ],
651                GenericFontFamily::Monospace => vec![
652                    "Ubuntu Mono".into(),
653                    "DejaVu Sans Mono".into(),
654                    "Liberation Mono".into(),
655                    "Noto Sans Mono".into(),
656                    "monospace".into(),
657                ],
658                _ => vec!["Ubuntu".into(), "sans-serif".into()],
659            },
660        }
661    }
662
663    /// Parses a CSS `font-family` property value and returns an ordered cascade of resolved font names.
664    pub fn parse_font_family_cascade(css_value: &str) -> Vec<String> {
665        let mut results = Vec::new();
666        for item in css_value.split(',') {
667            let trimmed = item.trim().trim_matches(|c| c == '\'' || c == '"');
668            if trimmed.is_empty() {
669                continue;
670            }
671            match trimmed.to_ascii_lowercase().as_str() {
672                "sans-serif" => {
673                    for f in Self::default_chain_for_generic(GenericFontFamily::SansSerif) {
674                        if !results.contains(&f) {
675                            results.push(f);
676                        }
677                    }
678                }
679                "serif" => {
680                    for f in Self::default_chain_for_generic(GenericFontFamily::Serif) {
681                        if !results.contains(&f) {
682                            results.push(f);
683                        }
684                    }
685                }
686                "monospace" => {
687                    for f in Self::default_chain_for_generic(GenericFontFamily::Monospace) {
688                        if !results.contains(&f) {
689                            results.push(f);
690                        }
691                    }
692                }
693                "system-ui" | "-apple-system" | "blinkmacsystemfont" => {
694                    let token = trimmed.to_string();
695                    if !results.contains(&token) {
696                        results.push(token);
697                    }
698                    for f in Self::default_chain_for_generic(GenericFontFamily::SystemUi) {
699                        if !results.contains(&f) {
700                            results.push(f);
701                        }
702                    }
703                }
704                _ => {
705                    let owned = trimmed.to_string();
706                    if !results.contains(&owned) {
707                        results.push(owned);
708                    }
709                }
710            }
711        }
712
713        if results.is_empty() {
714            results = Self::default_chain_for_generic(GenericFontFamily::SansSerif);
715        }
716        results
717    }
718}
719
720/// Fallback font resolution chain with per-glyph coverage checking.
721#[derive(Debug, Clone)]
722pub struct FontFallbackChain {
723    pub families: Vec<String>,
724}
725
726impl FontFallbackChain {
727    pub fn new(families: Vec<String>) -> Self {
728        Self { families }
729    }
730
731    pub fn from_css(css_value: &str) -> Self {
732        Self {
733            families: SystemFontResolver::parse_font_family_cascade(css_value),
734        }
735    }
736
737    pub fn primary_font(&self) -> Option<&str> {
738        self.families.first().map(|s| s.as_str())
739    }
740
741    /// Resolves whether a character is natively printable or mapped by the fallback table.
742    pub fn can_render(&self, c: char) -> bool {
743        get_glyph(c).is_some() || map_common_unicode(c).is_some()
744    }
745}