euv-core 0.48.3

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
use super::*;

/// Abstraction for native OS and deterministic glyph rasterization providers.
pub trait SystemFontProvider {
    /// Returns metadata describing this font provider's active backend and capabilities.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Font provider reference.
    ///
    /// # Returns
    ///
    /// - `SystemFontInfo` - Provider capabilities and family metadata.
    fn font_info(&self) -> SystemFontInfo;

    /// Rasterizes a quantized `GlyphKey` into an alpha8 coverage bitmap.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Font provider reference.
    /// - `GlyphKey` - Quantized character, font size, bold flag, and family.
    ///
    /// # Returns
    ///
    /// - `Option<RasterizedGlyph>` - Rasterized glyph bitmap if supported by this provider.
    fn rasterize(&self, key: GlyphKey) -> Option<RasterizedGlyph>;

    /// Rasterizes a batch of missing `GlyphKey` entries in a single provider pass to amortize OS/Web readbacks.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Font provider reference.
    /// - `&[GlyphKey]` - Slice of missing glyph keys to rasterize.
    ///
    /// # Returns
    ///
    /// - `Vec<Option<RasterizedGlyph>>` - Rasterized glyph results aligned 1:1 with `keys`.
    fn rasterize_batch(&self, keys: &[GlyphKey]) -> Vec<Option<RasterizedGlyph>> {
        let mut results: Vec<Option<RasterizedGlyph>> = Vec::with_capacity(keys.len());
        for &key in keys.iter() {
            results.push(self.rasterize(key));
        }
        results
    }

    /// Rasterizes `key` directly into a caller-owned reusable `dst` alpha8 staging buffer without allocating a fresh bitmap vector.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Font provider reference.
    /// - `GlyphKey` - Quantized glyph descriptor.
    /// - `&mut Vec<u8>` - Reusable destination staging buffer cleared and overwritten with row-major alpha8 pixels.
    ///
    /// # Returns
    ///
    /// - `Option<(u32, u32, u32)>` - Tuple `(width, height, advance)` when rasterization succeeded.
    fn rasterize_into(&self, key: GlyphKey, dst: &mut Vec<u8>) -> Option<(u32, u32, u32)> {
        let glyph: RasterizedGlyph = self.rasterize(key)?;
        dst.clear();
        dst.extend_from_slice(glyph.get_coverage().as_slice());
        Some((glyph.get_width(), glyph.get_height(), glyph.get_advance()))
    }
}