Skip to main content

TextRenderer

Struct TextRenderer 

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

Owns a Face (wrapped in a single-face FaceChain) and a long-lived Renderer for per-glyph bitmap-cache reuse across runs.

Callers construct one TextRenderer per face they want to use, and call TextRenderer::render_run_into for every TextRun they want composited.

Implementations§

Source§

impl TextRenderer

Source

pub fn new(face: Face) -> Self

Build a renderer around an already-parsed Face. The face is owned for the lifetime of the renderer; if you need to switch fonts mid-scene, build a second TextRenderer.

Source

pub fn face(&self) -> &Face

Borrow the underlying primary face — useful for caller-side metric queries (line height, ascent) without re-parsing.

Source

pub fn line_height_px(&self, size_px: f32) -> f32

Pixel line-height for size_px. Convenience wrapper around Face::line_height_px so callers laying out multi-line TextRun content don’t need to dig into Scribe directly.

Source

pub fn render_run(&mut self, run: &TextRun) -> Result<RgbaBitmap, Error>

Render a TextRun into a freshly-allocated straight-alpha RGBA bitmap sized to the run’s natural glyph bounds.

Returns an empty bitmap if the run shapes to zero glyphs (or every glyph is non-rendering — e.g. a string of spaces).

Source

pub fn render_run_into( &mut self, run: &TextRun, dst: &mut [u8], dst_w: u32, dst_h: u32, pen_x: i32, pen_y: i32, ) -> Result<(), Error>

Render a TextRun into a caller-provided RGBA destination at pen position (pen_x, pen_y). The destination buffer must be dst_w * dst_h * 4 bytes (straight-alpha RGBA8). Pixels outside the destination are clipped.

pen_x / pen_y is the top-left of the run’s bitmap (NOT the typographic baseline) to match the previous Scribe RgbaBitmap origin convention.

Source

pub fn render_run_wrapped( &mut self, run: &TextRun, max_width_px: f32, ) -> Result<Vec<RgbaBitmap>, Error>

Render a TextRun whose text may overflow max_width_px or contain \n characters. Output is one bitmap per laid-out line; the caller stacks them at the desired line-height.

Source

pub fn render_run_wrapped_into( &mut self, run: &TextRun, dst: &mut [u8], dst_w: u32, dst_h: u32, pen_x: i32, pen_y: i32, max_width_px: f32, line_height_override: Option<f32>, ) -> Result<(), Error>

Render a TextRun into the destination, wrapping at max_width_px (or splitting on \n). Lines stack downward from pen_y at intervals of self.line_height_px(size) (or line_height_override if Some).

Source

pub fn compose_run_at( &mut self, run: &TextRun, dst: &mut RgbaBitmap, pen_x: f32, pen_y: f32, ) -> Result<(), Error>

Lower-level path: shape run.text and composite directly into a caller-provided RgbaBitmap at pen origin (pen_x, pen_y). Reuses the renderer’s internal glyph-bitmap LRU. Useful when the caller is already tiling several runs into one bitmap and doesn’t want a fresh allocation per run.

pen_x / pen_y is the typographic baseline for this entry point (matching the previous Scribe compose_run convention), unlike the render_run_into family which uses the bitmap top-left.

Trait Implementations§

Source§

impl Debug for TextRenderer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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.