pub struct RasterRenderer { /* private fields */ }Expand description
Renders into an RGBA pixel buffer exactly like matplotlib’s
RendererAgg (straight alpha, initially transparent white).
Implementations§
Source§impl RasterRenderer
impl RasterRenderer
Sourcepub fn new(
width: f64,
height: f64,
dpi: f64,
) -> Result<Self, RasterBackendError>
pub fn new( width: f64, height: f64, dpi: f64, ) -> Result<Self, RasterBackendError>
A canvas of width × height display pixels at dpi.
Sourcepub fn with_simplify(self, settings: SimplifySettings) -> Self
pub fn with_simplify(self, settings: SimplifySettings) -> Self
Uses matplotlib’s path.simplify / path.simplify_threshold
settings (the defaults otherwise).
Sourcepub fn with_path_chunksize(self, chunksize: usize) -> Self
pub fn with_path_chunksize(self, chunksize: usize) -> Self
Draws unfilled, unhatched paths that would be simplified in pieces
of at most chunksize vertices when they have more, as matplotlib
does with agg.path.chunksize (0, the default, never splits; nor do
sizes up to 100).
Sourcepub fn pixmap_mut(&mut self) -> &mut Pixmap
pub fn pixmap_mut(&mut self) -> &mut Pixmap
The pixels, for changes made outside drawing calls (matplotlib’s
restore_region writes saved pixels back into the canvas).
Sourcepub fn into_pixmap(self) -> Pixmap
pub fn into_pixmap(self) -> Pixmap
Consumes the renderer, returning its pixels.
Sourcepub fn to_image(&self) -> RgbaImage
pub fn to_image(&self) -> RgbaImage
The pixels as an RgbaImage (a copy; see
into_image).
Sourcepub fn into_image(self) -> RgbaImage
pub fn into_image(self) -> RgbaImage
Consumes the renderer, returning its pixels as an RgbaImage
without copying them.
Sourcepub fn to_png(&self) -> Result<Vec<u8>, RasterBackendError>
pub fn to_png(&self) -> Result<Vec<u8>, RasterBackendError>
Encodes the pixels as an RGBA PNG carrying the resolution, without text entries.
§Errors
When the image cannot be encoded.
Sourcepub fn to_png_with(
&self,
metadata: &PngMetadata,
) -> Result<Vec<u8>, RasterBackendError>
pub fn to_png_with( &self, metadata: &PngMetadata, ) -> Result<Vec<u8>, RasterBackendError>
Encodes the canvas as PNG with the text entries of metadata, as
matplotlib’s savefig writes them.
§Errors
When the image cannot be encoded, or a keyword is not a valid PNG keyword (1 to 79 printable Latin-1 characters).
Sourcepub fn take_errors(&mut self) -> Vec<RasterError>
pub fn take_errors(&mut self) -> Vec<RasterError>
Problems met while drawing (matplotlib would have raised, e.g.
OverflowError for paths exceeding the cell limit), oldest first.
Trait Implementations§
Source§impl Debug for RasterRenderer
impl Debug for RasterRenderer
Source§impl Renderer for RasterRenderer
impl Renderer for RasterRenderer
Source§fn 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>, )
matplotlib’s wrapper rounds the position and forces the image alpha to 1 (images arrive with their opacity applied).
Source§fn 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, )
Glyph outlines filled at FreeType’s pen positions, unsnapped; see
the text module. While the thread draws text as paths
(set_texts_as_paths), the outlines
TextToPath makes are filled as paths instead.
Source§fn rounds_glyph_positions(&self) -> bool
fn rounds_glyph_positions(&self) -> bool
Glyphs are placed on the 26.6 grid as matplotlib’s Agg renderer rounds them, unless they are drawn as paths.
Source§fn 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>
TeX text from its DVI glyphs or dvipng’s image; see the tex
module.
Source§fn draw_quad_mesh(&mut self, gc: &GraphicsContext, mesh: &QuadMesh<'_>)
fn draw_quad_mesh(&mut self, gc: &GraphicsContext, mesh: &QuadMesh<'_>)
Agg’s quad mesh generator walks every cell down its first column first. Colours given per cell (or one for all) are split with the cells, which are then drawn a block at a time, so that their outlines need not all exist at once.
Source§fn option_image_nocomposite(&self) -> bool
fn option_image_nocomposite(&self) -> bool
Agg composites each image straight onto the canvas.
Source§fn canvas_size(&self) -> (f64, f64)
fn canvas_size(&self) -> (f64, f64)
Source§fn 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>, )
path with gc and fills it with fill, if given.Source§fn 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>, )
marker (in marker coordinates, mapped by marker_transform
to pixel offsets) at every vertex of path transformed by transform.Source§fn draw_path_collection(
&mut self,
gc: &GraphicsContext,
collection: &PathCollection<'_>,
)
fn draw_path_collection( &mut self, gc: &GraphicsContext, collection: &PathCollection<'_>, )
Source§fn 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, )
transform maps the vertices to display space.Source§fn start_filter(&mut self)
fn start_filter(&mut self)
stop_filter (matplotlib’s start_filter).
Only raster canvases filter; other backends draw as usual.Source§fn stop_filter(&mut self, filter: &FilterFn<'_>)
fn stop_filter(&mut self, filter: &FilterFn<'_>)
start_filter,
cropped to its visible pixels, to filter and draws the image it
returns in its place (matplotlib’s stop_filter).Source§fn points_to_pixels(&self, points: f64) -> f64
fn points_to_pixels(&self, points: f64) -> f64
Source§fn draw_text_lines(
&mut self,
_gc: &GraphicsContext,
_text: &TextLines<'_>,
) -> bool
fn draw_text_lines( &mut self, _gc: &GraphicsContext, _text: &TextLines<'_>, ) -> bool
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.Source§fn takes_texts_whole(&self) -> bool
fn takes_texts_whole(&self) -> bool
draw_text_lines), which those drawing
texts ask before they describe one.Source§fn open_group(&mut self, _name: &str, _gid: Option<&str>)
fn open_group(&mut self, _name: &str, _gid: Option<&str>)
Source§fn close_group(&mut self, _name: &str)
fn close_group(&mut self, _name: &str)
Source§fn open_part_group(&mut self, name: &str, gid: Option<&str>)
fn open_part_group(&mut self, name: &str, gid: Option<&str>)
open_group starts, but the PDF backend does
not set the clip regions again for the parts.Source§fn close_part_group(&mut self, name: &str)
fn close_part_group(&mut self, name: &str)
Source§fn start_rasterizing(&mut self)
fn start_rasterizing(&mut self)
stop_rasterizing (matplotlib’s
start_rasterizing); only vector output distinguishes the modes.Source§fn stop_rasterizing(&mut self)
fn stop_rasterizing(&mut self)
start_rasterizing in the output as an
image and resumes drawing directly.Source§fn raster_dpi(&self) -> Option<f64>
fn raster_dpi(&self) -> Option<f64>
None otherwise. Artists drawn meanwhile
compute their geometry at it, in canvas pixels (matplotlib changes
the figure’s dpi in start_rasterizing).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.Source§fn option_scale_image(&self) -> bool
fn option_scale_image(&self) -> bool
true, draw_image accepts arbitrary
affine transforms (vector backends); otherwise images arrive
pre-resampled at display resolution.Source§fn image_magnification(&self) -> f64
fn image_magnification(&self) -> f64
get_image_magnification): vector backends rasterize
images at their own resolution rather than at 72 dpi.