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, andTextStyletypes faithfully. finalizeconsumes the renderer and returns the encoded output bytes.
Required Methods§
Sourcefn fill_path(&mut self, path: &Path, paint: &Paint, transform: Affine)
fn fill_path(&mut self, path: &Path, paint: &Paint, transform: Affine)
Fills a path with the given paint, under the given transform.
Sourcefn stroke_path(
&mut self,
path: &Path,
paint: &Paint,
stroke: &Stroke,
transform: Affine,
)
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.
Sourcefn draw_text(
&mut self,
text: &str,
pos: Point,
style: &TextStyle,
transform: Affine,
)
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.
Sourcefn draw_image(&mut self, img: &Image, dst: Rect, transform: Affine)
fn draw_image(&mut self, img: &Image, dst: Rect, transform: Affine)
Draws a raster image into the destination rectangle, under the given transform.
Sourcefn push_clip(&mut self, path: &Path, transform: Affine)
fn push_clip(&mut self, path: &Path, transform: Affine)
Pushes a clipping path. All subsequent draws are clipped to this path.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".