Skip to main content

Canvas

Struct Canvas 

Source
pub struct Canvas<'a> { /* private fields */ }
Expand description

drawing on one page (Document::canvas). Coordinates are points (1/72 inch) from the origin the canvas was made with; what it draws goes into the page when it is dropped, with every save it left open restored. Several canvases on one page draw one after the other.

Implementations§

Source§

impl<'a> Canvas<'a>

Source

pub fn page(&self) -> PageId

the page this canvas draws on

Source

pub fn page_size(&self) -> (f64, f64)

width and height of the page in points

Source

pub fn ctm(&self) -> Matrix

the current transform from this canvas’s coordinates to PDF page space (points from the bottom left, y up)

Source

pub fn document(&self) -> &Document

the document (fonts, metrics, shaping) while drawing

Source

pub fn save(&mut self)

saves the whole state (transform, clip, colours, alpha, stroke and text settings)

Source

pub fn restore(&mut self)

back to the state of the matching save (none open: nothing happens)

Source

pub fn depth(&self) -> usize

how many saves are open

Source

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

m first, then the current transform (singular or not finite: ignored)

Source

pub fn translate(&mut self, tx: f64, ty: f64)

Source

pub fn scale(&mut self, sx: f64, sy: f64)

Source

pub fn rotate(&mut self, angle: f64)

radians: counter-clockwise where y points up, clockwise where it points down

Source

pub fn set_fill_color(&mut self, c: Rgb)

Source

pub fn set_stroke_color(&mut self, c: Rgb)

Source

pub fn set_fill_alpha(&mut self, a: f64)

opacity of fills, text fills and images, 0 to 1 (kept in thousandths)

Source

pub fn set_stroke_alpha(&mut self, a: f64)

opacity of strokes, 0 to 1 (kept in thousandths)

Source

pub fn set_line_width(&mut self, w: f64)

in the coordinates at the time of the stroke (0: the thinnest line the device draws)

Source

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

Source

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

Source

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

the longest miter, as a multiple of the line width (at least 1)

Source

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

dashes: lengths on, off, on, … from phase into the pattern; an empty list (or one with a negative length or only zeros) draws solid lines

Source

pub fn set_text_mode(&mut self, mode: TextMode)

Source

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

Source

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

Source

pub fn curve_to(&mut self, x1: f64, y1: f64, x2: f64, y2: f64, x: f64, y: f64)

Source

pub fn quad_to(&mut self, x1: f64, y1: f64, x: f64, y: f64)

Source

pub fn close(&mut self)

Source

pub fn rect(&mut self, x: f64, y: f64, w: f64, h: f64)

Source

pub fn rounded_rect(&mut self, x: f64, y: f64, w: f64, h: f64, r: f64)

Source

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

Source

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

Source

pub fn arc( &mut self, cx: f64, cy: f64, rx: f64, ry: f64, start: f64, sweep: f64, )

Path::arc on the canvas’s path

Source

pub fn append_path(&mut self, p: &Path)

a prepared path’s subpaths, in the current coordinates

Source

pub fn fill(&mut self, rule: FillRule)

fills the path and starts a new one

Source

pub fn stroke(&mut self)

strokes the path and starts a new one

Source

pub fn fill_stroke(&mut self, rule: FillRule)

fills, then strokes the path, and starts a new one

Source

pub fn clip(&mut self, rule: FillRule)

intersects the clip with the path (until the matching restore) and starts a new path

Source

pub fn end_path(&mut self)

drops the path without painting it

Source

pub fn fill_path(&mut self, p: &Path, rule: FillRule)

Source

pub fn stroke_path(&mut self, p: &Path)

Source

pub fn shade(&mut self, s: &Shading)

paints the gradient over the whole current clip (sh), its coordinates in the current user space, times the canvas’s fill alpha. Degenerate geometry paints the last stop’s colour (axial from = to, radial with both radii 0: everywhere; two equal circles: that disk); no stops, coordinates that are not finite or a negative radius: nothing. The path being built is kept.

Source

pub fn fill_shading(&mut self, rule: FillRule, s: &Shading)

fills the path with the gradient (q, clip with rule, sh, Q) and starts a new path, as fill() does; what shade() does with degenerate and invalid gradients, within the path (an invalid one drops the path)

Source

pub fn fill_hatch(&mut self, rule: FillRule, h: &Hatch)

fills the path with the hatch’s lines (q, clip with rule, the lines stroked, Q) and starts a new path, as fill() does. Lines at least as wide as their spacing fill the path solid; an angle, spacing, width or origin that is not finite (or a spacing or width <= 0), a path with coordinates that are not finite or more than 100 000 lines: nothing, the path dropped

Source

pub fn image(&mut self, img: ImageId, x: f64, y: f64, w: f64, h: f64)

the image upright (as it looks on the page) in the rectangle x, y, w, h of the current coordinates

Source

pub fn image_transform(&mut self, img: ImageId, m: Matrix)

the image’s unit square (row 0 along y = 1, column 0 along x = 0) mapped by m into the current coordinates

Source

pub fn text(&mut self, font: FontId, size: f64, x: f64, y: f64, s: &str) -> f64

one line of text shaped with the font (kerning, ligatures, marks, bidi), its baseline starting at (x, y), size the em in points; upright as it looks on the page. Returns the advance along the baseline (0 when nothing was drawn).

