-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbuild.rs
More file actions
681 lines (622 loc) · 21.8 KB
/
build.rs
File metadata and controls
681 lines (622 loc) · 21.8 KB
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
fn main() {
linker_be_nice();
println!("cargo:rustc-link-arg=-Tlinkall.x");
generate_bitmap_fonts();
}
fn hint(msg: &str) {
eprintln!();
eprintln!("hint: {msg}");
eprintln!();
}
fn linker_be_nice() {
let args: Vec<String> = std::env::args().collect();
// --error-handling-script passes two args: kind and symbol
if args.len() >= 3 {
let kind = &args[1];
let what = &args[2];
match kind.as_str() {
"undefined-symbol" => match what.as_str() {
what if what.starts_with("_defmt_") => hint(
"`defmt` not found - make sure `defmt.x` is added as a linker script and you have included `use defmt_rtt as _;`",
),
"_stack_start" => hint("is the linker script `linkall.x` missing?"),
what if what.starts_with("esp_rtos_") => hint(
"`esp-radio` has no scheduler enabled. make sure you have initialized `esp-rtos` or provided an external scheduler.",
),
"embedded_test_linker_file_not_added_to_rustflags" => hint(
"`embedded-test` not found - make sure `embedded-test.x` is added as a linker script for tests",
),
"free"
| "malloc"
| "calloc"
| "get_free_internal_heap_size"
| "malloc_internal"
| "realloc_internal"
| "calloc_internal"
| "free_internal" => hint(
"did you forget the `esp-alloc` dependency or didn't enable the `compat` feature on it?",
),
_ => (),
},
_ => {
std::process::exit(1);
}
}
std::process::exit(0);
}
println!(
"cargo:rustc-link-arg=--error-handling-script={}",
std::env::current_exe().unwrap().display()
);
}
// build-time font rasterisation: scan assets/fonts/ for TTFs, classify
// by weight/style, rasterise to 1-bit bitmaps, emit font_data.rs.
//
// five size tiers: XSmall / Small / Medium / Large / XLarge
// two glyph sets per font:
// ascii 0x20-0x7E (contiguous direct-indexed table)
// extended unicode (sorted codepoint table, binary-searched at runtime)
//
// extended set covers latin-1 supplement, common punctuation (smart
// quotes, dashes, ellipsis, bullet), and a handful of currency/math
// symbols, enough for the vast majority of european-language epubs.
use std::fs;
use std::io::Write;
use std::path::{Path, PathBuf};
// body sizes (px): 0=XSmall 1=Small 2=Medium 3=Large 4=XLarge
const BODY_PX: [(f32, &str); 5] = [
(16.0, "XSMALL"),
(19.0, "SMALL"),
(23.0, "MEDIUM"),
(28.0, "LARGE"),
(35.0, "XLARGE"),
];
// Heading sizes scale proportionally
const HEADING_PX: [(f32, &str); 5] = [
(23.0, "XSMALL"),
(27.0, "SMALL"),
(32.0, "MEDIUM"),
(38.0, "LARGE"),
(46.0, "XLARGE"),
];
// fontdue coverage threshold; values >= this become black
const THRESHOLD: u8 = 100;
// ASCII range (direct-indexed)
const FIRST_CHAR: u8 = 0x20;
const LAST_CHAR: u8 = 0x7E;
const GLYPH_COUNT: usize = (LAST_CHAR - FIRST_CHAR + 1) as usize;
// build the sorted list of extended unicode codepoints to rasterise
fn extended_codepoints() -> Vec<u32> {
let mut cps: Vec<u32> = Vec::new();
// latin-1 supplement (0x00A0-0x00FF): accented letters, symbols
// skip 0x00A0 (NBSP) and 0x00AD (soft hyphen), they are whitespace
for cp in 0x00A1..=0x00FFu32 {
if cp == 0x00AD {
continue; // soft hyphen, handled as whitespace
}
cps.push(cp);
}
// Latin Extended-A: most common characters in European languages
// Czech, Polish, Hungarian, Turkish, Romanian, etc.
let latin_ext_a: &[u32] = &[
0x0100, 0x0101, // Āā
0x0102, 0x0103, // Ăă
0x0104, 0x0105, // Ąą
0x0106, 0x0107, // Ćć
0x010C, 0x010D, // Čč
0x010E, 0x010F, // Ďď
0x0110, 0x0111, // Đđ
0x0118, 0x0119, // Ęę
0x011A, 0x011B, // Ěě
0x011E, 0x011F, // Ğğ
0x0130, 0x0131, // İı
0x0141, 0x0142, // Łł
0x0143, 0x0144, // Ńń
0x0147, 0x0148, // Ňň
0x0150, 0x0151, // Őő
0x0152, 0x0153, // Œœ
0x0158, 0x0159, // Řř
0x015A, 0x015B, // Śś
0x015E, 0x015F, // Şş
0x0160, 0x0161, // Šš
0x0162, 0x0163, // Ţţ
0x0164, 0x0165, // Ťť
0x016E, 0x016F, // Ůů
0x0170, 0x0171, // Űű
0x0178, // Ÿ
0x0179, 0x017A, // Źź
0x017B, 0x017C, // Żż
0x017D, 0x017E, // Žž
];
cps.extend_from_slice(latin_ext_a);
// General Punctuation: hyphens, dashes, quotes, ellipsis, bullet
let punctuation: &[u32] = &[
0x2010, // ‐ hyphen
0x2011, // ‑ non-breaking hyphen
0x2012, // ‒ figure dash
0x2013, // – en dash
0x2014, // — em dash
0x2015, // ― horizontal bar
0x2018, // ' left single quotation mark
0x2019, // ' right single quotation mark
0x201A, // ‚ single low-9 quotation mark
0x201B, // ‛ single high-reversed-9
0x201C, // " left double quotation mark
0x201D, // " right double quotation mark
0x201E, // „ double low-9 quotation mark
0x201F, // ‟ double high-reversed-9
0x2022, // • bullet
0x2026, // … horizontal ellipsis
0x2032, // ′ prime
0x2033, // ″ double prime
0x2039, // ‹ single left-pointing angle quotation
0x203A, // › single right-pointing angle quotation
];
cps.extend_from_slice(punctuation);
// Currency symbols (common ones for e-books)
let currency: &[u32] = &[
0x00A2, // ¢ cent sign (already in Latin-1, but explicit)
0x00A3, // £ pound sign (already in Latin-1)
0x00A5, // ¥ yen sign (already in Latin-1)
0x20AC, // € euro sign
0x20A3, // ₣ french franc
0x20A4, // ₤ lira sign
0x20A7, // ₧ peseta sign
0x20A9, // ₩ won sign
0x20B9, // ₹ indian rupee
0x20BD, // ₽ ruble sign
];
cps.extend_from_slice(currency);
// Math symbols (common in books)
let math: &[u32] = &[
0x00B1, // ± plus-minus (already in Latin-1)
0x00D7, // × multiplication (already in Latin-1)
0x00F7, // ÷ division (already in Latin-1)
0x2212, // − minus sign
0x2260, // ≠ not equal to
0x2264, // ≤ less than or equal to
0x2265, // ≥ greater than or equal to
0x2248, // ≈ almost equal to
0x221E, // ∞ infinity
0x221A, // √ square root
0x03C0, // π pi (Greek letter)
0x00B0, // ° degree sign (already in Latin-1)
0x2030, // ‰ per mille sign
0x2070, // ⁰ superscript 0
0x00B9, // ¹ superscript 1 (already in Latin-1)
0x00B2, // ² superscript 2 (already in Latin-1)
0x00B3, // ³ superscript 3 (already in Latin-1)
0x2074, // ⁴ superscript 4
0x2075, // ⁵ superscript 5
0x2076, // ⁶ superscript 6
0x2077, // ⁷ superscript 7
0x2078, // ⁸ superscript 8
0x2079, // ⁹ superscript 9
];
cps.extend_from_slice(math);
// Arrows (useful for navigation hints, diagrams)
let arrows: &[u32] = &[
0x2190, // ← leftwards arrow
0x2191, // ↑ upwards arrow
0x2192, // → rightwards arrow
0x2193, // ↓ downwards arrow
0x2194, // ↔ left right arrow
0x2195, // ↕ up down arrow
0x21D0, // ⇐ leftwards double arrow
0x21D2, // ⇒ rightwards double arrow
0x21D4, // ⇔ left right double arrow
];
cps.extend_from_slice(arrows);
// Miscellaneous symbols (common in e-books)
let misc: &[u32] = &[
0x2122, // ™ trade mark sign
0x00A9, // © copyright (already in Latin-1)
0x00AE, // ® registered (already in Latin-1)
0x2020, // † dagger
0x2021, // ‡ double dagger
0x2023, // ‣ triangular bullet
0x25A0, // ■ black square
0x25A1, // □ white square
0x25CF, // ● black circle
0x25CB, // ○ white circle
0x2605, // ★ black star
0x2606, // ☆ white star
0x2713, // ✓ check mark
0x2717, // ✗ ballot x
0x00A7, // § section sign (already in Latin-1)
0x00B6, // ¶ pilcrow / paragraph sign (already in Latin-1)
];
cps.extend_from_slice(misc);
// Additional Latin Extended-B for more complete European language support
let latin_ext_b: &[u32] = &[
0x0180, // ƀ b with stroke (Croatian)
0x0192, // ƒ f with hook (Dutch florin)
0x01A0, 0x01A1, // Ơơ O with horn (Vietnamese)
0x01AF, 0x01B0, // Ưư U with horn (Vietnamese)
0x01CD, 0x01CE, // Ǎǎ A with caron
0x01CF, 0x01D0, // Ǐǐ I with caron
0x01D1, 0x01D2, // Ǒǒ O with caron
0x01D3, 0x01D4, // Ǔǔ U with caron
0x0218, 0x0219, // Șș S with comma below (Romanian)
0x021A, 0x021B, // Țț T with comma below (Romanian)
];
cps.extend_from_slice(latin_ext_b);
cps.sort();
cps.dedup();
cps
}
// find first .ttf in dir whose name contains all keywords (case-insensitive);
// excludes BoldItalic unless explicitly requested
fn find_ttf(dir: &Path, keywords: &[&str]) -> Option<PathBuf> {
let Ok(entries) = fs::read_dir(dir) else {
return None;
};
let mut candidates: Vec<PathBuf> = entries
.filter_map(|e| e.ok())
.map(|e| e.path())
.filter(|p| {
p.extension()
.map(|e| e.eq_ignore_ascii_case("ttf"))
.unwrap_or(false)
})
.collect();
candidates.sort();
for path in &candidates {
let stem = path
.file_stem()
.unwrap_or_default()
.to_string_lossy()
.to_lowercase();
let all_match = keywords.iter().all(|kw| stem.contains(&kw.to_lowercase()));
if !all_match {
continue;
}
// reject BoldItalic when looking for just Bold or just Italic
if keywords.len() == 1 {
if keywords[0].eq_ignore_ascii_case("Bold") && stem.contains("italic") {
continue;
}
if keywords[0].eq_ignore_ascii_case("Italic") && stem.contains("bold") {
continue;
}
}
return Some(path.clone());
}
None
}
fn generate_bitmap_fonts() {
let out_dir = std::env::var("OUT_DIR").unwrap();
let dest = Path::new(&out_dir).join("font_data.rs");
let mut out = fs::File::create(&dest).unwrap();
let font_dir = Path::new("assets/fonts");
// discover TTFs and classify by style
let regular = find_ttf(font_dir, &["Regular"]);
let bold = find_ttf(font_dir, &["Bold"]);
let italic = find_ttf(font_dir, &["Italic"]);
// re-run build if any TTF changes
if let Some(ref p) = regular {
println!("cargo:rerun-if-changed={}", p.display());
}
if let Some(ref p) = bold {
println!("cargo:rerun-if-changed={}", p.display());
}
if let Some(ref p) = italic {
println!("cargo:rerun-if-changed={}", p.display());
}
println!("cargo:rerun-if-changed=assets/fonts");
let ext_codepoints = extended_codepoints();
// header
writeln!(out, "// AUTO-GENERATED by build.rs - do not edit").unwrap();
writeln!(
out,
"use crate::fonts::bitmap::{{BitmapFont, BitmapGlyph, GLYPH_COUNT}};"
)
.unwrap();
writeln!(out).unwrap();
let has_regular = regular.is_some();
writeln!(out, "pub const HAS_REGULAR: bool = {};", has_regular).unwrap();
// emit the total number of extended codepoints (used by bitmap.rs)
writeln!(
out,
"pub const EXT_GLYPH_COUNT: usize = {};",
ext_codepoints.len()
)
.unwrap();
writeln!(out).unwrap();
// regular
if let Some(ref path) = regular {
let data = fs::read(path).unwrap();
let font = fontdue::Font::from_bytes(data.as_slice(), fontdue::FontSettings::default())
.expect("failed to parse regular TTF");
eprintln!(
"cargo:warning=font: rasterising {} ({} glyphs, {} ext codepoints) body {:.0}/{:.0}/{:.0}/{:.0}/{:.0} px heading {:.0}/{:.0}/{:.0}/{:.0}/{:.0} px",
path.file_name().unwrap().to_string_lossy(),
font.glyph_count(),
ext_codepoints.len(),
BODY_PX[0].0,
BODY_PX[1].0,
BODY_PX[2].0,
BODY_PX[3].0,
BODY_PX[4].0,
HEADING_PX[0].0,
HEADING_PX[1].0,
HEADING_PX[2].0,
HEADING_PX[3].0,
HEADING_PX[4].0,
);
for (px, suffix) in &BODY_PX {
emit_font(
&mut out,
&font,
&format!("REGULAR_BODY_{suffix}"),
*px,
&ext_codepoints,
);
}
for (px, suffix) in &HEADING_PX {
emit_font(
&mut out,
&font,
&format!("REGULAR_HEADING_{suffix}"),
*px,
&ext_codepoints,
);
}
} else {
for (_px, suffix) in &BODY_PX {
emit_stub(&mut out, &format!("REGULAR_BODY_{suffix}"));
}
for (_px, suffix) in &HEADING_PX {
emit_stub(&mut out, &format!("REGULAR_HEADING_{suffix}"));
}
}
// bold
if let Some(ref path) = bold {
let data = fs::read(path).unwrap();
let font = fontdue::Font::from_bytes(data.as_slice(), fontdue::FontSettings::default())
.expect("failed to parse bold TTF");
eprintln!(
"cargo:warning=font: rasterising {} body {:.0}/{:.0}/{:.0}/{:.0}/{:.0} px",
path.file_name().unwrap().to_string_lossy(),
BODY_PX[0].0,
BODY_PX[1].0,
BODY_PX[2].0,
BODY_PX[3].0,
BODY_PX[4].0,
);
for (px, suffix) in &BODY_PX {
emit_font(
&mut out,
&font,
&format!("BOLD_BODY_{suffix}"),
*px,
&ext_codepoints,
);
}
} else {
for (_px, suffix) in &BODY_PX {
emit_stub(&mut out, &format!("BOLD_BODY_{suffix}"));
}
}
// italic
if let Some(ref path) = italic {
let data = fs::read(path).unwrap();
let font = fontdue::Font::from_bytes(data.as_slice(), fontdue::FontSettings::default())
.expect("failed to parse italic TTF");
eprintln!(
"cargo:warning=font: rasterising {} body {:.0}/{:.0}/{:.0}/{:.0}/{:.0} px",
path.file_name().unwrap().to_string_lossy(),
BODY_PX[0].0,
BODY_PX[1].0,
BODY_PX[2].0,
BODY_PX[3].0,
BODY_PX[4].0,
);
for (px, suffix) in &BODY_PX {
emit_font(
&mut out,
&font,
&format!("ITALIC_BODY_{suffix}"),
*px,
&ext_codepoints,
);
}
} else {
for (_px, suffix) in &BODY_PX {
emit_stub(&mut out, &format!("ITALIC_BODY_{suffix}"));
}
}
}
struct RasterGlyph {
advance: u8,
offset_x: i8,
offset_y: i8,
width: u8,
height: u8,
bits: Vec<u8>,
}
fn rasterize_char(font: &fontdue::Font, ch: char, px: f32) -> RasterGlyph {
let (metrics, coverage) = font.rasterize(ch, px);
let w = metrics.width;
let h = metrics.height;
let row_bytes = w.div_ceil(8);
// pack coverage to 1-bit MSB-first
let mut bits = Vec::with_capacity(row_bytes * h);
for y in 0..h {
for bx in 0..row_bytes {
let mut byte = 0u8;
for bit in 0..8usize {
let x = bx * 8 + bit;
if x < w && coverage[y * w + x] >= THRESHOLD {
byte |= 1 << (7 - bit);
}
}
bits.push(byte);
}
}
// offset_y: baseline to top row (y-down screen space).
// fontdue ymin = baseline to bottom edge; top = ymin+h above baseline;
// negate for screen coords.
let offset_y = -metrics.ymin - (h as i32);
RasterGlyph {
advance: (metrics.advance_width + 0.5) as u8,
offset_x: (metrics.xmin).clamp(-128, 127) as i8,
offset_y: offset_y.clamp(-128, 127) as i8,
width: w.min(255) as u8,
height: h.min(255) as u8,
bits,
}
}
fn emit_font(
out: &mut fs::File,
font: &fontdue::Font,
name: &str,
px: f32,
ext_codepoints: &[u32],
) {
// line metrics
let lm = font
.horizontal_line_metrics(px)
.expect("font has no horizontal metrics");
let line_height = lm.new_line_size.ceil() as u16;
let ascent = lm.ascent.ceil() as u16;
// ascii glyphs (direct-indexed 0x20-0x7E)
let mut ascii_glyphs: Vec<RasterGlyph> = Vec::with_capacity(GLYPH_COUNT);
let mut ascii_bits_total: usize = 0;
for code in FIRST_CHAR..=LAST_CHAR {
let g = rasterize_char(font, code as char, px);
ascii_bits_total += g.bits.len();
ascii_glyphs.push(g);
}
// emit ASCII glyph table
writeln!(out, "static {name}_GLYPHS: [BitmapGlyph; GLYPH_COUNT] = [").unwrap();
let mut offset: u16 = 0;
for (i, g) in ascii_glyphs.iter().enumerate() {
let ch = (FIRST_CHAR + i as u8) as char;
writeln!(
out,
" BitmapGlyph {{ advance: {:>2}, offset_x: {:>3}, offset_y: {:>4}, width: {:>2}, height: {:>2}, bitmap_offset: {:>5} }}, // {:?}",
g.advance, g.offset_x, g.offset_y, g.width, g.height, offset, ch
).unwrap();
offset += g.bits.len() as u16;
}
writeln!(out, "];").unwrap();
writeln!(out).unwrap();
// emit ASCII bitmap data
writeln!(out, "static {name}_BITMAPS: [u8; {ascii_bits_total}] = [").unwrap();
emit_bitmap_bytes(out, &ascii_glyphs);
writeln!(out, "];").unwrap();
writeln!(out).unwrap();
// extended unicode glyphs (sorted by codepoint)
let mut ext_glyphs: Vec<RasterGlyph> = Vec::with_capacity(ext_codepoints.len());
let mut ext_bits_total: usize = 0;
for &cp in ext_codepoints {
if let Some(ch) = char::from_u32(cp) {
let g = rasterize_char(font, ch, px);
ext_bits_total += g.bits.len();
ext_glyphs.push(g);
} else {
// invalid codepoint, push a zero-width space placeholder
ext_glyphs.push(RasterGlyph {
advance: 0,
offset_x: 0,
offset_y: 0,
width: 0,
height: 0,
bits: Vec::new(),
});
}
}
let ext_count = ext_codepoints.len();
// emit extended codepoint lookup array
writeln!(out, "static {name}_EXT_CP: [u32; {ext_count}] = [").unwrap();
let mut col = 0;
for &cp in ext_codepoints {
if col == 0 {
write!(out, " ").unwrap();
}
write!(out, "0x{cp:04X},").unwrap();
col += 1;
if col >= 10 {
writeln!(out).unwrap();
col = 0;
}
}
if col > 0 {
writeln!(out).unwrap();
}
writeln!(out, "];").unwrap();
writeln!(out).unwrap();
// emit extended glyph table
writeln!(
out,
"static {name}_EXT_GLYPHS: [BitmapGlyph; {ext_count}] = ["
)
.unwrap();
let mut offset: u16 = 0;
for (i, g) in ext_glyphs.iter().enumerate() {
let cp = ext_codepoints[i];
let ch_display = char::from_u32(cp)
.map(|c| format!("{:?}", c))
.unwrap_or_else(|| format!("U+{cp:04X}"));
writeln!(
out,
" BitmapGlyph {{ advance: {:>2}, offset_x: {:>3}, offset_y: {:>4}, width: {:>2}, height: {:>2}, bitmap_offset: {:>5} }}, // {}",
g.advance, g.offset_x, g.offset_y, g.width, g.height, offset, ch_display
).unwrap();
offset += g.bits.len() as u16;
}
writeln!(out, "];").unwrap();
writeln!(out).unwrap();
// emit extended bitmap data
writeln!(out, "static {name}_EXT_BITMAPS: [u8; {ext_bits_total}] = [").unwrap();
emit_bitmap_bytes(out, &ext_glyphs);
writeln!(out, "];").unwrap();
writeln!(out).unwrap();
// BitmapFont struct
writeln!(out, "pub static {name}: BitmapFont = BitmapFont {{").unwrap();
writeln!(out, " glyphs: &{name}_GLYPHS,").unwrap();
writeln!(out, " bitmaps: &{name}_BITMAPS,").unwrap();
writeln!(out, " ext_codepoints: &{name}_EXT_CP,").unwrap();
writeln!(out, " ext_glyphs: &{name}_EXT_GLYPHS,").unwrap();
writeln!(out, " ext_bitmaps: &{name}_EXT_BITMAPS,").unwrap();
writeln!(out, " line_height: {line_height},").unwrap();
writeln!(out, " ascent: {ascent},").unwrap();
writeln!(out, "}};").unwrap();
writeln!(out).unwrap();
}
fn emit_stub(out: &mut fs::File, name: &str) {
writeln!(
out,
"pub static {name}: BitmapFont = BitmapFont {{\
glyphs: &[BitmapGlyph {{ advance: 0, offset_x: 0, offset_y: 0, width: 0, height: 0, bitmap_offset: 0 }}; GLYPH_COUNT], \
bitmaps: &[], \
ext_codepoints: &[], \
ext_glyphs: &[], \
ext_bitmaps: &[], \
line_height: 13, \
ascent: 13 \
}};"
)
.unwrap();
writeln!(out).unwrap();
}
fn emit_bitmap_bytes(out: &mut fs::File, glyphs: &[RasterGlyph]) {
let mut col = 0;
for g in glyphs {
for &b in &g.bits {
if col == 0 {
write!(out, " ").unwrap();
}
write!(out, "0x{b:02X},").unwrap();
col += 1;
if col >= 16 {
writeln!(out).unwrap();
col = 0;
}
}
}
if col > 0 {
writeln!(out).unwrap();
}
}