pub trait Renderer {
Show 27 methods
// Required methods
fn canvas_size(&self) -> (f64, f64);
fn dpi(&self) -> f64;
fn draw_path(
&mut self,
gc: &GraphicsContext,
path: &Path,
transform: &Affine2D,
fill: Option<Rgba>,
);
fn draw_gouraud_triangles(
&mut self,
gc: &GraphicsContext,
triangles: &[[Point; 3]],
colors: &[[Rgba; 3]],
transform: &Affine2D,
);
fn draw_image(
&mut self,
gc: &GraphicsContext,
origin: Point,
image: &RgbaImage,
transform: Option<&Affine2D>,
);
// Provided methods
fn points_to_pixels(&self, points: f64) -> f64 { ... }
fn draw_markers(
&mut self,
gc: &GraphicsContext,
marker: &Path,
marker_transform: &Affine2D,
path: &Path,
transform: &Affine2D,
fill: Option<Rgba>,
) { ... }
fn draw_path_collection(
&mut self,
gc: &GraphicsContext,
collection: &PathCollection<'_>,
) { ... }
fn draw_quad_mesh(&mut self, gc: &GraphicsContext, mesh: &QuadMesh<'_>) { ... }
fn draw_text(
&mut self,
gc: &GraphicsContext,
run: &TextRun,
origin: Point,
angle: f64,
) { ... }
fn draw_text_lines(
&mut self,
_gc: &GraphicsContext,
_text: &TextLines<'_>,
) -> bool { ... }
fn takes_texts_whole(&self) -> bool { ... }
fn draw_tex(
&mut self,
gc: &GraphicsContext,
_run: &TextRun,
tex: &TexText,
origin: Point,
angle: f64,
) -> Result<(), TexError> { ... }
fn rounds_glyph_positions(&self) -> bool { ... }
fn open_group(&mut self, _name: &str, _gid: Option<&str>) { ... }
fn close_group(&mut self, _name: &str) { ... }
fn open_part_group(&mut self, name: &str, gid: Option<&str>) { ... }
fn close_part_group(&mut self, name: &str) { ... }
fn start_rasterizing(&mut self) { ... }
fn stop_rasterizing(&mut self) { ... }
fn raster_dpi(&self) -> Option<f64> { ... }
fn start_filter(&mut self) { ... }
fn stop_filter(&mut self, _filter: &FilterFn<'_>) { ... }
fn stop_shared_filter(&mut self, filter: &SharedFilter) { ... }
fn option_image_nocomposite(&self) -> bool { ... }
fn option_scale_image(&self) -> bool { ... }
fn image_magnification(&self) -> f64 { ... }
}Expand description
A drawing target: a raster canvas, an SVG/PDF/PS document, a window.
This mirrors matplotlib’s RendererBase. All geometry arrives in
display coordinates: pixels at the renderer’s dpi with the origin at
the bottom-left corner and y pointing up. Transforms passed alongside
paths are affine maps into that space; any non-affine part (log scales,
polar projections) has already been applied by the caller.
Only draw_path is mandatory; the batched operations
have correct but slow default implementations that backends override
when they can do better (e.g. stamping a pre-rasterised marker).
Required Methods§
Sourcefn canvas_size(&self) -> (f64, f64)
fn canvas_size(&self) -> (f64, f64)
Canvas width and height in pixels.
Sourcefn draw_path(
&mut self,
gc: &GraphicsContext,
path: &Path,
transform: &Affine2D,
fill: Option<Rgba>,
)
fn draw_path( &mut self, gc: &GraphicsContext, path: &Path, transform: &Affine2D, fill: Option<Rgba>, )
Strokes path with gc and fills it with fill, if given.
Sourcefn draw_gouraud_triangles(
&mut self,
gc: &GraphicsContext,
triangles: &[[Point; 3]],
colors: &[[Rgba; 3]],
transform: &Affine2D,
)
fn draw_gouraud_triangles( &mut self, gc: &GraphicsContext, triangles: &[[Point; 3]], colors: &[[Rgba; 3]], transform: &Affine2D, )
Draws triangles whose vertex colours are interpolated linearly
(Gouraud shading); transform maps the vertices to display space.
Sourcefn draw_image(
&mut self,
gc: &GraphicsContext,
origin: Point,
image: &RgbaImage,
transform: Option<&Affine2D>,
)
fn draw_image( &mut self, gc: &GraphicsContext, origin: Point, image: &RgbaImage, transform: Option<&Affine2D>, )
Draws an image with its bottom-left corner at origin (display
coordinates). With transform, the image’s unit square is mapped
through it instead (only used when
option_scale_image is true).
Provided Methods§
Sourcefn points_to_pixels(&self, points: f64) -> f64
fn points_to_pixels(&self, points: f64) -> f64
Converts a length in points (1/72 inch) to pixels.
Sourcefn draw_markers(
&mut self,
gc: &GraphicsContext,
marker: &Path,
marker_transform: &Affine2D,
path: &Path,
transform: &Affine2D,
fill: Option<Rgba>,
)
fn draw_markers( &mut self, gc: &GraphicsContext, marker: &Path, marker_transform: &Affine2D, path: &Path, transform: &Affine2D, fill: Option<Rgba>, )
Draws marker (in marker coordinates, mapped by marker_transform
to pixel offsets) at every vertex of path transformed by transform.
Sourcefn draw_path_collection(
&mut self,
gc: &GraphicsContext,
collection: &PathCollection<'_>,
)
fn draw_path_collection( &mut self, gc: &GraphicsContext, collection: &PathCollection<'_>, )
Draws many paths with per-item properties (scatter, patches, meshes).
Sourcefn draw_quad_mesh(&mut self, gc: &GraphicsContext, mesh: &QuadMesh<'_>)
fn draw_quad_mesh(&mut self, gc: &GraphicsContext, mesh: &QuadMesh<'_>)
Draws a flat-shaded quad mesh (matplotlib’s draw_quad_mesh): by
default as a path collection of its cells in matplotlib’s order
(QuadMesh::cell_paths) with the line width of gc.
Sourcefn draw_text(
&mut self,
gc: &GraphicsContext,
run: &TextRun,
origin: Point,
angle: f64,
)
fn draw_text( &mut self, gc: &GraphicsContext, run: &TextRun, origin: Point, angle: f64, )
Draws laid-out text with its origin (left end of the baseline) at
origin, rotated by angle degrees counter-clockwise about it.
The default fills every glyph outline and rule as a path in the
stroke colour, which is exact for vector output; raster backends
override it to reproduce FreeType’s glyph rendering.
Sourcefn draw_text_lines(
&mut self,
_gc: &GraphicsContext,
_text: &TextLines<'_>,
) -> bool
fn draw_text_lines( &mut self, _gc: &GraphicsContext, _text: &TextLines<'_>, ) -> bool
Draws text whole, as matplotlib’s Text.draw hands a renderer a
text’s lines one by one, each with its string, font and artist
(draw_text(gc, x, y, s, prop, angle, ismath, mtext)); whether
the renderer drew it. The renderers of this crate don’t (they draw
each line through draw_text or
draw_tex), a renderer of the program’s does.
Sourcefn takes_texts_whole(&self) -> bool
fn takes_texts_whole(&self) -> bool
Whether the renderer takes texts whole
(draw_text_lines), which those drawing
texts ask before they describe one.
Sourcefn draw_tex(
&mut self,
gc: &GraphicsContext,
_run: &TextRun,
tex: &TexText,
origin: Point,
angle: f64,
) -> Result<(), TexError>
fn draw_tex( &mut self, gc: &GraphicsContext, _run: &TextRun, tex: &TexText, origin: Point, angle: f64, ) -> Result<(), TexError>
Draws tex, a line of TeX text that is the source of run
(TextSource::Tex), with its origin at
origin, rotated by angle degrees counter-clockwise about it
(matplotlib’s draw_tex).
The default fills the outline matplotlib’s TextToPath makes of
the typeset text (RendererBase.draw_tex).
§Errors
When TeX cannot typeset the text or its fonts cannot be drawn.
Sourcefn rounds_glyph_positions(&self) -> bool
fn rounds_glyph_positions(&self) -> bool
Whether the renderer rounds where it puts each glyph (and each line
of TeX) to whole numbers as Python rounds them, as matplotlib’s Agg
renderer does (round(0x40 * x)), which refuses a position that is
not finite. Renderers drawing glyphs as paths don’t.
Sourcefn open_group(&mut self, _name: &str, _gid: Option<&str>)
fn open_group(&mut self, _name: &str, _gid: Option<&str>)
Starts a named group of draw calls (vector backends emit a group).
Sourcefn close_group(&mut self, _name: &str)
fn close_group(&mut self, _name: &str)
Ends the most recently opened group.
Sourcefn open_part_group(&mut self, name: &str, gid: Option<&str>)
fn open_part_group(&mut self, name: &str, gid: Option<&str>)
Starts a named group of the draw calls of a part of the artist
being drawn, which draws with that artist’s clip regions (the
background of a figure or an axes; an axis’ ticks and their lines
and labels, whose gridlines matplotlib clips to one box): a group as
open_group starts, but the PDF backend does
not set the clip regions again for the parts.
Sourcefn close_part_group(&mut self, name: &str)
fn close_part_group(&mut self, name: &str)
Ends the most recently opened group of a part.
Sourcefn start_rasterizing(&mut self)
fn start_rasterizing(&mut self)
Sends the following drawing to a raster canvas until
stop_rasterizing (matplotlib’s
start_rasterizing); only vector output distinguishes the modes.
Sourcefn stop_rasterizing(&mut self)
fn stop_rasterizing(&mut self)
Places what was drawn since
start_rasterizing in the output as an
image and resumes drawing directly.
Sourcefn raster_dpi(&self) -> Option<f64>
fn raster_dpi(&self) -> Option<f64>
The resolution of the raster canvas drawing goes to while a vector
renderer is rasterizing, None otherwise. Artists drawn meanwhile
compute their geometry at it, in canvas pixels (matplotlib changes
the figure’s dpi in start_rasterizing).
Sourcefn start_filter(&mut self)
fn start_filter(&mut self)
Sends the following drawing to a fresh transparent canvas until
stop_filter (matplotlib’s start_filter).
Only raster canvases filter; other backends draw as usual.
Sourcefn stop_filter(&mut self, _filter: &FilterFn<'_>)
fn stop_filter(&mut self, _filter: &FilterFn<'_>)
Hands what was drawn since start_filter,
cropped to its visible pixels, to filter and draws the image it
returns in its place (matplotlib’s stop_filter).
stop_filter with a filter the renderer may
keep, as matplotlib hands renderers the artist’s filter itself: a
renderer passing it on (to a program’s renderer, say) overrides
this; the others filter as stop_filter does.
Sourcefn option_image_nocomposite(&self) -> bool
fn option_image_nocomposite(&self) -> bool
When true, images are drawn one by one instead of being
composited into a single image first.
Sourcefn option_scale_image(&self) -> bool
fn option_scale_image(&self) -> bool
When true, draw_image accepts arbitrary
affine transforms (vector backends); otherwise images arrive
pre-resampled at display resolution.
Sourcefn image_magnification(&self) -> f64
fn image_magnification(&self) -> f64
The factor by which images are magnified before being drawn
(matplotlib’s get_image_magnification): vector backends rasterize
images at their own resolution rather than at 72 dpi.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".