Struct freya_engine::prelude::svg::Canvas
pub struct Canvas { /* private fields */ }
Implementations§
Methods from Deref<Target = Canvas>§
pub fn annotate_rect_with_url( &self, rect: impl AsRef<Rect>, data: &RCHandle<SkData>, ) -> &Canvas
pub fn annotate_named_destination( &self, point: impl Into<Point>, data: &RCHandle<SkData>, ) -> &Canvas
pub fn annotate_link_to_destination( &self, rect: impl AsRef<Rect>, data: &RCHandle<SkData>, ) -> &Canvas
pub fn image_info(&self) -> Handle<SkImageInfo>
pub fn image_info(&self) -> Handle<SkImageInfo>
Returns ImageInfo
for Canvas
. If Canvas
is not associated with raster surface or
GPU surface, returned crate::ColorType
is set to crate::ColorType::Unknown
Returns dimensions and crate::ColorType
of Canvas
pub fn props(&self) -> Option<SurfaceProps>
pub fn props(&self) -> Option<SurfaceProps>
Copies [SurfaceProps
], if Canvas
is associated with raster surface or GPU surface, and
returns true
. Otherwise, returns false
and leave props unchanged.
props
storage for writable [SurfaceProps
] Returnstrue
if [SurfaceProps
] was copied
pub fn base_props(&self) -> SurfaceProps
pub fn base_props(&self) -> SurfaceProps
Returns the [SurfaceProps
] associated with the canvas (i.e., at the base of the layer
stack).
pub fn top_props(&self) -> SurfaceProps
pub fn top_props(&self) -> SurfaceProps
Returns the [SurfaceProps
] associated with the canvas that are currently active (i.e., at
the top of the layer stack). This can differ from Self::base_props
depending on the flags
passed to saveLayer (see [SaveLayerFlags
]).
pub fn base_layer_size(&self) -> ISize
pub fn base_layer_size(&self) -> ISize
Gets the size of the base or root layer in global canvas coordinates. The origin of the base layer is always (0,0). The area available for drawing may be smaller (due to clipping or saveLayer).
Returns integral size of base layer
pub fn new_surface(
&self,
info: &Handle<SkImageInfo>,
props: Option<&SurfaceProps>,
) -> Option<RCHandle<SkSurface>>
pub fn new_surface( &self, info: &Handle<SkImageInfo>, props: Option<&SurfaceProps>, ) -> Option<RCHandle<SkSurface>>
Creates Surface
matching info and props, and associates it with Canvas
.
Returns None
if no match found.
If props is None
, matches [SurfaceProps
] in Canvas
. If props is None
and
Canvas
does not have [SurfaceProps
], creates Surface
with default
[SurfaceProps
].
info
width, height,crate::ColorType
, [crate::AlphaType
], andcrate::ColorSpace
props
[SurfaceProps
] to match; may beNone
to matchCanvas
ReturnsSurface
matching info and props, orNone
if no match is available
pub fn recording_context(&self) -> Option<RCHandle<GrRecordingContext>>
pub fn recording_context(&self) -> Option<RCHandle<GrRecordingContext>>
Returns Ganesh context of the GPU surface associated with Canvas
.
Returns GPU context, if available; None
otherwise
pub fn direct_context(&self) -> Option<RCHandle<GrDirectContext>>
pub fn direct_context(&self) -> Option<RCHandle<GrDirectContext>>
Returns the gpu::DirectContext
.
This is a rust-skia helper for that makes it simpler to call [Image::encode
].
pub unsafe fn surface(&self) -> Option<RCHandle<SkSurface>>
pub unsafe fn surface(&self) -> Option<RCHandle<SkSurface>>
Sometimes a canvas is owned by a surface. If it is, Self::surface()
will return a bare
pointer to that surface, else this will return None
.
§Safety
This function is unsafe because it is not clear how exactly the lifetime of the canvas
relates to surface returned.
See also [OwnedCanvas
], [RCHandle<SkSurface>::canvas()
].
pub fn access_top_layer_pixels(&self) -> Option<TopLayerPixels<'_>>
pub fn access_top_layer_pixels(&self) -> Option<TopLayerPixels<'_>>
Returns the pixel base address, ImageInfo
, row_bytes
, and origin if the pixels
can be read directly.
info
storage for writable pixels’ImageInfo
row_bytes
storage for writable pixels’ row bytesorigin
storage forCanvas
top layer origin, its top-left corner Returns address of pixels, orNone
if inaccessible
example: https://fiddle.skia.org/c/@Canvas_accessTopLayerPixels_a example: https://fiddle.skia.org/c/@Canvas_accessTopLayerPixels_b
pub fn peek_pixels(&self) -> Option<Pixmap<'_>>
pub fn peek_pixels(&self) -> Option<Pixmap<'_>>
Returns true
if Canvas
has direct access to its pixels.
Pixels are readable when Device
is raster. Pixels are not readable when Canvas
is
returned from GPU surface, returned by [crate::Document::begin_page()
], returned by
[Handle<SkPictureRecorder>::begin_recording()
], or Canvas
is the base of a utility
class like DebugCanvas
.
pixmap is valid only while Canvas
is in scope and unchanged. Any Canvas
or
Surface
call may invalidate the pixmap values.
Returns [Pixmap
] if Canvas
has direct access to pixels
pub fn read_pixels(
&self,
dst_info: &Handle<SkImageInfo>,
dst_pixels: &mut [u8],
dst_row_bytes: usize,
src_point: impl Into<IPoint>,
) -> bool
pub fn read_pixels( &self, dst_info: &Handle<SkImageInfo>, dst_pixels: &mut [u8], dst_row_bytes: usize, src_point: impl Into<IPoint>, ) -> bool
Copies Rect
of pixels from Canvas
into dst_pixels
. Matrix
and clip are
ignored.
Source Rect
corners are src_point
and (image_info().width(), image_info().height())
.
Destination Rect
corners are (0, 0)
and (dst_Info.width(), dst_info.height())
.
Copies each readable pixel intersecting both rectangles, without scaling,
converting to dst_info.color_type()
and dst_info.alpha_type()
if required.
Pixels are readable when Device
is raster, or backed by a GPU.
Pixels are not readable when Canvas
is returned by [crate::Document::begin_page()
],
returned by [Handle<SkPictureRecorder>::begin_recording()
], or Canvas
is the base of a
utility class like DebugCanvas
.
The destination pixel storage must be allocated by the caller.
Pixel values are converted only if crate::ColorType
and [crate::AlphaType
]
do not match. Only pixels within both source and destination rectangles
are copied. dst_pixels
contents outside Rect
intersection are unchanged.
Pass negative values for src_point.x
or src_point.y
to offset pixels across or down
destination.
Does not copy, and returns false
if:
-
Source and destination rectangles do not intersect.
-
Canvas
pixels could not be converted todst_info.color_type()
ordst_info.alpha_type()
. -
Canvas
pixels are not readable; for instance,Canvas
is document-based. -
dst_row_bytes
is too small to contain one row of pixels. -
dst_info
width, height,crate::ColorType
, and [crate::AlphaType
] of dstPixels -
dst_pixels
storage for pixels;dst_info.height()
timesdst_row_bytes
, or larger -
dst_row_bytes
size of one destination row;dst_info.width()
times pixel size, or larger -
src_point
offset into readable pixels; may be negative Returnstrue
if pixels were copied
pub fn read_pixels_to_pixmap(
&self,
pixmap: &mut Pixmap<'_>,
src: impl Into<IPoint>,
) -> bool
pub fn read_pixels_to_pixmap( &self, pixmap: &mut Pixmap<'_>, src: impl Into<IPoint>, ) -> bool
Copies Rect
of pixels from Canvas
into pixmap. Matrix
and clip are
ignored.
Source Rect
corners are (src.x, src.y)
and (image_info().width(), image_info().height())
.
Destination Rect
corners are (0, 0)
and (pixmap.width(), pixmap.height())
.
Copies each readable pixel intersecting both rectangles, without scaling,
converting to pixmap.color_type()
and pixmap.alpha_type()
if required.
Pixels are readable when Device
is raster, or backed by a GPU. Pixels are not readable
when Canvas
is returned by [crate::Document::begin_page()
], returned by
[Handle<SkPictureRecorder>::begin_recording()
], or Canvas
is the base of a utility
class like DebugCanvas
.
Caller must allocate pixel storage in pixmap if needed.
Pixel values are converted only if crate::ColorType
and [crate::AlphaType
] do not
match. Only pixels within both source and destination Rect
are copied. pixmap pixels
contents outside Rect
intersection are unchanged.
Pass negative values for src.x
or src.y
to offset pixels across or down pixmap.
Does not copy, and returns false
if:
-
Source and destination rectangles do not intersect.
-
Canvas
pixels could not be converted topixmap.color_type()
orpixmap.alpha_type()
. -
Canvas
pixels are not readable; for instance,Canvas
is document-based. -
[
Pixmap
] pixels could not be allocated. -
pixmap.row_bytes()
is too small to contain one row of pixels. -
pixmap
storage for pixels copied fromCanvas
-
src
offset into readable pixels ; may be negative Returnstrue
if pixels were copied
pub fn read_pixels_to_bitmap(
&self,
bitmap: &mut Handle<SkBitmap>,
src: impl Into<IPoint>,
) -> bool
pub fn read_pixels_to_bitmap( &self, bitmap: &mut Handle<SkBitmap>, src: impl Into<IPoint>, ) -> bool
Copies Rect
of pixels from Canvas
into bitmap. Matrix
and clip are
ignored.
Source Rect
corners are (src.x, src.y)
and (image_info().width(), image_info().height())
.
Destination Rect
corners are (0, 0)
and (bitmap.width(), bitmap.height())
.
Copies each readable pixel intersecting both rectangles, without scaling,
converting to bitmap.color_type()
and bitmap.alpha_type()
if required.
Pixels are readable when Device
is raster, or backed by a GPU. Pixels are not readable
when Canvas
is returned by [crate::Document::begin_page()
], returned by
[Handle<SkPictureRecorder>::begin_recording()
], or Canvas
is the base of a utility
class like DebugCanvas.
Caller must allocate pixel storage in bitmap if needed.
Bitmap
values are converted only if crate::ColorType
and [crate::AlphaType
]
do not match. Only pixels within both source and destination rectangles
are copied. Bitmap
pixels outside Rect
intersection are unchanged.
Pass negative values for srcX or srcY to offset pixels across or down bitmap.
Does not copy, and returns false
if:
-
Source and destination rectangles do not intersect.
-
Canvas
pixels could not be converted tobitmap.color_type()
orbitmap.alpha_type()
. -
Canvas
pixels are not readable; for instance,Canvas
is document-based. -
bitmap pixels could not be allocated.
-
bitmap.row_bytes()
is too small to contain one row of pixels. -
bitmap
storage for pixels copied fromCanvas
-
src
offset into readable pixels; may be negative Returnstrue
if pixels were copied
pub fn write_pixels(
&self,
info: &Handle<SkImageInfo>,
pixels: &[u8],
row_bytes: usize,
offset: impl Into<IPoint>,
) -> bool
pub fn write_pixels( &self, info: &Handle<SkImageInfo>, pixels: &[u8], row_bytes: usize, offset: impl Into<IPoint>, ) -> bool
Copies Rect
from pixels to Canvas
. Matrix
and clip are ignored.
Source Rect
corners are (0, 0)
and (info.width(), info.height())
.
Destination Rect
corners are (offset.x, offset.y)
and
(image_info().width(), image_info().height())
.
Copies each readable pixel intersecting both rectangles, without scaling,
converting to image_info().color_type()
and image_info().alpha_type()
if required.
Pixels are writable when Device
is raster, or backed by a GPU.
Pixels are not writable when Canvas
is returned by [crate::Document::begin_page()
],
returned by [Handle<SkPictureRecorder>::begin_recording()
], or Canvas
is the base of a
utility class like DebugCanvas
.
Pixel values are converted only if crate::ColorType
and [crate::AlphaType
]
do not match. Only pixels within both source and destination rectangles
are copied. Canvas
pixels outside Rect
intersection are unchanged.
Pass negative values for offset.x
or offset.y
to offset pixels to the left or
above Canvas
pixels.
Does not copy, and returns false
if:
-
Source and destination rectangles do not intersect.
-
pixels could not be converted to
Canvas
image_info().color_type()
orimage_info().alpha_type()
. -
Canvas
pixels are not writable; for instance,Canvas
is document-based. -
row_bytes
is too small to contain one row of pixels. -
info
width, height,crate::ColorType
, and [crate::AlphaType
] of pixels -
pixels
pixels to copy, of sizeinfo.height()
timesrow_bytes
, or larger -
row_bytes
size of one row of pixels; info.width() times pixel size, or larger -
offset
offset intoCanvas
writable pixels; may be negative Returnstrue
if pixels were written toCanvas
pub fn write_pixels_from_bitmap(
&self,
bitmap: &Handle<SkBitmap>,
offset: impl Into<IPoint>,
) -> bool
pub fn write_pixels_from_bitmap( &self, bitmap: &Handle<SkBitmap>, offset: impl Into<IPoint>, ) -> bool
Copies Rect
from pixels to Canvas
. Matrix
and clip are ignored.
Source Rect
corners are (0, 0)
and (bitmap.width(), bitmap.height())
.
Destination Rect
corners are (offset.x, offset.y)
and
(image_info().width(), image_info().height())
.
Copies each readable pixel intersecting both rectangles, without scaling,
converting to image_info().color_type()
and image_info().alpha_type()
if required.
Pixels are writable when Device
is raster, or backed by a GPU. Pixels are not writable
when Canvas
is returned by [crate::Document::begin_page()
], returned by
[Handle<SkPictureRecorder>::begin_recording()
], or Canvas
is the base of a utility
class like DebugCanvas
.
Pixel values are converted only if crate::ColorType
and [crate::AlphaType
]
do not match. Only pixels within both source and destination rectangles
are copied. Canvas
pixels outside Rect
intersection are unchanged.
Pass negative values for offset
to offset pixels to the left or
above Canvas
pixels.
Does not copy, and returns false
if:
-
Source and destination rectangles do not intersect.
-
bitmap does not have allocated pixels.
-
bitmap pixels could not be converted to
Canvas
image_info().color_type()
orimage_info().alpha_type()
. -
Canvas
pixels are not writable; for instance,Canvas
is document based. -
bitmap pixels are inaccessible; for instance, bitmap wraps a texture.
-
bitmap
contains pixels copied toCanvas
-
offset
offset intoCanvas
writable pixels; may be negative Returnstrue
if pixels were written toCanvas
example: https://fiddle.skia.org/c/@Canvas_writePixels_2 example: https://fiddle.skia.org/c/@State_Stack_a example: https://fiddle.skia.org/c/@State_Stack_b
pub fn save(&self) -> usize
pub fn save(&self) -> usize
Saves Matrix
and clip.
Calling Self::restore()
discards changes to Matrix
and clip,
restoring the Matrix
and clip to their state when Self::save()
was called.
Matrix
may be changed by Self::translate()
, Self::scale()
, Self::rotate()
,
Self::skew()
, Self::concat()
, Self::set_matrix()
, and Self::reset_matrix()
.
Clip may be changed by Self::clip_rect()
, Self::clip_rrect()
, Self::clip_path()
,
Self::clip_region()
.
Saved Canvas
state is put on a stack; multiple calls to Self::save()
should be
balance by an equal number of calls to Self::restore()
.
Call Self::restore_to_count()
with result to restore this and subsequent saves.
Returns depth of saved stack
pub fn save_layer_alpha_f(
&self,
bounds: impl Into<Option<Rect>>,
alpha: f32,
) -> usize
pub fn save_layer_alpha_f( &self, bounds: impl Into<Option<Rect>>, alpha: f32, ) -> usize
Saves Matrix
and clip, and allocates Surface
for subsequent drawing.
Calling Self::restore()
discards changes to Matrix
and clip, and blends layer with
alpha opacity onto prior layer.
Matrix
may be changed by Self::translate()
, Self::scale()
, Self::rotate()
,
Self::skew()
, Self::concat()
, Self::set_matrix()
, and Self::reset_matrix()
.
Clip may be changed by Self::clip_rect()
, Self::clip_rrect()
, Self::clip_path()
,
Self::clip_region()
.
Rect
bounds suggests but does not define layer size. To clip drawing to a specific
rectangle, use Self::clip_rect()
.
alpha of zero is fully transparent, 1.0 is fully opaque.
Call Self::restore_to_count()
with result to restore this and subsequent saves.
bounds
hint to limit the size of layer; may beNone
alpha
opacity of layer Returns depth of saved stack
pub fn save_layer_alpha(
&self,
bounds: impl Into<Option<Rect>>,
alpha: u32,
) -> usize
pub fn save_layer_alpha( &self, bounds: impl Into<Option<Rect>>, alpha: u32, ) -> usize
Helper that accepts an int between 0 and 255, and divides it by 255.0
pub fn save_layer(&self, layer_rec: &SaveLayerRec<'_>) -> usize
pub fn save_layer(&self, layer_rec: &SaveLayerRec<'_>) -> usize
Saves Matrix
and clip, and allocates Surface
for subsequent drawing.
Calling Self::restore()
discards changes to Matrix
and clip,
and blends Surface
with alpha opacity onto the prior layer.
Matrix
may be changed by Self::translate()
, Self::scale()
, Self::rotate()
,
Self::skew()
, Self::concat()
, Self::set_matrix()
, and Self::reset_matrix()
.
Clip may be changed by Self::clip_rect()
, Self::clip_rrect()
, Self::clip_path()
,
Self::clip_region()
.
[SaveLayerRec
] contains the state used to create the layer.
Call Self::restore_to_count()
with result to restore this and subsequent saves.
layer_rec
layer state Returns depth of save state stack before this call was made.
pub fn restore(&self) -> &Canvas
pub fn restore(&self) -> &Canvas
Removes changes to Matrix
and clip since Canvas
state was
last saved. The state is removed from the stack.
Does nothing if the stack is empty.
example: https://fiddle.skia.org/c/@AutoCanvasRestore_restore
pub fn save_count(&self) -> usize
pub fn save_count(&self) -> usize
Returns the number of saved states, each containing: Matrix
and clip.
Equals the number of Self::save()
calls less the number of Self::restore()
calls
plus one.
The save count of a new canvas is one.
Returns depth of save state stack
pub fn restore_to_count(&self, save_count: usize) -> &Canvas
pub fn restore_to_count(&self, save_count: usize) -> &Canvas
Restores state to Matrix
and clip values when Self::save()
, Self::save_layer()
,
or Self::save_layer_alpha()
returned save_count
.
Does nothing if save_count
is greater than state stack count.
Restores state to initial values if save_count
is less than or equal to one.
saveCount
depth of state stack to restore
pub fn translate(&self, d: impl Into<Point>) -> &Canvas
pub fn translate(&self, d: impl Into<Point>) -> &Canvas
pub fn scale(&self, _: (f32, f32)) -> &Canvas
pub fn scale(&self, _: (f32, f32)) -> &Canvas
pub fn rotate(&self, degrees: f32, p: Option<Point>) -> &Canvas
pub fn rotate(&self, degrees: f32, p: Option<Point>) -> &Canvas
Rotates Matrix
by degrees about a point at (p.x, p.y)
. Positive degrees rotates
clockwise.
Mathematically, constructs a rotation matrix; premultiplies the rotation matrix by a
translation matrix; then replaces Matrix
with the resulting matrix premultiplied with
Matrix
.
This has the effect of rotating the drawing about a given point before transforming the
result with Matrix
.
degrees
amount to rotate, in degreesp
the point to rotate about
pub fn skew(&self, _: (f32, f32)) -> &Canvas
pub fn skew(&self, _: (f32, f32)) -> &Canvas
Skews Matrix
by sx
on the x-axis and sy
on the y-axis. A positive value of sx
skews the drawing right as y-axis values increase; a positive value of sy
skews the
drawing down as x-axis values increase.
Mathematically, replaces Matrix
with a skew matrix premultiplied with Matrix
.
This has the effect of skewing the drawing by (sx, sy)
before transforming the result with
Matrix
.
sx
amount to skew on x-axissy
amount to skew on y-axis
pub fn concat(&self, matrix: &Matrix) -> &Canvas
pub fn concat(&self, matrix: &Matrix) -> &Canvas
pub fn concat_44(&self, m: &M44) -> &Canvas
pub fn set_matrix(&self, matrix: &M44) -> &Canvas
pub fn set_matrix(&self, matrix: &M44) -> &Canvas
Replaces Matrix
with matrix
.
Unlike Self::concat()
, any prior matrix state is overwritten.
matrix
matrix to copy, replacing existingMatrix
pub fn reset_matrix(&self) -> &Canvas
pub fn reset_matrix(&self) -> &Canvas
Sets Matrix
to the identity matrix.
Any prior matrix state is overwritten.
pub fn clip_rect(
&self,
rect: impl AsRef<Rect>,
op: impl Into<Option<SkClipOp>>,
do_anti_alias: impl Into<Option<bool>>,
) -> &Canvas
pub fn clip_rect( &self, rect: impl AsRef<Rect>, op: impl Into<Option<SkClipOp>>, do_anti_alias: impl Into<Option<bool>>, ) -> &Canvas
pub fn clip_irect( &self, irect: impl AsRef<IRect>, op: impl Into<Option<SkClipOp>>, ) -> &Canvas
pub fn clip_rrect(
&self,
rrect: impl AsRef<RRect>,
op: impl Into<Option<SkClipOp>>,
do_anti_alias: impl Into<Option<bool>>,
) -> &Canvas
pub fn clip_rrect( &self, rrect: impl AsRef<RRect>, op: impl Into<Option<SkClipOp>>, do_anti_alias: impl Into<Option<bool>>, ) -> &Canvas
pub fn clip_path(
&self,
path: &Handle<SkPath>,
op: impl Into<Option<SkClipOp>>,
do_anti_alias: impl Into<Option<bool>>,
) -> &Canvas
pub fn clip_path( &self, path: &Handle<SkPath>, op: impl Into<Option<SkClipOp>>, do_anti_alias: impl Into<Option<bool>>, ) -> &Canvas
Replaces clip with the intersection or difference of clip and path
,
with an aliased or anti-aliased clip edge. crate::path::FillType
determines if path
describes the area inside or outside its contours; and if path contour overlaps
itself or another path contour, whether the overlaps form part of the area.
path
is transformed by Matrix
before it is combined with clip.
pub fn clip_shader( &self, shader: impl Into<RCHandle<SkShader>>, op: impl Into<Option<SkClipOp>>, ) -> &Canvas
pub fn clip_region(
&self,
device_rgn: &Handle<SkRegion>,
op: impl Into<Option<SkClipOp>>,
) -> &Canvas
pub fn clip_region( &self, device_rgn: &Handle<SkRegion>, op: impl Into<Option<SkClipOp>>, ) -> &Canvas
pub fn local_clip_bounds(&self) -> Option<Rect>
pub fn local_clip_bounds(&self) -> Option<Rect>
Returns bounds of clip, transformed by inverse of Matrix
. If clip is empty,
return Rect::new_empty()
, where all Rect
sides equal zero.
Rect
returned is outset by one to account for partial pixel coverage if clip
is anti-aliased.
Returns bounds of clip in local coordinates
example: https://fiddle.skia.org/c/@Canvas_getLocalClipBounds
pub fn device_clip_bounds(&self) -> Option<IRect>
pub fn device_clip_bounds(&self) -> Option<IRect>
Returns IRect
bounds of clip, unaffected by Matrix
. If clip is empty,
return Rect::new_empty()
, where all Rect
sides equal zero.
Unlike Self::local_clip_bounds()
, returned IRect
is not outset.
Returns bounds of clip in Device
coordinates
example: https://fiddle.skia.org/c/@Canvas_getDeviceClipBounds
pub fn draw_color(
&self,
color: impl Into<Color4f>,
mode: impl Into<Option<SkBlendMode>>,
) -> &Canvas
pub fn draw_color( &self, color: impl Into<Color4f>, mode: impl Into<Option<SkBlendMode>>, ) -> &Canvas
Fills clip with color color
.
mode
determines how ARGB is combined with destination.
color
[Color4f
] representing unpremultiplied color.mode
[BlendMode
] used to combine source color and destination
pub fn clear(&self, color: impl Into<Color4f>) -> &Canvas
pub fn clear(&self, color: impl Into<Color4f>) -> &Canvas
Fills clip with color color
using [BlendMode::Src
].
This has the effect of replacing all pixels contained by clip with color
.
color
[Color4f
] representing unpremultiplied color.
pub fn discard(&self) -> &Canvas
pub fn discard(&self) -> &Canvas
Makes Canvas
contents undefined. Subsequent calls that read Canvas
pixels,
such as drawing with [BlendMode
], return undefined results. discard()
does
not change clip or Matrix
.
discard()
may do nothing, depending on the implementation of Surface
or Device
that created Canvas
.
discard()
allows optimized performance on subsequent draws by removing
cached data associated with Surface
or Device
.
It is not necessary to call discard()
once done with Canvas
;
any cached data is deleted when owning Surface
or Device
is deleted.
pub fn draw_paint(&self, paint: &Handle<SkPaint>) -> &Canvas
pub fn draw_paint(&self, paint: &Handle<SkPaint>) -> &Canvas
Fills clip with Paint
paint
. Paint
components, Shader
,
[crate::ColorFilter
], [ImageFilter
], and [BlendMode
] affect drawing;
crate::MaskFilter
and [crate::PathEffect
] in paint
are ignored.
paint
graphics state used to fillCanvas
pub fn draw_points(
&self,
mode: SkCanvas_PointMode,
pts: &[Point],
paint: &Handle<SkPaint>,
) -> &Canvas
pub fn draw_points( &self, mode: SkCanvas_PointMode, pts: &[Point], paint: &Handle<SkPaint>, ) -> &Canvas
Draws pts
using clip, Matrix
and Paint
pain
.
if the number of points is less than one, has no effect.
mode
may be one of: [PointMode::Points
], [PointMode::Lines
], or [PointMode::Polygon
]
If mode
is [PointMode::Points
], the shape of point drawn depends on paint
[crate::paint::Cap
]. If paint
is set to [crate::paint::Cap::Round
], each point draws a
circle of diameter Paint
stroke width. If paint
is set to [crate::paint::Cap::Square
]
or [crate::paint::Cap::Butt
], each point draws a square of width and height
Paint
stroke width.
If mode
is [PointMode::Lines
], each pair of points draws a line segment.
One line is drawn for every two points; each point is used once. If count is odd,
the final point is ignored.
If mode is [PointMode::Polygon
], each adjacent pair of points draws a line segment.
count minus one lines are drawn; the first and last point are used once.
Each line segment respects paint
[crate::paint::Cap
] and Paint
stroke width.
crate::paint::Style
is ignored, as if were set to crate::paint::Style::Stroke
.
Always draws each element one at a time; is not affected by
[crate::paint::Join
], and unlike Self::draw_path()
, does not create a mask from all points
and lines before drawing.
mode
whether pts draws points or linespts
array of points to drawpaint
stroke, blend, color, and so on, used to draw
pub fn draw_point(
&self,
p: impl Into<Point>,
paint: &Handle<SkPaint>,
) -> &Canvas
pub fn draw_point( &self, p: impl Into<Point>, paint: &Handle<SkPaint>, ) -> &Canvas
Draws point p
using clip, Matrix
and Paint
paint.
The shape of point drawn depends on paint
[crate::paint::Cap
].
If paint
is set to [crate::paint::Cap::Round
], draw a circle of diameter Paint
stroke width. If paint
is set to [crate::paint::Cap::Square
] or
[crate::paint::Cap::Butt
], draw a square of width and height Paint
stroke width.
crate::paint::Style
is ignored, as if were set to crate::paint::Style::Stroke
.
p
top-left edge of circle or squarepaint
stroke, blend, color, and so on, used to draw
pub fn draw_line(
&self,
p1: impl Into<Point>,
p2: impl Into<Point>,
paint: &Handle<SkPaint>,
) -> &Canvas
pub fn draw_line( &self, p1: impl Into<Point>, p2: impl Into<Point>, paint: &Handle<SkPaint>, ) -> &Canvas
Draws line segment from p1
to p2
using clip, Matrix
, and Paint
paint.
In paint: Paint
stroke width describes the line thickness;
[crate::paint::Cap
] draws the end rounded or square;
crate::paint::Style
is ignored, as if were set to crate::paint::Style::Stroke
.
p1
start of line segmentp2
end of line segmentpaint
stroke, blend, color, and so on, used to draw
pub fn draw_rect(
&self,
rect: impl AsRef<Rect>,
paint: &Handle<SkPaint>,
) -> &Canvas
pub fn draw_rect( &self, rect: impl AsRef<Rect>, paint: &Handle<SkPaint>, ) -> &Canvas
Draws Rect
rect using clip, Matrix
, and Paint
paint
.
In paint: crate::paint::Style
determines if rectangle is stroked or filled;
if stroked, Paint
stroke width describes the line thickness, and
[crate::paint::Join
] draws the corners rounded or square.
rect
rectangle to drawpaint
stroke or fill, blend, color, and so on, used to draw
pub fn draw_irect(
&self,
rect: impl AsRef<IRect>,
paint: &Handle<SkPaint>,
) -> &Canvas
pub fn draw_irect( &self, rect: impl AsRef<IRect>, paint: &Handle<SkPaint>, ) -> &Canvas
Draws IRect
rect using clip, Matrix
, and Paint
paint
.
In paint
: crate::paint::Style
determines if rectangle is stroked or filled;
if stroked, Paint
stroke width describes the line thickness, and
[crate::paint::Join
] draws the corners rounded or square.
rect
rectangle to drawpaint
stroke or fill, blend, color, and so on, used to draw
pub fn draw_region(
&self,
region: &Handle<SkRegion>,
paint: &Handle<SkPaint>,
) -> &Canvas
pub fn draw_region( &self, region: &Handle<SkRegion>, paint: &Handle<SkPaint>, ) -> &Canvas
Draws [Region
] region using clip, Matrix
, and Paint
paint
.
In paint
: crate::paint::Style
determines if rectangle is stroked or filled;
if stroked, Paint
stroke width describes the line thickness, and
[crate::paint::Join
] draws the corners rounded or square.
region
region to drawpaint
Paint
stroke or fill, blend, color, and so on, used to draw
pub fn draw_oval(
&self,
oval: impl AsRef<Rect>,
paint: &Handle<SkPaint>,
) -> &Canvas
pub fn draw_oval( &self, oval: impl AsRef<Rect>, paint: &Handle<SkPaint>, ) -> &Canvas
Draws oval oval using clip, Matrix
, and Paint
.
In paint
: crate::paint::Style
determines if oval is stroked or filled;
if stroked, Paint
stroke width describes the line thickness.
pub fn draw_rrect(
&self,
rrect: impl AsRef<RRect>,
paint: &Handle<SkPaint>,
) -> &Canvas
pub fn draw_rrect( &self, rrect: impl AsRef<RRect>, paint: &Handle<SkPaint>, ) -> &Canvas
Draws RRect
rrect using clip, Matrix
, and Paint
paint
.
In paint
: crate::paint::Style
determines if rrect is stroked or filled;
if stroked, Paint
stroke width describes the line thickness.
rrect
may represent a rectangle, circle, oval, uniformly rounded rectangle, or
may have any combination of positive non-square radii for the four corners.
pub fn draw_drrect(
&self,
outer: impl AsRef<RRect>,
inner: impl AsRef<RRect>,
paint: &Handle<SkPaint>,
) -> &Canvas
pub fn draw_drrect( &self, outer: impl AsRef<RRect>, inner: impl AsRef<RRect>, paint: &Handle<SkPaint>, ) -> &Canvas
Draws RRect
outer and inner
using clip, Matrix
, and Paint
paint
.
outer must contain inner or the drawing is undefined.
In paint: crate::paint::Style
determines if RRect
is stroked or filled;
if stroked, Paint
stroke width describes the line thickness.
If stroked and RRect
corner has zero length radii, [crate::paint::Join
] can
draw corners rounded or square.
GPU-backed platforms optimize drawing when both outer and inner are
concave and outer contains inner. These platforms may not be able to draw
Path
built with identical data as fast.
outer
RRect
outer bounds to drawinner
RRect
inner bounds to drawpaint
Paint
stroke or fill, blend, color, and so on, used to draw
example: https://fiddle.skia.org/c/@Canvas_drawDRRect_a example: https://fiddle.skia.org/c/@Canvas_drawDRRect_b
pub fn draw_circle(
&self,
center: impl Into<Point>,
radius: f32,
paint: &Handle<SkPaint>,
) -> &Canvas
pub fn draw_circle( &self, center: impl Into<Point>, radius: f32, paint: &Handle<SkPaint>, ) -> &Canvas
Draws circle at center with radius using clip, Matrix
, and Paint
paint
.
If radius is zero or less, nothing is drawn.
In paint
: crate::paint::Style
determines if circle is stroked or filled;
if stroked, Paint
stroke width describes the line thickness.
center
circle centerradius
half the diameter of circlepaint
Paint
stroke or fill, blend, color, and so on, used to draw
pub fn draw_arc(
&self,
oval: impl AsRef<Rect>,
start_angle: f32,
sweep_angle: f32,
use_center: bool,
paint: &Handle<SkPaint>,
) -> &Canvas
pub fn draw_arc( &self, oval: impl AsRef<Rect>, start_angle: f32, sweep_angle: f32, use_center: bool, paint: &Handle<SkPaint>, ) -> &Canvas
Draws arc using clip, Matrix
, and Paint
paint.
Arc is part of oval bounded by oval, sweeping from start_angle
to start_angle
plus
sweep_angle
. start_angle
and sweep_angle
are in degrees.
start_angle
of zero places start point at the right middle edge of oval.
A positive sweep_angle
places arc end point clockwise from start point;
a negative sweep_angle
places arc end point counterclockwise from start point.
sweep_angle
may exceed 360 degrees, a full circle.
If use_center
is true
, draw a wedge that includes lines from oval
center to arc end points. If use_center
is false
, draw arc between end points.
If Rect
oval is empty or sweep_angle
is zero, nothing is drawn.
pub fn draw_arc_2(&self, arc: &Arc, paint: &Handle<SkPaint>) -> &Canvas
pub fn draw_arc_2(&self, arc: &Arc, paint: &Handle<SkPaint>) -> &Canvas
Draws arc using clip, Matrix
, and Paint
paint.
Arc is part of oval bounded by oval, sweeping from start_angle
to start_angle
plus
sweep_angle
. start_angle
and sweep_angle
are in degrees.
start_angle
of zero places start point at the right middle edge of oval.
A positive sweep_angle
places arc end point clockwise from start point;
a negative sweep_angle
places arc end point counterclockwise from start point.
sweep_angle
may exceed 360 degrees, a full circle.
If use_center
is true
, draw a wedge that includes lines from oval
center to arc end points. If use_center
is false
, draw arc between end points.
If Rect
oval is empty or sweep_angle
is zero, nothing is drawn.
arc
[Arc
] SkArc specifying oval, startAngle, sweepAngle, and arc-vs-wedgepaint
Paint
stroke or fill, blend, color, and so on, used to draw
pub fn draw_round_rect(
&self,
rect: impl AsRef<Rect>,
rx: f32,
ry: f32,
paint: &Handle<SkPaint>,
) -> &Canvas
pub fn draw_round_rect( &self, rect: impl AsRef<Rect>, rx: f32, ry: f32, paint: &Handle<SkPaint>, ) -> &Canvas
Draws RRect
bounded by Rect
rect, with corner radii (rx, ry)
using clip,
Matrix
, and Paint
paint
.
In paint
: crate::paint::Style
determines if RRect
is stroked or filled;
if stroked, Paint
stroke width describes the line thickness.
If rx
or ry
are less than zero, they are treated as if they are zero.
If rx
plus ry
exceeds rect width or rect height, radii are scaled down to fit.
If rx
and ry
are zero, RRect
is drawn as Rect
and if stroked is affected by
[crate::paint::Join
].
pub fn draw_path(
&self,
path: &Handle<SkPath>,
paint: &Handle<SkPaint>,
) -> &Canvas
pub fn draw_path( &self, path: &Handle<SkPath>, paint: &Handle<SkPaint>, ) -> &Canvas
Draws Path
path using clip, Matrix
, and Paint
paint
.
Path
contains an array of path contour, each of which may be open or closed.
In paint
: crate::paint::Style
determines if RRect
is stroked or filled:
if filled, crate::path::FillType
determines whether path contour describes inside or
outside of fill; if stroked, Paint
stroke width describes the line thickness,
[crate::paint::Cap
] describes line ends, and [crate::paint::Join
] describes how
corners are drawn.
path
Path
to drawpaint
stroke, blend, color, and so on, used to draw
pub fn draw_image( &self, image: impl AsRef<RCHandle<SkImage>>, left_top: impl Into<Point>, paint: Option<&Handle<SkPaint>>, ) -> &Canvas
pub fn draw_image_rect( &self, image: impl AsRef<RCHandle<SkImage>>, src: Option<(&Rect, SkCanvas_SrcRectConstraint)>, dst: impl AsRef<Rect>, paint: &Handle<SkPaint>, ) -> &Canvas
pub fn draw_image_with_sampling_options( &self, image: impl AsRef<RCHandle<SkImage>>, left_top: impl Into<Point>, sampling: impl Into<SamplingOptions>, paint: Option<&Handle<SkPaint>>, ) -> &Canvas
pub fn draw_image_rect_with_sampling_options( &self, image: impl AsRef<RCHandle<SkImage>>, src: Option<(&Rect, SkCanvas_SrcRectConstraint)>, dst: impl AsRef<Rect>, sampling: impl Into<SamplingOptions>, paint: &Handle<SkPaint>, ) -> &Canvas
pub fn draw_image_nine(
&self,
image: impl AsRef<RCHandle<SkImage>>,
center: impl AsRef<IRect>,
dst: impl AsRef<Rect>,
filter_mode: SkFilterMode,
paint: Option<&Handle<SkPaint>>,
) -> &Canvas
pub fn draw_image_nine( &self, image: impl AsRef<RCHandle<SkImage>>, center: impl AsRef<IRect>, dst: impl AsRef<Rect>, filter_mode: SkFilterMode, paint: Option<&Handle<SkPaint>>, ) -> &Canvas
Draws Image
image
stretched proportionally to fit into Rect
dst
.
IRect
center
divides the image into nine sections: four sides, four corners, and
the center. Corners are unmodified or scaled down proportionately if their sides
are larger than dst
; center and four sides are scaled to fit remaining space, if any.
Additionally transform draw using clip, Matrix
, and optional Paint
paint
.
If Paint
paint
is supplied, apply [crate::ColorFilter
], alpha, [ImageFilter
], and
[BlendMode
]. If image
is crate::ColorType::Alpha8
, apply Shader
.
If paint
contains crate::MaskFilter
, generate mask from image
bounds.
Any crate::MaskFilter
on paint
is ignored as is paint anti-aliasing state.
If generated mask extends beyond image bounds, replicate image edge colors, just
as Shader
made from [RCHandle<Image>::to_shader()
] with crate::TileMode::Clamp
set
replicates the image edge color when it samples outside of its bounds.
pub fn draw_image_lattice(
&self,
image: impl AsRef<RCHandle<SkImage>>,
lattice: &Lattice<'_>,
dst: impl AsRef<Rect>,
filter: SkFilterMode,
paint: Option<&Handle<SkPaint>>,
) -> &Canvas
pub fn draw_image_lattice( &self, image: impl AsRef<RCHandle<SkImage>>, lattice: &Lattice<'_>, dst: impl AsRef<Rect>, filter: SkFilterMode, paint: Option<&Handle<SkPaint>>, ) -> &Canvas
Draws Image
image
stretched proportionally to fit into Rect
dst
.
[lattice::Lattice
] lattice divides image into a rectangular grid.
Each intersection of an even-numbered row and column is fixed;
fixed lattice elements never scale larger than their initial
size and shrink proportionately when all fixed elements exceed the bitmap
dimension. All other grid elements scale to fill the available space, if any.
Additionally transform draw using clip, Matrix
, and optional Paint
paint
.
If Paint
paint
is supplied, apply [crate::ColorFilter
], alpha, [ImageFilter
], and
[BlendMode
]. If image is crate::ColorType::Alpha8
, apply Shader
.
If paint
contains crate::MaskFilter
, generate mask from image bounds.
Any crate::MaskFilter
on paint
is ignored as is paint
anti-aliasing state.
If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
just as Shader
made from SkShader::MakeBitmapShader
with
crate::TileMode::Clamp
set replicates the bitmap edge color when it samples
outside of its bounds.
image
Image
containing pixels, dimensions, and formatlattice
division of bitmap into fixed and variable rectanglesdst
destinationRect
of image to draw tofilter
what technique to use when sampling the imagepaint
Paint
containing [BlendMode
], [crate::ColorFilter
], [ImageFilter
], and so on; orNone
pub fn draw_str(
&self,
str: impl AsRef<str>,
origin: impl Into<Point>,
font: &Handle<SkFont>,
paint: &Handle<SkPaint>,
) -> &Canvas
pub fn draw_str( &self, str: impl AsRef<str>, origin: impl Into<Point>, font: &Handle<SkFont>, paint: &Handle<SkPaint>, ) -> &Canvas
Draws String
, with origin at (origin.x, origin.y)
, using clip, Matrix
, [Font
]
font
, and Paint
paint
.
This function uses the default character-to-glyph mapping from the crate::Typeface
in
font. It does not perform typeface fallback for characters not found in the
crate::Typeface
. It does not perform kerning; glyphs are positioned based on their
default advances.
Text size is affected by Matrix
and [Font
] text size. Default text size is 12 point.
All elements of paint
: [crate::PathEffect
], crate::MaskFilter
, Shader
,
[crate::ColorFilter
], and [ImageFilter
]; apply to text. By default, draws filled black
glyphs.
str
character code points drawn, ending with a char value of zeroorigin
start of string on x,y-axisfont
typeface, text size and so, used to describe the textpaint
blend, color, and so on, used to draw
pub fn draw_glyphs_utf8(
&self,
glyphs: &[u16],
positions: &[Point],
clusters: &[u32],
utf8_text: impl AsRef<str>,
origin: impl Into<Point>,
font: &Handle<SkFont>,
paint: &Handle<SkPaint>,
)
pub fn draw_glyphs_utf8( &self, glyphs: &[u16], positions: &[Point], clusters: &[u32], utf8_text: impl AsRef<str>, origin: impl Into<Point>, font: &Handle<SkFont>, paint: &Handle<SkPaint>, )
Draws glyphs at positions relative to origin
styled with font
and paint
with
supporting utf8 and cluster information.
This function draw glyphs at the given positions relative to the given origin. It does not
perform typeface fallback for glyphs not found in the crate::Typeface
in font.
The drawing obeys the current transform matrix and clipping.
All elements of paint: [crate::PathEffect
], crate::MaskFilter
, Shader
,
[crate::ColorFilter
], and [ImageFilter
]; apply to text. By default, draws filled black
glyphs.
count
number of glyphs to drawglyphs
the array of glyphIDs to drawpositions
where to draw each glyph relative to originclusters
array of size count of cluster informationutf8_text
utf8text supporting information for the glyphsorigin
the origin of all the positionsfont
typeface, text size and so, used to describe the textpaint
blend, color, and so on, used to draw
pub fn draw_glyphs_at<'a>(
&self,
glyphs: &[u16],
positions: impl Into<GlyphPositions<'a>>,
origin: impl Into<Point>,
font: &Handle<SkFont>,
paint: &Handle<SkPaint>,
)
pub fn draw_glyphs_at<'a>( &self, glyphs: &[u16], positions: impl Into<GlyphPositions<'a>>, origin: impl Into<Point>, font: &Handle<SkFont>, paint: &Handle<SkPaint>, )
Draws count
glyphs, at positions relative to origin
styled with font
and paint
.
This function draw glyphs at the given positions relative to the given origin.
It does not perform typeface fallback for glyphs not found in the crate::Typeface
] in
font.
The drawing obeys the current transform matrix and clipping.
All elements of paint: [crate::PathEffect
], crate::MaskFilter
, Shader
,
[crate::ColorFilter
], and [ImageFilter
]; apply to text. By default, draws filled black
glyphs.
count
number of glyphs to drawglyphs
the array of glyphIDs to drawpositions
where to draw each glyph relative to origin, either a&[Point]
or&[RSXform]
sliceorigin
the origin of all the positionsfont
typeface, text size and so, used to describe the textpaint
blend, color, and so on, used to draw
pub fn draw_text_blob(
&self,
blob: impl AsRef<RCHandle<SkTextBlob>>,
origin: impl Into<Point>,
paint: &Handle<SkPaint>,
) -> &Canvas
pub fn draw_text_blob( &self, blob: impl AsRef<RCHandle<SkTextBlob>>, origin: impl Into<Point>, paint: &Handle<SkPaint>, ) -> &Canvas
Draws [TextBlob
] blob at (origin.x, origin.y)
, using clip, Matrix
, and Paint
paint.
blob
contains glyphs, their positions, and paint attributes specific to text:
crate::Typeface
, Paint
text size, Paint
text scale x, Paint
text skew x,
Paint
align, Paint
hinting, anti-alias, Paint
fake bold, Paint
font embedded
bitmaps, Paint
full hinting spacing, LCD text, Paint
linear text, and Paint
subpixel text.
[TextEncoding
] must be set to [TextEncoding::GlyphId
].
Elements of paint
: [crate::PathEffect
], crate::MaskFilter
, Shader
,
[crate::ColorFilter
], and [ImageFilter
]; apply to blob.
blob
glyphs, positions, and their paints’ text size, typeface, and so onorigin
horizontal and vertical offset applied to blobpaint
blend, color, stroking, and so on, used to draw
pub fn draw_picture(
&self,
picture: impl AsRef<RCHandle<SkPicture>>,
matrix: Option<&Matrix>,
paint: Option<&Handle<SkPaint>>,
) -> &Canvas
pub fn draw_picture( &self, picture: impl AsRef<RCHandle<SkPicture>>, matrix: Option<&Matrix>, paint: Option<&Handle<SkPaint>>, ) -> &Canvas
Draws [Picture
] picture, using clip and Matrix
; transforming picture with
Matrix
matrix, if provided; and use Paint
paint
alpha, [crate::ColorFilter
],
[ImageFilter
], and [BlendMode
], if provided.
If paint is not None
, then the picture is always drawn into a temporary layer before
actually landing on the canvas. Note that drawing into a layer can also change its
appearance if there are any non-associative blend modes inside any of the pictures elements.
pub fn draw_vertices(
&self,
vertices: &RCHandle<SkVertices>,
mode: SkBlendMode,
paint: &Handle<SkPaint>,
) -> &Canvas
pub fn draw_vertices( &self, vertices: &RCHandle<SkVertices>, mode: SkBlendMode, paint: &Handle<SkPaint>, ) -> &Canvas
Draws [Vertices
] vertices, a triangle mesh, using clip and Matrix
.
If paint
contains an Shader
and vertices does not contain tex coords, the shader is
mapped using the vertices’ positions.
[BlendMode
] is ignored if [Vertices
] does not have colors. Otherwise, it combines
- the
Shader
ifPaint
contains [Shader
- or the opaque
Paint
color ifPaint
does not containShader
as the src of the blend and the interpolated vertex colors as the dst.
crate::MaskFilter
, [crate::PathEffect
], and antialiasing on Paint
are ignored.
vertices
triangle mesh to drawmode
combines vertices’ colors withShader
if present orPaint
opaque color if not. Ignored if the vertices do not contain color.paint
specifies theShader
, used as [Vertices
] texture, and [crate::ColorFilter
].
example: https://fiddle.skia.org/c/@Canvas_drawVertices example: https://fiddle.skia.org/c/@Canvas_drawVertices_2
pub fn draw_patch<'a>(
&self,
cubics: &[Point; 12],
colors: impl Into<Option<&'a [Color; 4]>>,
tex_coords: Option<&[Point; 4]>,
mode: SkBlendMode,
paint: &Handle<SkPaint>,
) -> &Canvas
pub fn draw_patch<'a>( &self, cubics: &[Point; 12], colors: impl Into<Option<&'a [Color; 4]>>, tex_coords: Option<&[Point; 4]>, mode: SkBlendMode, paint: &Handle<SkPaint>, ) -> &Canvas
Draws a Coons patch: the interpolation of four cubics with shared corners,
associating a color, and optionally a texture Point
, with each corner.
Point
array cubics specifies four Path
cubic starting at the top-left corner,
in clockwise order, sharing every fourth point. The last Path
cubic ends at the
first point.
Color array color associates colors with corners in top-left, top-right, bottom-right, bottom-left order.
If paint contains Shader
, Point
array tex_coords
maps Shader
as texture to
corners in top-left, top-right, bottom-right, bottom-left order. If tex_coords
is
None
, Shader
is mapped using positions (derived from cubics).
[BlendMode
] is ignored if colors is None
. Otherwise, it combines
- the
Shader
ifPaint
containsShader
- or the opaque
Paint
color ifPaint
does not containShader
as the src of the blend and the interpolated patch colors as the dst.
crate::MaskFilter
, [crate::PathEffect
], and antialiasing on Paint
are ignored.
cubics
Path
cubic array, sharing common pointscolors
color array, one for each cornertex_coords
Point
array of texture coordinates, mappingShader
to corners; may beNone
mode
combines patch’s colors withShader
if present orPaint
opaque color if not. Ignored if colors isNone
.paint
Shader
, [crate::ColorFilter
], [BlendMode
], used to draw
pub fn draw_atlas<'a>(
&self,
atlas: &RCHandle<SkImage>,
xform: &[RSXform],
tex: &[Rect],
colors: impl Into<Option<&'a [Color]>>,
mode: SkBlendMode,
sampling: impl Into<SamplingOptions>,
cull_rect: impl Into<Option<Rect>>,
paint: impl Into<Option<&'a Handle<SkPaint>>>,
)
pub fn draw_atlas<'a>( &self, atlas: &RCHandle<SkImage>, xform: &[RSXform], tex: &[Rect], colors: impl Into<Option<&'a [Color]>>, mode: SkBlendMode, sampling: impl Into<SamplingOptions>, cull_rect: impl Into<Option<Rect>>, paint: impl Into<Option<&'a Handle<SkPaint>>>, )
Draws a set of sprites from atlas, using clip, Matrix
, and optional Paint
paint.
paint uses anti-alias, alpha, [crate::ColorFilter
], [ImageFilter
], and [BlendMode
]
to draw, if present. For each entry in the array, Rect
tex locates sprite in
atlas, and [RSXform
] xform transforms it into destination space.
crate::MaskFilter
and [crate::PathEffect
] on paint are ignored.
xform, tex, and colors if present, must contain the same number of entries.
Optional colors are applied for each sprite using [BlendMode
] mode, treating
sprite as source and colors as destination.
Optional cull_rect
is a conservative bounds of all transformed sprites.
If cull_rect
is outside of clip, canvas can skip drawing.
atlas
-Image
containing spritesxform
- [RSXform
] mappings for sprites in atlastex
-Rect
locations of sprites in atlascolors
- one per sprite, blended with sprite using [BlendMode
]; may beNone
count
- number of sprites to drawmode
- [BlendMode
] combining colors and spritessampling
-SamplingOptions
used when sampling from the atlas imagecull_rect
- bounds of transformed sprites for efficient clipping; may beNone
paint
- [crate::ColorFilter
], [ImageFilter
], [BlendMode
], and so on; may beNone
pub fn draw_drawable(
&self,
drawable: &mut RCHandle<SkDrawable>,
matrix: Option<&Matrix>,
)
pub fn draw_drawable( &self, drawable: &mut RCHandle<SkDrawable>, matrix: Option<&Matrix>, )
Draws [Drawable
] drawable using clip and Matrix
, concatenated with
optional matrix.
If Canvas
has an asynchronous implementation, as is the case when it is recording into
[Picture
], then drawable will be referenced, so that [RCHandle<Drawable>::draw()
] can be
called when the operation is finalized. To force immediate drawing, call
[RCHandle<Drawable>::draw()
] instead.
drawable
custom struct encapsulating drawing commandsmatrix
transformation applied to drawing; may beNone
pub fn draw_drawable_at(
&self,
drawable: &mut RCHandle<SkDrawable>,
offset: impl Into<Point>,
)
pub fn draw_drawable_at( &self, drawable: &mut RCHandle<SkDrawable>, offset: impl Into<Point>, )
Draws [Drawable
] drawable using clip and Matrix
, offset by (offset.x, offset.y)
.
If Canvas
has an asynchronous implementation, as is the case when it is recording into
[Picture
], then drawable will be referenced, so that [RCHandle<Drawable>::draw()
] can be
called when the operation is finalized. To force immediate drawing, call
[RCHandle<Drawable>::draw()
] instead.
drawable
custom struct encapsulating drawing commandsoffset
offset intoCanvas
writable pixels on x,y-axis
pub fn draw_annotation(
&self,
rect: impl AsRef<Rect>,
key: &str,
value: &RCHandle<SkData>,
) -> &Canvas
pub fn draw_annotation( &self, rect: impl AsRef<Rect>, key: &str, value: &RCHandle<SkData>, ) -> &Canvas
Associates Rect
on Canvas
when an annotation; a key-value pair, where the key is
a UTF-8 string, and optional value is stored as Data
.
Only some canvas implementations, such as recording to [Picture
], or drawing to
document PDF, use annotations.
rect
Rect
extent of canvas to annotatekey
string used for lookupvalue
data holding value stored in annotation
pub fn is_clip_empty(&self) -> bool
pub fn is_clip_empty(&self) -> bool
Returns true
if clip is empty; that is, nothing will draw.
May do work when called; it should not be called more often than needed. However, once called, subsequent calls perform no work until clip changes.
Returns true
if clip is empty
pub fn is_clip_rect(&self) -> bool
pub fn is_clip_rect(&self) -> bool
pub fn local_to_device(&self) -> M44
pub fn local_to_device(&self) -> M44
Returns the current transform from local coordinates to the ‘device’, which for most purposes means pixels.
Returns transformation from local coordinates to device / pixels.
pub fn local_to_device_as_3x3(&self) -> Matrix
pub fn local_to_device_as_3x3(&self) -> Matrix
Throws away the 3rd row and column in the matrix, so be warned.
pub fn total_matrix(&self) -> Matrix
👎Deprecated since 0.38.0: use local_to_device() or local_to_device_as_3x3() instead
pub fn total_matrix(&self) -> Matrix
DEPRECATED
Legacy version of Self::local_to_device()
, which strips away any Z information, and just
returns a 3x3 version.
Returns 3x3 version of Self::local_to_device()
example: https://fiddle.skia.org/c/@Canvas_getTotalMatrix example: https://fiddle.skia.org/c/@Clip