plutovg/path
path-create
(path-create :ptr<void>)
allocate a new empty path.
(ok handle) on success; (err 0) on allocation failure. Free with path-destroy when done.
(let [r (path-create)] (if (ok? r) (let [p (ok-val r)] ...)))
Since: PV2
path-destroy
(path-destroy [p :int] :void)
release a path allocated by path-create or path-clone.
| p | path handle |
void
(path-destroy p)
Since: PV2
path-move-to
(path-move-to [p :int x :float y :float] :void)
begin a new subpath at (x, y).
| p | path handle | |
| x | destination x | |
| y | destination y |
(path-move-to p 10.0 10.0)
Since: PV2
path-line-to
(path-line-to [p :int x :float y :float] :void)
append a straight line to (x, y).
Since: PV2
path-quad-to
(path-quad-to [p :int x1 :float y1 :float x :float y :float] :void)
append a quadratic Bezier to (x, y) via control (x1, y1).
Since: PV2
path-cubic-to
(path-cubic-to [p :int x1 :float y1 :float x2 :float y2 :float x :float y :float] :void)
append a cubic Bezier with controls (x1,y1)/(x2,y2).
Since: PV2
path-arc-to
(path-arc-to [p :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).
| p | path handle | |
| rx | horizontal radius | |
| ry | vertical radius | |
| rotation | x-axis rotation in radians | |
| large-arc? | :bool, choose the large (true) or small (false) arc sweep | |
| sweep? | :bool, sweep direction (true = clockwise) | |
| x | destination x | |
| y | destination y |
Since: PV2
path-close
(path-close [p :int] :void)
close the current subpath with a straight line to its origin.
Since: PV2
path-add-rect
(path-add-rect [p :int x :float y :float w :float h :float] :void)
append an axis-aligned rectangle as a closed subpath.
Since: PV2
path-add-round-rect
(path-add-round-rect [p :int x :float y :float w :float h :float rx :float ry :float] :void)
append a rounded-corner rectangle as a closed subpath.
| p | path handle | |
| x | top-left x | |
| y | top-left y | |
| w | width | |
| h | height | |
| rx | horizontal corner radius | |
| ry | vertical corner radius |
Since: PV2
path-add-ellipse
(path-add-ellipse [p :int cx :float cy :float rx :float ry :float] :void)
append an axis-aligned ellipse as a closed subpath.
Since: PV2
path-add-circle
(path-add-circle [p :int cx :float cy :float r :float] :void)
convenience: append a circle subpath.
Since: PV2
path-add-arc
(path-add-arc [p :int cx :float cy :float r :float start-angle :float sweep-angle :float] :void)
append a circular arc centered at (cx, cy).
| p | path handle | |
| cx | center x | |
| cy | center y | |
| r | radius | |
| start-angle | start angle in radians | |
| sweep-angle | end angle in radians (interpreted by plutovg) | |
| The plutovg helper expects start and end angles plus a `ccw` flag; | ||
| we expose the simpler "start + sweep" form by interpreting sweep-angle | ||
| as the end angle and defaulting ccw to false (clockwise sweep). Callers | ||
| that need counter-clockwise sweeps should construct the arc manually | ||
| with arc-to. |
Since: PV2
path-clone
(path-clone [p :int] :ptr<void>)
create an independent copy of a path.
(ok handle) on success; (err 0) on allocation failure.
Since: PV2
path-clone-flatten
(path-clone-flatten [p :int] :ptr<void>)
copy a path with all curves approximated by line segments.
(ok handle) on success; (err 0) on allocation failure.
Since: PV2
path-clone-dashed
(path-clone-dashed [p :int offset :float dashes :int] :ptr<void>)
copy a path, replacing every segment with the
| p | source path handle | |
| offset | phase offset into the dash pattern | |
| dashes | dash-array handle (from plutovg/canvas dash-array-create / | |
| dash-array-add); empty buffer disables dashing |
(ok handle) on success; (err 0) on allocation failure. Release the returned path with path-destroy.
(let [da (ok-val (dash-array-create))]
(dash-array-add da 4.0) ; 4 on
(dash-array-add da 2.0) ; 2 off
(let [r (path-clone-dashed p 0.0 da)] ...)
(dash-array-destroy da))
Since: PV6
path-parse
(path-parse [p :int svg :cstr] :ptr<void>)
populate p with an SVG path-data string.
| p | destination path (existing contents are preserved; new commands | |
| are appended after the current point) | ||
| svg | SVG path-data, e.g. "M 10 20 L 30 40 Z" |
(ok 0) on success; (err 0) if plutovg rejected the string.
(path-parse p "M 0 0 L 4 0 L 4 4 Z")
Since: PV2
path-extents
(path-extents [p :int] :ptr<void>)
compute the bounding box of a path.
| p | path handle |
(ok rect-handle) holding x/y/w/h floats accessible via rect-x etc. Release with rect-destroy.
(let [r (path-extents p)]
(let [box (ok-val r)]
(println (rect-w box))
(rect-destroy box)))
Since: PV2
path-length
(path-length [p :int] :float)
compute the total length of all path segments in pixels.
| p | path handle |
Total path length as :float.
(println (path-length p))
Since: PV2
rect-destroy
(rect-destroy [box :int] :void)
release a rect allocated by path-extents / text-extents.
Since: PV2
rect-x
(rect-x [box :int] :float)
read the x component of a rect.
Since: PV2
rect-y
(rect-y [box :int] :float)
read the y component of a rect.
Since: PV2
rect-w
(rect-w [box :int] :float)
read the width of a rect.
Since: PV2
rect-h
(rect-h [box :int] :float)
read the height of a rect.
Since: PV2
Internal definitions
__ok-- create an ok result wrapping integer value v.__err-- create an err result wrapping integer error value e.