pub enum DrawOp {
Fill(Shape, Paint),
Stroke(Shape, Paint, StrokeStyle),
Text {
text: String,
at: Point,
size: f64,
color: Color,
anchor: TextAnchor,
font: CanvasFont,
},
Stamp(Box<Stamp>),
Image {
image: BitmapId,
rect: Rect,
opacity: f64,
},
Clip(Shape),
Save,
Restore,
Concat(Affine),
}Variants§
Fill(Shape, Paint)
Stroke(Shape, Paint, StrokeStyle)
Stroke shape. The paint may be a gradient, and StrokeStyle carries width, dash, cap
and join; Draw::stroke builds the plain width-only case.
Text
One line of text. size is absolute canvas points (no accessibility scale: canvas
text is a label inside a drawing, docs/canvas.md); font picks the family, weight and
slant, and its default is the platform’s own UI face.
Stamp(Box<Stamp>)
Draw one shape at many positions, the batched form of DrawOp::Fill/DrawOp::Stroke
(docs/canvas.md “Stamping”).
Boxed because the payload is wider than the largest other op, and a bigger DrawOp would
cost every op in every drawing, the exact thing this variant exists to stop paying.
Image
Draw an image into rect (docs/images.md).
The source is a BitmapId and never bytes: a canvas re-records on every tracked read,
so carrying a buffer here would hand the backend a megabyte to compare, and re-decode, on
every frame. The app decodes once with day::decode_image and draws the handle.
opacity multiplies the image’s own alpha. A backend that cannot draw a bitmap at all
draws nothing rather than a placeholder rectangle, the same way an unknown op is skipped.
Clip(Shape)
Intersect the clip with shape; everything drawn afterwards is confined to it.
Scoped by DrawOp::Save/DrawOp::Restore, which is the only way to widen a clip
again; every native 2-D context works this way, so there is no “unclip”.
Save
Push the current transform + clip (§11, shapes). Backends map to save/restore of the
native 2-D context; Concat multiplies an affine onto the CTM (shape rotate/scale/offset).