S or /

SourceClass PathBuilder

from skia import PathBuilder
class PathBuilder:

Constants§

AddMode: Final[type]§
ArcSize: Final[type]§
Direction: Final[type]§
FillType: Final[type]§

Properties§

Source@property def fill_type(self, /) -> PathFillType§

Returns PathFillType, the rule used to fill Path.

Returns

current PathFillType setting

Source@fill_type.setter def fill_type(self, /, fill_type: PathFillType) -> None§

Sets PathFillType, the rule used to fill Path. While there is no check that ft is legal, values outside of PathFillType are not supported.

Returns

reference to PathBuilder

Source@property def is_empty(self, /) -> bool§

Returns if Path is empty. Empty PathBuilder may have PathFillType but has no Point2d, PathVerb, or conic weight. PathBuilder() constructs empty PathBuilder; reset() and rewind() make Path empty.

Returns

true if the path contains no PathVerb array

Source@property def is_finite(self, /) -> bool§

Returns true if the builder is empty, or all of its points are finite.

Source@property def is_inverse_fill_type(self, /) -> bool§

Returns if PathFillType describes area outside Path geometry. The inverse fill area extends indefinitely.

Returns

true if PathFillType is PathFillType.InverseWinding or PathFillType.InverseEvenOdd

@is_inverse_fill_type.setter def is_inverse_fill_type(self, /, value: bool) -> None§
@property def is_volatile(self, /) -> bool§
Source@is_volatile.setter def is_volatile(self, /, value: bool) -> None§

Specifies whether Path is volatile; whether it will be altered or discarded by the caller after it is drawn. Path by default have volatile set false, allowing Skia to attach a cache of data which speeds repeated drawing.

Mark temporary paths, discarded or modified after use, as volatile to inform Skia that the path need not be cached.

Mark animating Path volatile to improve performance. Mark unchanging Path non-volatile to improve repeated rendering.

raster surface Path draws are affected by volatile for some shadows. GPU surface Path draws are affected by volatile for some shadows and concave geometries.

  • is_volatile true if caller will alter Path after drawing

Returns

reference to PathBuilder

Methods§

Sourcedef add_arc(self, /, rect: Any, start_angle: float, sweep_angle: float) -> None§

Appends arc to the builder, as the start of new contour. Arc added is part of ellipse bounded by oval, from start_angle through sweep_angle. Both start_angle and sweep_angle are measured in degrees, where zero degrees is aligned with the positive x-axis, and positive sweeps extends arc clockwise.

If sweep_angle <= -360, or sweep_angle >= 360; and start_angle modulo 90 is nearly zero, append oval instead of arc. Otherwise, sweep_angle values are treated modulo 360, and arc may or may not draw depending on numeric rounding.

Returns

reference to this builder

Sourcedef add_circle(self, /, cx: float, cy: float, radius: float, dir: PathDirection |None) -> None§

Adds circle centered at (x, y) of size radius to PathBuilder, appending PathVerb.Move, four PathVerb.Conic, and PathVerb.Close. Circle begins at: (x + radius, y), continuing clockwise if dir is PathDirection.CW, and counterclockwise if dir is PathDirection.CCW.

Has no effect if radius is zero or negative.

  • radius distance from center to edge
  • dir PathDirection to wind circle

Returns

reference to PathBuilder

Sourcedef add_line(self, /, x1: float, y1: float, x2: float, y2: float) -> None§
Sourcedef add_oval(self, /, rect: Any, direction: PathDirection |None, start: int |None = None) -> None§

Adds oval to PathBuilder, appending PathVerb.Move, four PathVerb.Conic, and PathVerb.Close. Oval is upright ellipse bounded by Rect oval with radii equal to half oval width and half oval height. Oval begins at (oval.right, oval.center_y()) and continues clockwise if dir is PathDirection.CW, counterclockwise if dir is PathDirection.CCW.

  • rect bounds of ellipse added

Returns

reference to PathBuilder

Sourcedef add_path(self, /, other: Path, *, transform: Matrix |None = None, mode: AddMode |None = None) -> None§

