pub struct RunicTextEngine { /* private fields */ }Expand description
The main text shaping and layout engine.
Implementations§
Source§impl RunicTextEngine
impl RunicTextEngine
Sourcepub fn new() -> Self
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.
Sourcepub fn new_light() -> Self
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.
Sourcepub fn new_test() -> Self
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).
Sourcepub fn load_font_data(&mut self, data: Vec<u8>)
pub fn load_font_data(&mut self, data: Vec<u8>)
Load a font from file data.
Sourcepub fn shape_layout(
&mut self,
spans: &[TextSpan],
max_width: Option<f32>,
align: TextAlign,
overflow: TextOverflow,
) -> Result<ShapedText, ShapingError>
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.
Sourcepub 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>
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.
Sourcepub fn rasterize_glyph(
&mut self,
glyph_id: u16,
style: &TextStyle,
) -> Result<GlyphImage, ShapingError>
pub fn rasterize_glyph( &mut self, glyph_id: u16, style: &TextStyle, ) -> Result<GlyphImage, ShapingError>
Rasterize a glyph to a bitmap image.
Sourcepub fn extract_glyph_path(
&mut self,
glyph_id: u16,
size: f32,
style: &TextStyle,
) -> Result<Vec<RunicPathSegment>, ShapingError>
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.
Sourcepub fn font_metrics(
&mut self,
style: &TextStyle,
) -> Result<FontMetrics, ShapingError>
pub fn font_metrics( &mut self, style: &TextStyle, ) -> Result<FontMetrics, ShapingError>
Get font metrics for a style.
Sourcepub fn clear_cache(&mut self)
pub fn clear_cache(&mut self)
Clear the shape cache.
Sourcepub fn cache_stats(&self) -> (usize, usize)
pub fn cache_stats(&self) -> (usize, usize)
Get cache statistics.
Sourcepub fn font_count(&self) -> usize
pub fn font_count(&self) -> usize
Get the number of faces in the database.
Sourcepub fn query_font_axes(
&mut self,
family: &str,
_font_size: f32,
) -> Result<Option<Vec<FontAxisInfo>>, ShapingError>
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.
Sourcepub fn shape(&mut self, text: &str, family: &str, size: f32) -> ShapedText
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.
Sourcepub fn rasterize(&mut self, cache_key: u64) -> Option<GlyphImage>
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.