Struct RenderContext

Source
pub struct RenderContext { /* private fields */ }
Expand description

A render context.

Implementations§

Source§

impl RenderContext

Source

pub fn new(width: u16, height: u16) -> Self

Create a new render context with the given width and height in pixels.

Source

pub fn fill_path(&mut self, path: &BezPath)

Fill a path.

Source

pub fn stroke_path(&mut self, path: &BezPath)

Stroke a path.

Source

pub fn fill_rect(&mut self, rect: &Rect)

Fill a rectangle.

Source

pub fn fill_blurred_rounded_rect( &mut self, rect: &Rect, radius: f32, std_dev: f32, )

Fill a blurred rectangle with the given radius and standard deviation.

Note that this only works properly if the current paint is set to a solid color. If not, it will fall back to using black as the fill color.

Source

pub fn stroke_rect(&mut self, rect: &Rect)

Stroke a rectangle.

Source

pub fn glyph_run(&mut self, font: &Font) -> GlyphRunBuilder<'_, Self>

Creates a builder for drawing a run of glyphs that have the same attributes.

Source

pub fn push_layer( &mut self, clip_path: Option<&BezPath>, blend_mode: Option<BlendMode>, opacity: Option<f32>, mask: Option<Mask>, )

Push a new layer with the given properties.

Note that the mask, if provided, needs to have the same size as the render context. Otherwise, it will be ignored. In addition to that, the mask will not be affected by the current transformation matrix in place.

Source

pub fn push_clip_layer(&mut self, path: &BezPath)

Push a new clip layer.

Source

pub fn push_blend_layer(&mut self, blend_mode: BlendMode)

Push a new blend layer.

Source

pub fn push_opacity_layer(&mut self, opacity: f32)

Push a new opacity layer.

Source

pub fn push_mask_layer(&mut self, mask: Mask)

Push a new mask layer.

Note that the mask, if provided, needs to have the same size as the render context. Otherwise, it will be ignored. In addition to that, the mask will not be affected by the current transformation matrix in place.

Source

pub fn pop_layer(&mut self)

Pop the last-pushed layer.

Source

pub fn set_stroke(&mut self, stroke: Stroke)

Set the current stroke.

Source

pub fn set_paint(&mut self, paint: impl Into<PaintType>)

Set the current paint.

Source

pub fn set_paint_transform(&mut self, paint_transform: Affine)

Set the current paint transform.

The paint transform is applied to the paint after the transform of the geometry the paint is drawn in, i.e., the paint transform is applied after the global transform. This allows transforming the paint independently from the drawn geometry.

Source

pub fn reset_paint_transform(&mut self)

Reset the current paint transform.

Source

pub fn set_fill_rule(&mut self, fill_rule: Fill)

Set the current fill rule.

Source

pub fn set_transform(&mut self, transform: Affine)

Set the current transform.

Source

pub fn reset_transform(&mut self)

Reset the current transform.

Source

pub fn reset(&mut self)

Reset the render context.

Source

pub fn render_to_buffer( &self, buffer: &mut [u8], width: u16, height: u16, render_mode: RenderMode, )

Render the current context into a buffer. The buffer is expected to be in premultiplied RGBA8 format with length width * height * 4

Source

pub fn render_to_pixmap(&self, pixmap: &mut Pixmap, render_mode: RenderMode)

Render the current context into a pixmap.

Source

pub fn width(&self) -> u16

Return the width of the pixmap.

Source

pub fn height(&self) -> u16

Return the height of the pixmap.

Trait Implementations§

Source§

impl ColrRenderer for RenderContext

Source§

fn push_clip_layer(&mut self, clip: &BezPath)

Push a new clip layer.
Source§

fn push_blend_layer(&mut self, blend_mode: BlendMode)

Push a new blend layer.
Source§

fn fill_solid(&mut self, color: AlphaColor<Srgb>)

Fill the current area with the given solid color.
Source§

fn fill_gradient(&mut self, gradient: Gradient)

Fill the current area with the given gradient color.
Source§

fn set_paint_transform(&mut self, affine: Affine)

Set the transform for paints.
Source§

fn pop_layer(&mut self)

Pop the last clip/blend layer.
Source§

impl Debug for RenderContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl GlyphRenderer for RenderContext

Source§

fn fill_glyph(&mut self, prepared_glyph: PreparedGlyph<'_>)

Fill glyphs with the current paint and fill rule.
Source§

fn stroke_glyph(&mut self, prepared_glyph: PreparedGlyph<'_>)

Stroke glyphs with the current paint and stroke settings.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.