Appends src to PathBuilder.

If mode is path.AddPathMode.Append, src verb array, Point2d array, and conic weights are added unaltered. If mode is path.AddPathMode.Extend, add line before appending verbs, Point2d, and conic weights.

Returns

reference to PathBuilder

Sourcedef add_polygon(self, /, pypoints: Sequence[Any], close: bool) -> None§

Adds contour created from line array, adding (pts.len() - 1) line segments. Contour added starts at pts[0], then adds a line for every additional Point2d in pts array. If close is true, appends PathVerb.Close to Path, connecting pts[count - 1] and pts[0].

  • close true to add line connecting contour end and start

Returns

reference to PathBuilder

Sourcedef add_rect(self, /, rect: Any, direction: PathDirection |None, start: int |None = None) -> None§

Adds a new contour to the PathBuilder, defined by the rect, and wound in the specified direction. The verbs added to the path will be:

PathVerb.Move, PathVerb.Line, PathVerb.Line, PathVerb.Line, PathVerb.Close

start specifies which corner to begin the contour: 0: upper-left corner 1: upper-right corner 2: lower-right corner 3: lower-left corner

This start point also acts as the implied beginning of the subsequent, contour, if it does not have an explicit move_to(). e.g.

path.add_rect(...)
// if we don't say move_to() here, we will use the rect's start point
path.line_to(...)
  • rect Rect to add as a closed contour

Returns

reference to PathBuilder

Sourcedef add_rrect(self, /, rrect: RoundRect, direction: PathDirection |None, start: int |None = None) -> None§

Appends RoundRect to PathBuilder, creating a new closed contour. If dir is PathDirection.CW, RoundRect winds clockwise. If dir is PathDirection.CCW, RoundRect winds counterclockwise.

After appending, PathBuilder may be empty, or may contain: Rect, oval, or RoundRect.

Returns

reference to PathBuilder

Sourcedef arc_to(self, /, oval: Any, start_angle: float, sweep_angle: float, force_move_to: bool = False) -> None§

Appends arc to the builder. Arc added is part of ellipse bounded by oval, from start_angle through sweep_angle. Both start_angle and sweep_angle are measured in degrees, where zero degrees is aligned with the positive x-axis, and positive sweeps extends arc clockwise.

arc_to() adds line connecting the builder's last point to initial arc point if force_move_to is false and the builder is not empty. Otherwise, added contour begins with first point of arc. Angles greater than -360 and less than 360 are treated modulo 360.

  • oval bounds of ellipse containing arc

  • force_move_to true to start a new contour with arc

Returns

reference to the builder

Sourcedef arc_to_radius(self, /, rx: float, ry: float, x_rotate: float, size: ArcSize, sweep: PathDirection, x: float, y: float) -> None§

Appends arc to Path. Arc is implemented by one or more conic weighted to describe part of oval with radii (r.fX, r.fY) rotated by x_axis_rotate degrees. Arc curves from last Path Point2d to (xy.fX, xy.fY), choosing one of four possible routes: clockwise or counterclockwise, and smaller or larger.

Arc sweep is always less than 360 degrees. arc_to_radius() appends line to xy if either radii are zero, or if last Path Point2d equals (xy.fX, xy.fY). arc_to_radius() scales radii r to fit last Path Point2d and xy if both are greater than zero but too small to describe an arc.

arc_to_radius() appends up to four conic curves. arc_to_radius() implements the functionality of SVG arc, although SVG sweep-flag value is opposite the integer value of sweep; SVG sweep-flag uses 1 for clockwise, while PathDirection.CW cast to int is zero.

  • sweep chooses clockwise or counterclockwise arc

Returns

reference to PathBuilder

Sourcedef arc_to_tangent(self, /, x1: float, y1: float, x2: float, y2: float, radius: float) -> None§

Appends arc to Path, after appending line if needed. Arc is implemented by conic weighted to describe part of circle. Arc is contained by tangent from last Path point to p1, and tangent from p1 to p2. Arc is part of circle sized to radius, positioned so it touches both tangent lines.

