fullbleed/
glyph_report.rs1use std::collections::BTreeMap;
2
3#[derive(Debug, Clone, Default)]
4pub struct GlyphCoverageReport {
5 missing: BTreeMap<u32, MissingGlyph>,
6}
7
8#[derive(Debug, Clone)]
9pub struct MissingGlyph {
10 pub codepoint: u32,
11 pub ch: char,
12 pub fonts_tried: Vec<String>,
13 pub count: usize,
14}
15
16impl GlyphCoverageReport {
17 pub fn record_missing(&mut self, ch: char, fonts_tried: Vec<String>) {
18 let codepoint = ch as u32;
19 let entry = self.missing.entry(codepoint).or_insert(MissingGlyph {
20 codepoint,
21 ch,
22 fonts_tried,
23 count: 0,
24 });
25 entry.count = entry.count.saturating_add(1);
26 }
27
28 pub fn merge(&mut self, other: GlyphCoverageReport) {
29 for (codepoint, missing) in other.missing {
30 let entry = self.missing.entry(codepoint).or_insert(MissingGlyph {
31 codepoint,
32 ch: missing.ch,
33 fonts_tried: missing.fonts_tried.clone(),
34 count: 0,
35 });
36 entry.count = entry.count.saturating_add(missing.count);
37 }
38 }
39
40 pub fn missing(&self) -> Vec<MissingGlyph> {
41 self.missing.values().cloned().collect()
42 }
43
44 pub fn is_empty(&self) -> bool {
45 self.missing.is_empty()
46 }
47}