mirage-engine 0.1.1

Mirage, an immediate-mode 3D engine for simple games on desktop and the browser
Documentation
//! The fonts a source holds, read by the decoder the UI draws text with.

use std::sync::Arc;

use crate::Error;

/// The font `bytes` hold, kept as they were loaded.
///
/// Fails with the decoder's own text where they are no font, so a source
/// that is no font is a startup error and never reaches the UI.
pub(crate) fn decode(bytes: &[u8]) -> Result<Arc<[u8]>, Error> {
    skrifa::FontRef::new(bytes).map_err(|error| Error::msg(format!("did not decode: {error}")))?;
    Ok(Arc::from(bytes))
}

/// Fails where `bytes` hold no font at `index`.
#[cfg(feature = "ui")]
pub(crate) fn decode_at(bytes: &[u8], index: u32) -> Result<(), Error> {
    skrifa::FontRef::from_index(bytes, index)
        .map(drop)
        .map_err(|error| Error::msg(format!("did not decode: {error}")))
}