Skip to main content

Canvas

Struct Canvas 

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

An imperative painter producing content-stream operators.

Implementations§

Source§

impl Canvas

Source

pub fn new() -> Canvas

Creates an empty canvas.

Source

pub fn save(&mut self)

Pushes the graphics state (q).

Source

pub fn restore(&mut self)

Pops the graphics state (Q).

Source

pub fn transform(&mut self, m: Matrix)

Concatenates m onto the current transformation matrix (cm).

Source

pub fn set_line_width(&mut self, width: f32)

Sets the stroke line width (w).

Source

pub fn set_line_cap(&mut self, cap: LineCap)

Sets the line cap style (J).

Source

pub fn set_line_join(&mut self, join: LineJoin)

Sets the line join style (j).

Source

pub fn set_miter_limit(&mut self, limit: f32)

Sets the miter limit (M).

Source

pub fn set_dash(&mut self, pattern: &[f32], phase: f32)

Sets the dash pattern (d).

Source

pub fn set_fill(&mut self, color: Color)

Sets the fill color (g/rg/k).

Source

pub fn set_stroke(&mut self, color: Color)

Sets the stroke color (G/RG/K).

Source

pub fn move_to(&mut self, x: f32, y: f32)

Begins a new subpath at (x, y) (m).

Source

pub fn line_to(&mut self, x: f32, y: f32)

Straight segment to (x, y) (l).

Source

pub fn curve_to(&mut self, x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32)

Cubic Bézier with two control points (c).

Source

pub fn close(&mut self)

Closes the current subpath (h).

Source

pub fn rect(&mut self, x: f32, y: f32, width: f32, height: f32)

Appends a rectangle subpath (re).

Source

pub fn circle(&mut self, cx: f32, cy: f32, r: f32)

Appends a circle as four Bézier arcs, starting at the rightmost point (cx + r, cy) and running counter-clockwise.

Source

pub fn ellipse(&mut self, cx: f32, cy: f32, rx: f32, ry: f32)

Appends an axis-aligned ellipse as four Bézier arcs, starting at the rightmost point (cx + rx, cy) and running counter-clockwise.

Source

pub fn polygon(&mut self, points: &[Point])

Appends a closed polygon through points. Fewer than three points appends nothing.

Source

pub fn fill(&mut self)

Fills the current path, nonzero winding (f).

Source

pub fn fill_even_odd(&mut self)

Fills the current path, even-odd (f*).

Source

pub fn stroke(&mut self)

Strokes the current path (S).

Source

pub fn close_stroke(&mut self)

Closes and strokes the current path (s).

Source

pub fn fill_stroke(&mut self)

Fills then strokes the current path (B).

Source

pub fn clip(&mut self)

Intersects the clip with the current path, nonzero (W n). The path is consumed: it is ended without painting and a fresh path starts afterwards.

Source

pub fn clip_even_odd(&mut self)

Intersects the clip with the current path, even-odd (W* n). The path is consumed: it is ended without painting and a fresh path starts afterwards.

Source

pub fn end_path(&mut self)

Ends the current path without painting (n).

Source

pub fn text( &mut self, text: &str, x: f32, y: f32, font: Standard14, size: f32, ) -> Result<()>

Shows one line of text with its baseline origin at (x, y) (BT/Tf/Td/Tj/ET). Errors on unencodable characters before any operator is pushed, leaving the canvas untouched.

Source

pub fn add_image(&mut self, image: ImageData) -> ImageHandle

Registers an image for use with draw_image.

Source

pub fn draw_image( &mut self, image: ImageHandle, x: f32, y: f32, width: f32, height: f32, )

Paints a registered image into the axis-aligned box at (x, y) with the given size (q cm Do Q).

Source

pub fn group(&mut self, canvas: Canvas, bbox: [f32; 4]) -> GroupHandle

Registers a finished sub-canvas as a form group, with bbox ([llx, lly, urx, ury]) becoming the form’s /BBox. Paint it with draw_group.

Source

pub fn draw_group(&mut self, group: GroupHandle, matrix: Matrix)

Paints a registered group under matrix (q cm /GpN Do Q). Two calls with the same group reference the same form resource.

Source

pub fn set_fill_alpha(&mut self, alpha: f32)

Sets the nonstroking alpha constant (gs referencing /ca).

Source

pub fn set_stroke_alpha(&mut self, alpha: f32)

Sets the stroking alpha constant (gs referencing /CA).

Source

pub fn set_blend_mode(&mut self, mode: BlendMode)

Sets the blend mode (gs referencing /BM).

Source

pub fn op(&mut self, op: Op)

Pushes a raw operator — the escape hatch for anything the methods above don’t cover. Resource-referencing operators are the caller’s responsibility to keep consistent with the naming contract.

Source

pub fn ops(&self) -> &[Op]

The operators accumulated so far, in paint order.

Trait Implementations§

Source§

impl Debug for Canvas

Source§

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

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

impl Default for Canvas

Source§

fn default() -> Canvas

Returns the “default value” for a type. Read more

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 = !

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.