Skip to main content

Renderer

Trait Renderer 

Source
pub trait Renderer {
    // Required methods
    fn size(&self) -> (u32, u32);
    fn fill_path(&mut self, path: &Path, paint: &Paint, transform: Affine);
    fn stroke_path(
        &mut self,
        path: &Path,
        paint: &Paint,
        stroke: &Stroke,
        transform: Affine,
    );
    fn draw_text(
        &mut self,
        text: &str,
        pos: Point,
        style: &TextStyle,
        transform: Affine,
    );
    fn draw_image(&mut self, img: &Image, dst: Rect, transform: Affine);
    fn push_clip(&mut self, path: &Path, transform: Affine);
    fn pop_clip(&mut self);
    fn measure_text(&self, text: &str, style: &TextStyle) -> (f64, f64);
    fn finalize(self) -> Vec<u8> ;
}
Expand description

A rendering backend that can produce raster or vector output.

Implementations translate plotkit’s core primitive types into backend-specific draw calls. PNG, SVG, PDF, and WASM are all implementations of this trait.

§Contract

  • All coordinates and transforms use plotkit’s coordinate system (origin top-left, y-down).
  • The renderer must handle the full Paint, Stroke, and TextStyle types faithfully.
  • finalize consumes the renderer and returns the encoded output bytes.

Required Methods§

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.).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§