Skip to main content

RunicTextEngine

Struct RunicTextEngine 

Source
pub struct RunicTextEngine { /* private fields */ }
Expand description

The main text shaping and layout engine.

Implementations§

Source§

impl RunicTextEngine

Source

pub fn new() -> Self

Create a new text engine with system fonts and user fonts.

§Contract

Guaranteed to successfully instantiate a usable text engine. Loads all standard system and user fonts first, and then embeds Jupiteroid.ttf as an absolute last-resort fallback so text rendering cannot fail even on zero-font systems.

Source

pub fn new_light() -> Self

Create a light text engine for testing — no system/user font loading. Only bundled fonts (loaded via load_font_data()) are available.

Source

pub fn new_test() -> Self

Create a test engine with only the bundled Jupiteroid font loaded. Avoids loading system fonts (which cause OOM in CI with many parallel tests).

Source

pub fn load_font_data(&mut self, data: Vec<u8>)

Load a font from file data.

Source

pub fn shape_layout( &mut self, spans: &[TextSpan], max_width: Option<f32>, align: TextAlign, overflow: TextOverflow, ) -> Result<ShapedText, ShapingError>

Shape and layout text with the given spans.

Source

pub fn shape_layout_ex( &mut self, spans: &[TextSpan], max_width: Option<f32>, align: TextAlign, overflow: TextOverflow, path: Option<TextPath>, boundary: Option<LayoutBoundary>, ) -> Result<ShapedText, ShapingError>

Shape and layout text with advanced capabilities (curved text paths and boundaries).

§Contract

Performs shaping over the spans and applies line breaking. If a path is provided, positions and rotates glyphs along the Bezier curve. If a boundary is provided, wrapping reflows dynamically to fit within the geometry.

Source

pub fn rasterize_glyph( &mut self, glyph_id: u16, style: &TextStyle, ) -> Result<GlyphImage, ShapingError>

Rasterize a glyph to a bitmap image.

Source

pub fn extract_glyph_path( &mut self, glyph_id: u16, size: f32, style: &TextStyle, ) -> Result<Vec<RunicPathSegment>, ShapingError>

Extract the vector outline path for a given glyph at the specified size.

§Contract

Resolves the font using the provided TextStyle and extracts its Bezier outline. Returns a list of RunicPathSegment representing the raw MoveTo, LineTo, QuadTo, CubicTo, and Close commands of the glyph contours, scaled to the given size. If the font does not contain outline data or the glyph is empty, returns an empty path.

Source

pub fn font_metrics( &mut self, style: &TextStyle, ) -> Result<FontMetrics, ShapingError>

Get font metrics for a style.

Source

pub fn clear_cache(&mut self)

Clear the shape cache.

Source

pub fn cache_stats(&self) -> (usize, usize)

Get cache statistics.

Source

pub fn font_count(&self) -> usize

Get the number of faces in the database.

Source

pub fn query_font_axes( &mut self, family: &str, _font_size: f32, ) -> Result<Option<Vec<FontAxisInfo>>, ShapingError>

Query the variable font axes available for a given font family.

Returns Ok(None) if the font is not variable. Returns Err if the font cannot be found.

§Arguments
  • family — Font family name.
  • font_size — Font size for resolving the face.
Source

pub fn shape(&mut self, text: &str, family: &str, size: f32) -> ShapedText

Shape text with a simple family/size interface (backward-compatible).

This wraps shape_layout with a single span and default settings for use by the cvkg-render-gpu crate.

Source

pub fn rasterize(&mut self, cache_key: u64) -> Option<GlyphImage>

Rasterizes a glyph by lookup using its unique composite cache key.

§Contract

The cache_key must match a key generated during text shaping that hashes the font data identity, size, styling, and glyph ID. This function resolves the matching glyph parameters from the shape cache and rasterizes it at the correct size and weight to prevent cache collisions and visual distortion. Returns None if no matching shaped glyph is present in the cache.

Trait Implementations§

Source§

impl Default for RunicTextEngine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.