If last Path Point2d does not start arc, arc_to() appends connecting line to Path. The length of vector from p1 to p2 does not affect arc.

Arc sweep is always less than 180 degrees. If radius is zero, or if tangents are nearly parallel, arc_to() appends line from last Path Point2d to p1.

arc_to() appends at most one line and one conic. arc_to() implements the functionality of PostScript arct and HTML Canvas arcTo.

  • radius distance from arc to circle center

Returns

reference to PathBuilder

Sourcedef close(self, /) -> None§

Appends PathVerb.Close to PathBuilder. A closed contour connects the first and last Point2d with line, forming a continuous loop. Open and closed contour draw the same with skia.PaintStyle.Fill. With skia.PaintStyle.Stroke, open contour draws skia.PaintCap at contour start and end; closed contour draws skia.PaintJoin at contour start and end.

close() has no effect if PathBuilder is empty or last PathVerb is PathVerb.Close.

Returns

reference to PathBuilder

Sourcedef compute_bounds(self, /) -> Rect§

Returns minimum and maximum axes values of Point2d array.

Returns

Bounds of all Point2d in Point2d array, or an empty Rect if the bounds are non-finite.

Deprecated

Use skia.PathBuilder.compute_finite_bounds() instead, which returns None when the bounds are non-finite.

Sourcedef compute_finite_bounds(self, /) -> Rect |None§

Returns minimum and maximum axes values of Point2d array. Returns None if PathBuilder contains no points.

Rect returned includes all Point2d added to PathBuilder, including Point2d associated with PathVerb.Move that define empty contours.

If any of the points are non-finite, returns None.

Returns

Bounds of all Point2d in Point2d array, or None.

Sourcedef compute_tight_bounds(self, /) -> Rect |None§

Like skia.PathBuilder.compute_finite_bounds() but returns a 'tight' bounds, meaning when there are curve segments, this computes the X/Y limits of the curve itself, not the curve's control point(s). For a polygon, this returns the same as skia.PathBuilder.compute_finite_bounds().

Sourcedef conic_to(self, /, x0: float, y0: float, x1: float, y1: float, w: float) -> None§

Adds conic from last point towards pt1, to pt2, weighted by w. If PathBuilder is empty, or last PathVerb is PathVerb.Close, last point is set to (0, 0) before adding conic.

Appends PathVerb.Move to verb array and (0, 0) to Point2d array, if needed.

If w is finite, positive, and not one, appends PathVerb.Conic to verb array; and pt1, pt2 to Point2d array; and w to conic weights.

If w is one, appends PathVerb.Quad to verb array, and pt1, pt2 to Point2d array.

If w is zero, this is the same as line_to(pt2).

If w is not finite, appends PathVerb.Line twice to verb array, and pt1, pt2 to Point2d array.

  • pt1 control Point2d of conic
  • pt2 end Point2d of conic
  • w weight of added conic

Returns

reference to PathBuilder

Sourcedef conic_weights(self, /) -> list[float]§
Sourcedef contains(self, /, x: float, y: float) -> bool§
Sourcedef count_points(self, /) -> int§

Returns the number of points in PathBuilder. Point2d count is initially zero.

Returns

PathBuilder Point2d array length

Sourcedef cubic_to(self, /, x0: float, y0: float, x1: float, y1: float, x2: float, y2: float) -> None§

Adds cubic from last point towards Point2d p1, then towards Point2d p2, ending at Point2d p3. If PathBuilder is empty, or last PathVerb is PathVerb.Close, last point is set to (0, 0) before adding cubic.

Appends PathVerb.Move to verb array and (0, 0) to Point2d array, if needed; then appends PathVerb.Cubic to verb array; and Point2d p1, p2, p3 to Point2d array.

Returns

reference to PathBuilder

Sourcedef detach(self, /, *, matrix: Matrix |None = None) -> Path§

Returns a Path representing the current state of the PathBuilder. The builder is reset to empty after returning the path.

