Bookmaker delimits formulas and equations to allow representing variables and symbols without tripping up reference lookup, spell checking, and comment generation. Before, formulas were represented with: some text #Formula (x + y, 0) ## , and more text This made it difficult to know when spacing should be preserved before and after the formula. Now, formulas are represented with: some text #Formula # (x + y, 0) ##, and more text The presence or absence of a space between ## and , is now significant (before it was not). Also, formulas are bracketed by <code> in markdown generation, so that variables stand out better. See: https://skia.org/user/api/SkBlendMode_Reference?cl=152781#Dst_Out for an example. Also fixed 100 column offenders and added a code check to identify them. For the moment, 100 column offenders are outed with SkDebugf but their presence does not cause bookmaker to fail. TBR=caryclark@google.com Docs-Preview: https://skia.org/?cl=152781 Bug: skia:6898 Change-Id: If92a65a234f5d616bf4485984a8d219a6f04821a Reviewed-on: https://skia-review.googlesource.com/152781 Commit-Queue: Cary Clark <caryclark@skia.org> Auto-Submit: Cary Clark <caryclark@skia.org> Reviewed-by: Cary Clark <caryclark@skia.org>
331 KiB
SkPath Reference
Path
Path contains Lines and Curves which can be stroked or filled. Contour is composed of a series of connected Lines and Curves. Path may contain zero, one, or more Contours. Each Line and Curve are described by Verb, Points, and optional Conic Weight.
Each pair of connected Lines and Curves share common Point; for instance, Path containing two connected Lines are described the Verb sequence: SkPath::kMove Verb, SkPath::kLine Verb, SkPath::kLine Verb; and a Point sequence with three entries, sharing the middle entry as the end of the first Line and the start of the second Line.
Path components Arc, Rect, Round Rect, Circle, and Oval are composed of Lines and Curves with as many Verbs and Points required for an exact description. Once added to Path, these components may lose their identity; although Path can be inspected to determine if it describes a single Rect, Oval, Round Rect, and so on.
Example
Path contains a Fill Type which determines whether overlapping Contours form fills or holes. Fill Type also determines whether area inside or outside Lines and Curves is filled.
Example
Path contents are never shared. Copying Path by value effectively creates a new Path independent of the original. Internally, the copy does not duplicate its contents until it is edited, to reduce memory use and improve performance.
Contour
Contour contains one or more Verbs, and as many Points as are required to satisfy Verb Array. First Verb in Path is always SkPath::kMove Verb; each SkPath::kMove Verb that follows starts a new Contour.
Example
If final Verb in Contour is SkPath::kClose Verb, Line connects Last Point in Contour with first Point. A closed Contour, stroked, draws Paint Stroke Join at Last Point and first Point. Without SkPath::kClose Verb as final Verb, Last Point and first Point are not connected; Contour remains open. An open Contour, stroked, draws Paint Stroke Cap at Last Point and first Point.
Example
Contour Zero Length
Contour length is distance traveled from first Point to Last Point, plus, if Contour is closed, distance from Last Point to first Point. Even if Contour length is zero, stroked Lines are drawn if Paint Stroke Cap makes them visible.
Example
Class SkPath
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.
Overview
Topic | Description |
---|---|
Class Declarations | embedded class members |
Constants | enum and enum class, and their const values |
Constructors | functions that construct SkPath |
Functions | global and class member functions |
Operators | operator overloading methods |
Related Functions | similar member functions grouped together |
Related Function
SkPath global, struct
, and class
related member functions share a topic.
Topic | Description |
---|---|
Arc | part of Oval or Circle |
Build | adds points and verbs to path |
Conic | conic section defined by three points and a weight |
Conic Weight | strength of Conic control Point |
Contour | loop of lines and curves |
Contour Zero Length | consideration when contour has no length |
Convexity | if Path is concave or convex |
Cubic | curve described by third-order polynomial |
Direction | contour orientation, clockwise or counterclockwise |
Fill Type | fill rule, normal and inverted |
Generation ID | value reflecting contents change |
Interpolate | weighted average of Path pair |
Last Point | final Point in Contour |
Point Array | end points and control points for lines and curves |
Property | metrics and attributes |
Quad | curve described by second-order polynomial |
Transform | modify all points |
Utility | rarely called management functions |
Verb | line and curve type |
Verb Array | line and curve type for points |
Volatile | caching attribute |
Constant
SkPath related constants are defined by enum
, enum class
, #define
, const
, and constexpr
.
Topic | Description |
---|---|
AddPathMode | sets addPath options |
ArcSize | used by arcTo variation |
Convexity | returns if Path is convex or concave |
Direction | sets Contour clockwise or counterclockwise |
FillType | sets winding rule and inverse fill |
SegmentMask | returns Verb types in Path |
Verb | controls how Path Points are interpreted |
kAppend AddPathMode | appended to destination unaltered |
kCCW Direction | contour travels counterclockwise |
kCW Direction | contour travels clockwise |
kClose Verb | closes Contour |
kConcave Convexity | more than one Contour, or a geometry with indentations |
kConic SegmentMask | contains one or more Conics |
kConic Verb | adds Conic from Last Point |
kConvex Convexity | one Contour made of a simple geometry without indentations |
kCubic SegmentMask | contains one or more Cubics |
kCubic Verb | adds Cubic from Last Point |
kDone Verb | terminates Path |
kEvenOdd FillType | is enclosed by an odd number of Contours |
kExtend AddPathMode | add line if prior Contour is not closed |
kInverseEvenOdd FillType | is enclosed by an even number of Contours |
kInverseWinding FillType | is enclosed by a zero sum of Contour Directions |
kLarge ArcSize | larger of Arc pair |
kLine SegmentMask | contains one or more Lines |
kLine Verb | adds Line from Last Point to next Point |
kMove Verb | starts new Contour at next Point |
kQuad SegmentMask | contains one or more Quads |
kQuad Verb | adds Quad from Last Point |
kSmall ArcSize | smaller of Arc pair |
kUnknown Convexity | indicates Convexity has not been determined |
kWinding FillType | is enclosed by a non-zero sum of Contour Directions |
Class
SkPath uses C++ classes to declare the public data structures and interfaces.
Topic | Description |
---|---|
Iter | data iterator |
RawIter | raw data iterator |
Constructor
SkPath can be constructed or initialized by these functions, including C++ class constructors.
Topic | Description |
---|---|
SkPath() | constructs with default values |
SkPath(const SkPath& path) | makes a shallow copy |
reset | removes Verb Array, Point Array, and Weights; frees memory |
rewind | removes Verb Array, Point Array, and Weights, keeping memory |
~SkPath() | decreases Reference Count of owned objects |
Operator
SkPath operators inline class member functions with arithmetic equivalents.
Topic | Description |
---|---|
operator!=(const SkPath& a, const SkPath& b) | compares paths for inequality |
operator=(const SkPath& path) | makes a shallow copy |
operator==(const SkPath& a, const SkPath& b) | compares Paths for equality |
swap | exchanges Path pair |
Member Function
SkPath member functions read and modify the structure properties.
Topic | Description |
---|---|
ConvertConicToQuads | approximates Conic with Quad array |
ConvertToNonInverseFillType | returns Fill Type representing inside geometry |
IsCubicDegenerate | returns if Cubic is very small |
IsInverseFillType | returns if Fill Type represents outside geometry |
IsLineDegenerate | returns if Line is very small |
IsQuadDegenerate | returns if Quad is very small |
addArc | adds one Contour containing Arc |
addCircle | adds one Contour containing Circle |
addOval | adds one Contour containing Oval |
addPath | adds contents of Path |
addPoly | adds one Contour containing connected lines |
addRRect | adds one Contour containing Round Rect |
addRect | adds one Contour containing Rect |
addRoundRect | adds one Contour containing Round Rect with common corner radii |
arcTo | appends Arc |
close | makes last Contour a loop |
computeTightBounds | returns extent of geometry |
conicTo | appends Conic |
conservativelyContainsRect | returns true if Rect may be inside |
contains | returns if Point is in fill area |
countPoints | returns Point Array length |
countVerbs | returns Verb Array length |
cubicTo | appends Cubic |
dump | sends text representation to stream |
dumpHex | sends text representation using hexadecimal to standard output |
getBounds | returns maximum and minimum of Point Array |
getConvexity | returns geometry convexity, computing if necessary |
getConvexityOrUnknown | returns geometry convexity if known |
getFillType | returns Fill Type: winding, even-odd, inverse |
getGenerationID | returns unique ID |
getLastPt | returns Last Point |
getPoint | returns entry from Point Array |
getPoints | returns Point Array |
getSegmentMasks | returns types in Verb Array |
getVerbs | returns Verb Array |
incReserve | reserves space for additional data |
interpolate | interpolates between Path pair |
isConvex | returns if geometry is convex |
isEmpty | returns if verb count is zero |
isFinite | returns if all Point values are finite |
isInterpolatable | returns if pair contains equal counts of Verb Array and Weights |
isInverseFillType | returns if Fill Type fills outside geometry |
isLastContourClosed | returns if final Contour forms a loop |
isLine | returns if describes Line |
isNestedFillRects | returns if describes Rect pair, one inside the other |
isOval | returns if describes Oval |
isRRect | returns if describes Round Rect |
isRect | returns if describes Rect |
isValid | returns if data is internally consistent |
isVolatile | returns if Device should not cache |
lineTo | appends Line |
moveTo | starts Contour |
offset | translates Point Array |
quadTo | appends Quad |
rArcTo | appends Arc relative to Last Point |
rConicTo | appends Conic relative to Last Point |
rCubicTo | appends Cubic relative to Last Point |
rLineTo | appends Line relative to Last Point |
rMoveTo | starts Contour relative to Last Point |
rQuadTo | appends Quad relative to Last Point |
readFromMemory | initializes from buffer |
reset | removes Verb Array, Point Array, and Weights; frees memory |
reverseAddPath | adds contents of Path back to front |
rewind | removes Verb Array, Point Array, and Weights, keeping memory |
serialize | copies data to buffer |
setConvexity | sets if geometry is convex to avoid future computation |
setFillType | sets Fill Type: winding, even-odd, inverse |
setIsVolatile | sets if Device should not cache |
setLastPt | replaces Last Point |
shrinkToFit | removes unused reserved space |
swap | exchanges Path pair |
toggleInverseFillType | toggles Fill Type between inside and outside geometry |
transform | applies Matrix to Point Array and Weights |
updateBoundsCache | refreshes result of getBounds |
writeToMemory | copies data to buffer |
Verb
Enum SkPath::Verb
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
Direction
Enum SkPath::Direction
enum Direction { 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[2][3][4][5] rArcTo isRect isNestedFillRects addRect[2][3] addOval[2]
SkPath
SkPath()
Constucts an empty Path. By default, Path has no Verbs, no Points, and no Weights. Fill Type is set to kWinding FillType.
Return Value
empty Path
Example
Example Output
path is empty
See Also
SkPath
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, Point Array and Weights are copied when modified.
Creating a Path copy is very efficient and never allocates memory. Paths are always copied by value from the interface; the underlying shared pointers are not exposed.
Parameters
path |
Path to copy by value |
Return Value
copy of Path
Example
Example Output
path verbs: 2
path2 verbs: 3
after reset
path verbs: 0
path2 verbs: 3
See Also
~SkPath
~SkPath()
Releases ownership of any shared data and deletes data if Path is sole owner.
Example
See Also
SkPath() SkPath(const SkPath& path) operator=(const SkPath& path)
operator=
SkPath& operator=(const SkPath& path)
Constructs a copy of an existing path. Path assignment makes two paths identical by value. Internally, assignment shares pointer values. The underlying Verb Array, Point Array and Weights are copied when modified.
Copying Paths by assignment is very efficient and never allocates memory. Paths are always copied by value from the interface; the underlying shared pointers are not exposed.
Parameters
path |
Verb Array, Point Array, Weights, and Fill Type to copy |
Return Value
Path copied by value
Example
Example Output
path1 bounds = 10, 20, 30, 40
path2 bounds = 10, 20, 30, 40
See Also
swap SkPath(const SkPath& path)
operator==
bool operator==(const SkPath& a, const SkPath& b)
Compares a and b; returns true if Fill Type, Verb Array, Point Array, and Weights are equivalent.
Parameters
a |
Path to compare |
b |
Path to compare |
Return Value
true if Path 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& path)
operator!=
bool operator!=(const SkPath& a, const SkPath& b)
Compares a and b; returns true if Fill Type, Verb Array, Point Array, and Weights are not equivalent.
Parameters
a |
Path to compare |
b |
Path to compare |
Return Value
true if Path pair are not equivalent
Example
Example Output
empty one == two
add rect one == two
setConvexity one == two
convexity !=
Property
Topic | Description |
---|---|
IsCubicDegenerate | returns if Cubic is very small |
IsInverseFillType | returns if Fill Type represents outside geometry |
IsLineDegenerate | returns if Line is very small |
IsQuadDegenerate | returns if Quad is very small |
computeTightBounds | returns extent of geometry |
conservativelyContainsRect | returns true if Rect may be inside |
contains | returns if Point is in fill area |
getBounds | returns maximum and minimum of Point Array |
getLastPt | returns Last Point |
isEmpty | returns if verb count is zero |
isFinite | returns if all Point values are finite |
isInterpolatable | returns if pair contains equal counts of Verb Array and Weights |
isLastContourClosed | returns if final Contour forms a loop |
isLine | returns if describes Line |
isNestedFillRects | returns if describes Rect pair, one inside the other |
isOval | returns if describes Oval |
isRRect | returns if describes Round Rect |
isRect | returns if describes Rect |
isValid | returns if data is internally consistent |
isVolatile | returns if Device should not cache |
isInterpolatable
bool isInterpolatable(const SkPath& compare) const
Returns true if Paths contain equal Verbs and equal Weights. If Paths 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 Paths containing Conics with different Conic Weight values.
Parameters
compare |
Path to compare |
Return Value
true if Paths Verb Array and Weights are equivalent
Example
Example Output
paths are interpolatable
See Also
Interpolate
Topic | Description |
---|---|
interpolate | interpolates between Path pair |
interpolate
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
unique
bool unique() const
To be deprecated soon.
Only valid for Android framework.
Fill Type
Enum SkPath::FillType
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
getFillType
FillType getFillType() const
Returns FillType, the rule used to fill Path. FillType of a new Path is kWinding FillType.
Return Value
one of: kWinding FillType, kEvenOdd FillType, kInverseWinding FillType, kInverseEvenOdd FillType
Example
Example Output
default path fill type is kWinding_FillType
See Also
FillType setFillType isInverseFillType
setFillType
void setFillType(FillType ft)
Sets FillType, the rule used to fill Path. 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, kInverseEvenOdd FillType |
Example
See Also
FillType getFillType toggleInverseFillType
isInverseFillType
bool isInverseFillType() const
Returns if FillType describes area outside Path 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
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
Convexity
Enum SkPath::Convexity
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
getConvexity
Convexity getConvexity() const
Computes Convexity if required, and returns stored value. Convexity is computed if stored value is kUnknown Convexity, or if Path has been altered since Convexity was computed or set.
Return Value
computed or stored Convexity
Example
See Also
Convexity Contour Direction getConvexityOrUnknown setConvexity isConvex
getConvexityOrUnknown
Convexity getConvexityOrUnknown() const
Returns last computed Convexity, or kUnknown Convexity if Path has been altered since Convexity was computed or set.
Return Value
stored Convexity
Example
See Also
Convexity Contour Direction getConvexity setConvexity isConvex
setConvexity
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 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
isConvex
bool isConvex() const
Computes 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, Convexity is not recomputed.
Return Value
true if Convexity stored or computed is kConvex Convexity
Example
See Also
Convexity Contour Direction getConvexity getConvexityOrUnknown setConvexity
isOval
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 Rect of Oval; may be nullptr |
Return Value
true if Path is recognized as an oval or circle
Example
See Also
isRRect
bool isRRect(SkRRect* rrect) const
Returns true if this path is recognized as a SkRRect (but not an oval/circle or rect).
rrect receives bounds of Round Rect.
rrect is unmodified if Round Rect is not found.
Parameters
rrect |
storage for bounding Rect of Round Rect; may be nullptr |
Return Value
true if Path contains only Round Rect
Example
See Also
Round Rect addRoundRect[2] addRRect[2]
reset
SkPath& reset()
Sets Path to its initial state. Removes Verb Array, Point Array, and Weights, and sets FillType to kWinding FillType. Internal storage associated with Path is released.
Return Value
reference to Path
Example
See Also
rewind
SkPath& rewind()
Sets Path to its initial state, preserving internal storage. Removes Verb Array, Point Array, and Weights, and sets FillType to kWinding FillType. Internal storage associated with Path is retained.
Use rewind instead of reset if Path storage will be reused and performance is critical.
Return Value
reference to Path
Example
See Also
isEmpty
bool isEmpty() const
Returns if Path is empty. Empty Path may have FillType but has no SkPoint, Verb, or Conic Weight. SkPath() constructs empty Path; reset and rewind make Path empty.
Return Value
true if the path contains no 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
isLastContourClosed
bool isLastContourClosed() const
Returns if Contour is closed. Contour is closed if Path Verb array was last modified by close. When stroked, closed Contour draws Paint Stroke Join instead of Paint Stroke Cap at first and last Point.
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
isFinite
bool isFinite() const
Returns true for finite Point array values between negative SK ScalarMax and positive SK ScalarMax. Returns false for any Point array value of SK ScalarInfinity, SK ScalarNegativeInfinity, or SK ScalarNaN.
Return Value
true if all Point values are finite
Example
Example Output
initial path is finite
after line path is finite
after scale path is not finite
See Also
isVolatile
bool isVolatile() const
Returns true if the path is volatile; it will not be altered or discarded by the caller after it is drawn. Paths by default have volatile set false, allowing Surface to attach a cache of data which speeds repeated drawing. If true, Surface may not speed repeated drawing.
Return Value
true if caller will alter Path after drawing
Example
Example Output
volatile by default is false
See Also
Volatile
Topic | Description |
---|---|
setIsVolatile | sets if Device should not cache |
setIsVolatile
void setIsVolatile(bool isVolatile)
Specifies whether Path is volatile; whether it will be altered or discarded by the caller after it is drawn. Paths by default have volatile set false, allowing Device to attach a cache of data which speeds repeated drawing.
Mark temporary paths, discarded or modified after use, as volatile to inform Device 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.
Parameters
isVolatile |
true if caller will alter Path after drawing |
Example
See Also
IsLineDegenerate
static bool IsLineDegenerate(const SkPoint& p1, const SkPoint& p2, bool exact)
Tests if Line between Point 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
IsQuadDegenerate
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
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
isLine
bool isLine(SkPoint line[2]) const
Returns true if Path contains only one Line; Path Verb array has two entries: kMove Verb, kLine Verb. If Path contains one Line and line is not nullptr, line is set to Line start point and Line end point. Returns false if Path is not one Line; line is unaltered.
Parameters
line |
storage for Line. May be nullptr |
Return Value
true if Path 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
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: Verb::kMoveTo, Verb::kLineTo, Verb::kQuadTo; 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.
getPoints
int getPoints(SkPoint points[], int max) const
Returns number of points in Path. 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 Path Point array. May be nullptr |
max |
maximum to copy; must be greater than or equal to zero |
Return Value
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
countPoints
int countPoints() const
Returns the number of points in Path. Point 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
getPoint
SkPoint getPoint(int index) const
Returns Point at index in Point Array. Valid range for index is 0 to countPoints - 1. Returns (0, 0) if index is out of range.
Parameters
index |
Point array element selector |
Return Value
Point array value or (0, 0)
Example
Example Output
point 0: (-10,-10)
point 1: (10,10)
See Also
Verb Array
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.
countVerbs
int countVerbs() const
Returns the number of Verbs: kMove Verb, kLine Verb, kQuad Verb, kConic Verb, kCubic Verb, and kClose Verb; added to Path.
Return Value
length of Verb Array
Example
Example Output
empty verb count: 0
round rect verb count: 10
See Also
getVerbs
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
swap
void swap(SkPath& other)
Exchanges the Verb Array, Point Array, Weights, and Fill Type 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 operator=(const SkPath& path). Paths do not copy their content on assignment until they are written to, making assignment as efficient as swap.
Parameters
other |
Path exchanged by value |
Example
Example Output
path1 bounds = 0, 0, 0, 0
path2 bounds = 10, 20, 30, 40
See Also
getBounds
const SkRect& getBounds() const
Returns minimum and maximum axes values of Point Array. Returns (0, 0, 0, 0) if Path contains no points. Returned bounds width and height may be larger or smaller than area affected when Path is drawn.
Rect returned includes all Points added to Path, including Points associated with kMove Verb that define empty Contours.
Return Value
bounds of all Points in Point 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
Utility
Topic | Description |
---|---|
ConvertConicToQuads | approximates Conic with Quad array |
ConvertToNonInverseFillType | returns Fill Type representing inside geometry |
dump | sends text representation to stream |
dump(SkWStream* stream, bool forceClose, bool dumpAsHex) const | |
dump const | |
dumpHex | sends text representation using hexadecimal to standard output |
getSegmentMasks | returns types in Verb Array |
incReserve | reserves space for additional data |
readFromMemory | initializes from buffer |
serialize | copies data to buffer |
setLastPt | replaces Last Point |
setLastPt(SkScalar x, SkScalar y) | |
shrinkToFit | removes unused reserved space |
updateBoundsCache | refreshes result of getBounds |
writeToMemory | copies data to buffer |
updateBoundsCache
void updateBoundsCache() const
Updates internal bounds so that subsequent calls to getBounds are instantaneous. Unaltered copies of Path may also access cached bounds through getBounds.
For now, identical to calling getBounds and ignoring the returned value.
Call to prepare Path 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
computeTightBounds
SkRect computeTightBounds() const
Returns minimum and maximum axes values of the lines and curves in Path. Returns (0, 0, 0, 0) if Path contains no points. Returned bounds width and height may be larger or smaller than area affected when Path is drawn.
Includes Points associated with kMove Verb that define empty Contours.
Behaves identically to getBounds when Path contains only lines. If Path 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 Path
Example
Example Output
empty bounds = 0, 0, 0, 0
circle bounds = 25, 20, 75, 70
rotated circle bounds = 25, 20, 75, 70
See Also
conservativelyContainsRect
bool conservativelyContainsRect(const SkRect& rect) const
Returns true if rect is contained by Path. May return false when rect is contained by Path.
For now, only returns true if Path has one Contour and is convex. rect may share points and edges with Path and be contained. Returns true if rect is empty, that is, it has zero width or height; and the Point or Line described by rect is contained by Path.
Parameters
rect |
Rect, Line, or Point checked for containment |
Return Value
true if rect is contained
Example
See Also
incReserve
void incReserve(unsigned extraPtCount)
Grows Path Verb Array and Point Array to contain extraPtCount additional Points. May improve performance and use less memory by reducing the number and size of allocations when creating Path.
Parameters
extraPtCount |
number of additional Points to allocate |
Example
See Also
shrinkToFit
void shrinkToFit()
Shrinks Path Verb Array and Point Array storage to discard unused capacity. May reduce the heap overhead for Paths known to be fully constructed.
See Also
Build
moveTo
SkPath& moveTo(SkScalar x, SkScalar y)
Adds beginning of Contour at Point (x, y).
Parameters
x |
x-axis value of Contour start |
y |
y-axis value of Contour start |
Return Value
reference to Path
Example
See Also
Contour lineTo[2] rMoveTo quadTo[2] conicTo[2] cubicTo[2] close
SkPath& moveTo(const SkPoint& p)
Adds beginning of Contour at Point p.
Parameters
p |
contour start |
Return Value
reference to Path
Example
See Also
Contour lineTo[2] rMoveTo quadTo[2] conicTo[2] cubicTo[2] close
rMoveTo
SkPath& rMoveTo(SkScalar dx, SkScalar dy)
Adds beginning of Contour relative to Last Point. If Path 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 Path
Example
See Also
Contour lineTo[2] moveTo[2] quadTo[2] conicTo[2] cubicTo[2] close
lineTo
SkPath& lineTo(SkScalar x, SkScalar y)
Adds Line from Last Point to (x, y). If Path is empty, or last 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 Point Array, if needed. lineTo then appends kLine Verb to Verb Array and (x, y) to Point Array.
Parameters
x |
end of added Line in x |
y |
end of added Line in y |
Return Value
reference to Path
Example
See Also
Contour moveTo[2] rLineTo addRect[2][3]
SkPath& lineTo(const SkPoint& p)
Adds Line from Last Point to Point p. If Path is empty, or last 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 Point Array, if needed. lineTo then appends kLine Verb to Verb Array and Point p to Point Array.
Parameters
p |
end Point of added Line |
Return Value
reference to Path
Example
See Also
Contour moveTo[2] rLineTo addRect[2][3]
rLineTo
SkPath& rLineTo(SkScalar dx, SkScalar dy)
Adds Line from Last Point to Vector (dx, dy). If Path is empty, or last Verb is kClose Verb, Last Point is set to (0, 0) before adding Line.
Appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed; then appends kLine Verb to Verb Array and Line end to Point 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 Path
Example
See Also
Contour moveTo[2] lineTo[2] addRect[2][3]
Quad
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
quadTo
SkPath& quadTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2)
Adds Quad from Last Point towards (x1, y1), to (x2, y2). If Path is empty, or last Verb is kClose Verb, Last Point is set to (0, 0) before adding Quad.
Appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed; then appends kQuad Verb to Verb Array; and (x1, y1), (x2, y2) to Point Array.
Parameters
x1 |
control Point of Quad in x |
y1 |
control Point of Quad in y |
x2 |
end Point of Quad in x |
y2 |
end Point of Quad in y |
Return Value
reference to Path
Example
See Also
Contour moveTo[2] conicTo[2] rQuadTo
SkPath& quadTo(const SkPoint& p1, const SkPoint& p2)
Adds Quad from Last Point towards Point p1, to Point p2. If Path is empty, or last Verb is kClose Verb, Last Point is set to (0, 0) before adding Quad.
Appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed; then appends kQuad Verb to Verb Array; and Points p1, p2 to Point Array.
Parameters
p1 |
control Point of added Quad |
p2 |
end Point of added Quad |
Return Value
reference to Path
Example
See Also
Contour moveTo[2] conicTo[2] rQuadTo
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 Path is empty, or last Verb is kClose Verb, Last Point is set to (0, 0) before adding Quad.
Appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed; then appends kQuad Verb to Verb Array; and appends Quad control and Quad end to Point 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 Path
Example
See Also
Contour moveTo[2] conicTo[2] quadTo[2]
Conic
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.
Conic Weight
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
1 / sqrt(2)
.
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
conicTo
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 Path is empty, or last Verb is kClose Verb, Last Point is set to (0, 0) before adding Conic.
Appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed.
If w is finite and not one, appends kConic Verb to Verb Array; and (x1, y1), (x2, y2) to Point Array; and w to Conic Weights.
If w is one, appends kQuad Verb to Verb Array, and (x1, y1), (x2, y2) to Point Array.
If w is not finite, appends kLine Verb twice to Verb Array, and (x1, y1), (x2, y2) to Point Array.
Parameters
x1 |
control Point of Conic in x |
y1 |
control Point of Conic in y |
x2 |
end Point of Conic in x |
y2 |
end Point of Conic in y |
w |
weight of added Conic |
Return Value
reference to Path
Example
See Also
rConicTo arcTo[2][3][4][5] addArc quadTo[2]
SkPath& conicTo(const SkPoint& p1, const SkPoint& p2, SkScalar w)
Adds Conic from Last Point towards Point p1, to Point p2, weighted by w. If Path is empty, or last Verb is kClose Verb, Last Point is set to (0, 0) before adding Conic.
Appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed.
If w is finite and not one, appends kConic Verb to Verb Array; and Points p1, p2 to Point Array; and w to Conic Weights.
If w is one, appends kQuad Verb to Verb Array, and Points p1, p2 to Point Array.
If w is not finite, appends kLine Verb twice to Verb Array, and Points p1, p2 to Point Array.
Parameters
p1 |
control Point of added Conic |
p2 |
end Point of added Conic |
w |
weight of added Conic |
Return Value
reference to Path
Example
See Also
rConicTo arcTo[2][3][4][5] addArc quadTo[2]
rConicTo
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 Path is empty, or last Verb is kClose Verb, Last Point is set to (0, 0) before adding Conic.
Appends kMove Verb to Verb Array and (0, 0) to Point 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 Points control and end to Point 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 Path
Example
See Also
conicTo[2] arcTo[2][3][4][5] addArc quadTo[2]
Cubic
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
cubicTo
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 Path is empty, or last Verb is kClose Verb, Last Point is set to (0, 0) before adding Cubic.
Appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed; then appends kCubic Verb to Verb Array; and (x1, y1), (x2, y2), (x3, y3) to Point Array.
Parameters
x1 |
first control Point of Cubic in x |
y1 |
first control Point of Cubic in y |
x2 |
second control Point of Cubic in x |
y2 |
second control Point of Cubic in y |
x3 |
end Point of Cubic in x |
y3 |
end Point of Cubic in y |
Return Value
reference to Path
Example
See Also
Contour moveTo[2] rCubicTo quadTo[2]
SkPath& cubicTo(const SkPoint& p1, const SkPoint& p2, const SkPoint& p3)
Adds Cubic from Last Point towards Point p1, then towards Point p2, ending at Point p3. If Path is empty, or last Verb is kClose Verb, Last Point is set to (0, 0) before adding Cubic.
Appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed; then appends kCubic Verb to Verb Array; and Points p1, p2, p3 to Point Array.
Parameters
p1 |
first control Point of Cubic |
p2 |
second control Point of Cubic |
p3 |
end Point of Cubic |
Return Value
reference to Path
Example
See Also
Contour moveTo[2] rCubicTo quadTo[2]
rCubicTo
SkPath& rCubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar x3, SkScalar y3)
Adds Cubic from Last Point towards Vector (dx1, dy1), then towards Vector (dx2, dy2), to Vector (dx3, dy3). If Path is empty, or last Verb is kClose Verb, Last Point is set to (0, 0) before adding Cubic.
Appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed; then appends kCubic Verb to Verb Array; and appends Cubic control and Cubic end to Point 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
x1 |
offset from Last Point to first Cubic control on x-axis |
y1 |
offset from Last Point to first Cubic control on y-axis |
x2 |
offset from Last Point to second Cubic control on x-axis |
y2 |
offset from Last Point to second Cubic control on y-axis |
x3 |
offset from Last Point to Cubic end on x-axis |
y3 |
offset from Last Point to Cubic end on y-axis |
Return Value
reference to Path
Example
See Also
Contour moveTo[2] cubicTo[2] quadTo[2]
Arc
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.
arcTo(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. Canvas::drawArc draws without requiring Path.
arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar radius) describes Arc as tangent to the line (x0, y0), (x1, y1) and tangent to the line (x1, y1), (x2, y2) where (x0, y0) is the last Point added to Path. This construction is similar to PostScript and HTML Canvas arcs.
arcTo(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 arcTo(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, bool forceMoveTo) |
2 parameter sets force MoveTo |
3 start angle must be multiple of 90 degrees |
4 arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar radius) |
5 arcTo(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. |
arcTo
SkPath& arcTo(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, bool forceMoveTo)
Appends Arc to Path. 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 Path last Point to initial Arc Point if forceMoveTo is false and Path 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 Path
Example
See Also
addArc SkCanvas::drawArc conicTo[2]
SkPath& arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar radius)
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 (x0, y0) 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.
Example
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.
Example
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 Path
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 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 Point does not start Arc, arcTo 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, arcTo appends Line from last Path Point to p1.
arcTo appends at most one Line and one Conic. arcTo implements the functionality of PostScript Arct and HTML Canvas ArcTo.
Parameters
p1 |
Point common to pair of tangents |
p2 |
end of second tangent |
radius |
distance from Arc to Circle center |
Return Value
reference to Path
Example
Example Output
move to (156,20)
line (156,20),(200,20)
See Also
Enum SkPath::ArcSize
enum ArcSize { kSmall ArcSize, kLarge ArcSize, };
Four Oval parts with radii (rx, ry) start at last Path Point and ends at (x, y). ArcSize and Direction select one of the four Oval parts.
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 Path. 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 Path Point 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 Path Point equals (x, y). arcTo scales radii (rx, ry) to fit last Path Point 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 in x before x-axis rotation |
ry |
radius in y 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 Path
Example
See Also
SkPath& arcTo(const SkPoint r, SkScalar xAxisRotate, ArcSize largeArc, Direction sweep, const SkPoint xy)
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 xAxisRotate degrees. Arc curves from last Path Point 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 Path Point equals (x, y). arcTo scales radii r to fit last Path Point 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 Path
Example
See Also
rArcTo
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 (x0, y0) to end Point:
(x0 + dx, y0 + 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
arcTo[2][3][4][5] ArcSize Direction
close
SkPath& close()
Appends kClose Verb to Path. A closed Contour connects the first and last Point with Line, forming a continuous loop. Open and closed Contour draw the same with SkPaint::kFill Style. With SkPaint::kStroke Style, open Contour draws Paint Stroke Cap at Contour start and end; closed Contour draws Paint Stroke Join at Contour start and end.
close has no effect if Path is empty or last Path Verb is kClose Verb.
Return Value
reference to Path
Example
See Also
IsInverseFillType
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
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
ConvertConicToQuads
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
isRect
bool isRect(SkRect* rect, bool* isClosed = nullptr, Direction* direction = nullptr) const
Returns true if Path is equivalent to Rect 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 Path bounds. Path bounds may include kMove Verb points that do not alter the area drawn by the returned rect.
Parameters
rect |
storage for bounds of Rect; may be nullptr |
isClosed |
storage set to true if Path is closed; may be nullptr |
direction |
storage set to Rect direction; may be nullptr |
Return Value
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
isNestedFillRects
bool isNestedFillRects(SkRect rect[2], Direction dirs[2] = nullptr) const
Returns true if Path is equivalent to nested Rect 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 Rect, and rect[1] to inner Rect; setting dirs[0] to Direction of outer Rect, and dirs[1] to Direction of inner Rect.
Parameters
rect |
storage for Rect pair; may be nullptr |
dirs |
storage for Direction pair; may be nullptr |
Return Value
true if Path contains nested Rect 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
addRect
SkPath& addRect(const SkRect& rect, Direction dir = kCW Direction)
Adds Rect to Path, appending kMove Verb, three kLine Verb, and kClose Verb, starting with top-left corner of Rect; 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 |
Rect to add as a closed contour |
dir |
Direction to wind added contour |
Return Value
reference to Path
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 Rect (left, top, right, bottom) to Path, appending kMove Verb, three kLine Verb, and kClose Verb, starting with top-left corner of Rect; 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 Rect |
top |
smaller y-axis value of Rect |
right |
larger x-axis value of Rect |
bottom |
larger y-axis value of Rect |
dir |
Direction to wind added contour |
Return Value
reference to Path
Example
See Also
addOval
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 Rect 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 |
Direction to wind ellipse |
Return Value
reference to Path
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
addCircle
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[2] Direction Circle
addArc
SkPath& addArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle)
Appends Arc to Path, 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 Path
Example
See Also
Arc arcTo[2][3][4][5] SkCanvas::drawArc
addRoundRect
SkPath& addRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry, 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 (rx, ry). 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 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 Rect rect to Path.
After appending, Path may be empty, or may contain: Rect, Oval, or RoundRect.
Parameters
rect |
bounds of Round Rect |
rx |
x-axis radius of rounded corners on the Round Rect |
ry |
y-axis radius of rounded corners on the Round Rect |
dir |
Direction to wind Round Rect |
Return Value
reference to Path
Example
See Also
addRRect[2] 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 RoundRect.
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[2] SkCanvas::drawRoundRect
addRRect
SkPath& addRRect(const SkRRect& rrect, Direction dir = kCW Direction)
Adds rrect to Path, 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, 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 |
Return Value
reference to Path
Example
See Also
addRoundRect[2] 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[2] SkCanvas::drawRRect
addPoly
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 Point in pts array. If close is true, appends kClose Verb to Path, 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 Point |
count |
length of Point array |
close |
true to add Line connecting Contour end and start |
Return Value
reference to Path
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 Point in list. If close is true, appends kClose Verb to Path, connecting last and first Point in list.
If list is empty, append kMove Verb to path.
Parameters
list |
array of Points |
close |
true to add Line connecting Contour end and start |
Return Value
reference to Path
Example
See Also
Enum SkPath::AddPathMode
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 remining Verbs, Points, and Conic Weights. |
Example
See Also
addPath
SkPath& addPath(const SkPath& src, SkScalar dx, SkScalar dy, AddPathMode mode = kAppend AddPathMode)
Appends src to Path, offset by (dx, dy).
If mode is kAppend AddPathMode, src Verb Array, Point Array, and Conic Weights are added unaltered. If mode is kExtend AddPathMode, add Line before appending Verbs, Points, and Conic Weights.
Parameters
src |
Path Verbs, Points, and Conic Weights to add |
dx |
offset added to src Point Array x-axis coordinates |
dy |
offset added to src Point Array y-axis coordinates |
mode |
kAppend AddPathMode or kExtend AddPathMode |
Return Value
reference to Path
Example
See Also
AddPathMode offset[2] reverseAddPath
SkPath& addPath(const SkPath& src, AddPathMode mode = kAppend AddPathMode)
If mode is kAppend AddPathMode, src Verb Array, Point Array, and Conic Weights are added unaltered. If mode is kExtend AddPathMode, add Line before appending Verbs, Points, and Conic Weights.
Parameters
src |
Path Verbs, Points, and Conic Weights to add |
mode |
kAppend AddPathMode or kExtend AddPathMode |
Return Value
reference to Path
Example
See Also
SkPath& addPath(const SkPath& src, const SkMatrix& matrix, AddPathMode mode = kAppend AddPathMode)
Appends src to Path, transformed by matrix. Transformed curves may have different Verbs, Points, and Conic Weights.
If mode is kAppend AddPathMode, src Verb Array, Point Array, and Conic Weights are added unaltered. If mode is kExtend AddPathMode, add Line before appending Verbs, Points, and Conic Weights.
Parameters
src |
Path Verbs, Points, and Conic Weights to add |
matrix |
transform applied to src |
mode |
kAppend AddPathMode or kExtend AddPathMode |
Return Value
reference to Path
Example
See Also
AddPathMode transform[2] offset[2] reverseAddPath
reverseAddPath
SkPath& reverseAddPath(const SkPath& src)
Appends src to Path, from back to front. Reversed src always appends a new Contour to Path.
Parameters
src |
Path Verbs, Points, and Conic Weights to add |
Return Value
reference to Path
Example
See Also
AddPathMode transform[2] offset[2] addPath[2][3]
offset
void offset(SkScalar dx, SkScalar dy, SkPath* dst) const
Offsets Point Array by (dx, dy). Offset Path replaces dst. If dst is nullptr, Path is replaced by offset data.
Parameters
dx |
offset added to Point Array x-axis coordinates |
dy |
offset added to Point Array y-axis coordinates |
dst |
overwritten, translated copy of Path; may be nullptr |
Example
See Also
Transform
Topic | Description |
---|---|
offset | translates Point Array |
offset(SkScalar dx, SkScalar dy, SkPath* dst) const | |
offset(SkScalar dx, SkScalar dy) | |
transform | applies Matrix to Point Array and Weights |
transform(const SkMatrix& matrix, SkPath* dst) const | |
transform(const SkMatrix& matrix) |
void offset(SkScalar dx, SkScalar dy)
Offsets Point Array by (dx, dy). Path is replaced by offset data.
Parameters
dx |
offset added to Point Array x-axis coordinates |
dy |
offset added to Point Array y-axis coordinates |
Example
See Also
addPath[2][3] transform[2] SkCanvas::translate()
transform
void transform(const SkMatrix& matrix, SkPath* dst) const
Transforms Verb Array, Point Array, and weight by matrix. transform may change Verbs and increase their number. Transformed Path replaces dst; if dst is nullptr, original data is replaced.
Parameters
matrix |
Matrix to apply to Path |
dst |
overwritten, transformed copy of Path; may be nullptr |
Example
See Also
addPath[2][3] offset[2] SkCanvas::concat() SkMatrix
void transform(const SkMatrix& matrix)
Transforms Verb Array, Point Array, and weight by matrix. transform may change Verbs and increase their number. Path is replaced by transformed data.
Parameters
matrix |
Matrix to apply to Path |
Example
See Also
addPath[2][3] offset[2] SkCanvas::concat() SkMatrix
Last Point
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.
getLastPt
bool getLastPt(SkPoint* lastPt) const
Returns Last Point on Path in lastPt. Returns false if Point Array is empty, storing (0, 0) if lastPt is not nullptr.
Parameters
lastPt |
storage for final Point in Point Array; may be nullptr |
Return Value
true if Point Array contains one or more Points
Example
Example Output
last point: 35.2786, 52.9772
See Also
setLastPt
void setLastPt(SkScalar x, SkScalar y)
Sets Last Point to (x, y). If Point Array is empty, append kMove Verb to Verb Array and append (x, y) to Point 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 Point Array is empty, append kMove Verb to Verb Array and append p to Point Array.
Parameters
p |
set value of Last Point |
Example
See Also
Enum SkPath::SegmentMask
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
getSegmentMasks
uint32_t getSegmentMasks() const
Returns a mask, where each set bit corresponds to a SegmentMask constant if Path contains one or more Verbs of that type. Returns zero if Path 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
contains
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
dump
void dump(SkWStream* stream, bool forceClose, bool dumpAsHex) const
Writes text representation of Path to stream. If stream is nullptr, writes to standard output. Set forceClose to true to get edges used to fill Path. Set dumpAsHex true to generate exact binary representations of floating point numbers used in Point Array and Conic Weights.
Parameters
stream |
writable WStream receiving Path 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()[2] SkRRect::dump()[2] SkPathMeasure::dump()
void dump() const
Writes text representation of Path 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 Path 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()[2] SkRRect::dump()[2] SkPathMeasure::dump() writeToMemory
dumpHex
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[2] SkRect::dumpHex SkRRect::dumpHex writeToMemory
writeToMemory
size_t writeToMemory(void* buffer) const
Writes Path to buffer, returning the number of bytes written. Pass nullptr to obtain the storage size.
Writes Fill Type, Verb Array, Point Array, Conic Weight, and additionally writes computed information like Convexity and bounds.
Use only be used in concert with readFromMemory; the format used for Path in memory is not guaranteed.
Parameters
buffer |
storage for Path; may be nullptr |
Return Value
size of storage required for Path; always a multiple of 4
Example
Example Output
path is equal to copy
See Also
serialize readFromMemory dump[2] dumpHex
serialize
sk sp<SkData> serialize() const
Writes Path to buffer, returning the buffer written to, wrapped in Data.
serialize writes Fill Type, Verb Array, Point Array, Conic Weight, and additionally writes computed information like Convexity and bounds.
serialize should only be used in concert with readFromMemory. The format used for Path in memory is not guaranteed.
Return Value
Path data wrapped in Data buffer
Example
Example Output
path is equal to copy
See Also
writeToMemory readFromMemory dump[2] dumpHex
readFromMemory
size_t readFromMemory(const void* buffer, size_t length)
Initializes Path from buffer of size length. Returns zero if the buffer is data is inconsistent, or the length is too small.
Reads Fill Type, Verb Array, Point Array, Conic Weight, and additionally reads computed information like Convexity and bounds.
Used only in concert with writeToMemory; the format used for Path in memory is not guaranteed.
Parameters
buffer |
storage for Path |
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
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.
getGenerationID
uint32_t getGenerationID() const
Returns a non-zero, globally unique value. A different value is returned if Verb Array, Point Array, or Conic Weight changes.
Setting Fill Type does not change Generation ID.
Each time the path is modified, a different Generation ID will be returned.
Fill Type does affect Generation ID 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)
isValid
bool isValid() const
Returns if Path data is consistent. Corrupt Path data is detected if internal values are out of range or internal storage does not match array dimensions.
Return Value
true if Path data is consistent
pathRefIsValid
bool pathRefIsValid() const
To be deprecated soon.
Class SkPath::Iter
Constructor
SkPath::Iter can be constructed or initialized by these functions, including C++ class constructors.
Topic | Description |
---|---|
Iter(const SkPath& path, bool forceClose) | constructs Path iterator |
Member_Function
SkPath::Iter member functions read and modify the structure properties.
Topic | Description |
---|---|
Iter() | constructs Path iterator |
conicWeight | returns Conic Weight |
isCloseLine | returns if Line was generated by kClose Verb |
isClosedContour | returns if Contour has kClose Verb |
next | returns next Verb |
setPath | resets Iter to Path |
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
Iter()
Initializes Iter with an empty Path. next on Iter returns kDone Verb. Call setPath to initialize Iter at a later time.
Return Value
Example
Example Output
iter is done
iter is done
See Also
Iter
Iter(const SkPath& path, bool forceClose)
Sets Iter to return elements of Verb Array, Point Array, and Conic Weight in path. If forceClose is true, Iter will add kLine Verb and kClose Verb after each open Contour. path is not altered.
Parameters
path |
Path 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
setPath
void setPath(const SkPath& path, bool forceClose)
Sets Iter to return elements of Verb Array, Point Array, and Conic Weight in path. If forceClose is true, Iter will add kLine Verb and kClose Verb after each open Contour. path is not altered.
Parameters
path |
Path 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)
next
Verb next(SkPoint pts[4], bool doConsumeDegenerates = true, bool exact = false)
Returns next Verb in Verb Array, and advances Iter. When Verb Array is exhausted, returns kDone Verb.
Zero to four Points are stored in pts, depending on the returned 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 Point data describing returned Verb |
doConsumeDegenerates |
if true, skip degenerate Verbs |
exact |
skip zero length curves |
Return Value
next 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
conicWeight
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 Points 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
isCloseLine
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
isClosedContour
bool isClosedContour() const
Returns true if subsequent calls to next return kClose Verb before returning kMove Verb. if true, Contour Iter is processing may end with kClose Verb, or 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 SkPath::RawIter
Constructor
SkPath::RawIter can be constructed or initialized by these functions, including C++ class constructors.
Topic | Description |
---|---|
RawIter(const SkPath& path) | constructs with Path to iterate over |
Member_Function
SkPath::RawIter member functions read and modify the structure properties.
Topic | Description |
---|---|
RawIter() | constructs empty Path iterator |
conicWeight | returns Conic Weight |
next | returns next Verb and associated Points |
peek | returns next Verb |
setPath | sets Path to iterate over |
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
RawIter()
Initializes RawIter with an empty Path. next on RawIter returns kDone Verb. Call setPath to initialize SkPath::Iter at a later time.
Return Value
RawIter
RawIter(const SkPath& path)
Sets RawIter to return elements of Verb Array, Point Array, and Conic Weight in path.
Parameters
path |
Path to iterate |
Return Value
setPath
void setPath(const SkPath& path)
Sets SkPath::Iter to return elements of Verb Array, Point Array, and Conic Weight in path.
Parameters
path |
Path to iterate |
next
Verb next(SkPoint pts[4])
Returns next Verb in Verb Array, and advances RawIter. When Verb Array is exhausted, returns kDone Verb. Zero to four Points are stored in pts, depending on the returned Verb.
Parameters
pts |
storage for Point data describing returned Verb |
Return Value
next 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
peek
Verb peek() const
Returns next Verb, but does not advance RawIter.
Return Value
next 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
StdOut is not really volatile, it just produces the wrong result. A simple fix changes the output of hairlines and needs to be investigated to see if the change is correct or not. see change 21340 (abandoned for now)
See Also
conicWeight
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 Points 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