Skip to main content

SkiaRenderer

Struct SkiaRenderer 

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

A renderer that produces PNG output via tiny-skia CPU rasterization.

Text is rendered using cosmic-text for shaping/layout and swash for glyph rasterization. The embedded Inter font ensures deterministic rendering across all platforms.

FontSystem is wrapped in RefCell so that measure_text (which receives &self per the Renderer trait) can still perform shaping.

Implementations§

Source§

impl SkiaRenderer

Source

pub fn new(width: u32, height: u32) -> Self

Creates a new renderer with the given dimensions.

Uses the embedded Inter font for deterministic cross-platform text.

§Panics

Panics if width or height is zero, or if the allocation exceeds platform limits.

Source

pub fn with_white_background(width: u32, height: u32) -> Self

Creates a new renderer with the given dimensions and a white background.

Source

pub fn pixmap(&self) -> &Pixmap

Returns a reference to the underlying pixmap.

Trait Implementations§

Source§

impl Renderer for SkiaRenderer

Source§

fn size(&self) -> (u32, u32)

Returns the output dimensions in pixels.
Source§

fn fill_path(&mut self, path: &Path, paint: &Paint, transform: Affine)

Fills a path with the given paint, under the given transform.
Source§

fn stroke_path( &mut self, path: &Path, paint: &Paint, stroke: &Stroke, transform: Affine, )

Strokes a path with the given paint and stroke style, under the given transform.
Source§

fn draw_text( &mut self, text: &str, pos: Point, style: &TextStyle, _transform: Affine, )

Draws text at the given position with the given style, under the given transform.
Source§

fn draw_image(&mut self, img: &Image, dst: Rect, transform: Affine)

Draws a raster image into the destination rectangle, under the given transform.
Source§

fn push_clip(&mut self, path: &Path, transform: Affine)

Pushes a clipping path. All subsequent draws are clipped to this path.
Source§

fn pop_clip(&mut self)

Pops the most recent clipping path.
Source§

fn measure_text(&self, text: &str, style: &TextStyle) -> (f64, f64)

Measures the bounding box of the given text with the given style. Returns the width and height in pixels.
Source§

fn finalize(self) -> Vec<u8>

Consumes the renderer and returns the encoded output (PNG bytes, SVG string as bytes, etc.).

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.