Returns

Path representing the current state of the builder.

Sourcedef dump(self, /, format: str = "hex") -> str |None§

Dumps the path to stdout using the specified format.

Arguments

  • format - The format to use for dumping (Decimal or Hex)
@classmethod def from_path(cls, /, path: Path) -> PathBuilder§
def get_last_point(self, /) -> Point2d |None§
Sourcedef inc_reserve(self, /, extra_pt_count: int, extra_verb_count: int, extra_conic_count: int) -> None§

Grows PathBuilder verb array and Point2d array to contain additional space. May improve performance and use less memory by reducing the number and size of allocations when creating PathBuilder.

  • extra_pt_count number of additional Point2d to allocate
  • extra_verb_count number of additional verbs
  • extra_conic_count number of additional conic weights
Sourcedef line_to(self, /, x: float, y: float) -> None§

Adds line from last point to Point2d p. If PathBuilder is empty, or last PathVerb is PathVerb.Close, last point is set to (0, 0) before adding line.

line_to() first appends PathVerb.Move to verb array and (0, 0) to Point2d array, if needed. line_to() then appends PathVerb.Line to verb array and Point2d p to Point2d array.

Returns

reference to PathBuilder

Sourcedef move_to(self, /, x: float, y: float) -> None§

Specifies the beginning of contour. If the previous verb was a "move" verb, then this just replaces the point value of that move, otherwise it appends a new "move" verb to the builder using the point.

Thus, each contour can only have 1 move verb in it (the last one specified).

Sourcedef offset(self, /, dx: float, dy: float) -> None§

Offsets Point2d array by (dx, dy).

Returns

reference to PathBuilder

Sourcedef points(self, /) -> list[Point2d]§
Sourcedef polyline_to(self, /, pypoints: Sequence[Any]) -> None§

Append a series of line_to(...)

Returns

reference to PathBuilder

Sourcedef quad_to(self, /, x0: float, y0: float, x1: float, y1: float) -> None§

Adds quad from last point towards Point2d p1, to Point2d p2. If PathBuilder is empty, or last PathVerb is PathVerb.Close, last point is set to (0, 0) before adding quad.

Appends PathVerb.Move to verb array and (0, 0) to Point2d array, if needed; then appends PathVerb.Quad to verb array; and Point2d p1, p2 to Point2d array.

Returns

reference to PathBuilder

def rarc_to(self, /, rx: float, ry: float, x_rotate: float, size: ArcSize, sweep: PathDirection, x: float, y: float) -> None§
def rconic_to(self, /, dx0: float, dy0: float, dx1: float, dy1: float, w: float) -> None§
def rcubic_to(self, /, dx0: float, dy0: float, dx1: float, dy1: float, dx2: float, dy2: float) -> None§
Sourcedef reset(self, /) -> None§

Sets PathBuilder to its initial state. Removes verb array, Point2d array, and weights, and sets PathFillType to PathFillType.Winding. Internal storage associated with PathBuilder is preserved.

Returns

reference to PathBuilder

def rline_to(self, /, dx: float, dy: float) -> None§
def rmove_to(self, /, dx: float, dy: float) -> None§
def rquad_to(self, /, dx0: float, dy0: float, dx1: float, dy1: float) -> None§
Sourcedef set_last_point(self, /, x: float, y: float) -> None§

Change the last point in the builder. If the builder is empty, the call does nothing.

Sourcedef set_point(self, /, index: int, px: float, py: float) -> None§

Change the point at the specified index (see count_points()). If index is out of range, the call does nothing.

  • index which point to replace
Sourcedef snapshot(self, /, *, matrix: Matrix |None = None) -> Path§

Returns a Path representing the current state of the PathBuilder. The builder is unchanged after returning the path.

Returns

Path representing the current state of the builder.

Sourcedef transform(self, /, matrix: Matrix) -> None§

Transforms verb array, Point2d array, and weight by matrix. transform may change verbs and increase their number.

Returns

reference to PathBuilder

Sourcedef verbs(self, /) -> list[str]§