plutovg/canvas
canvas-create
(canvas-create [s :int] :ptr<void>)
allocate a drawing context that writes into surface s.
| s | surface handle (ok-val from surface-create) |
(ok handle) on success; (err 0) on failure. Free with canvas-destroy when done. The surface must outlive the canvas.
(let [r (canvas-create s)]
(if (ok? r) (let [c (ok-val r)] ...) (println "create failed")))
Since: PV0
canvas-destroy
(canvas-destroy [c :int] :void)
release a canvas allocated by canvas-create.
| c | canvas handle (ok-val from canvas-create) |
void
(canvas-destroy c)
Since: PV0
canvas-set-source-color
(canvas-set-source-color [c :int r :float g :float b :float a :float] :void)
set the current paint to a solid RGBA color.
| c | canvas handle | |
| r | red in [0.0, 1.0] | |
| g | green in [0.0, 1.0] | |
| b | blue in [0.0, 1.0] | |
| a | alpha in [0.0, 1.0] |
void
(canvas-set-source-color c 1.0 0.0 0.0 1.0) ; opaque red
Since: PV0
canvas-fill-rect
(canvas-fill-rect [c :int x :float y :float w :float h :float] :void)
fill an axis-aligned rectangle with the current paint.
| c | canvas handle | |
| x | top-left x in surface space | |
| y | top-left y in surface space | |
| w | width in pixels | |
| h | height in pixels |
void
(canvas-fill-rect c 10.0 10.0 100.0 50.0)
Since: PV0
canvas-move-to
(canvas-move-to [c :int x :float y :float] :void)
start a new subpath at (x, y).
| c | canvas handle | |
| x | destination x in surface space | |
| y | destination y in surface space |
void
(canvas-move-to c 10.0 10.0)
Since: PV1
canvas-line-to
(canvas-line-to [c :int x :float y :float] :void)
append a straight line from the current point to (x, y).
| c | canvas handle | |
| x | destination x | |
| y | destination y |
void
(canvas-line-to c 100.0 10.0)
Since: PV1
canvas-quad-to
(canvas-quad-to [c :int x1 :float y1 :float x :float y :float] :void)
append a quadratic Bezier from the current point to (x, y) via control (x1, y1).
| c | canvas handle | |
| x1 | control point x | |
| y1 | control point y | |
| x | destination x | |
| y | destination y |
void
(canvas-quad-to c 50.0 0.0 100.0 50.0)
Since: PV1
canvas-cubic-to
(canvas-cubic-to [c :int x1 :float y1 :float x2 :float y2 :float x :float y :float] :void)
append a cubic Bezier from the current point.
| c | canvas handle | |
| x1 | first control point x | |
| y1 | first control point y | |
| x2 | second control point x | |
| y2 | second control point y | |
| x | destination x | |
| y | destination y |
void
(canvas-cubic-to c 25.0 0.0 75.0 0.0 100.0 50.0)
Since: PV1
canvas-close-path
(canvas-close-path [c :int] :void)
close the current subpath with a straight line to its origin.
| c | canvas handle |
void
(canvas-close-path c)
Since: PV1
canvas-rect
(canvas-rect [c :int x :float y :float w :float h :float] :void)
append an axis-aligned rectangle subpath to the current path.
| c | canvas handle | |
| x | top-left x | |
| y | top-left y | |
| w | width in pixels | |
| h | height in pixels |
void
(canvas-rect c 0.0 0.0 100.0 50.0)
Since: PV1
canvas-ellipse
(canvas-ellipse [c :int cx :float cy :float rx :float ry :float] :void)
append an axis-aligned ellipse subpath.
| c | canvas handle | |
| cx | center x | |
| cy | center y | |
| rx | horizontal radius | |
| ry | vertical radius |
void
(canvas-ellipse c 50.0 50.0 30.0 20.0)
Since: PV1
canvas-circle
(canvas-circle [c :int cx :float cy :float r :float] :void)
append a circle subpath (convenience for canvas-ellipse with rx == ry).
| c | canvas handle | |
| cx | center x | |
| cy | center y | |
| r | radius |
void
(canvas-circle c 50.0 50.0 25.0)
Since: PV1
canvas-fill
(canvas-fill [c :int] :void)
fill the current path with the current paint, then clear the path.
| c | canvas handle |
void
(canvas-rect c 0.0 0.0 100.0 50.0) (canvas-fill c)
Since: PV1
canvas-stroke
(canvas-stroke [c :int] :void)
stroke the current path with the current paint, then clear the path.
| c | canvas handle |
void
(canvas-rect c 0.0 0.0 100.0 50.0) (canvas-stroke c)
Since: PV1
canvas-clip
(canvas-clip [c :int] :void)
intersect the clip region with the current path, then clear the path.
| c | canvas handle |
void
(canvas-circle c 50.0 50.0 25.0) (canvas-clip c)
Since: PV1
canvas-add-path
(canvas-add-path [c :int path :int] :void)
append a pre-built path to the canvas's current path.
| c | canvas handle | |
| path | path handle (from plutovg/path) |
void
(canvas-add-path c my-path)
Since: PV2
canvas-fill-path
(canvas-fill-path [c :int path :int] :void)
fill a pre-built path without disturbing the
| c | canvas handle | |
| path | path handle |
void
Since: PV2
canvas-stroke-path
(canvas-stroke-path [c :int path :int] :void)
stroke a pre-built path without disturbing the
| c | canvas handle | |
| path | path handle |
void
Since: PV2
canvas-save
(canvas-save [c :int] :void)
push the current drawing state (transform, paint, stroke
Since: PV4
canvas-restore
(canvas-restore [c :int] :void)
pop the most recently saved drawing state.
Since: PV4
canvas-translate
(canvas-translate [c :int tx :float ty :float] :void)
prepend a translation to the current transform.
| c | canvas handle | |
| tx | x offset | |
| ty | y offset |
Since: PV4
canvas-scale
(canvas-scale [c :int sx :float sy :float] :void)
prepend a scale to the current transform.
Since: PV4
canvas-rotate
(canvas-rotate [c :int radians :float] :void)
prepend a rotation (in radians) to the current transform.
| c | canvas handle | |
| radians | rotation angle |
Since: PV4
canvas-transform
(canvas-transform [c :int a :float b :float cc :float d :float e :float f :float] :void)
multiply the current transform by a raw 2D matrix.
| c | canvas handle | |
| a | horizontal scaling factor | |
| b | vertical shear / skew | |
| cc | horizontal shear / skew | |
| d | vertical scaling factor | |
| e | horizontal translation | |
| f | vertical translation |
Since: PV4
canvas-reset-transform
(canvas-reset-transform [c :int] :void)
reset the current transform to the identity.
Since: PV4
canvas-set-line-width
(canvas-set-line-width [c :int w :float] :void)
set the stroke width in surface units.
Since: PV4
canvas-set-line-cap
(canvas-set-line-cap [c :int cap :cstr] :void)
set the stroke end-cap style.
| c | canvas handle | |
| cap | ":butt" (default), ":round", or ":square" |
Since: PV4
canvas-set-line-join
(canvas-set-line-join [c :int join :cstr] :void)
set the stroke join style.
| c | canvas handle | |
| join | ":miter" (default), ":round", or ":bevel" |
Since: PV4
canvas-set-miter-limit
(canvas-set-miter-limit [c :int limit :float] :void)
set the miter-limit ratio for ":miter" joins.
Since: PV4
dash-array-create
(dash-array-create :ptr<void>)
allocate an empty dash-length buffer.
(ok dash-handle) on success; (err 0) on allocation failure.
Since: PV4
dash-array-add
(dash-array-add [dashes :int length :float] :void)
append a dash-segment length.
Since: PV4
dash-array-count
(dash-array-count [dashes :int] :int)
return the number of dash lengths added.
Since: PV4
dash-array-destroy
(dash-array-destroy [dashes :int] :void)
release a dash-array buffer.
Since: PV4
canvas-set-dash-offset
(canvas-set-dash-offset [c :int offset :float] :void)
set the phase offset into the dash pattern.
Since: PV4
canvas-set-dash-array
(canvas-set-dash-array [c :int dashes :int] :void)
set the dash pattern to the lengths in a
| c | canvas handle | |
| dashes | dash-array handle (from dash-array-create / dash-array-add) |
Since: PV4
canvas-set-fill-rule
(canvas-set-fill-rule [c :int rule :cstr] :void)
set the polygon fill rule for canvas-fill.
| c | canvas handle | |
| rule | ":non-zero" (default) or ":even-odd" |
Since: PV4
canvas-set-operator
(canvas-set-operator [c :int op :cstr] :void)
set the Porter-Duff compositing operator.
| c | canvas handle | |
| op | one of: | |
| ":clear" ":src" ":dst" ":src-over" (default) | ||
| ":dst-over" ":src-in" ":dst-in" ":src-out" ":dst-out" | ||
| ":src-atop" ":dst-atop" ":xor" |
Since: PV4
canvas-set-opacity
(canvas-set-opacity [c :int alpha :float] :void)
set the global opacity multiplier in [0.0, 1.0].
Since: PV4
canvas-arc
(canvas-arc [c :int cx :float cy :float r :float start-angle :float sweep-angle :float] :void)
append a circular arc subpath centered at (cx, cy).
| c | canvas handle | |
| cx | center x | |
| cy | center y | |
| r | radius | |
| start-angle | start angle in radians | |
| sweep-angle | end angle in radians (interpreted as a0..a1; pass | |
| start + sweep for a "start + delta" shape) | ||
| The underlying plutovg API takes a clockwise/counter-clockwise flag; | ||
| this binding uses clockwise (`ccw = false`). For counter-clockwise | ||
| arcs build the path manually with canvas-arc-to. |
Since: PV6
canvas-arc-to
(canvas-arc-to [c :int rx :float ry :float rotation :float large-arc? :bool sweep? :bool x :float y :float] :void)
append an SVG-style elliptical arc to (x, y).
| c | canvas handle | |
| rx | horizontal radius | |
| ry | vertical radius | |
| rotation | x-axis rotation in radians | |
| large-arc? | :bool, choose the long (true) or short (false) arc | |
| sweep? | :bool, sweep direction (true = clockwise) | |
| x | destination x | |
| y | destination y |
Since: PV6
canvas-round-rect
(canvas-round-rect [c :int x :float y :float w :float h :float rx :float ry :float] :void)
append a rounded-corner rectangle subpath.
| c | canvas handle | |
| x | top-left x | |
| y | top-left y | |
| w | width | |
| h | height | |
| rx | horizontal corner radius | |
| ry | vertical corner radius |
Since: PV6
canvas-draw-image
(canvas-draw-image [c :int src :int x :float y :float w :float h :float] :void)
composite the pixels of `src` onto the canvas,
| c | canvas handle | |
| src | source surface handle | |
| x | destination top-left x | |
| y | destination top-left y | |
| w | destination width | |
| h | destination height |
void
Since: PV6
Internal definitions
__ok-- create an ok result wrapping integer value v.__err-- create an err result wrapping integer error value e.