nandi/jolt-nativepublic Fork 0
c4f56b0a96ecb29336e2cf16c522b794ae62ad3f
Commits
Clone
git clone https://git.rickub.com/nandi/jolt-native.git
git clone ssh://git@rickub.com/nandi/jolt-native.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Bring vidya in cfd3e36 · on c4f56b0a96ecb29336e2cf16c522b794ae62ad3f · nandi · 19d ago
fonts.rs · 76 lines · 2.6 KBRust Blame HistoryRaw
 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
//! Extra glyph coverage for UI punctuation, math-in-prose, and block art.
//!
//! egui’s default Ubuntu Light lacks many symbols used in HIG-style copy
//! (`→`, `●`, `○`, `▾`/`▴`, en/em dashes, curly quotes, …), common LLM
//! math outside `$…$` (`ℝ`, `ⁿ`, `∑`, Greek, …), and box/block elements
//! used in Bluesky bios (`█▄▀░`, box drawing). On Android those codepoints
//! render as hollow boxes (“tofu”).
//!
//! [`install_symbol_font`] registers a DejaVu Sans subset as a **fallback**
//! so primary text stays Ubuntu, but missing symbols still draw.

use egui::{
    epaint::text::{FontInsert, FontPriority, InsertFontFamily},
    Context, FontData, FontFamily,
};

/// Subset of DejaVu Sans covering UI symbols, math-in-prose, and box/block art.
/// See `assets/NOTICE` and `scripts/rebuild-symbols-ttf.sh`.
static VIDYA_SYMBOLS_TTF: &[u8] = include_bytes!("../assets/vidya-symbols.ttf");

const FONT_NAME: &str = "vidya-symbols";

/// Install the symbol fallback font (idempotent).
///
/// Safe to call every frame / from [`crate::apply`]: egui skips re-install when
/// the font name is already present.
pub fn install_symbol_font(ctx: &Context) {
    ctx.add_font(FontInsert::new(
        FONT_NAME,
        FontData::from_static(VIDYA_SYMBOLS_TTF),
        vec![
            InsertFontFamily {
                family: FontFamily::Proportional,
                // After Ubuntu / emoji — only used when those lack the glyph.
                priority: FontPriority::Lowest,
            },
            InsertFontFamily {
                family: FontFamily::Monospace,
                priority: FontPriority::Lowest,
            },
        ],
    ));
}

#[cfg(test)]
mod tests {
    use super::{install_symbol_font, VIDYA_SYMBOLS_TTF};

    /// Glyphs from a real Bluesky bio (nandi.uk) that previously tofued in Sleek.
    const BLOCK_ART: &str = "█▄▀░";

    #[test]
    fn symbol_font_covers_block_elements() {
        assert!(
            VIDYA_SYMBOLS_TTF.len() > 10_000,
            "vidya-symbols.ttf looks empty/truncated"
        );

        let ctx = egui::Context::default();
        install_symbol_font(&ctx);
        // Allocate fonts so fallback families are built.
        ctx.begin_pass(egui::RawInput::default());

        let missing: Vec<char> = ctx.fonts(|fonts| {
            let font_id = egui::FontId::proportional(16.0);
            BLOCK_ART
                .chars()
                .filter(|&c| !fonts.has_glyph(&font_id, c))
                .collect()
        });
        assert!(
            missing.is_empty(),
            "proportional fallback missing glyphs: {missing:?}"
        );
    }
}