Remove references to old SkPaint::Hinting. Also fix bug recently introduced that made unlinkable words use the last link found. TBR=reed@google.com Docs-Preview: https://skia.org/?cl=170266 Bug: skia: Change-Id: I8b83bcb479bd3f79699a1c74818a817190fd42a5 Reviewed-on: https://skia-review.googlesource.com/c/170266 Commit-Queue: Cary Clark <caryclark@skia.org> Auto-Submit: Cary Clark <caryclark@skia.org> Reviewed-by: Cary Clark <caryclark@skia.org>
290 KiB
SkPath Reference
class SkPath { public: enum Direction : int { kCW_Direction, kCCW_Direction, }; SkPath(); SkPath(const SkPath& path); ~SkPath(); SkPath& operator=(const SkPath& path); friend bool operator==(const SkPath& a, const SkPath& b); friend bool operator!=(const SkPath& a, const SkPath& b); bool isInterpolatable(const SkPath& compare) const; bool interpolate(const SkPath& ending, SkScalar weight, SkPath* out) const; bool unique() const; enum FillType { kWinding_FillType, kEvenOdd_FillType, kInverseWinding_FillType, kInverseEvenOdd_FillType, }; FillType getFillType() const; void setFillType(FillType ft); bool isInverseFillType() const; void toggleInverseFillType(); enum Convexity : uint8_t { kUnknown_Convexity, kConvex_Convexity, kConcave_Convexity, }; Convexity getConvexity() const; Convexity getConvexityOrUnknown() const; void setConvexity(Convexity convexity); bool isConvex() const; bool isOval(SkRect* bounds) const; bool isRRect(SkRRect* rrect) const; SkPath& reset(); SkPath& rewind(); bool isEmpty() const; bool isLastContourClosed() const; bool isFinite() const; bool isVolatile() const; void setIsVolatile(bool isVolatile); static bool IsLineDegenerate(const SkPoint& p1, const SkPoint& p2, bool exact); static bool IsQuadDegenerate(const SkPoint& p1, const SkPoint& p2, const SkPoint& p3, bool exact); static bool IsCubicDegenerate(const SkPoint& p1, const SkPoint& p2, const SkPoint& p3, const SkPoint& p4, bool exact); bool isLine(SkPoint line[2]) const; int countPoints() const; SkPoint getPoint(int index) const; int getPoints(SkPoint points[], int max) const; int countVerbs() const; int getVerbs(uint8_t verbs[], int max) const; void swap(SkPath& other); const SkRect& getBounds() const; void updateBoundsCache() const; SkRect computeTightBounds() const; bool conservativelyContainsRect(const SkRect& rect) const; void incReserve(int extraPtCount); void shrinkToFit(); SkPath& moveTo(SkScalar x, SkScalar y); SkPath& moveTo(const SkPoint& p); SkPath& rMoveTo(SkScalar dx, SkScalar dy); SkPath& lineTo(SkScalar x, SkScalar y); SkPath& lineTo(const SkPoint& p); SkPath& rLineTo(SkScalar dx, SkScalar dy); SkPath& quadTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2); SkPath& quadTo(const SkPoint& p1, const SkPoint& p2); SkPath& rQuadTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2); SkPath& conicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar w); SkPath& conicTo(const SkPoint& p1, const SkPoint& p2, SkScalar w); SkPath& rConicTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2, SkScalar w); SkPath& cubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar x3, SkScalar y3); SkPath& cubicTo(const SkPoint& p1, const SkPoint& p2, const SkPoint& p3); SkPath& rCubicTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2, SkScalar dx3, SkScalar dy3); SkPath& arcTo(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, bool forceMoveTo); SkPath& arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar radius); SkPath& arcTo(const SkPoint p1, const SkPoint p2, SkScalar radius); enum ArcSize { kSmall_ArcSize, kLarge_ArcSize, }; SkPath& arcTo(SkScalar rx, SkScalar ry, SkScalar xAxisRotate, ArcSize largeArc, Direction sweep, SkScalar x, SkScalar y); SkPath& arcTo(const SkPoint r, SkScalar xAxisRotate, ArcSize largeArc, Direction sweep, const SkPoint xy); SkPath& rArcTo(SkScalar rx, SkScalar ry, SkScalar xAxisRotate, ArcSize largeArc, Direction sweep, SkScalar dx, SkScalar dy); SkPath& close(); static bool IsInverseFillType(FillType fill); static FillType ConvertToNonInverseFillType(FillType fill); static int ConvertConicToQuads(const SkPoint& p0, const SkPoint& p1, const SkPoint& p2, SkScalar w, SkPoint pts[], int pow2); bool isRect(SkRect* rect, bool* isClosed = nullptr, Direction* direction = nullptr) const; bool isNestedFillRects(SkRect rect[2], Direction dirs[2] = nullptr) const; SkPath& addRect(const SkRect& rect, Direction dir = kCW_Direction); SkPath& addRect(const SkRect& rect, Direction dir, unsigned start); SkPath& addRect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom, Direction dir = kCW_Direction); SkPath& addOval(const SkRect& oval, Direction dir = kCW_Direction); SkPath& addOval(const SkRect& oval, Direction dir, unsigned start); SkPath& addCircle(SkScalar x, SkScalar y, SkScalar radius, Direction dir = kCW_Direction); SkPath& addArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle); SkPath& addRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry, Direction dir = kCW_Direction); SkPath& addRoundRect(const SkRect& rect, const SkScalar radii[], Direction dir = kCW_Direction); SkPath& addRRect(const SkRRect& rrect, Direction dir = kCW_Direction); SkPath& addRRect(const SkRRect& rrect, Direction dir, unsigned start); SkPath& addPoly(const SkPoint pts[], int count, bool close); SkPath& addPoly(const std::initializer_list<SkPoint>& list, bool close); enum AddPathMode { kAppend_AddPathMode, kExtend_AddPathMode, }; SkPath& addPath(const SkPath& src, SkScalar dx, SkScalar dy, AddPathMode mode = kAppend_AddPathMode); SkPath& addPath(const SkPath& src, AddPathMode mode = kAppend_AddPathMode); SkPath& addPath(const SkPath& src, const SkMatrix& matrix, AddPathMode mode = kAppend_AddPathMode); SkPath& reverseAddPath(const SkPath& src); void offset(SkScalar dx, SkScalar dy, SkPath* dst) const; void offset(SkScalar dx, SkScalar dy); void transform(const SkMatrix& matrix, SkPath* dst) const; void transform(const SkMatrix& matrix); bool getLastPt(SkPoint* lastPt) const; void setLastPt(SkScalar x, SkScalar y); void setLastPt(const SkPoint& p); enum SegmentMask { kLine_SegmentMask = 1 << 0, kQuad_SegmentMask = 1 << 1, kConic_SegmentMask = 1 << 2, kCubic_SegmentMask = 1 << 3, }; uint32_t getSegmentMasks() const; enum Verb { kMove_Verb, kLine_Verb, kQuad_Verb, kConic_Verb, kCubic_Verb, kClose_Verb, kDone_Verb, }; class Iter { public: Iter(); Iter(const SkPath& path, bool forceClose); void setPath(const SkPath& path, bool forceClose); Verb next(SkPoint pts[4], bool doConsumeDegenerates = true, bool exact = false); SkScalar conicWeight() const; bool isCloseLine() const; bool isClosedContour() const; }; class RawIter { public: RawIter(); RawIter(const SkPath& path); void setPath(const SkPath& path); Verb next(SkPoint pts[4]); Verb peek() const; SkScalar conicWeight() const; }; bool contains(SkScalar x, SkScalar y) const; void dump(SkWStream* stream, bool forceClose, bool dumpAsHex) const; void dump() const; void dumpHex() const; size_t writeToMemory(void* buffer) const; sk_sp<SkData> serialize() const; size_t readFromMemory(const void* buffer, size_t length); uint32_t getGenerationID() const; bool isValid() const; bool isValid() const; bool pathRefIsValid() const; };
Paths contain geometry. Paths may be empty, or contain one or more Verbs that outline a figure. Path always starts with a move verb to a Cartesian_Coordinate, and may be followed by additional verbs that add lines or curves. Adding a close verb makes the geometry into a continuous loop, a closed contour. Paths may contain any number of contours, each beginning with a move verb.
Path contours may contain only a move verb, or may also contain lines, Quadratic_Beziers, Conics, and Cubic_Beziers. Path contours may be open or closed.
When used to draw a filled area, Path describes whether the fill is inside or outside the geometry. Path also describes the winding rule used to fill overlapping contours.
Internally, Path lazily computes metrics likes bounds and convexity. Call SkPath::updateBoundsCache to make Path thread safe.
enum Verb { kMove_Verb, kLine_Verb, kQuad_Verb, kConic_Verb, kCubic_Verb, kClose_Verb, kDone_Verb, };
Verb instructs Path how to interpret one or more Point and optional Conic_Weight; manage Contour, and terminate Path.
Constants
Each Verb has zero or more Points stored in Path. Path iterator returns complete curve descriptions, duplicating shared Points for consecutive entries.Const | Value | Description |
---|---|---|
SkPath::kMove_Verb |
0 | Consecutive kMove_Verb are preserved but all but the last kMove_Verb is ignored. kMove_Verb after other Verbs implicitly closes the previous Contour if SkPaint::kFill_Style is set when drawn; otherwise, stroke is drawn open. kMove_Verb as the last Verb is preserved but ignored. |
SkPath::kLine_Verb |
1 | Line is a straight segment from Point to Point. Consecutive kLine_Verb extend Contour. kLine_Verb at same position as prior kMove_Verb is preserved, and draws Point if SkPaint::kStroke_Style is set, and SkPaint::Cap is SkPaint::kSquare_Cap or SkPaint::kRound_Cap. kLine_Verb at same position as prior line or curve Verb is preserved but is ignored. |
SkPath::kQuad_Verb |
2 | Adds Quad from Last_Point, using control Point, and end Point. Quad is a parabolic section within tangents from Last_Point to control Point, and control Point to end Point. |
SkPath::kConic_Verb |
3 | Adds Conic from Last_Point, using control Point, end Point, and Conic_Weight. Conic is a elliptical, parabolic, or hyperbolic section within tangents from Last_Point to control Point, and control Point to end Point, constrained by Conic_Weight. Conic_Weight less than one is elliptical; equal to one is parabolic (and identical to Quad); greater than one hyperbolic. |
SkPath::kCubic_Verb |
4 | Adds Cubic from Last_Point, using two control Points, and end Point. Cubic is a third-order Bezier_Curve section within tangents from Last_Point to first control Point, and from second control Point to end Point. |
SkPath::kClose_Verb |
5 | Closes Contour, connecting Last_Point to kMove_Verb Point. Consecutive kClose_Verb are preserved but only first has an effect. kClose_Verb after kMove_Verb has no effect. |
SkPath::kDone_Verb |
6 | Not in Verb_Array, but returned by Path iterator. |
Verb | Allocated Points | Iterated Points | Weights |
---|---|---|---|
kMove_Verb | 1 | 1 | 0 |
kLine_Verb | 1 | 2 | 0 |
kQuad_Verb | 2 | 3 | 0 |
kConic_Verb | 2 | 3 | 1 |
kCubic_Verb | 3 | 4 | 0 |
kClose_Verb | 0 | 1 | 0 |
kDone_Verb | -- | 0 | 0 |
Example
Example Output
verb count: 7
verbs: kMove_Verb kLine_Verb kQuad_Verb kClose_Verb kMove_Verb kCubic_Verb kConic_Verb
enum Direction : int { kCW_Direction, kCCW_Direction, };
Direction describes whether Contour is clockwise or counterclockwise. When Path contains multiple overlapping Contours, Direction together with Fill_Type determines whether overlaps are filled or form holes.
Direction also determines how Contour is measured. For instance, dashing measures along Path to determine where to start and stop stroke; Direction will change dashed results as it steps clockwise or counterclockwise.
Closed Contours like Rect, Round_Rect, Circle, and Oval added with kCW_Direction travel clockwise; the same added with kCCW_Direction travel counterclockwise.
Constants
Const | Value | Description |
---|---|---|
SkPath::kCW_Direction |
0 | contour travels clockwise |
SkPath::kCCW_Direction |
1 | contour travels counterclockwise |
Example
See Also
arcTo rArcTo isRect isNestedFillRects addRect addOval
SkPath()
Constructs an empty SkPath. By default, SkPath has no verbs, no SkPoint, and no weights. SkPath::FillType is set to kWinding_FillType.
Return Value
empty SkPath
Example
Example Output
path is empty
See Also
SkPath(const SkPath& path)
Constructs a copy of an existing path. Copy constructor makes two paths identical by value. Internally, path and the returned result share pointer values. The underlying verb array, SkPoint array and weights are copied when modified.
Creating a SkPath copy is very efficient and never allocates memory. SkPath are always copied by value from the interface; the underlying shared pointers are not exposed.
Parameters
path |
SkPath to copy by value |
Return Value
copy of SkPath
Example
Example Output
path verbs: 2
path2 verbs: 3
after reset
path verbs: 0
path2 verbs: 3
See Also
~SkPath()
Releases ownership of any shared data and deletes data if SkPath is sole owner.
Example
See Also
SkPath() SkPath()SkPath(const SkPath& path) SkPath(const SkPath& path)operator=(const SkPath& path)
SkPath& operator=(const SkPath& path)
Constructs a copy of an existing path. SkPath assignment makes two paths identical by value. Internally, assignment shares pointer values. The underlying verb array, SkPoint array and weights are copied when modified.
Copying SkPath by assignment is very efficient and never allocates memory. SkPath are always copied by value from the interface; the underlying shared pointers are not exposed.
Parameters
path |
verb array, SkPoint array, weights, and SkPath::FillType to copy |
Return Value
SkPath copied by value
Example
Example Output
path1 bounds = 10, 20, 30, 40
path2 bounds = 10, 20, 30, 40
See Also
swap swapSkPath(const SkPath& path)
bool operator==(const SkPath& a, const SkPath& b)
Compares a and b; returns true if SkPath::FillType, verb array, SkPoint array, and weights are equivalent.
Parameters
a |
SkPath to compare |
b |
SkPath to compare |
Return Value
true if SkPath pair are equivalent
Example
Example Output
empty one == two
moveTo one != two
rewind one == two
reset one == two
See Also
operator!=(const SkPath& a, const SkPath& b) operator!=(const SkPath& a, const SkPath& b)operator=(const SkPath& path)
bool operator!=(const SkPath& a, const SkPath& b)
Compares a and b; returns true if SkPath::FillType, verb array, SkPoint array, and weights are not equivalent.
Parameters
a |
SkPath to compare |
b |
SkPath to compare |
Return Value
true if SkPath pair are not equivalent
Example
Example Output
empty one == two
add rect one == two
setConvexity one == two
convexity !=
bool isInterpolatable(const SkPath& compare) const
Returns true if SkPath contain equal verbs and equal weights. If SkPath contain one or more conics, the weights must match.
conicTo() may add different verbs depending on conic weight, so it is not trivial to interpolate a pair of SkPath containing conics with different conic weight values.
Parameters
compare |
SkPath to compare |
Return Value
true if SkPath verb array and weights are equivalent
Example
Example Output
paths are interpolatable
See Also
bool interpolate(const SkPath& ending, SkScalar weight, SkPath* out) const
Interpolates between Paths with Point_Array of equal size.
Copy Verb_Array and Weights to out, and set out Point_Array to a weighted
average of this Point_Array and ending Point_Array, using the formula:
(Path Point * weight) + ending Point * (1 - weight)
.
weight is most useful when between zero (ending Point_Array) and one (this Point_Array); will work with values outside of this range.
interpolate() returns false and leaves out unchanged if Point_Array is not the same size as ending Point_Array. Call isInterpolatable to check Path compatibility prior to calling interpolate().
Parameters
ending |
Point_Array averaged with this Point_Array |
weight |
contribution of this Point_Array, and one minus contribution of ending Point_Array |
out |
Path replaced by interpolated averages |
Return Value
true if Paths contain same number of Points
Example
See Also
bool unique() const
To be deprecated soon.
Only valid for Android framework.
enum FillType { kWinding_FillType, kEvenOdd_FillType, kInverseWinding_FillType, kInverseEvenOdd_FillType, };
Fill_Type selects the rule used to fill Path. Path set to kWinding_FillType fills if the sum of Contour edges is not zero, where clockwise edges add one, and counterclockwise edges subtract one. Path set to kEvenOdd_FillType fills if the number of Contour edges is odd. Each Fill_Type has an inverse variant that reverses the rule: kInverseWinding_FillType fills where the sum of Contour edges is zero; kInverseEvenOdd_FillType fills where the number of Contour edges is even.
Example
Constants
Const | Value | Description |
---|---|---|
SkPath::kWinding_FillType |
0 | is enclosed by a non-zero sum of Contour Directions |
SkPath::kEvenOdd_FillType |
1 | is enclosed by an odd number of Contours |
SkPath::kInverseWinding_FillType |
2 | is enclosed by a zero sum of Contour Directions |
SkPath::kInverseEvenOdd_FillType |
3 | is enclosed by an even number of Contours |
Example
See Also
SkPaint::Style Direction getFillType setFillType
FillType getFillType() const
Returns FillType, the rule used to fill SkPath. FillType of a new SkPath is kWinding_FillType.
Return Value
one of: kWinding_FillType, kEvenOdd_FillType, kInverseWinding_FillType,
Example
Example Output
default path fill type is kWinding_FillType
See Also
FillType setFillType isInverseFillType
void setFillType(FillType ft)
Sets FillType, the rule used to fill SkPath. While there is no check that ft is legal, values outside of FillType are not supported.
Parameters
ft |
one of: kWinding_FillType, kEvenOdd_FillType, kInverseWinding_FillType, |
Example
See Also
FillType getFillType toggleInverseFillType
bool isInverseFillType() const
Returns if FillType describes area outside SkPath geometry. The inverse fill area extends indefinitely.
Return Value
true if FillType is kInverseWinding_FillType or kInverseEvenOdd_FillType
Example
Example Output
default path fill type is inverse: false
See Also
FillType getFillType setFillType toggleInverseFillType
void toggleInverseFillType()
Replaces FillType with its inverse. The inverse of FillType describes the area unmodified by the original FillType.
FillType | toggled FillType |
---|---|
kWinding_FillType | kInverseWinding_FillType |
kEvenOdd_FillType | kInverseEvenOdd_FillType |
kInverseWinding_FillType | kWinding_FillType |
kInverseEvenOdd_FillType | kEvenOdd_FillType |
Example
See Also
FillType getFillType setFillType isInverseFillType
enum Convexity : uint8_t { kUnknown_Convexity, kConvex_Convexity, kConcave_Convexity, };
Path is convex if it contains one Contour and Contour loops no more than 360 degrees, and Contour angles all have same Direction. Convex Path may have better performance and require fewer resources on GPU_Surface.
Path is concave when either at least one Direction change is clockwise and another is counterclockwise, or the sum of the changes in Direction is not 360 degrees.
Initially Path Convexity is kUnknown_Convexity. Path Convexity is computed if needed by destination Surface.
Constants
Const | Value | Description |
---|---|---|
SkPath::kUnknown_Convexity |
0 | indicates Convexity has not been determined |
SkPath::kConvex_Convexity |
1 | one Contour made of a simple geometry without indentations |
SkPath::kConcave_Convexity |
2 | more than one Contour, or a geometry with indentations |
Example
See Also
Contour Direction getConvexity getConvexityOrUnknown setConvexity isConvex
Convexity getConvexity() const
Computes SkPath::Convexity if required, and returns stored value. SkPath::Convexity is computed if stored value is kUnknown_Convexity, or if SkPath has been altered since SkPath::Convexity was computed or set.
Return Value
computed or stored SkPath::Convexity
Example
See Also
Convexity Contour Direction getConvexityOrUnknown setConvexity isConvex
Convexity getConvexityOrUnknown() const
Returns last computed SkPath::Convexity, or kUnknown_Convexity if SkPath has been altered since SkPath::Convexity was computed or set.
Return Value
Example
See Also
Convexity Contour Direction getConvexity setConvexity isConvex
void setConvexity(Convexity convexity)
Stores convexity so that it is later returned by getConvexity() or getConvexityOrUnknown(). convexity may differ from getConvexity(), although setting an incorrect value may cause incorrect or inefficient drawing.
If convexity is kUnknown_Convexity: getConvexity() will compute SkPath::Convexity, and getConvexityOrUnknown() will return kUnknown_Convexity.
If convexity is kConvex_Convexity or kConcave_Convexity, getConvexity() and getConvexityOrUnknown() will return convexity until the path is altered.
Parameters
convexity |
one of: kUnknown_Convexity, kConvex_Convexity, or kConcave_Convexity |
Example
See Also
Convexity Contour Direction getConvexity getConvexityOrUnknown isConvex
bool isConvex() const
Computes SkPath::Convexity if required, and returns true if value is kConvex_Convexity. If setConvexity() was called with kConvex_Convexity or kConcave_Convexity, and the path has not been altered, SkPath::Convexity is not recomputed.
Return Value
true if SkPath::Convexity stored or computed is kConvex_Convexity
Example
See Also
Convexity Contour Direction getConvexity getConvexityOrUnknown setConvexity
bool isOval(SkRect* bounds) const
Returns true if this path is recognized as an oval or circle.
bounds receives bounds of oval.
bounds is unmodified if oval is not found.
Parameters
bounds |
storage for bounding SkRect of oval; may be nullptr |
Return Value
true if SkPath is recognized as an oval or circle
Example
See Also
bool isRRect(SkRRect* rrect) const
Returns true if path is representable as SkRRect. Returns false if path is representable as oval, circle, or SkRect.
rrect receives bounds of SkRRect.
rrect is unmodified if SkRRect is not found.
Parameters
rrect |
storage for bounding SkRect of SkRRect; may be nullptr |
Return Value
true if SkPath contains only SkRRect
Example
See Also
Round_Rect addRoundRect addRRect
SkPath& reset()
Sets SkPath to its initial state. Removes verb array, SkPoint array, and weights, and sets FillType to kWinding_FillType. Internal storage associated with SkPath is released.
Return Value
reference to SkPath
Example
See Also
SkPath& rewind()
Sets SkPath to its initial state, preserving internal storage. Removes verb array, SkPoint array, and weights, and sets FillType to kWinding_FillType. Internal storage associated with SkPath is retained.
Use rewind() instead of reset() if SkPath storage will be reused and performance is critical.
Return Value
reference to SkPath
Example
See Also
bool isEmpty() const
Returns if SkPath is empty. Empty SkPath may have FillType but has no SkPoint, SkPath::Verb, or conic weight. SkPath() constructs empty SkPath; reset() and rewind() make SkPath empty.
Return Value
true if the path contains no SkPath::Verb array
Example
Example Output
initial path is empty
after moveTo path is not empty
after rewind path is empty
after lineTo path is not empty
after reset path is empty
See Also
bool isLastContourClosed() const
Returns if contour is closed. Contour is closed if SkPath SkPath::Verb array was last modified by close(). When stroked, closed contour draws SkPaint::Join instead of SkPaint::Cap at first and last SkPoint.
Return Value
true if the last contour ends with a kClose_Verb
Example
Example Output
initial last contour is not closed
after close last contour is not closed
after lineTo last contour is not closed
after close last contour is closed
See Also
bool isFinite() const
Returns true for finite SkPoint array values between negative SK_ScalarMax and positive SK_ScalarMax. Returns false for any SkPoint array value of SK_ScalarInfinity, SK_ScalarNegativeInfinity, or SK_ScalarNaN.
Return Value
true if all SkPoint values are finite
Example
Example Output
initial path is finite
after line path is finite
after scale path is not finite
See Also
bool isVolatile() const
Returns true if the path is volatile; it will not be altered or discarded by the caller after it is drawn. SkPath by default have volatile set false, allowing SkSurface to attach a cache of data which speeds repeated drawing. If true, SkSurface may not speed repeated drawing.
Return Value
true if caller will alter SkPath after drawing
Example
Example Output
volatile by default is false
See Also
void setIsVolatile(bool isVolatile)
Specifies whether SkPath is volatile; whether it will be altered or discarded by the caller after it is drawn. SkPath by default have volatile set false, allowing SkBaseDevice to attach a cache of data which speeds repeated drawing.
Mark temporary paths, discarded or modified after use, as volatile to inform SkBaseDevice that the path need not be cached.
Mark animating SkPath volatile to improve performance. Mark unchanging SkPath non-volatile to improve repeated rendering.
raster surface SkPath draws are affected by volatile for some shadows. GPU surface SkPath draws are affected by volatile for some shadows and concave geometries.
Parameters
isVolatile |
true if caller will alter SkPath after drawing |
Example
See Also
static bool IsLineDegenerate(const SkPoint& p1, const SkPoint& p2, bool exact)
Tests if line between SkPoint pair is degenerate. Line with no length or that moves a very short distance is degenerate; it is treated as a point.
exact changes the equality test. If true, returns true only if p1 equals p2. If false, returns true if p1 equals or nearly equals p2.
Parameters
p1 |
line start point |
p2 |
line end point |
exact |
if false, allow nearly equals |
Return Value
true if line is degenerate; its length is effectively zero
Example
Example Output
line from (100,100) to (100,100) is degenerate, nearly
line from (100,100) to (100,100) is degenerate, exactly
line from (100,100) to (100.0001,100.0001) is degenerate, nearly
line from (100,100) to (100.0001,100.0001) is not degenerate, exactly
See Also
IsQuadDegenerate IsCubicDegenerate
static bool IsQuadDegenerate(const SkPoint& p1, const SkPoint& p2, const SkPoint& p3, bool exact)
Tests if quad is degenerate. Quad with no length or that moves a very short distance is degenerate; it is treated as a point.
Parameters
p1 |
quad start point |
p2 |
quad control point |
p3 |
quad end point |
exact |
if true, returns true only if p1, p2, and p3 are equal; |
if false, returns true if p1, p2, and p3 are equal or nearly equal
Return Value
true if quad is degenerate; its length is effectively zero
Example
Example Output
quad (100,100), (100.00001,100.00001), (100.00002,100.00002) is degenerate, nearly
quad (1100,1100), (1100,1100), (1100,1100) is degenerate, nearly
quad (100,100), (100.00001,100.00001), (100.00002,100.00002) is not degenerate, exactly
quad (1100,1100), (1100,1100), (1100,1100) is degenerate, exactly
See Also
IsLineDegenerate IsCubicDegenerate
static bool IsCubicDegenerate(const SkPoint& p1, const SkPoint& p2, const SkPoint& p3, const SkPoint& p4, bool exact)
Tests if cubic is degenerate. Cubic with no length or that moves a very short distance is degenerate; it is treated as a point.
Parameters
p1 |
cubic start point |
p2 |
cubic control point 1 |
p3 |
cubic control point 2 |
p4 |
cubic end point |
exact |
if true, returns true only if p1, p2, p3, and p4 are equal; |
if false, returns true if p1, p2, p3, and p4 are equal or nearly equal
Return Value
true if cubic is degenerate; its length is effectively zero
Example
Example Output
0.00024414062 is degenerate
0.00024414065 is length
bool isLine(SkPoint line[2]) const
Returns true if SkPath contains only one line; SkPath::Verb array has two entries: kMove_Verb, kLine_Verb. If SkPath contains one line and line is not nullptr, line is set to line start point and line end point. Returns false if SkPath is not one line; line is unaltered.
Parameters
line |
storage for line. May be nullptr |
Return Value
true if SkPath contains exactly one line
Example
Example Output
empty is not line
zero line is line (0,0) (0,0)
line is line (10,10) (20,20)
second move is not line
Point_Array contains Points satisfying the allocated Points for each Verb in Verb_Array. For instance, Path containing one Contour with Line and Quad is described by Verb_Array: kMove_Verb, kLine_Verb, kQuad_Verb; and one Point for move, one Point for Line, two Points for Quad; totaling four Points.
Point_Array may be read directly from Path with getPoints, or inspected with getPoint, with Iter, or with RawIter.
int getPoints(SkPoint points[], int max) const
Returns number of points in SkPath. Up to max points are copied. points may be nullptr; then, max must be zero. If max is greater than number of points, excess points storage is unaltered.
Parameters
points |
storage for SkPath SkPoint array. May be nullptr |
max |
maximum to copy; must be greater than or equal to zero |
Return Value
SkPath SkPoint array length
Example
Example Output
no points point count: 3
zero max point count: 3
too small point count: 3 (0,0) (20,20)
just right point count: 3 (0,0) (20,20) (-10,-10)
See Also
int countPoints() const
Returns the number of points in SkPath. SkPoint count is initially zero.
Return Value
Example
Example Output
empty point count: 0
zero line point count: 2
line point count: 2
second move point count: 3
See Also
SkPoint getPoint(int index) const
Returns SkPoint at index in SkPoint array. Valid range for index is 0 to countPoints() - 1. Returns (0, 0) if index is out of range.
Parameters
index |
SkPoint array element selector |
Return Value
SkPoint array value or (0, 0)
Example
Example Output
point 0: (-10,-10)
point 1: (10,10)
See Also
Verb_Array always starts with kMove_Verb. If kClose_Verb is not the last entry, it is always followed by kMove_Verb; the quantity of kMove_Verb equals the Contour count. Verb_Array does not include or count kDone_Verb; it is a convenience returned when iterating through Verb_Array.
Verb_Array may be read directly from Path with getVerbs, or inspected with Iter, or with RawIter.
int countVerbs() const
Returns the number of verbs: kMove_Verb, kLine_Verb, kQuad_Verb, kConic_Verb, kCubic_Verb, and kClose_Verb; added to SkPath.
Return Value
length of verb array
Example
Example Output
empty verb count: 0
round rect verb count: 10
See Also
int getVerbs(uint8_t verbs[], int max) const
Returns the number of verbs in the path. Up to max verbs are copied. The verbs are copied as one byte per verb.
Parameters
verbs |
storage for verbs, may be nullptr |
max |
maximum number to copy into verbs |
Return Value
the actual number of verbs in the path
Example
Example Output
no verbs verb count: 3
zero max verb count: 3
too small verb count: 3 move line
just right verb count: 3 move line line
See Also
countVerbs getPoints Iter RawIter
void swap(SkPath& other)
Exchanges the verb array, SkPoint array, weights, and SkPath::FillType with other. Cached state is also exchanged. swap() internally exchanges pointers, so it is lightweight and does not allocate memory.
swap() usage has largely been replaced by byoperator=(const SkPath& path). SkPath do not copy their content on assignment until they are written to, making assignment as efficient as swap().
Parameters
other |
SkPath exchanged by value |
Example
Example Output
path1 bounds = 0, 0, 0, 0
path2 bounds = 10, 20, 30, 40
See Also
const SkRect& getBounds() const
Returns minimum and maximum axes values of SkPoint array. Returns (0, 0, 0, 0) if SkPath contains no points. Returned bounds width and height may be larger or smaller than area affected when SkPath is drawn.
SkRect returned includes all SkPoint added to SkPath, including SkPoint associated with kMove_Verb that define empty contours.
Return Value
bounds of all SkPoint in SkPoint array
Example
Example Output
empty bounds = 0, 0, 0, 0
circle bounds = 25, 20, 75, 70
rotated circle bounds = 14.6447, 9.64466, 85.3553, 80.3553
See Also
computeTightBounds updateBoundsCache
void updateBoundsCache() const
Updates internal bounds so that subsequent calls to getBounds() are instantaneous. Unaltered copies of SkPath may also access cached bounds through getBounds().
For now, identical to calling getBounds() and ignoring the returned value.
Call to prepare SkPath subsequently drawn from multiple threads, to avoid a race condition where each draw separately computes the bounds.
Example
Example Output
#Volatile
uncached avg: 0.18048 ms
cached avg: 0.182784 ms
See Also
SkRect computeTightBounds() const
Returns minimum and maximum axes values of the lines and curves in SkPath. Returns (0, 0, 0, 0) if SkPath contains no points. Returned bounds width and height may be larger or smaller than area affected when SkPath is drawn.
Includes SkPoint associated with kMove_Verb that define empty contours.
Behaves identically to getBounds() when SkPath contains only lines. If SkPath contains curves, computed bounds includes the maximum extent of the quad, conic, or cubic; is slower than getBounds(); and unlike getBounds(), does not cache the result.
Return Value
tight bounds of curves in SkPath
Example
Example Output
empty bounds = 0, 0, 0, 0
circle bounds = 25, 20, 75, 70
rotated circle bounds = 25, 20, 75, 70
See Also
bool conservativelyContainsRect(const SkRect& rect) const
Returns true if rect is contained by SkPath. May return false when rect is contained by SkPath.
For now, only returns true if SkPath has one contour and is convex. rect may share points and edges with SkPath and be contained. Returns true if rect is empty, that is, it has zero width or height; and the SkPoint or line described by rect is contained by SkPath.
Parameters
rect |
SkRect, line, or SkPoint checked for containment |
Return Value
true if rect is contained
Example
See Also
void incReserve(int extraPtCount)
Grows SkPath verb array and SkPoint array to contain extraPtCount additional SkPoint. May improve performance and use less memory by reducing the number and size of allocations when creating SkPath.
Parameters
extraPtCount |
number of additional SkPoint to allocate |
Example
See Also
void shrinkToFit()
Shrinks SkPath verb array and SkPoint array storage to discard unused capacity. May reduce the heap overhead for SkPath known to be fully constructed.
See Also
SkPath& moveTo(SkScalar x, SkScalar y)
Adds beginning of contour at SkPoint (x, y).
Parameters
x |
x-axis value of contour start |
y |
y-axis value of contour start |
Return Value
reference to SkPath
Example
See Also
Contour lineTo rMoveTo quadTo conicTo cubicTo close()
SkPath& moveTo(const SkPoint& p)
Adds beginning of contour at SkPoint p.
Parameters
p |
contour start |
Return Value
reference to SkPath
Example
See Also
Contour lineTo rMoveTo quadTo conicTo cubicTo close()
SkPath& rMoveTo(SkScalar dx, SkScalar dy)
Adds beginning of contour relative to last point. If SkPath is empty, starts contour at (dx, dy). Otherwise, start contour at last point offset by (dx, dy). Function name stands for "relative move to".
Parameters
dx |
offset from last point to contour start on x-axis |
dy |
offset from last point to contour start on y-axis |
Return Value
reference to SkPath
Example
See Also
Contour lineTo moveTo quadTo conicTo cubicTo close()
SkPath& lineTo(SkScalar x, SkScalar y)
Adds line from last point to (x, y). If SkPath is empty, or last SkPath::Verb is kClose_Verb, last point is set to (0, 0) before adding line.
lineTo() appends kMove_Verb to verb array and (0, 0) to SkPoint array, if needed. lineTo() then appends kLine_Verb to verb array and (x, y) to SkPoint array.
Parameters
x |
end of added line on x-axis |
y |
end of added line on y-axis |
Return Value
reference to SkPath
Example
See Also
Contour moveTo rLineTo addRect
SkPath& lineTo(const SkPoint& p)
Adds line from last point to SkPoint p. If SkPath is empty, or last SkPath::Verb is kClose_Verb, last point is set to (0, 0) before adding line.
lineTo() first appends kMove_Verb to verb array and (0, 0) to SkPoint array, if needed. lineTo() then appends kLine_Verb to verb array and SkPoint p to SkPoint array.
Parameters
p |
end SkPoint of added line |
Return Value
reference to SkPath
Example
See Also
Contour moveTo rLineTo addRect
SkPath& rLineTo(SkScalar dx, SkScalar dy)
Adds line from last point to vector (dx, dy). If SkPath is empty, or last SkPath::Verb is kClose_Verb, last point is set to (0, 0) before adding line.
Appends kMove_Verb to verb array and (0, 0) to SkPoint array, if needed; then appends kLine_Verb to verb array and line end to SkPoint array. Line end is last point plus vector (dx, dy). Function name stands for "relative line to".
Parameters
dx |
offset from last point to line end on x-axis |
dy |
offset from last point to line end on y-axis |
Return Value
reference to SkPath
Example
See Also
Quad describes a Quadratic_Bezier, a second-order curve identical to a section of a parabola. Quad begins at a start Point, curves towards a control Point, and then curves to an end Point.
Example
Quad is a special case of Conic where Conic_Weight is set to one.
Quad is always contained by the triangle connecting its three Points. Quad begins tangent to the line between start Point and control Point, and ends tangent to the line between control Point and end Point.
Example
SkPath& quadTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2)
Adds quad from last point towards (x1, y1), to (x2, y2). If SkPath is empty, or last SkPath::Verb is kClose_Verb, last point is set to (0, 0) before adding quad.
Appends kMove_Verb to verb array and (0, 0) to SkPoint array, if needed; then appends kQuad_Verb to verb array; and (x1, y1), (x2, y2) to SkPoint array.
Parameters
x1 |
control SkPoint of quad on x-axis |
y1 |
control SkPoint of quad on y-axis |
x2 |
end SkPoint of quad on x-axis |
y2 |
end SkPoint of quad on y-axis |
Return Value
reference to SkPath
Example
See Also
Contour moveTo conicTo rQuadTo
SkPath& quadTo(const SkPoint& p1, const SkPoint& p2)
Adds quad from last point towards SkPoint p1, to SkPoint p2. If SkPath is empty, or last SkPath::Verb is kClose_Verb, last point is set to (0, 0) before adding quad.
Appends kMove_Verb to verb array and (0, 0) to SkPoint array, if needed; then appends kQuad_Verb to verb array; and SkPoint p1, p2 to SkPoint array.
Parameters
p1 |
control SkPoint of added quad |
p2 |
end SkPoint of added quad |
Return Value
reference to SkPath
Example
See Also
Contour moveTo conicTo rQuadTo
SkPath& rQuadTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2)
Adds quad from last point towards vector (dx1, dy1), to vector (dx2, dy2). If SkPath is empty, or last SkPath::Verb is kClose_Verb, last point is set to (0, 0) before adding quad.
Appends kMove_Verb to verb array and (0, 0) to SkPoint array, if needed; then appends kQuad_Verb to verb array; and appends quad control and quad end to SkPoint array. Quad control is last point plus vector (dx1, dy1). Quad end is last point plus vector (dx2, dy2). Function name stands for "relative quad to".
Parameters
dx1 |
offset from last point to quad control on x-axis |
dy1 |
offset from last point to quad control on y-axis |
dx2 |
offset from last point to quad end on x-axis |
dy2 |
offset from last point to quad end on y-axis |
Return Value
reference to SkPath
Example
See Also
Conic describes a conical section: a piece of an ellipse, or a piece of a parabola, or a piece of a hyperbola. Conic begins at a start Point, curves towards a control Point, and then curves to an end Point. The influence of the control Point is determined by Conic_Weight.
Each Conic in Path adds two Points and one Conic_Weight. Conic_Weights in Path may be inspected with Iter, or with RawIter.
Weight determines both the strength of the control Point and the type of Conic. Weight varies from zero to infinity. At zero, Weight causes the control Point to have no effect; Conic is identical to a line segment from start Point to end point. If Weight is less than one, Conic follows an elliptical arc. If Weight is exactly one, then Conic is identical to Quad; Conic follows a parabolic arc. If Weight is greater than one, Conic follows a hyperbolic arc. If Weight is infinity, Conic is identical to two line segments, connecting start Point to control Point, and control Point to end Point.
Example
Example Output
move {0, 0},
quad {0, 0}, {20, 30}, {50, 60},
done
If weight is less than one, Conic is an elliptical segment.
Example
Example Output
move {0, 0},
conic {0, 0}, {20, 0}, {20, 20}, weight = 0.707107
done
If weight is greater than one, Conic is a hyperbolic segment. As weight gets large, a hyperbolic segment can be approximated by straight lines connecting the control Point with the end Points.
Example
Example Output
move {0, 0},
line {0, 0}, {20, 0},
line {20, 0}, {20, 20},
done
SkPath& conicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar w)
Adds conic from last point towards (x1, y1), to (x2, y2), weighted by w. If SkPath is empty, or last SkPath::Verb is kClose_Verb, last point is set to (0, 0) before adding conic.
Appends kMove_Verb to verb array and (0, 0) to SkPoint array, if needed.
If w is finite and not one, appends kConic_Verb to verb array; and (x1, y1), (x2, y2) to SkPoint array; and w to conic weights.
If w is one, appends kQuad_Verb to verb array, and (x1, y1), (x2, y2) to SkPoint array.
If w is not finite, appends kLine_Verb twice to verb array, and (x1, y1), (x2, y2) to SkPoint array.
Parameters
x1 |
control SkPoint of conic on x-axis |
y1 |
control SkPoint of conic on y-axis |
x2 |
end SkPoint of conic on x-axis |
y2 |
end SkPoint of conic on y-axis |
w |
weight of added conic |
Return Value
reference to SkPath
Example
See Also
SkPath& conicTo(const SkPoint& p1, const SkPoint& p2, SkScalar w)
Adds conic from last point towards SkPoint p1, to SkPoint p2, weighted by w. If SkPath is empty, or last SkPath::Verb is kClose_Verb, last point is set to (0, 0) before adding conic.
Appends kMove_Verb to verb array and (0, 0) to SkPoint array, if needed.
If w is finite and not one, appends kConic_Verb to verb array; and SkPoint p1, p2 to SkPoint array; and w to conic weights.
If w is one, appends kQuad_Verb to verb array, and SkPoint p1, p2 to SkPoint array.
If w is not finite, appends kLine_Verb twice to verb array, and SkPoint p1, p2 to SkPoint array.
Parameters
p1 |
control SkPoint of added conic |
p2 |
end SkPoint of added conic |
w |
weight of added conic |
Return Value
reference to SkPath
Example
See Also
SkPath& rConicTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2, SkScalar w)
Adds conic from last point towards vector (dx1, dy1), to vector (dx2, dy2), weighted by w. If SkPath is empty, or last SkPath::Verb is kClose_Verb, last point is set to (0, 0) before adding conic.
Appends kMove_Verb to verb array and (0, 0) to SkPoint array, if needed.
If w is finite and not one, next appends kConic_Verb to verb array, and w is recorded as conic weight; otherwise, if w is one, appends kQuad_Verb to verb array; or if w is not finite, appends kLine_Verb twice to verb array.
In all cases appends SkPoint control and end to SkPoint array. control is last point plus vector (dx1, dy1). end is last point plus vector (dx2, dy2).
Function name stands for "relative conic to".
Parameters
dx1 |
offset from last point to conic control on x-axis |
dy1 |
offset from last point to conic control on y-axis |
dx2 |
offset from last point to conic end on x-axis |
dy2 |
offset from last point to conic end on y-axis |
w |
weight of added conic |
Return Value
reference to SkPath
Example
See Also
Cubic describes a Bezier_Curve segment described by a third-order polynomial. Cubic begins at a start Point, curving towards the first control Point; and curves from the end Point towards the second control Point.
Example
SkPath& cubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar x3, SkScalar y3)
Adds cubic from last point towards (x1, y1), then towards (x2, y2), ending at (x3, y3). If SkPath is empty, or last SkPath::Verb is kClose_Verb, last point is set to (0, 0) before adding cubic.
Appends kMove_Verb to verb array and (0, 0) to SkPoint array, if needed; then appends kCubic_Verb to verb array; and (x1, y1), (x2, y2), (x3, y3) to SkPoint array.
Parameters
x1 |
first control SkPoint of cubic on x-axis |
y1 |
first control SkPoint of cubic on y-axis |
x2 |
second control SkPoint of cubic on x-axis |
y2 |
second control SkPoint of cubic on y-axis |
x3 |
end SkPoint of cubic on x-axis |
y3 |
end SkPoint of cubic on y-axis |
Return Value
reference to SkPath
Example
See Also
Contour moveTo rCubicTo quadTo
SkPath& cubicTo(const SkPoint& p1, const SkPoint& p2, const SkPoint& p3)
Adds cubic from last point towards SkPoint p1, then towards SkPoint p2, ending at SkPoint p3. If SkPath is empty, or last SkPath::Verb is kClose_Verb, last point is set to (0, 0) before adding cubic.
Appends kMove_Verb to verb array and (0, 0) to SkPoint array, if needed; then appends kCubic_Verb to verb array; and SkPoint p1, p2, p3 to SkPoint array.
Parameters
p1 |
first control SkPoint of cubic |
p2 |
second control SkPoint of cubic |
p3 |
end SkPoint of cubic |
Return Value
reference to SkPath
Example
See Also
Contour moveTo rCubicTo quadTo
SkPath& rCubicTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2, SkScalar dx3, SkScalar dy3)
Adds cubic from last point towards vector (dx1, dy1), then towards vector (dx2, dy2), to vector (dx3, dy3). If SkPath is empty, or last SkPath::Verb is kClose_Verb, last point is set to (0, 0) before adding cubic.
Appends kMove_Verb to verb array and (0, 0) to SkPoint array, if needed; then appends kCubic_Verb to verb array; and appends cubic control and cubic end to SkPoint array. Cubic control is last point plus vector (dx1, dy1). Cubic end is last point plus vector (dx2, dy2). Function name stands for "relative cubic to".
Parameters
dx1 |
offset from last point to first cubic control on x-axis |
dy1 |
offset from last point to first cubic control on y-axis |
dx2 |
offset from last point to second cubic control on x-axis |
dy2 |
offset from last point to second cubic control on y-axis |
dx3 |
offset from last point to cubic end on x-axis |
dy3 |
offset from last point to cubic end on y-axis |
Return Value
reference to SkPath
Example
See Also
Arc can be constructed in a number of ways. Arc may be described by part of Oval and angles, by start point and end point, and by radius and tangent lines. Each construction has advantages, and some constructions correspond to Arc drawing in graphics standards.
All Arc draws are implemented by one or more Conic draws. When Conic_Weight is less than one, Conic describes an Arc of some Oval or Circle.
CirclearcTo(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, bool forceMoveTo) describes Arc as a piece of Oval, beginning at start angle, sweeping clockwise or counterclockwise, which may continue Contour or start a new one. This construction is similar to PostScript and HTML_Canvas arcs. Variation addArc always starts new Contour. SkCanvas::drawArc draws without requiring Path.
PatharcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar radius) describes Arc as tangent to the line segment from last Point added to Path to (x1, y1); and tangent to the line segment from (x1, y1) to (x2, y2). This construction is similar to PostScript and HTML_Canvas arcs.
arcsarcTo(SkScalar rx, SkScalar ry, SkScalar xAxisRotate, ArcSize largeArc, Direction sweep, SkScalar x, SkScalar y) describes Arc as part of Oval with radii (rx, ry), beginning at last Point added to Path and ending at (x, y). More than one Arc satisfies this criteria, so additional values choose a single solution. This construction is similar to SVG arcs.
conicTo describes Arc of less than 180 degrees as a pair of tangent lines and Conic_Weight. conicTo can represent any Arc with a sweep less than 180 degrees at any rotation. All arcTo constructions are converted to Conic data when added to Path.
1 suparcTo(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, bool forceMoveTo) |
2 parameter adds move to first point |
3 start angle must be multiple of 90 degrees |
4 suparcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar radius) |
5 suparcTo(SkScalar rx, SkScalar ry, SkScalar xAxisRotate, ArcSize largeArc, Direction sweep, SkScalar x, SkScalar y) |
Example
In the example above:
1 describes an arc from an oval, a starting angle, and a sweep angle. |
2 is similar to 1, but does not require building a path to draw. |
3 is similar to 1, but always begins new Contour. |
4 describes an arc from a pair of tangent lines and a radius. |
5 describes an arc from Oval center, arc start Point and arc end Point. |
6 describes an arc from a pair of tangent lines and a Conic_Weight. |
SkPath& arcTo(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, bool forceMoveTo)
Appends arc to SkPath. Arc added is part of ellipse bounded by oval, from startAngle through sweepAngle. Both startAngle and sweepAngle are measured in degrees, where zero degrees is aligned with the positive x-axis, and positive sweeps extends arc clockwise.
arcTo() adds line connecting SkPath last SkPoint to initial arc SkPoint if forceMoveTo is false and SkPath is not empty. Otherwise, added contour begins with first point of arc. Angles greater than -360 and less than 360 are treated modulo 360.
Parameters
oval |
bounds of ellipse containing arc |
startAngle |
starting angle of arc in degrees |
sweepAngle |
sweep, in degrees. Positive is clockwise; treated modulo 360 |
forceMoveTo |
true to start a new contour with arc |
Return Value
reference to SkPath
Example
See Also
addArc SkCanvas::drawArc conicTo
SkPath& arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar radius)
Appends arc to SkPath, after appending line if needed. Arc is implemented by conic weighted to describe part of circle. Arc is contained by tangent from last SkPath point to (x1, y1), and tangent from (x1, y1) to (x2, y2). Arc is part of circle sized to radius, positioned so it touches both tangent lines.
If last Path Point does not start Arc, arcTo appends connecting Line to Path. The length of Vector from (x1, y1) to (x2, y2) does not affect Arc.
Arc sweep is always less than 180 degrees. If radius is zero, or if tangents are nearly parallel, arcTo appends Line from last Path Point to (x1, y1).
arcTo appends at most one Line and one conic. arcTo implements the functionality of PostScript arct and HTML Canvas arcTo.
Parameters
x1 |
x-axis value common to pair of tangents |
y1 |
y-axis value common to pair of tangents |
x2 |
x-axis value end of second tangent |
y2 |
y-axis value end of second tangent |
radius |
distance from arc to circle center |
Return Value
reference to SkPath
Example
Example
Example
Example Output
move to (156,20)
line (156,20),(79.2893,20)
conic (79.2893,20),(200,20),(114.645,105.355) weight 0.382683
See Also
SkPath& arcTo(const SkPoint p1, const SkPoint p2, SkScalar radius)
Appends arc to SkPath, after appending line if needed. Arc is implemented by conic weighted to describe part of circle. Arc is contained by tangent from last SkPath 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 SkPath SkPoint does not start arc, arcTo() appends connecting line to SkPath. 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, arcTo() appends line from last SkPath SkPoint to p1.
arcTo() appends at most one line and one conic. arcTo() implements the functionality of PostScript arct and HTML Canvas arcTo.
Parameters
p1 |
SkPoint common to pair of tangents |
p2 |
end of second tangent |
radius |
distance from arc to circle center |
Return Value
reference to SkPath
Example
Example Output
move to (156,20)
line (156,20),(200,20)
See Also
enum ArcSize { kSmall_ArcSize, kLarge_ArcSize, };
Four axis-aligned Ovals with the same height and width intersect a pair of Points. ArcSize and Direction select one of the four Ovals, by choosing the larger or smaller arc between the Points; and by choosing the arc Direction, clockwise or counterclockwise.
Constants
Const | Value | Description |
---|---|---|
SkPath::kSmall_ArcSize |
0 | smaller of Arc pair |
SkPath::kLarge_ArcSize |
1 | larger of Arc pair |
Example
See Also
SkPath& arcTo(SkScalar rx, SkScalar ry, SkScalar xAxisRotate, ArcSize largeArc, Direction sweep, SkScalar x, SkScalar y)
Appends arc to SkPath. Arc is implemented by one or more conics weighted to describe part of oval with radii (rx, ry) rotated by xAxisRotate degrees. Arc curves from last SkPath SkPoint to (x, y), choosing one of four possible routes: clockwise or counterclockwise, and smaller or larger.
Arc sweep is always less than 360 degrees. arcTo() appends line to (x, y) if either radii are zero, or if last SkPath SkPoint equals (x, y). arcTo() scales radii (rx, ry) to fit last SkPath SkPoint and (x, y) if both are greater than zero but too small.
arcTo() appends up to four conic curves. arcTo() 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 kCW_Direction cast to int is zero.
Parameters
rx |
radius on x-axis before x-axis rotation |
ry |
radius on y-axis before x-axis rotation |
xAxisRotate |
x-axis rotation in degrees; positive values are clockwise |
largeArc |
chooses smaller or larger arc |
sweep |
chooses clockwise or counterclockwise arc |
x |
end of arc |
y |
end of arc |
Return Value
reference to SkPath
Example
See Also
SkPath& arcTo(const SkPoint r, SkScalar xAxisRotate, ArcSize largeArc, Direction sweep, const SkPoint xy)
Appends arc to SkPath. Arc is implemented by one or more conic weighted to describe part of oval with radii (r.fX, r.fY) rotated by xAxisRotate degrees. Arc curves from last SkPath SkPoint 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. arcTo() appends line to xy if either radii are zero, or if last SkPath SkPoint equals (xy.fX, xy.fY). arcTo() scales radii r to fit last SkPath SkPoint and xy if both are greater than zero but too small to describe an arc.
arcTo() appends up to four conic curves. arcTo() 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 kCW_Direction cast to int is zero.
Parameters
r |
radii on axes before x-axis rotation |
xAxisRotate |
x-axis rotation in degrees; positive values are clockwise |
largeArc |
chooses smaller or larger arc |
sweep |
chooses clockwise or counterclockwise arc |
xy |
end of arc |
Return Value
reference to SkPath
Example
See Also
SkPath& rArcTo(SkScalar rx, SkScalar ry, SkScalar xAxisRotate, ArcSize largeArc, Direction sweep, SkScalar dx, SkScalar dy)
Appends Arc to Path, relative to last Path Point. Arc is implemented by one or more Conic, weighted to describe part of Oval with radii (rx, ry) rotated by xAxisRotate degrees. Arc curves from last Path Point to relative end Point (dx, dy), choosing one of four possible routes: clockwise or counterclockwise, and smaller or larger. If Path is empty, the start Arc Point is (0, 0).
Arc sweep is always less than 360 degrees. arcTo appends Line to end Point if either radii are zero, or if last Path Point equals end Point. arcTo scales radii (rx, ry) to fit last Path Point and end Point if both are greater than zero but too small to describe an arc.
arcTo appends up to four Conic curves. arcTo 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 kCW_Direction cast to int is zero.
Parameters
rx |
radius before x-axis rotation |
ry |
radius before x-axis rotation |
xAxisRotate |
x-axis rotation in degrees; positive values are clockwise |
largeArc |
chooses smaller or larger Arc |
sweep |
chooses clockwise or counterclockwise Arc |
dx |
x-axis offset end of Arc from last Path Point |
dy |
y-axis offset end of Arc from last Path Point |
Return Value
reference to Path
Example
See Also
SkPath& close()
Appends kClose_Verb to SkPath. A closed contour connects the first and last SkPoint with line, forming a continuous loop. Open and closed contour draw the same with SkPaint::kFill_Style. With SkPaint::kStroke_Style, open contour draws SkPaint::Cap at contour start and end; closed contour draws SkPaint::Join at contour start and end.
close() has no effect if SkPath is empty or last SkPath SkPath::Verb is kClose_Verb.
Return Value
reference to SkPath
Example
See Also
static bool IsInverseFillType(FillType fill)
Returns true if fill is inverted and Path with fill represents area outside of its geometric bounds.
FillType | is inverse |
---|---|
kWinding_FillType | false |
kEvenOdd_FillType | false |
kInverseWinding_FillType | true |
kInverseEvenOdd_FillType | true |
Parameters
fill |
one of: kWinding_FillType, kEvenOdd_FillType, kInverseWinding_FillType, kInverseEvenOdd_FillType |
Return Value
true if Path fills outside its bounds
Example
Example Output
IsInverseFillType(kWinding_FillType) == false
IsInverseFillType(kEvenOdd_FillType) == false
IsInverseFillType(kInverseWinding_FillType) == true
IsInverseFillType(kInverseEvenOdd_FillType) == true
See Also
FillType getFillType setFillType ConvertToNonInverseFillType
static FillType ConvertToNonInverseFillType(FillType fill)
Returns equivalent Fill_Type representing Path fill inside its bounds.
FillType | inside FillType |
---|---|
kWinding_FillType | kWinding_FillType |
kEvenOdd_FillType | kEvenOdd_FillType |
kInverseWinding_FillType | kWinding_FillType |
kInverseEvenOdd_FillType | kEvenOdd_FillType |
Parameters
fill |
one of: kWinding_FillType, kEvenOdd_FillType, kInverseWinding_FillType, kInverseEvenOdd_FillType |
Return Value
fill, or kWinding_FillType or kEvenOdd_FillType if fill is inverted
Example
Example Output
ConvertToNonInverseFillType(kWinding_FillType) == kWinding_FillType
ConvertToNonInverseFillType(kEvenOdd_FillType) == kEvenOdd_FillType
ConvertToNonInverseFillType(kInverseWinding_FillType) == kWinding_FillType
ConvertToNonInverseFillType(kInverseEvenOdd_FillType) == kEvenOdd_FillType
See Also
FillType getFillType setFillType IsInverseFillType
static int ConvertConicToQuads(const SkPoint& p0, const SkPoint& p1, const SkPoint& p2, SkScalar w, SkPoint pts[], int pow2)
Approximates Conic with Quad array. Conic is constructed from start Point p0,
control Point p1, end Point p2, and weight w.
Quad array is stored in pts; this storage is supplied by caller.
Maximum Quad count is 2 to the pow2.
Every third point in array shares last Point of previous Quad and first Point of
next Quad. Maximum pts storage size is given by:
(1 + 2 * (1 << pow2)) * sizeof(SkPoint)
.
Returns Quad count used the approximation, which may be smaller than the number requested.
Conic_Weight determines the amount of influence Conic control point has on the curve. w less than one represents an elliptical section. w greater than one represents a hyperbolic section. w equal to one represents a parabolic section.
Two Quad curves are sufficient to approximate an elliptical Conic with a sweep of up to 90 degrees; in this case, set pow2 to one.
Parameters
p0 |
Conic start Point |
p1 |
Conic control Point |
p2 |
Conic end Point |
w |
Conic weight |
pts |
storage for Quad array |
pow2 |
Quad count, as power of two, normally 0 to 5 (1 to 32 Quad curves) |
Return Value
number of Quad curves written to pts
Example
See Also
bool isRect(SkRect* rect, bool* isClosed = nullptr, Direction* direction = nullptr) const
Returns true if SkPath is equivalent to SkRect when filled. If false: rect, isClosed, and direction are unchanged. If true: rect, isClosed, and direction are written to if not nullptr.
rect may be smaller than the SkPath bounds. SkPath bounds may include kMove_Verb points that do not alter the area drawn by the returned rect.
Parameters
rect |
storage for bounds of SkRect; may be nullptr |
isClosed |
storage set to true if SkPath is closed; may be nullptr |
direction |
storage set to SkRect direction; may be nullptr |
Return Value
true if SkPath contains SkRect
Example
Example Output
empty is not rect
addRect is rect (10, 20, 30, 40); is closed; direction CW
moveTo is rect (10, 20, 30, 40); is closed; direction CW
lineTo is not rect
addPoly is rect (0, 0, 80, 80); is not closed; direction CCW
See Also
computeTightBounds conservativelyContainsRect getBounds isConvex isLastContourClosed isNestedFillRects
bool isNestedFillRects(SkRect rect[2], Direction dirs[2] = nullptr) const
Returns true if SkPath is equivalent to nested SkRect pair when filled. If false, rect and dirs are unchanged. If true, rect and dirs are written to if not nullptr: setting rect[0] to outer SkRect, and rect[1] to inner SkRect; setting dirs[0] to SkPath::Direction of outer SkRect, and dirs[1] to SkPath::Direction of inner SkRect.
Parameters
rect |
storage for SkRect pair; may be nullptr |
dirs |
storage for SkPath::Direction pair; may be nullptr |
Return Value
true if SkPath contains nested SkRect pair
Example
Example Output
outer (7.5, 17.5, 32.5, 42.5); direction CW
inner (12.5, 22.5, 27.5, 37.5); direction CCW
See Also
computeTightBounds conservativelyContainsRect getBounds isConvex isLastContourClosed isRect
SkPath& addRect(const SkRect& rect, Direction dir = kCW_Direction)
Adds SkRect to SkPath, appending kMove_Verb, three kLine_Verb, and kClose_Verb, starting with top-left corner of SkRect; followed by top-right, bottom-right, and bottom-left if dir is kCW_Direction; or followed by bottom-left, bottom-right, and top-right if dir is kCCW_Direction.
Parameters
rect |
SkRect to add as a closed contour |
dir |
SkPath::Direction to wind added contour |
Return Value
reference to SkPath
Example
See Also
SkPath& addRect(const SkRect& rect, Direction dir, unsigned start)
Adds Rect to Path, appending kMove_Verb, three kLine_Verb, and kClose_Verb. If dir is kCW_Direction, Rect corners are added clockwise; if dir is kCCW_Direction, Rect corners are added counterclockwise. start determines the first corner added.
start | first corner |
---|---|
0 | top-left |
1 | top-right |
2 | bottom-right |
3 | bottom-left |
Parameters
rect |
Rect to add as a closed contour |
dir |
Direction to wind added contour |
start |
initial corner of Rect to add |
Return Value
reference to Path
Example
See Also
SkPath& addRect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom, Direction dir = kCW_Direction)
Adds SkRect (left, top, right, bottom) to SkPath, appending kMove_Verb, three kLine_Verb, and kClose_Verb, starting with top-left corner of SkRect; followed by top-right, bottom-right, and bottom-left if dir is kCW_Direction; or followed by bottom-left, bottom-right, and top-right if dir is kCCW_Direction.
Parameters
left |
smaller x-axis value of SkRect |
top |
smaller y-axis value of SkRect |
right |
larger x-axis value of SkRect |
bottom |
larger y-axis value of SkRect |
dir |
SkPath::Direction to wind added contour |
Return Value
reference to SkPath
Example
See Also
SkPath& addOval(const SkRect& oval, Direction dir = kCW_Direction)
Adds oval to path, appending kMove_Verb, four kConic_Verb, and kClose_Verb. Oval is upright ellipse bounded by SkRect oval with radii equal to half oval width and half oval height. Oval begins at (oval.fRight, oval.centerY()) and continues clockwise if dir is kCW_Direction, counterclockwise if dir is kCCW_Direction.
Parameters
oval |
bounds of ellipse added |
dir |
SkPath::Direction to wind ellipse |
Return Value
reference to SkPath
Example
See Also
SkCanvas::drawOval Direction Oval
SkPath& addOval(const SkRect& oval, Direction dir, unsigned start)
Adds Oval to Path, appending kMove_Verb, four kConic_Verb, and kClose_Verb. Oval is upright ellipse bounded by Rect oval with radii equal to half oval width and half oval height. Oval begins at start and continues clockwise if dir is kCW_Direction, counterclockwise if dir is kCCW_Direction.
start | Point |
---|---|
0 | oval.centerX(), oval.fTop |
1 | oval.fRight, oval.centerY() |
2 | oval.centerX(), oval.fBottom |
3 | oval.fLeft, oval.centerY() |
Parameters
oval |
bounds of ellipse added |
dir |
Direction to wind ellipse |
start |
index of initial point of ellipse |
Return Value
reference to Path
Example
See Also
SkCanvas::drawOval Direction Oval
SkPath& addCircle(SkScalar x, SkScalar y, SkScalar radius, Direction dir = kCW_Direction)
Adds Circle centered at (x, y) of size radius to Path, appending kMove_Verb,
four kConic_Verb, and kClose_Verb. Circle begins at: (x + radius, y)
, continuing
clockwise if dir is kCW_Direction, and counterclockwise if dir is kCCW_Direction.
Has no effect if radius is zero or negative.
Parameters
x |
center of Circle |
y |
center of Circle |
radius |
distance from center to edge |
dir |
Direction to wind Circle |
Return Value
reference to Path
Example
See Also
SkCanvas::drawCircle Direction Circle
SkPath& addArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle)
Appends arc to SkPath, as the start of new contour. Arc added is part of ellipse bounded by oval, from startAngle through sweepAngle. Both startAngle and sweepAngle are measured in degrees, where zero degrees is aligned with the positive x-axis, and positive sweeps extends arc clockwise.
If sweepAngle <= -360, or sweepAngle >= 360; and startAngle modulo 90 is nearly zero, append oval instead of arc. Otherwise, sweepAngle values are treated modulo 360, and arc may or may not draw depending on numeric rounding.
Parameters
oval |
bounds of ellipse containing arc |
startAngle |
starting angle of arc in degrees |
sweepAngle |
sweep, in degrees. Positive is clockwise; treated modulo 360 |
Return Value
reference to SkPath
Example
See Also
SkPath& addRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry, Direction dir = kCW_Direction)
Appends SkRRect to SkPath, creating a new closed contour. SkRRect has bounds equal to rect; each corner is 90 degrees of an ellipse with radii (rx, ry). If dir is kCW_Direction, SkRRect starts at top-left of the lower-left corner and winds clockwise. If dir is kCCW_Direction, SkRRect starts at the bottom-left of the upper-left corner and winds counterclockwise.
If either rx or ry is too large, rx and ry are scaled uniformly until the corners fit. If rx or ry is less than or equal to zero, addRoundRect() appends SkRect rect to SkPath.
After appending, SkPath may be empty, or may contain: SkRect, oval, or SkRRect.
Parameters
rect |
bounds of SkRRect |
rx |
x-axis radius of rounded corners on the SkRRect |
ry |
y-axis radius of rounded corners on the SkRRect |
dir |
SkPath::Direction to wind SkRRect |
Return Value
reference to SkPath
Example
See Also
addRRect SkCanvas::drawRoundRect
SkPath& addRoundRect(const SkRect& rect, const SkScalar radii[], Direction dir = kCW_Direction)
Appends Round_Rect to Path, creating a new closed Contour. Round_Rect has bounds equal to rect; each corner is 90 degrees of an ellipse with radii from the array.
radii index | location |
---|---|
0 | x-axis radius of top-left corner |
1 | y-axis radius of top-left corner |
2 | x-axis radius of top-right corner |
3 | y-axis radius of top-right corner |
4 | x-axis radius of bottom-right corner |
5 | y-axis radius of bottom-right corner |
6 | x-axis radius of bottom-left corner |
7 | y-axis radius of bottom-left corner |
If dir is kCW_Direction, Round_Rect starts at top-left of the lower-left corner and winds clockwise. If dir is kCCW_Direction, Round_Rect starts at the bottom-left of the upper-left corner and winds counterclockwise.
If both radii on any side of rect exceed its length, all radii are scaled uniformly until the corners fit. If either radius of a corner is less than or equal to zero, both are treated as zero.
After appending, Path may be empty, or may contain: Rect, Oval, or Round_Rect.
Parameters
rect |
bounds of Round_Rect |
radii |
array of 8 SkScalar values, a radius pair for each corner |
dir |
Direction to wind Round_Rect |
Return Value
reference to Path
Example
See Also
addRRect SkCanvas::drawRoundRect
SkPath& addRRect(const SkRRect& rrect, Direction dir = kCW_Direction)
Adds rrect to SkPath, creating a new closed contour. If dir is kCW_Direction, rrect starts at top-left of the lower-left corner and winds clockwise. If dir is kCCW_Direction, rrect starts at the bottom-left of the upper-left corner and winds counterclockwise.
After appending, SkPath may be empty, or may contain: SkRect, oval, or SkRRect.
Parameters
rrect |
bounds and radii of rounded rectangle |
dir |
SkPath::Direction to wind SkRRect |
Return Value
reference to SkPath
Example
See Also
addRoundRect SkCanvas::drawRRect
SkPath& addRRect(const SkRRect& rrect, Direction dir, unsigned start)
Adds rrect to Path, creating a new closed Contour. If dir is kCW_Direction, rrect winds clockwise; if dir is kCCW_Direction, rrect winds counterclockwise. start determines the first point of rrect to add.
start | location |
---|---|
0 | right of top-left corner |
1 | left of top-right corner |
2 | bottom of top-right corner |
3 | top of bottom-right corner |
4 | left of bottom-right corner |
5 | right of bottom-left corner |
6 | top of bottom-left corner |
7 | bottom of top-left corner |
After appending, Path may be empty, or may contain: Rect, Oval, or Round_Rect.
Parameters
rrect |
bounds and radii of rounded rectangle |
dir |
Direction to wind Round_Rect |
start |
index of initial point of Round_Rect |
Return Value
reference to Path
Example
See Also
addRoundRect SkCanvas::drawRRect
SkPath& addPoly(const SkPoint pts[], int count, bool close)
Adds contour created from line array, adding (count - 1) line segments. Contour added starts at pts[0], then adds a line for every additional SkPoint in pts array. If close is true, appends kClose_Verb to SkPath, connecting pts[count - 1] and pts[0].
If count is zero, append kMove_Verb to path. Has no effect if count is less than one.
Parameters
pts |
array of line sharing end and start SkPoint |
count |
length of SkPoint array |
close |
true to add line connecting contour end and start |
Return Value
reference to SkPath
Example
See Also
SkPath& addPoly(const std::initializer_list<SkPoint>& list, bool close)
Adds contour created from list. Contour added starts at list[0], then adds a line for every additional SkPoint in list. If close is true, appends kClose_Verb to SkPath, connecting last and first SkPoint in list.
If list is empty, append kMove_Verb to path.
Parameters
list |
array of SkPoint |
close |
true to add line connecting contour end and start |
Return Value
reference to SkPath
Example
See Also
enum AddPathMode { kAppend_AddPathMode, kExtend_AddPathMode, };
AddPathMode chooses how addPath appends. Adding one Path to another can extend the last Contour or start a new Contour.
Constants
Const | Value | Description |
---|---|---|
SkPath::kAppend_AddPathMode |
#Line # appended to destination unaltered ## | Path Verbs, Points, and Conic_Weights are appended to destination unaltered. Since Path Verb_Array begins with kMove_Verb if src is not empty, this starts a new Contour. |
SkPath::kExtend_AddPathMode |
#Line # add line if prior Contour is not closed ## | If destination is closed or empty, start a new Contour. If destination is not empty, add Line from Last_Point to added Path first Point. Skip added Path initial kMove_Verb, then append remaining Verbs, Points, and Conic_Weights. |
Example
See Also
SkPath& addPath(const SkPath& src, SkScalar dx, SkScalar dy, AddPathMode mode = kAppend_AddPathMode)
Appends src to SkPath, offset by (dx, dy).
If mode is kAppend_AddPathMode, src verb array, SkPoint array, and conic weights are added unaltered. If mode is kExtend_AddPathMode, add line before appending verbs, SkPoint, and conic weights.
Parameters
src |
SkPath verbs, SkPoint, and conic weights to add |
dx |
offset added to src SkPoint array x-axis coordinates |
dy |
offset added to src SkPoint array y-axis coordinates |
mode |
kAppend_AddPathMode or kExtend_AddPathMode |
Return Value
reference to SkPath
Example
See Also
AddPathMode offset reverseAddPath
SkPath& addPath(const SkPath& src, AddPathMode mode = kAppend_AddPathMode)
If mode is kAppend_AddPathMode, src verb array, SkPoint array, and conic weights are added unaltered. If mode is kExtend_AddPathMode, add line before appending verbs, SkPoint, and conic weights.
Parameters
src |
SkPath verbs, SkPoint, and conic weights to add |
mode |
kAppend_AddPathMode or kExtend_AddPathMode |
Return Value
reference to SkPath
Example
See Also
SkPath& addPath(const SkPath& src, const SkMatrix& matrix, AddPathMode mode = kAppend_AddPathMode)
Appends src to SkPath, transformed by matrix. Transformed curves may have different verbs, SkPoint, and conic weights.
If mode is kAppend_AddPathMode, src verb array, SkPoint array, and conic weights are added unaltered. If mode is kExtend_AddPathMode, add line before appending verbs, SkPoint, and conic weights.
Parameters
src |
SkPath verbs, SkPoint, and conic weights to add |
matrix |
transform applied to src |
mode |
kAppend_AddPathMode or kExtend_AddPathMode |
Return Value
reference to SkPath
Example
See Also
AddPathMode transform offset reverseAddPath
SkPath& reverseAddPath(const SkPath& src)
Appends src to SkPath, from back to front. Reversed src always appends a new contour to SkPath.
Parameters
src |
SkPath verbs, SkPoint, and conic weights to add |
Return Value
reference to SkPath
Example
See Also
AddPathMode transform offset addPath
void offset(SkScalar dx, SkScalar dy, SkPath* dst) const
Offsets SkPoint array by (dx, dy). Offset SkPath replaces dst. If dst is nullptr, SkPath is replaced by offset data.
Parameters
dx |
offset added to SkPoint array x-axis coordinates |
dy |
offset added to SkPoint array y-axis coordinates |
dst |
overwritten, translated copy of SkPath; may be nullptr |
Example
See Also
void offset(SkScalar dx, SkScalar dy)
Offsets SkPoint array by (dx, dy). SkPath is replaced by offset data.
Parameters
dx |
offset added to SkPoint array x-axis coordinates |
dy |
offset added to SkPoint array y-axis coordinates |
Example
See Also
addPath transform SkCanvas::translate()
void transform(const SkMatrix& matrix, SkPath* dst) const
Transforms verb array, SkPoint array, and weight by matrix. transform may change verbs and increase their number. Transformed SkPath replaces dst; if dst is nullptr, original data is replaced.
Parameters
matrix |
SkMatrix to apply to SkPath |
dst |
overwritten, transformed copy of SkPath; may be nullptr |
Example
See Also
addPath offset SkCanvas::concat() SkMatrix
void transform(const SkMatrix& matrix)
Transforms verb array, SkPoint array, and weight by matrix. transform may change verbs and increase their number. SkPath is replaced by transformed data.
Parameters
matrix |
SkMatrix to apply to SkPath |
Example
See Also
addPath offset SkCanvas::concat() SkMatrix
Path is defined cumulatively, often by adding a segment to the end of last Contour. Last_Point of Contour is shared as first Point of added Line or Curve. Last_Point can be read and written directly with getLastPt and setLastPt.
bool getLastPt(SkPoint* lastPt) const
Returns last point on SkPath in lastPt. Returns false if SkPoint array is empty, storing (0, 0) if lastPt is not nullptr.
Parameters
lastPt |
storage for final SkPoint in SkPoint array; may be nullptr |
Return Value
true if SkPoint array contains one or more SkPoint
Example
Example Output
last point: 35.2786, 52.9772
See Also
void setLastPt(SkScalar x, SkScalar y)
Sets last point to (x, y). If SkPoint array is empty, append kMove_Verb to verb array and append (x, y) to SkPoint array.
Parameters
x |
set x-axis value of last point |
y |
set y-axis value of last point |
Example
See Also
void setLastPt(const SkPoint& p)
Sets the last point on the path. If SkPoint array is empty, append kMove_Verb to verb array and append p to SkPoint array.
Parameters
p |
set value of last point |
Example
See Also
enum SegmentMask { kLine_SegmentMask = 1 << 0, kQuad_SegmentMask = 1 << 1, kConic_SegmentMask = 1 << 2, kCubic_SegmentMask = 1 << 3, };
SegmentMask constants correspond to each drawing Verb type in Path; for instance, if Path only contains Lines, only the kLine_SegmentMask bit is set.
Constants
Const | Value | Description |
---|---|---|
SkPath::kLine_SegmentMask |
1 | Set if Verb_Array contains kLine_Verb. |
SkPath::kQuad_SegmentMask |
2 | Set if Verb_Array contains kQuad_Verb. Note that conicTo may add a Quad. |
SkPath::kConic_SegmentMask |
4 | Set if Verb_Array contains kConic_Verb. |
SkPath::kCubic_SegmentMask |
8 | Set if Verb_Array contains kCubic_Verb. |
Example
Example Output
Path kConic_SegmentMask is clear
Path kQuad_SegmentMask is set
See Also
uint32_t getSegmentMasks() const
Returns a mask, where each set bit corresponds to a SegmentMask constant if SkPath contains one or more verbs of that type. Returns zero if SkPath contains no lines, or curves: quads, conics, or cubics.
getSegmentMasks() returns a cached result; it is very fast.
Return Value
SegmentMask bits or zero
Example
Example Output
mask quad set
See Also
bool contains(SkScalar x, SkScalar y) const
Returns true if the point (x, y) is contained by Path, taking into account FillType.
FillType | contains() returns true if Point is enclosed by |
---|---|
kWinding_FillType | a non-zero sum of Contour Directions. |
kEvenOdd_FillType | an odd number of Contours. |
kInverseWinding_FillType | a zero sum of Contour Directions. |
kInverseEvenOdd_FillType | and even number of Contours. |
Parameters
x |
x-axis value of containment test |
y |
y-axis value of containment test |
Return Value
Example
See Also
conservativelyContainsRect Fill_Type Op
void dump(SkWStream* stream, bool forceClose, bool dumpAsHex) const
Writes text representation of SkPath to stream. If stream is nullptr, writes to standard output. Set forceClose to true to get edges used to fill SkPath. Set dumpAsHex true to generate exact binary representations of floating point numbers used in SkPoint array and conic weights.
Parameters
stream |
writable SkWStream receiving SkPath text representation; may be nullptr |
forceClose |
true if missing kClose_Verb is output |
dumpAsHex |
true if SkScalar values are written as hexadecimal |
Example
Example Output
path.setFillType(SkPath::kWinding_FillType);
path.moveTo(0, 0);
path.quadTo(20, 30, 40, 50);
path.setFillType(SkPath::kWinding_FillType);
path.moveTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0
path.quadTo(SkBits2Float(0x41a00000), SkBits2Float(0x41f00000), SkBits2Float(0x42200000), SkBits2Float(0x42480000)); // 20, 30, 40, 50
path.setFillType(SkPath::kWinding_FillType);
path.moveTo(0, 0);
path.quadTo(20, 30, 40, 50);
path.lineTo(0, 0);
path.close();
path.setFillType(SkPath::kWinding_FillType);
path.moveTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0
path.quadTo(SkBits2Float(0x41a00000), SkBits2Float(0x41f00000), SkBits2Float(0x42200000), SkBits2Float(0x42480000)); // 20, 30, 40, 50
path.lineTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0
path.close();
See Also
dumpHex SkRect::dump() SkRRect::dump() SkPathMeasure::dump()
void dump() const
Writes text representation of SkPath to standard output. The representation may be directly compiled as C++ code. Floating point values are written with limited precision; it may not be possible to reconstruct original SkPath from output.
Example
Example Output
path.setFillType(SkPath::kWinding_FillType);
path.moveTo(0, 0);
path.lineTo(0.857143f, 0.666667f);
path is not equal to copy
See Also
dumpHex SkRect::dump() SkRRect::dump() SkPathMeasure::dump() writeToMemory
void dumpHex() const
Writes text representation of Path to standard output. The representation may be directly compiled as C++ code. Floating point values are written in hexadecimal to preserve their exact bit pattern. The output reconstructs the original Path.
Use instead of dump() when submitting bug reports against Skia .
Example
Example Output
path.setFillType(SkPath::kWinding_FillType);
path.moveTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0
path.lineTo(SkBits2Float(0x3f5b6db7), SkBits2Float(0x3f2aaaab)); // 0.857143f, 0.666667f
path is equal to copy
See Also
dump SkRect::dumpHex SkRRect::dumpHex writeToMemory
size_t writeToMemory(void* buffer) const
Writes SkPath to buffer, returning the number of bytes written. Pass nullptr to obtain the storage size.
Writes SkPath::FillType, verb array, SkPoint array, conic weight, and additionally writes computed information like SkPath::Convexity and bounds.
Use only be used in concert with readFromMemory(); the format used for SkPath in memory is not guaranteed.
Parameters
buffer |
storage for SkPath; may be nullptr |
Return Value
size of storage required for SkPath; always a multiple of 4
Example
Example Output
path is equal to copy
See Also
serialize readFromMemory dump dumpHex
sk_sp<SkData> serialize() const
Writes SkPath to buffer, returning the buffer written to, wrapped in SkData.
serialize() writes SkPath::FillType, verb array, SkPoint array, conic weight, and additionally writes computed information like SkPath::Convexity and bounds.
serialize() should only be used in concert with readFromMemory(). The format used for SkPath in memory is not guaranteed.
Return Value
SkPath data wrapped in SkData buffer
Example
Example Output
path is equal to copy
See Also
writeToMemory readFromMemory dump dumpHex
size_t readFromMemory(const void* buffer, size_t length)
Initializes SkPath from buffer of size length. Returns zero if the buffer is data is inconsistent, or the length is too small.
Reads SkPath::FillType, verb array, SkPoint array, conic weight, and additionally reads computed information like SkPath::Convexity and bounds.
Used only in concert with writeToMemory(); the format used for SkPath in memory is not guaranteed.
Parameters
buffer |
storage for SkPath |
length |
buffer size in bytes; must be multiple of 4 |
Return Value
number of bytes read, or zero on failure
Example
Example Output
length = 32; returned by readFromMemory = 0
length = 40; returned by readFromMemory = 36
See Also
Generation_ID provides a quick way to check if Verb_Array, Point_Array, or Conic_Weight has changed. Generation_ID is not a hash; identical Paths will not necessarily have matching Generation_IDs.
Empty Paths have a Generation_ID of one.
uint32_t getGenerationID() const
(See Skia bug 1762.) Returns a non-zero, globally unique value. A different value is returned if verb array, SkPoint array, or conic weight changes.
Setting SkPath::FillType does not change generation identifier.
Each time the path is modified, a different generation identifier will be returned. SkPath::FillType does affect generation identifier on Android framework.
Return Value
non-zero, globally unique value
Example
Example Output
empty genID = 1
1st lineTo genID = 2
empty genID = 1
2nd lineTo genID = 3
See Also
operator==(const SkPath& a, const SkPath& b)
bool isValid() const
Returns if SkPath data is consistent. Corrupt SkPath data is detected if internal values are out of range or internal storage does not match array dimensions.
Return Value
true if SkPath data is consistent
bool pathRefIsValid() const
To be deprecated soon.
class Iter { public: Iter(); Iter(const SkPath& path, bool forceClose); void setPath(const SkPath& path, bool forceClose); Verb next(SkPoint pts[4], bool doConsumeDegenerates = true, bool exact = false); SkScalar conicWeight() const; bool isCloseLine() const; bool isClosedContour() const; };
Iterates through Verb_Array, and associated Point_Array and Conic_Weight. Provides options to treat open Contours as closed, and to ignore degenerate data.
Example
See Also
Iter()
Initializes SkPath::Iter with an empty SkPath. next() on SkPath::Iter returns kDone_Verb. Call setPath to initialize SkPath::Iter at a later time.
Return Value
Example
Example Output
iter is done
iter is done
See Also
Iter(const SkPath& path, bool forceClose)
Sets SkPath::Iter to return elements of verb array, SkPoint array, and conic weight in path. If forceClose is true, SkPath::Iter will add kLine_Verb and kClose_Verb after each open contour. path is not altered.
Parameters
path |
SkPath to iterate |
forceClose |
true if open contours generate kClose_Verb |
Return Value
Example
Example Output
open:
kMove_Verb {0, 0},
kQuad_Verb {0, 0}, {10, 20}, {30, 40},
kDone_Verb
closed:
kMove_Verb {0, 0},
kQuad_Verb {0, 0}, {10, 20}, {30, 40},
kLine_Verb {30, 40}, {0, 0},
kClose_Verb {0, 0},
kDone_Verb
See Also
void setPath(const SkPath& path, bool forceClose)
Sets SkPath::Iter to return elements of verb array, SkPoint array, and conic weight in path. If forceClose is true, SkPath::Iter will add kLine_Verb and kClose_Verb after each open contour. path is not altered.
Parameters
path |
SkPath to iterate |
forceClose |
true if open contours generate kClose_Verb |
Example
Example Output
quad open:
kMove_Verb {0, 0},
kQuad_Verb {0, 0}, {10, 20}, {30, 40},
kDone_Verb
conic closed:
kMove_Verb {0, 0},
kConic_Verb {0, 0}, {1, 2}, {3, 4}, weight = 0.5
kLine_Verb {3, 4}, {0, 0},
kClose_Verb {0, 0},
kDone_Verb
See Also
Iter(const SkPath& path, bool forceClose)
Verb next(SkPoint pts[4], bool doConsumeDegenerates = true, bool exact = false)
Returns next SkPath::Verb in verb array, and advances SkPath::Iter. When verb array is exhausted, returns kDone_Verb.
Zero to four SkPoint are stored in pts, depending on the returned SkPath::Verb.
If doConsumeDegenerates is true, skip consecutive kMove_Verb entries, returning only the last in the series; and skip very small lines, quads, and conics; and skip kClose_Verb following kMove_Verb. if doConsumeDegenerates is true and exact is true, only skip lines, quads, and conics with zero lengths.
Parameters
pts |
storage for SkPoint data describing returned SkPath::Verb |
doConsumeDegenerates |
if true, skip degenerate verbs |
exact |
skip zero length curves |
Return Value
next SkPath::Verb from verb array
Example
skip degenerate if exact skips the same as skip degenerate, but shows the very small Line.
Example Output
skip degenerate:
kMove_Verb {20, 20},
kQuad_Verb {20, 20}, {10, 20}, {30, 40},
kDone_Verb
skip degenerate if exact:
kMove_Verb {20, 20},
kQuad_Verb {20, 20}, {10, 20}, {30, 40},
kMove_Verb {30, 30},
kLine_Verb {30, 30}, {30.00001, 30},
kDone_Verb
skip none:
kMove_Verb {10, 10},
kMove_Verb {20, 20},
kQuad_Verb {20, 20}, {10, 20}, {30, 40},
kMove_Verb {1, 1},
kClose_Verb {1, 1},
kMove_Verb {30, 30},
kLine_Verb {30, 30}, {30, 30},
kMove_Verb {30, 30},
kLine_Verb {30, 30}, {30.00001, 30},
kDone_Verb
See Also
Verb IsLineDegenerate IsCubicDegenerate IsQuadDegenerate
SkScalar conicWeight() const
Returns conic weight if next() returned kConic_Verb.
If next() has not been called, or next() did not return kConic_Verb, result is undefined.
Return Value
conic weight for conic SkPoint returned by next()
Example
Example Output
first verb is move
next verb is conic
conic points: {0,0}, {1,2}, {3,4}
conic weight: 0.5
See Also
bool isCloseLine() const
Returns true if last kLine_Verb returned by next() was generated by kClose_Verb. When true, the end point returned by next() is also the start point of contour.
If next() has not been called, or next() did not return kLine_Verb, result is undefined.
Return Value
true if last kLine_Verb was generated by kClose_Verb
Example
Example Output
1st verb is move
moveTo point: {6,7}
2nd verb is conic
3rd verb is line
line points: {3,4}, {6,7}
line generated by close
4th verb is close
See Also
bool isClosedContour() const
Returns true if subsequent calls to next() return kClose_Verb before returning kMove_Verb. if true, contour SkPath::Iter is processing may end with kClose_Verb, or SkPath::Iter may have been initialized with force close set to true.
Return Value
true if contour is closed
Example
Example Output
without close(), forceClose is false: isClosedContour returns false
with close(), forceClose is false: isClosedContour returns true
without close(), forceClose is true : isClosedContour returns true
with close(), forceClose is true : isClosedContour returns true
See Also
Iter(const SkPath& path, bool forceClose)
class RawIter { public: RawIter(); RawIter(const SkPath& path); void setPath(const SkPath& path); Verb next(SkPoint pts[4]); Verb peek() const; SkScalar conicWeight() const; };
Iterates through Verb_Array, and associated Point_Array and Conic_Weight. Verb_Array, Point_Array, and Conic_Weight are returned unaltered.
RawIter()
Initializes RawIter with an empty SkPath. next() on RawIter returns kDone_Verb. Call setPath to initialize SkPath::Iter at a later time.
Return Value
RawIter(const SkPath& path)
Sets RawIter to return elements of verb array, SkPoint array, and conic weight in path.
Parameters
path |
SkPath to iterate |
Return Value
void setPath(const SkPath& path)
Sets SkPath::Iter to return elements of verb array, SkPoint array, and conic weight in path.
Parameters
path |
SkPath to iterate |
Verb next(SkPoint pts[4])
Returns next SkPath::Verb in verb array, and advances RawIter. When verb array is exhausted, returns kDone_Verb. Zero to four SkPoint are stored in pts, depending on the returned SkPath::Verb.
Parameters
pts |
storage for SkPoint data describing returned SkPath::Verb |
Return Value
next SkPath::Verb from verb array
Example
Example Output
kMove_Verb {50, 60},
kQuad_Verb {50, 60}, {10, 20}, {30, 40},
kClose_Verb {50, 60},
kMove_Verb {50, 60},
kLine_Verb {50, 60}, {30, 30},
kConic_Verb {30, 30}, {1, 2}, {3, 4}, weight = 0.5
kCubic_Verb {3, 4}, {-1, -2}, {-3, -4}, {-5, -6},
kDone_Verb
See Also
Verb peek() const
Returns next SkPath::Verb, but does not advance RawIter.
Return Value
next SkPath::Verb from verb array
Example
Example Output
#Volatile
peek Move == verb Move
peek Quad == verb Quad
peek Conic == verb Conic
peek Cubic == verb Cubic
peek Done == verb Done
peek Done == verb Done
See Also
SkScalar conicWeight() const
Returns conic weight if next() returned kConic_Verb.
If next() has not been called, or next() did not return kConic_Verb, result is undefined.
Return Value
conic weight for conic SkPoint returned by next()
Example
Example Output
first verb is move
next verb is conic
conic points: {0,0}, {1,2}, {3,4}
conic weight: 0.5