truce-iced 0.49.14

Iced GUI backend for truce plugins
Documentation
//! Font loading for iced renderers.

/// Load a TrueType font into iced's font system and return the `iced::Font`
/// to use as the renderer default.
///
/// Used by both the live editor and the snapshot renderer.
///
/// # Panics
///
/// Panics if iced's process-wide font-system `RwLock` is poisoned -
/// in normal operation no holder panics while writing, so this is a
/// recovery-impossible condition rather than a runtime contract.
#[must_use]
pub fn apply_font(family: &'static str, data: &'static [u8]) -> iced::Font {
    let mut fs = iced_graphics::text::font_system()
        .write()
        .expect("font system lock");
    let v_before = fs.version();
    fs.load_font(std::borrow::Cow::Borrowed(data));
    let v_after = fs.version();
    log::debug!(
        "[truce-iced] font loaded: family={family:?}, {} bytes, version {v_before:?}->{v_after:?}",
        data.len()
    );
    drop(fs);
    iced::Font {
        family: iced::font::Family::Name(family),
        ..iced::Font::DEFAULT
    }
}