Source

pub fn text_fallback( &mut self, fonts: &[FontId], size: f64, x: f64, y: f64, s: &str, ) -> f64

the same with fallback fonts: a run of one script the first font cannot show comes from the first of the others that can

Source

pub fn glyphs( &mut self, fonts: &[FontId], size: f64, x: f64, y: f64, glyphs: &[Glyph], text: &str, ) -> f64

shaped glyphs (in visual order; Glyph::font indexes fonts) from the pen at (x, y); text is the shaped string (each glyph’s cluster is a byte range of it) for search and copy. Returns the advance.

a link on the rectangle x, y, w, h (its box on the page when turned) to a URI

a link on the rectangle x, y, w, h to a place in the document

Source

pub fn dest(&self, x: f64, y: f64) -> Dest

a destination showing the point (x, y) of this canvas at the top left of the window, the zoom unchanged

Source§

impl Canvas<'_>

Source

pub fn text_field( &mut self, x: f64, y: f64, w: f64, h: f64, name: &str, f: &TextField<'_>, )

a text field on the rectangle x, y, w, h

Source

pub fn check_box( &mut self, x: f64, y: f64, w: f64, h: f64, name: &str, checked: bool, style: &FieldStyle, )

a check box, checked or not

Source

pub fn radio( &mut self, x: f64, y: f64, w: f64, h: f64, name: &str, value: &str, selected: bool, style: &FieldStyle, )

a radio button of the group name with the export value value; the last one selected of a group is on. Its on state is its place in the group (“0”, “1”, …), its export value that place of the group’s /Opt (12.7.4.2.4), so any text is an export value

Source

pub fn combo_box( &mut self, x: f64, y: f64, w: f64, h: f64, name: &str, options: &[&str], value: &str, editable: bool, style: &FieldStyle, )

a combo box: one of the options shown, typed text too when editable

Source

pub fn list_box( &mut self, x: f64, y: f64, w: f64, h: f64, name: &str, options: &[&str], selected: &[&str], multi: bool, style: &FieldStyle, )

a list box with the options selected chosen (several only with multi)

Source

pub fn push_button( &mut self, x: f64, y: f64, w: f64, h: f64, name: &str, caption: &str, uri: Option<&str>, style: &FieldStyle, )

a push button with a caption, opening uri when pressed

Source

pub fn signature_field(&mut self, x: f64, y: f64, w: f64, h: f64, name: &str)

an empty signature field, to be signed later

Trait Implementations§

Source§

impl Drop for Canvas<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Canvas<'a>

§

impl<'a> !UnwindSafe for Canvas<'a>

§

impl<'a> Forget for Canvas<'a>

§

impl<'a> Freeze for Canvas<'a>
where &'a mut Document: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, PhantomData<f64>: Freeze, PhantomData<(Matrix, Paint, Paint)>: Freeze, PhantomData<Seg>: Freeze,

§

impl<'a> Move for Canvas<'a>

§

impl<'a> Send for Canvas<'a>
where RawVecInner: Send, NodeRef<Owned, usize, SetValZST, LeafOrInternal>: Send, BoxRaw<(usize, SetValZST)>: Send, Arc<SharedFontRepr>: Send, Arc<VariedInstance>: Send, NodeRef<Owned, u16, Option<String>, LeafOrInternal>: Send, BoxRaw<(u16, Option<String>)>: Send, NodeRef<Owned, (u16, u16), usize, LeafOrInternal>: Send, BoxRaw<((u16, u16), usize)>: Send, NodeRef<Owned, Vec<u8>, usize, LeafOrInternal>: Send, BoxRaw<(Vec<u8>, usize)>: Send, NodeRef<Owned, (usize, Vec<u8>), usize, LeafOrInternal>: Send, BoxRaw<((usize, Vec<u8>), usize)>: Send, NodeRef<Owned, String, usize, LeafOrInternal>: Send, BoxRaw<(String, usize)>: Send, &'static str: Send,

§

impl<'a> Sync for Canvas<'a>
where RawVecInner: Sync, NodeRef<Owned, usize, SetValZST, LeafOrInternal>: Sync, BoxRaw<(usize, SetValZST)>: Sync, Arc<SharedFontRepr>: Sync, Arc<VariedInstance>: Sync, NodeRef<Owned, u16, Option<String>, LeafOrInternal>: Sync, BoxRaw<(u16, Option<String>)>: Sync, NodeRef<Owned, (u16, u16), usize, LeafOrInternal>: Sync, BoxRaw<((u16, u16), usize)>: Sync, NodeRef<Owned, Vec<u8>, usize, LeafOrInternal>: Sync, BoxRaw<(Vec<u8>, usize)>: Sync, NodeRef<Owned, (usize, Vec<u8>), usize, LeafOrInternal>: Sync, BoxRaw<((usize, Vec<u8>), usize)>: Sync, NodeRef<Owned, String, usize, LeafOrInternal>: Sync, BoxRaw<(String, usize)>: Sync,

§

impl<'a> Unpin for Canvas<'a>
where &'a mut Document: Unpin, *const u8 is !null: Unpin,

§

impl<'a> UnsafeUnpin for Canvas<'a>

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> ErasedDestructor for T
where T: 'static,

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

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.