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
impl TextRenderer
Sourcepub fn new(face: Face) -> Self
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.
Sourcepub fn face(&self) -> &Face
pub fn face(&self) -> &Face
Borrow the underlying primary face — useful for caller-side metric queries (line height, ascent) without re-parsing.
Sourcepub fn line_height_px(&self, size_px: f32) -> f32
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.
Sourcepub fn render_run(&mut self, run: &TextRun) -> Result<RgbaBitmap, Error>
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).
Sourcepub 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>
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.
Sourcepub fn render_run_wrapped(
&mut self,
run: &TextRun,
max_width_px: f32,
) -> Result<Vec<RgbaBitmap>, Error>
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.
Sourcepub 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>
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).
Sourcepub fn compose_run_at(
&mut self,
run: &TextRun,
dst: &mut RgbaBitmap,
pen_x: f32,
pen_y: f32,
) -> Result<(), Error>
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.