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>
impl<'a> Canvas<'a>
Sourcepub fn ctm(&self) -> Matrix
pub fn ctm(&self) -> Matrix
the current transform from this canvas’s coordinates to PDF page space (points from the bottom left, y up)
Sourcepub fn save(&mut self)
pub fn save(&mut self)
saves the whole state (transform, clip, colours, alpha, stroke and text settings)
Sourcepub fn transform(&mut self, m: Matrix)
pub fn transform(&mut self, m: Matrix)
m first, then the current transform (singular or not finite: ignored)
pub fn translate(&mut self, tx: f64, ty: f64)
pub fn scale(&mut self, sx: f64, sy: f64)
Sourcepub fn rotate(&mut self, angle: f64)
pub fn rotate(&mut self, angle: f64)
radians: counter-clockwise where y points up, clockwise where it points down
pub fn set_fill_color(&mut self, c: Rgb)
pub fn set_stroke_color(&mut self, c: Rgb)
Sourcepub fn set_fill_alpha(&mut self, a: f64)
pub fn set_fill_alpha(&mut self, a: f64)
opacity of fills, text fills and images, 0 to 1 (kept in thousandths)
Sourcepub fn set_stroke_alpha(&mut self, a: f64)
pub fn set_stroke_alpha(&mut self, a: f64)
opacity of strokes, 0 to 1 (kept in thousandths)
Sourcepub fn set_line_width(&mut self, w: f64)
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)
pub fn set_line_cap(&mut self, cap: LineCap)
pub fn set_line_join(&mut self, join: LineJoin)
Sourcepub fn set_miter_limit(&mut self, limit: f64)
pub fn set_miter_limit(&mut self, limit: f64)
the longest miter, as a multiple of the line width (at least 1)
Sourcepub fn set_dash(&mut self, pattern: &[f64], phase: f64)
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
pub fn set_text_mode(&mut self, mode: TextMode)
pub fn move_to(&mut self, x: f64, y: f64)
pub fn line_to(&mut self, x: f64, y: f64)
pub fn curve_to(&mut self, x1: f64, y1: f64, x2: f64, y2: f64, x: f64, y: f64)
pub fn quad_to(&mut self, x1: f64, y1: f64, x: f64, y: f64)
pub fn close(&mut self)
pub fn rect(&mut self, x: f64, y: f64, w: f64, h: f64)
pub fn rounded_rect(&mut self, x: f64, y: f64, w: f64, h: f64, r: f64)
pub fn ellipse(&mut self, cx: f64, cy: f64, rx: f64, ry: f64)
pub fn circle(&mut self, cx: f64, cy: f64, r: f64)
Sourcepub fn arc(
&mut self,
cx: f64,
cy: f64,
rx: f64,
ry: f64,
start: f64,
sweep: f64,
)
pub fn arc( &mut self, cx: f64, cy: f64, rx: f64, ry: f64, start: f64, sweep: f64, )
Path::arc on the canvas’s path
Sourcepub fn append_path(&mut self, p: &Path)
pub fn append_path(&mut self, p: &Path)
a prepared path’s subpaths, in the current coordinates
Sourcepub fn fill_stroke(&mut self, rule: FillRule)
pub fn fill_stroke(&mut self, rule: FillRule)
fills, then strokes the path, and starts a new one
Sourcepub fn clip(&mut self, rule: FillRule)
pub fn clip(&mut self, rule: FillRule)
intersects the clip with the path (until the matching restore) and starts a new path
pub fn fill_path(&mut self, p: &Path, rule: FillRule)
pub fn stroke_path(&mut self, p: &Path)
Sourcepub fn shade(&mut self, s: &Shading)
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.
Sourcepub fn fill_shading(&mut self, rule: FillRule, s: &Shading)
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)
Sourcepub fn fill_hatch(&mut self, rule: FillRule, h: &Hatch)
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
Sourcepub fn image(&mut self, img: ImageId, x: f64, y: f64, w: f64, h: f64)
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
Sourcepub fn image_transform(&mut self, img: ImageId, m: Matrix)
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
Sourcepub fn text(&mut self, font: FontId, size: f64, x: f64, y: f64, s: &str) -> f64
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).
Sourcepub fn text_fallback(
&mut self,
fonts: &[FontId],
size: f64,
x: f64,
y: f64,
s: &str,
) -> f64
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
Sourcepub fn glyphs(
&mut self,
fonts: &[FontId],
size: f64,
x: f64,
y: f64,
glyphs: &[Glyph],
text: &str,
) -> f64
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.
Sourcepub fn link_uri(&mut self, x: f64, y: f64, w: f64, h: f64, uri: &str)
pub fn link_uri(&mut self, x: f64, y: f64, w: f64, h: f64, uri: &str)
a link on the rectangle x, y, w, h (its box on the page when turned) to a URI
Source§impl Canvas<'_>
impl Canvas<'_>
Sourcepub fn text_field(
&mut self,
x: f64,
y: f64,
w: f64,
h: f64,
name: &str,
f: &TextField<'_>,
)
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
Sourcepub fn check_box(
&mut self,
x: f64,
y: f64,
w: f64,
h: f64,
name: &str,
checked: bool,
style: &FieldStyle,
)
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
Sourcepub fn radio(
&mut self,
x: f64,
y: f64,
w: f64,
h: f64,
name: &str,
value: &str,
selected: bool,
style: &FieldStyle,
)
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
Sourcepub fn combo_box(
&mut self,
x: f64,
y: f64,
w: f64,
h: f64,
name: &str,
options: &[&str],
value: &str,
editable: bool,
style: &FieldStyle,
)
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
Sourcepub fn list_box(
&mut self,
x: f64,
y: f64,
w: f64,
h: f64,
name: &str,
options: &[&str],
selected: &[&str],
multi: bool,
style: &FieldStyle,
)
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)
a push button with a caption, opening uri when pressed