Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1 | #Topic Path |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 2 | #Alias Path_Reference ## |
| 3 | #Alias Paths ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5 | Path contains Lines and Curves which can be stroked or filled. Contour is |
| 6 | composed of a series of connected Lines and Curves. Path may contain zero, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 7 | one, or more Contours. |
| 8 | Each Line and Curve are described by Verb, Points, and optional Conic_Weight. |
| 9 | |
| 10 | Each pair of connected Lines and Curves share common Point; for instance, Path |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 11 | containing two connected Lines are described the Verb sequence: |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 12 | SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb; and a Point sequence |
| 13 | with three entries, sharing |
| 14 | the middle entry as the end of the first Line and the start of the second Line. |
| 15 | |
| 16 | Path components Arc, Rect, Round_Rect, Circle, and Oval are composed of |
| 17 | Lines and Curves with as many Verbs and Points required |
| 18 | for an exact description. Once added to Path, these components may lose their |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 19 | identity; although Path can be inspected to determine if it describes a single |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 20 | Rect, Oval, Round_Rect, and so on. |
| 21 | |
| 22 | #Example |
| 23 | #Height 192 |
| 24 | #Description |
| 25 | Path contains three Contours: Line, Circle, and Quad. Line is stroked but |
| 26 | not filled. Circle is stroked and filled; Circle stroke forms a loop. Quad |
| 27 | is stroked and filled, but since it is not closed, Quad does not stroke a loop. |
| 28 | ## |
| 29 | void draw(SkCanvas* canvas) { |
| 30 | SkPaint paint; |
| 31 | paint.setAntiAlias(true); |
| 32 | SkPath path; |
| 33 | path.moveTo(124, 108); |
| 34 | path.lineTo(172, 24); |
| 35 | path.addCircle(50, 50, 30); |
| 36 | path.moveTo(36, 148); |
| 37 | path.quadTo(66, 188, 120, 136); |
| 38 | canvas->drawPath(path, paint); |
| 39 | paint.setStyle(SkPaint::kStroke_Style); |
| 40 | paint.setColor(SK_ColorBLUE); |
| 41 | paint.setStrokeWidth(3); |
| 42 | canvas->drawPath(path, paint); |
| 43 | } |
| 44 | ## |
| 45 | |
| 46 | Path contains a Fill_Type which determines whether overlapping Contours |
| 47 | form fills or holes. Fill_Type also determines whether area inside or outside |
| 48 | Lines and Curves is filled. |
| 49 | |
| 50 | #Example |
| 51 | #Height 192 |
| 52 | #Description |
| 53 | Path is drawn filled, then stroked, then stroked and filled. |
| 54 | ## |
| 55 | void draw(SkCanvas* canvas) { |
| 56 | SkPaint paint; |
| 57 | paint.setAntiAlias(true); |
| 58 | SkPath path; |
| 59 | path.moveTo(36, 48); |
| 60 | path.quadTo(66, 88, 120, 36); |
| 61 | canvas->drawPath(path, paint); |
| 62 | paint.setStyle(SkPaint::kStroke_Style); |
| 63 | paint.setColor(SK_ColorBLUE); |
| 64 | paint.setStrokeWidth(8); |
| 65 | canvas->translate(0, 50); |
| 66 | canvas->drawPath(path, paint); |
| 67 | paint.setStyle(SkPaint::kStrokeAndFill_Style); |
| 68 | paint.setColor(SK_ColorRED); |
| 69 | canvas->translate(0, 50); |
| 70 | canvas->drawPath(path, paint); |
| 71 | } |
| 72 | ## |
| 73 | |
| 74 | Path contents are never shared. Copying Path by value effectively creates |
| 75 | a new Path independent of the original. Internally, the copy does not duplicate |
| 76 | its contents until it is edited, to reduce memory use and improve performance. |
| 77 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 78 | #Subtopic Contour |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 79 | #Alias Contours ## |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 80 | #Line # loop of lines and curves ## |
| 81 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 82 | Contour contains one or more Verbs, and as many Points as |
| 83 | are required to satisfy Verb_Array. First Verb in Path is always |
| 84 | SkPath::kMove_Verb; each SkPath::kMove_Verb that follows starts a new Contour. |
| 85 | |
| 86 | #Example |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 87 | #Description |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 88 | Each SkPath::moveTo starts a new Contour, and content after SkPath::close() |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 89 | also starts a new Contour. Since SkPath::conicTo is not preceded by |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 90 | SkPath::moveTo, the first Point of the third Contour starts at the last Point |
| 91 | of the second Contour. |
| 92 | ## |
| 93 | #Height 192 |
| 94 | SkPaint paint; |
| 95 | paint.setAntiAlias(true); |
| 96 | canvas->drawString("1st contour", 150, 100, paint); |
| 97 | canvas->drawString("2nd contour", 130, 160, paint); |
| 98 | canvas->drawString("3rd contour", 40, 30, paint); |
| 99 | paint.setStyle(SkPaint::kStroke_Style); |
| 100 | SkPath path; |
| 101 | path.moveTo(124, 108); |
| 102 | path.lineTo(172, 24); |
| 103 | path.moveTo(36, 148); |
| 104 | path.quadTo(66, 188, 120, 136); |
| 105 | path.close(); |
| 106 | path.conicTo(70, 20, 110, 40, 0.6f); |
| 107 | canvas->drawPath(path, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 108 | ## |
| 109 | |
| 110 | If final Verb in Contour is SkPath::kClose_Verb, Line connects Last_Point in |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 111 | Contour with first Point. A closed Contour, stroked, draws |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 112 | Paint_Stroke_Join at Last_Point and first Point. Without SkPath::kClose_Verb |
| 113 | as final Verb, Last_Point and first Point are not connected; Contour |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 114 | remains open. An open Contour, stroked, draws Paint_Stroke_Cap at |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 115 | Last_Point and first Point. |
| 116 | |
| 117 | #Example |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 118 | #Height 160 |
| 119 | #Description |
| 120 | Path is drawn stroked, with an open Contour and a closed Contour. |
| 121 | ## |
| 122 | void draw(SkCanvas* canvas) { |
| 123 | SkPaint paint; |
| 124 | paint.setAntiAlias(true); |
| 125 | paint.setStyle(SkPaint::kStroke_Style); |
| 126 | paint.setStrokeWidth(8); |
| 127 | SkPath path; |
| 128 | path.moveTo(36, 48); |
| 129 | path.quadTo(66, 88, 120, 36); |
| 130 | canvas->drawPath(path, paint); |
| 131 | path.close(); |
| 132 | canvas->translate(0, 50); |
| 133 | canvas->drawPath(path, paint); |
| 134 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 135 | ## |
| 136 | |
| 137 | #Subtopic Zero_Length |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 138 | #Alias Zero_Length_Contour ## |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 139 | #Line # consideration when contour has no length ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 140 | Contour length is distance traveled from first Point to Last_Point, |
| 141 | plus, if Contour is closed, distance from Last_Point to first Point. |
| 142 | Even if Contour length is zero, stroked Lines are drawn if Paint_Stroke_Cap |
| 143 | makes them visible. |
| 144 | |
| 145 | #Example |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 146 | #Height 64 |
| 147 | SkPaint paint; |
| 148 | paint.setAntiAlias(true); |
| 149 | paint.setStyle(SkPaint::kStroke_Style); |
| 150 | paint.setStrokeWidth(8); |
| 151 | paint.setStrokeCap(SkPaint::kRound_Cap); |
| 152 | SkPath path; |
| 153 | path.moveTo(36, 48); |
| 154 | path.lineTo(36, 48); |
| 155 | canvas->drawPath(path, paint); |
| 156 | path.reset(); |
| 157 | paint.setStrokeCap(SkPaint::kSquare_Cap); |
| 158 | path.moveTo(56, 48); |
| 159 | path.close(); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 160 | canvas->drawPath(path, paint); |
| 161 | ## |
| 162 | |
| 163 | #Subtopic Zero_Length ## |
| 164 | |
| 165 | #Subtopic Contour ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 166 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 167 | # ------------------------------------------------------------------------------ |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 168 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 169 | #Class SkPath |
| 170 | |
| 171 | Paths contain geometry. Paths may be empty, or contain one or more Verbs that |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 172 | outline a figure. Path always starts with a move verb to a Cartesian_Coordinate, |
| 173 | and may be followed by additional verbs that add lines or curves. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 174 | Adding a close verb makes the geometry into a continuous loop, a closed contour. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 175 | Paths may contain any number of contours, each beginning with a move verb. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 176 | |
| 177 | Path contours may contain only a move verb, or may also contain lines, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 178 | Quadratic_Beziers, Conics, and Cubic_Beziers. Path contours may be open or |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 179 | closed. |
| 180 | |
| 181 | When used to draw a filled area, Path describes whether the fill is inside or |
| 182 | outside the geometry. Path also describes the winding rule used to fill |
| 183 | overlapping contours. |
| 184 | |
| 185 | Internally, Path lazily computes metrics likes bounds and convexity. Call |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 186 | SkPath::updateBoundsCache to make Path thread safe. |
| 187 | |
| 188 | #Subtopic Overview |
| 189 | #Populate |
| 190 | ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 191 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 192 | #Subtopic Related_Function |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 193 | #Populate |
| 194 | ## |
Cary Clark | 5081eed | 2018-01-22 07:55:48 -0500 | [diff] [blame] | 195 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 196 | #Subtopic Constant |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 197 | #Populate |
| 198 | ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 199 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 200 | #Subtopic Class |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 201 | #Populate |
| 202 | ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 203 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 204 | #Subtopic Constructor |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 205 | #Populate |
| 206 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 207 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 208 | #Subtopic Operator |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 209 | #Populate |
| 210 | ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 211 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 212 | #Subtopic Member_Function |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 213 | #Populate |
| 214 | ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 215 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 216 | #Subtopic Verb |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 217 | #Alias Verbs ## |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 218 | #Line # line and curve type ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 219 | #Enum Verb |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 220 | #Line # controls how Path Points are interpreted ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 221 | |
| 222 | #Code |
| 223 | enum Verb { |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 224 | kMove_Verb, |
| 225 | kLine_Verb, |
| 226 | kQuad_Verb, |
| 227 | kConic_Verb, |
| 228 | kCubic_Verb, |
| 229 | kClose_Verb, |
| 230 | kDone_Verb, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 231 | }; |
| 232 | ## |
| 233 | |
| 234 | Verb instructs Path how to interpret one or more Point and optional Conic_Weight; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 235 | manage Contour, and terminate Path. |
| 236 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 237 | #Const kMove_Verb 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 238 | #Line # starts new Contour at next Point ## |
| 239 | Consecutive kMove_Verb are preserved but all but the last kMove_Verb is |
| 240 | ignored. kMove_Verb after other Verbs implicitly closes the previous Contour |
| 241 | if SkPaint::kFill_Style is set when drawn; otherwise, stroke is drawn open. |
| 242 | kMove_Verb as the last Verb is preserved but ignored. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 243 | ## |
| 244 | #Const kLine_Verb 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 245 | #Line # adds Line from Last_Point to next Point ## |
| 246 | Line is a straight segment from Point to Point. Consecutive kLine_Verb |
| 247 | extend Contour. kLine_Verb at same position as prior kMove_Verb is |
| 248 | preserved, and draws Point if SkPaint::kStroke_Style is set, and |
| 249 | SkPaint::Cap is SkPaint::kSquare_Cap or SkPaint::kRound_Cap. kLine_Verb |
| 250 | at same position as prior line or curve Verb is preserved but is ignored. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 251 | ## |
| 252 | #Const kQuad_Verb 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 253 | #Line # adds Quad from Last_Point ## |
| 254 | Adds Quad from Last_Point, using control Point, and end Point. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 255 | Quad is a parabolic section within tangents from Last_Point to control Point, |
| 256 | and control Point to end Point. |
| 257 | ## |
| 258 | #Const kConic_Verb 3 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 259 | #Line # adds Conic from Last_Point ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 260 | Adds Conic from Last_Point, using control Point, end Point, and Conic_Weight. |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 261 | Conic is a elliptical, parabolic, or hyperbolic section within tangents |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 262 | from Last_Point to control Point, and control Point to end Point, constrained |
| 263 | by Conic_Weight. Conic_Weight less than one is elliptical; equal to one is |
| 264 | parabolic (and identical to Quad); greater than one hyperbolic. |
| 265 | ## |
| 266 | #Const kCubic_Verb 4 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 267 | #Line # adds Cubic from Last_Point ## |
| 268 | Adds Cubic from Last_Point, using two control Points, and end Point. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 269 | Cubic is a third-order Bezier_Curve section within tangents from Last_Point |
| 270 | to first control Point, and from second control Point to end Point. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 271 | ## |
| 272 | #Const kClose_Verb 5 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 273 | #Line # closes Contour ## |
| 274 | Closes Contour, connecting Last_Point to kMove_Verb Point. Consecutive |
| 275 | kClose_Verb are preserved but only first has an effect. kClose_Verb after |
| 276 | kMove_Verb has no effect. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 277 | ## |
| 278 | #Const kDone_Verb 6 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 279 | #Line # terminates Path ## |
| 280 | Not in Verb_Array, but returned by Path iterator. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 281 | ## |
| 282 | |
| 283 | Each Verb has zero or more Points stored in Path. |
| 284 | Path iterator returns complete curve descriptions, duplicating shared Points |
| 285 | for consecutive entries. |
| 286 | |
| 287 | #Table |
| 288 | #Legend |
| 289 | # Verb # Allocated Points # Iterated Points # Weights ## |
| 290 | ## |
| 291 | # kMove_Verb # 1 # 1 # 0 ## |
| 292 | # kLine_Verb # 1 # 2 # 0 ## |
| 293 | # kQuad_Verb # 2 # 3 # 0 ## |
| 294 | # kConic_Verb # 2 # 3 # 1 ## |
| 295 | # kCubic_Verb # 3 # 4 # 0 ## |
| 296 | # kClose_Verb # 0 # 1 # 0 ## |
| 297 | # kDone_Verb # -- # 0 # 0 ## |
| 298 | ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 299 | |
| 300 | #Example |
| 301 | void draw(SkCanvas* canvas) { |
| 302 | SkPath path; |
| 303 | path.lineTo(20, 20); |
| 304 | path.quadTo(-10, -10, 30, 30); |
| 305 | path.close(); |
| 306 | path.cubicTo(1, 2, 3, 4, 5, 6); |
| 307 | path.conicTo(0, 0, 0, 0, 2); |
| 308 | uint8_t verbs[7]; |
| 309 | int count = path.getVerbs(verbs, (int) SK_ARRAY_COUNT(verbs)); |
| 310 | const char* verbStr[] = { "Move", "Line", "Quad", "Conic", "Cubic", "Close" }; |
| 311 | SkDebugf("verb count: %d\nverbs: ", count); |
| 312 | for (int i = 0; i < count; ++i) { |
| 313 | SkDebugf("k%s_Verb ", verbStr[verbs[i]]); |
| 314 | } |
| 315 | SkDebugf("\n"); |
| 316 | } |
| 317 | #StdOut |
| 318 | verb count: 7 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 319 | verbs: kMove_Verb kLine_Verb kQuad_Verb kClose_Verb kMove_Verb kCubic_Verb kConic_Verb |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 320 | ## |
| 321 | ## |
| 322 | |
| 323 | #Enum Verb ## |
| 324 | #Subtopic Verb ## |
| 325 | |
| 326 | # ------------------------------------------------------------------------------ |
| 327 | #Subtopic Direction |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 328 | #Line # contour orientation, clockwise or counterclockwise ## |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 329 | #Alias Directions ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 330 | |
| 331 | #Enum Direction |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 332 | #Line # sets Contour clockwise or counterclockwise ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 333 | |
| 334 | #Code |
| 335 | enum Direction { |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 336 | kCW_Direction, |
| 337 | kCCW_Direction, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 338 | }; |
| 339 | ## |
| 340 | |
| 341 | Direction describes whether Contour is clockwise or counterclockwise. |
| 342 | When Path contains multiple overlapping Contours, Direction together with |
| 343 | Fill_Type determines whether overlaps are filled or form holes. |
| 344 | |
| 345 | Direction also determines how Contour is measured. For instance, dashing |
| 346 | measures along Path to determine where to start and stop stroke; Direction |
| 347 | will change dashed results as it steps clockwise or counterclockwise. |
| 348 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 349 | Closed Contours like Rect, Round_Rect, Circle, and Oval added with |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 350 | kCW_Direction travel clockwise; the same added with kCCW_Direction |
| 351 | travel counterclockwise. |
| 352 | |
| 353 | #Const kCW_Direction 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 354 | #Line # contour travels clockwise ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 355 | ## |
| 356 | #Const kCCW_Direction 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 357 | #Line # contour travels counterclockwise ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 358 | ## |
| 359 | |
| 360 | |
| 361 | #Example |
| 362 | #Height 100 |
| 363 | void draw(SkCanvas* canvas) { |
| 364 | const SkPoint arrow[] = { {40, -5}, {45, 0}, {40, 5} }; |
| 365 | const SkRect rect = {10, 10, 90, 90}; |
| 366 | SkPaint rectPaint; |
| 367 | rectPaint.setAntiAlias(true); |
| 368 | SkPaint textPaint(rectPaint); |
| 369 | textPaint.setTextAlign(SkPaint::kCenter_Align); |
| 370 | rectPaint.setStyle(SkPaint::kStroke_Style); |
| 371 | SkPaint arrowPaint(rectPaint); |
| 372 | SkPath arrowPath; |
| 373 | arrowPath.addPoly(arrow, SK_ARRAY_COUNT(arrow), true); |
| 374 | arrowPaint.setPathEffect(SkPath1DPathEffect::Make(arrowPath, 320, 0, |
| 375 | SkPath1DPathEffect::kRotate_Style)); |
| 376 | for (auto direction : { SkPath::kCW_Direction, SkPath::kCCW_Direction } ) { |
| 377 | canvas->drawRect(rect, rectPaint); |
| 378 | for (unsigned start : { 0, 1, 2, 3 } ) { |
| 379 | SkPath path; |
| 380 | path.addRect(rect, direction, start); |
| 381 | canvas->drawPath(path, arrowPaint); |
| 382 | } |
| 383 | canvas->drawString(SkPath::kCW_Direction == direction ? "CW" : "CCW", rect.centerX(), |
| 384 | rect.centerY(), textPaint); |
| 385 | canvas->translate(120, 0); |
| 386 | } |
| 387 | } |
| 388 | ## |
| 389 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 390 | #SeeAlso arcTo rArcTo isRect isNestedFillRects addRect addOval |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 391 | |
| 392 | #Enum Direction ## |
| 393 | #Subtopic Direction ## |
| 394 | |
| 395 | # ------------------------------------------------------------------------------ |
| 396 | |
| 397 | #Method SkPath() |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 398 | #In Constructor |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 399 | #Line # constructs with default values ## |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 400 | Constucts an empty Path. By default, Path has no Verbs, no Points, and no Weights. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 401 | Fill_Type is set to kWinding_FillType. |
| 402 | |
| 403 | #Return empty Path ## |
| 404 | |
| 405 | #Example |
| 406 | SkPath path; |
| 407 | SkDebugf("path is " "%s" "empty", path.isEmpty() ? "" : "not "); |
| 408 | #StdOut |
| 409 | path is empty |
| 410 | ## |
| 411 | ## |
| 412 | |
| 413 | #SeeAlso reset rewind |
| 414 | |
| 415 | ## |
| 416 | |
| 417 | # ------------------------------------------------------------------------------ |
| 418 | |
| 419 | #Method SkPath(const SkPath& path) |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 420 | #In Constructor |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 421 | #Line # makes a shallow copy ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 422 | Constructs a copy of an existing path. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 423 | Copy constructor makes two paths identical by value. Internally, path and |
| 424 | the returned result share pointer values. The underlying Verb_Array, Point_Array |
| 425 | and Weights are copied when modified. |
| 426 | |
| 427 | Creating a Path copy is very efficient and never allocates memory. |
| 428 | Paths are always copied by value from the interface; the underlying shared |
| 429 | pointers are not exposed. |
| 430 | |
| 431 | #Param path Path to copy by value ## |
| 432 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 433 | #Return copy of Path ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 434 | |
| 435 | #Example |
| 436 | #Description |
| 437 | Modifying one path does not effect another, even if they started as copies |
| 438 | of each other. |
| 439 | ## |
| 440 | SkPath path; |
| 441 | path.lineTo(20, 20); |
| 442 | SkPath path2(path); |
| 443 | path2.close(); |
| 444 | SkDebugf("path verbs: %d\n", path.countVerbs()); |
| 445 | SkDebugf("path2 verbs: %d\n", path2.countVerbs()); |
| 446 | path.reset(); |
| 447 | SkDebugf("after reset\n" "path verbs: %d\n", path.countVerbs()); |
| 448 | SkDebugf("path2 verbs: %d\n", path2.countVerbs()); |
| 449 | #StdOut |
| 450 | path verbs: 2 |
| 451 | path2 verbs: 3 |
| 452 | after reset |
| 453 | path verbs: 0 |
| 454 | path2 verbs: 3 |
| 455 | ## |
| 456 | ## |
| 457 | |
| 458 | #SeeAlso operator=(const SkPath& path) |
| 459 | |
| 460 | ## |
| 461 | |
| 462 | # ------------------------------------------------------------------------------ |
| 463 | |
| 464 | #Method ~SkPath() |
| 465 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 466 | #Line # decreases Reference_Count of owned objects ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 467 | Releases ownership of any shared data and deletes data if Path is sole owner. |
| 468 | |
| 469 | #Example |
| 470 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 471 | delete calls Path Destructor, but copy of original in path2 is unaffected. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 472 | ## |
| 473 | void draw(SkCanvas* canvas) { |
| 474 | SkPath* path = new SkPath(); |
| 475 | path->lineTo(20, 20); |
| 476 | SkPath path2(*path); |
| 477 | delete path; |
| 478 | SkDebugf("path2 is " "%s" "empty", path2.isEmpty() ? "" : "not "); |
| 479 | } |
| 480 | ## |
| 481 | |
| 482 | #SeeAlso SkPath() SkPath(const SkPath& path) operator=(const SkPath& path) |
| 483 | |
| 484 | ## |
| 485 | |
| 486 | # ------------------------------------------------------------------------------ |
| 487 | |
| 488 | #Method SkPath& operator=(const SkPath& path) |
| 489 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 490 | #Line # makes a shallow copy ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 491 | Constructs a copy of an existing path. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 492 | Path assignment makes two paths identical by value. Internally, assignment |
| 493 | shares pointer values. The underlying Verb_Array, Point_Array and Weights |
| 494 | are copied when modified. |
| 495 | |
| 496 | Copying Paths by assignment is very efficient and never allocates memory. |
| 497 | Paths are always copied by value from the interface; the underlying shared |
| 498 | pointers are not exposed. |
| 499 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 500 | #Param path Verb_Array, Point_Array, Weights, and Fill_Type to copy ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 501 | |
| 502 | #Return Path copied by value ## |
| 503 | |
| 504 | #Example |
| 505 | SkPath path1; |
| 506 | path1.addRect({10, 20, 30, 40}); |
| 507 | SkPath path2 = path1; |
| 508 | const SkRect& b1 = path1.getBounds(); |
| 509 | SkDebugf("path1 bounds = %g, %g, %g, %g\n", b1.fLeft, b1.fTop, b1.fRight, b1.fBottom); |
| 510 | const SkRect& b2 = path2.getBounds(); |
| 511 | SkDebugf("path2 bounds = %g, %g, %g, %g\n", b2.fLeft, b2.fTop, b2.fRight, b2.fBottom); |
| 512 | #StdOut |
| 513 | path1 bounds = 10, 20, 30, 40 |
| 514 | path2 bounds = 10, 20, 30, 40 |
| 515 | #StdOut ## |
| 516 | ## |
| 517 | |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 518 | #SeeAlso swap SkPath(const SkPath& path) |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 519 | |
| 520 | ## |
| 521 | |
| 522 | # ------------------------------------------------------------------------------ |
| 523 | |
| 524 | #Method bool operator==(const SkPath& a, const SkPath& b) |
| 525 | |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 526 | #Line # compares Paths for equality ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 527 | Compares a and b; returns true if Fill_Type, Verb_Array, Point_Array, and Weights |
| 528 | are equivalent. |
| 529 | |
| 530 | #Param a Path to compare ## |
| 531 | #Param b Path to compare ## |
| 532 | |
| 533 | #Return true if Path pair are equivalent ## |
| 534 | |
| 535 | #Example |
| 536 | #Description |
| 537 | Rewind removes Verb_Array but leaves storage; since storage is not compared, |
| 538 | Path pair are equivalent. |
| 539 | ## |
| 540 | void draw(SkCanvas* canvas) { |
| 541 | auto debugster = [](const char* prefix, const SkPath& a, const SkPath& b) -> void { |
| 542 | SkDebugf("%s one %c= two\n", prefix, a == b ? '=' : '!'); |
| 543 | }; |
| 544 | SkPath one; |
| 545 | SkPath two; |
| 546 | debugster("empty", one, two); |
| 547 | one.moveTo(0, 0); |
| 548 | debugster("moveTo", one, two); |
| 549 | one.rewind(); |
| 550 | debugster("rewind", one, two); |
| 551 | one.moveTo(0, 0); |
| 552 | one.reset(); |
| 553 | debugster("reset", one, two); |
| 554 | } |
| 555 | #StdOut |
| 556 | empty one == two |
| 557 | moveTo one != two |
| 558 | rewind one == two |
| 559 | reset one == two |
| 560 | ## |
| 561 | ## |
| 562 | |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 563 | #SeeAlso operator!=(const SkPath& a, const SkPath& b) operator=(const SkPath& path) |
| 564 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 565 | ## |
| 566 | |
| 567 | # ------------------------------------------------------------------------------ |
| 568 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 569 | #Method bool operator!=(const SkPath& a, const SkPath& b) |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 570 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 571 | #Line # compares paths for inequality ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 572 | Compares a and b; returns true if Fill_Type, Verb_Array, Point_Array, and Weights |
| 573 | are not equivalent. |
| 574 | |
| 575 | #Param a Path to compare ## |
| 576 | #Param b Path to compare ## |
| 577 | |
| 578 | #Return true if Path pair are not equivalent ## |
| 579 | |
| 580 | #Example |
| 581 | #Description |
| 582 | Path pair are equal though their convexity is not equal. |
| 583 | ## |
| 584 | void draw(SkCanvas* canvas) { |
| 585 | auto debugster = [](const char* prefix, const SkPath& a, const SkPath& b) -> void { |
| 586 | SkDebugf("%s one %c= two\n", prefix, a != b ? '!' : '='); |
| 587 | }; |
| 588 | SkPath one; |
| 589 | SkPath two; |
| 590 | debugster("empty", one, two); |
| 591 | one.addRect({10, 20, 30, 40}); |
| 592 | two.addRect({10, 20, 30, 40}); |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 593 | debugster("add rect", one, two); |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 594 | one.setConvexity(SkPath::kConcave_Convexity); |
| 595 | debugster("setConvexity", one, two); |
| 596 | SkDebugf("convexity %c=\n", one.getConvexity() == two.getConvexity() ? '=' : '!'); |
| 597 | } |
| 598 | #StdOut |
| 599 | empty one == two |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 600 | add rect one == two |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 601 | setConvexity one == two |
| 602 | convexity != |
| 603 | ## |
| 604 | ## |
| 605 | |
| 606 | ## |
| 607 | |
| 608 | # ------------------------------------------------------------------------------ |
| 609 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 610 | #Subtopic Property |
| 611 | #Populate |
| 612 | #Line # metrics and attributes ## |
| 613 | ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 614 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 615 | #Method bool isInterpolatable(const SkPath& compare) const |
| 616 | #In Property |
| 617 | #In Interpolate |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 618 | #Line # returns if pair contains equal counts of Verb_Array and Weights ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 619 | Returns true if Paths contain equal Verbs and equal Weights. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 620 | If Paths contain one or more Conics, the Weights must match. |
| 621 | |
| 622 | conicTo may add different Verbs depending on Conic_Weight, so it is not |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 623 | trivial to interpolate a pair of Paths containing Conics with different |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 624 | Conic_Weight values. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 625 | |
| 626 | #Param compare Path to compare ## |
| 627 | |
| 628 | #Return true if Paths Verb_Array and Weights are equivalent ## |
| 629 | |
| 630 | #Example |
| 631 | SkPath path, path2; |
| 632 | path.moveTo(20, 20); |
| 633 | path.lineTo(40, 40); |
| 634 | path.lineTo(20, 20); |
| 635 | path.lineTo(40, 40); |
| 636 | path.close(); |
| 637 | path2.addRect({20, 20, 40, 40}); |
| 638 | SkDebugf("paths are " "%s" "interpolatable", path.isInterpolatable(path2) ? "" : "not "); |
| 639 | #StdOut |
| 640 | paths are interpolatable |
| 641 | ## |
| 642 | ## |
| 643 | |
| 644 | #SeeAlso isInterpolatable |
| 645 | |
| 646 | ## |
| 647 | |
| 648 | # ------------------------------------------------------------------------------ |
| 649 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 650 | #Subtopic Interpolate |
| 651 | #Populate |
| 652 | #Line # weighted average of Path pair ## |
| 653 | ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 654 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 655 | #Method bool interpolate(const SkPath& ending, SkScalar weight, SkPath* out) const |
| 656 | #In Interpolate |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 657 | #Line # interpolates between Path pair ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 658 | Interpolates between Paths with Point_Array of equal size. |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 659 | Copy Verb_Array and Weights to out, and set out Point_Array to a weighted |
| 660 | average of this Point_Array and ending Point_Array, using the formula: |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 661 | #Formula |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 662 | (Path Point * weight) + ending Point * (1 - weight) |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 663 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 664 | . |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 665 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 666 | weight is most useful when between zero (ending Point_Array) and |
| 667 | one (this Point_Array); will work with values outside of this |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 668 | range. |
| 669 | |
| 670 | interpolate() returns false and leaves out unchanged if Point_Array is not |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 671 | the same size as ending Point_Array. Call isInterpolatable to check Path |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 672 | compatibility prior to calling interpolate(). |
| 673 | |
| 674 | #Param ending Point_Array averaged with this Point_Array ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 675 | #Param weight contribution of this Point_Array, and |
| 676 | one minus contribution of ending Point_Array |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 677 | ## |
| 678 | #Param out Path replaced by interpolated averages ## |
| 679 | |
| 680 | #Return true if Paths contain same number of Points ## |
| 681 | |
| 682 | #Example |
| 683 | #Height 60 |
| 684 | void draw(SkCanvas* canvas) { |
| 685 | SkPaint paint; |
| 686 | paint.setAntiAlias(true); |
| 687 | paint.setStyle(SkPaint::kStroke_Style); |
| 688 | SkPath path, path2; |
| 689 | path.moveTo(20, 20); |
| 690 | path.lineTo(40, 40); |
| 691 | path.lineTo(20, 40); |
| 692 | path.lineTo(40, 20); |
| 693 | path.close(); |
| 694 | path2.addRect({20, 20, 40, 40}); |
| 695 | for (SkScalar i = 0; i <= 1; i += 1.f / 6) { |
| 696 | SkPath interp; |
| 697 | path.interpolate(path2, i, &interp); |
| 698 | canvas->drawPath(interp, paint); |
| 699 | canvas->translate(30, 0); |
| 700 | } |
| 701 | } |
| 702 | ## |
| 703 | |
| 704 | #SeeAlso isInterpolatable |
| 705 | |
| 706 | ## |
| 707 | |
| 708 | # ------------------------------------------------------------------------------ |
| 709 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 710 | #Method bool unique() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 711 | #Deprecated soon |
| 712 | Only valid for Android framework. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 713 | ## |
| 714 | |
| 715 | # ------------------------------------------------------------------------------ |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 716 | #Subtopic Fill_Type |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 717 | #Line # fill rule, normal and inverted ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 718 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 719 | #Enum FillType |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 720 | #Line # sets winding rule and inverse fill ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 721 | |
| 722 | #Code |
| 723 | enum FillType { |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 724 | kWinding_FillType, |
| 725 | kEvenOdd_FillType, |
| 726 | kInverseWinding_FillType, |
| 727 | kInverseEvenOdd_FillType, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 728 | }; |
| 729 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 730 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 731 | Fill_Type selects the rule used to fill Path. Path set to kWinding_FillType |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 732 | fills if the sum of Contour edges is not zero, where clockwise edges add one, and |
| 733 | counterclockwise edges subtract one. Path set to kEvenOdd_FillType fills if the |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 734 | number of Contour edges is odd. Each Fill_Type has an inverse variant that |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 735 | reverses the rule: |
| 736 | kInverseWinding_FillType fills where the sum of Contour edges is zero; |
| 737 | kInverseEvenOdd_FillType fills where the number of Contour edges is even. |
| 738 | |
| 739 | #Example |
| 740 | #Height 100 |
| 741 | #Description |
| 742 | The top row has two clockwise rectangles. The second row has one clockwise and |
| 743 | one counterclockwise rectangle. The even-odd variants draw the same. The |
| 744 | winding variants draw the top rectangle overlap, which has a winding of 2, the |
| 745 | same as the outer parts of the top rectangles, which have a winding of 1. |
| 746 | ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 747 | void draw(SkCanvas* canvas) { |
| 748 | SkPath path; |
| 749 | path.addRect({10, 10, 30, 30}, SkPath::kCW_Direction); |
| 750 | path.addRect({20, 20, 40, 40}, SkPath::kCW_Direction); |
| 751 | path.addRect({10, 60, 30, 80}, SkPath::kCW_Direction); |
| 752 | path.addRect({20, 70, 40, 90}, SkPath::kCCW_Direction); |
| 753 | SkPaint strokePaint; |
| 754 | strokePaint.setStyle(SkPaint::kStroke_Style); |
| 755 | SkRect clipRect = {0, 0, 51, 100}; |
| 756 | canvas->drawPath(path, strokePaint); |
| 757 | SkPaint fillPaint; |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 758 | for (auto fillType : { SkPath::kWinding_FillType, SkPath::kEvenOdd_FillType, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 759 | SkPath::kInverseWinding_FillType, SkPath::kInverseEvenOdd_FillType } ) { |
| 760 | canvas->translate(51, 0); |
| 761 | canvas->save(); |
| 762 | canvas->clipRect(clipRect); |
| 763 | path.setFillType(fillType); |
| 764 | canvas->drawPath(path, fillPaint); |
| 765 | canvas->restore(); |
| 766 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 767 | } |
| 768 | ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 769 | |
| 770 | #Const kWinding_FillType 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 771 | #Line # is enclosed by a non-zero sum of Contour Directions ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 772 | ## |
| 773 | #Const kEvenOdd_FillType 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 774 | #Line # is enclosed by an odd number of Contours ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 775 | ## |
| 776 | #Const kInverseWinding_FillType 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 777 | #Line # is enclosed by a zero sum of Contour Directions ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 778 | ## |
| 779 | #Const kInverseEvenOdd_FillType 3 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 780 | #Line # is enclosed by an even number of Contours ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 781 | ## |
| 782 | |
| 783 | #Example |
| 784 | #Height 230 |
| 785 | void draw(SkCanvas* canvas) { |
| 786 | SkPath path; |
| 787 | path.addRect({20, 10, 80, 70}, SkPath::kCW_Direction); |
| 788 | path.addRect({40, 30, 100, 90}, SkPath::kCW_Direction); |
| 789 | SkPaint strokePaint; |
| 790 | strokePaint.setStyle(SkPaint::kStroke_Style); |
| 791 | SkRect clipRect = {0, 0, 128, 128}; |
| 792 | canvas->drawPath(path, strokePaint); |
| 793 | canvas->drawLine({0, 50}, {120, 50}, strokePaint); |
| 794 | SkPaint textPaint; |
| 795 | textPaint.setAntiAlias(true); |
| 796 | textPaint.setTextAlign(SkPaint::kCenter_Align); |
| 797 | SkScalar textHPos[] = { 10, 30, 60, 90, 110 }; |
| 798 | canvas->drawPosTextH("01210", 5, textHPos, 48, textPaint); |
| 799 | textPaint.setTextSize(18); |
| 800 | canvas->translate(0, 128); |
| 801 | canvas->scale(.5f, .5f); |
| 802 | canvas->drawString("inverse", 384, 150, textPaint); |
| 803 | SkPaint fillPaint; |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 804 | for (auto fillType : { SkPath::kWinding_FillType, SkPath::kEvenOdd_FillType, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 805 | SkPath::kInverseWinding_FillType, SkPath::kInverseEvenOdd_FillType } ) { |
| 806 | canvas->save(); |
| 807 | canvas->clipRect(clipRect); |
| 808 | path.setFillType(fillType); |
| 809 | canvas->drawPath(path, fillPaint); |
| 810 | canvas->restore(); |
| 811 | canvas->drawString(fillType & 1 ? "even-odd" : "winding", 64, 170, textPaint); |
| 812 | canvas->translate(128, 0); |
| 813 | } |
| 814 | } |
| 815 | ## |
| 816 | |
| 817 | #SeeAlso SkPaint::Style Direction getFillType setFillType |
| 818 | |
| 819 | ## |
| 820 | |
| 821 | # ------------------------------------------------------------------------------ |
| 822 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 823 | #Method FillType getFillType() const |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 824 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 825 | #In Fill_Type |
| 826 | #Line # returns Fill_Type: winding, even-odd, inverse ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 827 | Returns FillType, the rule used to fill Path. FillType of a new Path is |
| 828 | kWinding_FillType. |
| 829 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 830 | #Return one of: kWinding_FillType, kEvenOdd_FillType, kInverseWinding_FillType, |
| 831 | kInverseEvenOdd_FillType |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 832 | ## |
| 833 | |
| 834 | #Example |
| 835 | SkPath path; |
| 836 | SkDebugf("default path fill type is %s\n", |
| 837 | path.getFillType() == SkPath::kWinding_FillType ? "kWinding_FillType" : |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 838 | path.getFillType() == SkPath::kEvenOdd_FillType ? "kEvenOdd_FillType" : |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 839 | path.getFillType() == SkPath::kInverseWinding_FillType ? "kInverseWinding_FillType" : |
| 840 | "kInverseEvenOdd_FillType"); |
| 841 | #StdOut |
| 842 | default path fill type is kWinding_FillType |
| 843 | ## |
| 844 | ## |
| 845 | |
| 846 | #SeeAlso FillType setFillType isInverseFillType |
| 847 | |
| 848 | ## |
| 849 | |
| 850 | # ------------------------------------------------------------------------------ |
| 851 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 852 | #Method void setFillType(FillType ft) |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 853 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 854 | #In Fill_Type |
| 855 | #Line # sets Fill_Type: winding, even-odd, inverse ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 856 | Sets FillType, the rule used to fill Path. While there is no check |
| 857 | that ft is legal, values outside of FillType are not supported. |
| 858 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 859 | #Param ft one of: kWinding_FillType, kEvenOdd_FillType, kInverseWinding_FillType, |
| 860 | kInverseEvenOdd_FillType |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 861 | ## |
| 862 | |
| 863 | #Example |
| 864 | #Description |
| 865 | If empty Path is set to inverse FillType, it fills all pixels. |
| 866 | ## |
| 867 | #Height 64 |
| 868 | SkPath path; |
| 869 | path.setFillType(SkPath::kInverseWinding_FillType); |
| 870 | SkPaint paint; |
| 871 | paint.setColor(SK_ColorBLUE); |
| 872 | canvas->drawPath(path, paint); |
| 873 | ## |
| 874 | |
| 875 | #SeeAlso FillType getFillType toggleInverseFillType |
| 876 | |
| 877 | ## |
| 878 | |
| 879 | # ------------------------------------------------------------------------------ |
| 880 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 881 | #Method bool isInverseFillType() const |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 882 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 883 | #In Fill_Type |
| 884 | #Line # returns if Fill_Type fills outside geometry ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 885 | Returns if FillType describes area outside Path geometry. The inverse fill area |
| 886 | extends indefinitely. |
| 887 | |
| 888 | #Return true if FillType is kInverseWinding_FillType or kInverseEvenOdd_FillType ## |
| 889 | |
| 890 | #Example |
| 891 | SkPath path; |
| 892 | SkDebugf("default path fill type is inverse: %s\n", |
| 893 | path.isInverseFillType() ? "true" : "false"); |
| 894 | #StdOut |
| 895 | default path fill type is inverse: false |
| 896 | ## |
| 897 | ## |
| 898 | |
| 899 | #SeeAlso FillType getFillType setFillType toggleInverseFillType |
| 900 | |
| 901 | ## |
| 902 | |
| 903 | # ------------------------------------------------------------------------------ |
| 904 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 905 | #Method void toggleInverseFillType() |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 906 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 907 | #In Fill_Type |
| 908 | #Line # toggles Fill_Type between inside and outside geometry ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 909 | Replaces FillType with its inverse. The inverse of FillType describes the area |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 910 | unmodified by the original FillType. |
| 911 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 912 | #Table |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 913 | #Legend |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 914 | # FillType # toggled FillType ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 915 | ## |
| 916 | # kWinding_FillType # kInverseWinding_FillType ## |
| 917 | # kEvenOdd_FillType # kInverseEvenOdd_FillType ## |
| 918 | # kInverseWinding_FillType # kWinding_FillType ## |
| 919 | # kInverseEvenOdd_FillType # kEvenOdd_FillType ## |
| 920 | ## |
| 921 | |
| 922 | #Example |
| 923 | #Description |
| 924 | Path drawn normally and through its inverse touches every pixel once. |
| 925 | ## |
| 926 | #Height 100 |
| 927 | SkPath path; |
| 928 | SkPaint paint; |
| 929 | paint.setColor(SK_ColorRED); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 930 | paint.setTextSize(80); |
| 931 | paint.getTextPath("ABC", 3, 20, 80, &path); |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 932 | canvas->drawPath(path, paint); |
| 933 | path.toggleInverseFillType(); |
| 934 | paint.setColor(SK_ColorGREEN); |
| 935 | canvas->drawPath(path, paint); |
| 936 | ## |
| 937 | |
| 938 | #SeeAlso FillType getFillType setFillType isInverseFillType |
| 939 | |
| 940 | ## |
| 941 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 942 | #Subtopic Fill_Type ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 943 | |
| 944 | # ------------------------------------------------------------------------------ |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 945 | |
| 946 | #Subtopic Convexity |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 947 | #Line # if Path is concave or convex ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 948 | |
| 949 | #Enum Convexity |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 950 | #Line # returns if Path is convex or concave ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 951 | |
| 952 | #Code |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame] | 953 | enum Convexity : uint8_t { |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 954 | kUnknown_Convexity, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 955 | kConvex_Convexity, |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 956 | kConcave_Convexity, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 957 | }; |
| 958 | ## |
| 959 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 960 | Path is convex if it contains one Contour and Contour loops no more than |
| 961 | 360 degrees, and Contour angles all have same Direction. Convex Path |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 962 | may have better performance and require fewer resources on GPU_Surface. |
| 963 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 964 | Path is concave when either at least one Direction change is clockwise and |
| 965 | another is counterclockwise, or the sum of the changes in Direction is not 360 |
| 966 | degrees. |
| 967 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 968 | Initially Path Convexity is kUnknown_Convexity. Path Convexity is computed |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 969 | if needed by destination Surface. |
| 970 | |
| 971 | #Const kUnknown_Convexity 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 972 | #Line # indicates Convexity has not been determined ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 973 | ## |
| 974 | #Const kConvex_Convexity 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 975 | #Line # one Contour made of a simple geometry without indentations ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 976 | ## |
| 977 | #Const kConcave_Convexity 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 978 | #Line # more than one Contour, or a geometry with indentations ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 979 | ## |
| 980 | |
| 981 | #Example |
| 982 | void draw(SkCanvas* canvas) { |
| 983 | SkPaint paint; |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 984 | SkPoint quad[] = {{70, 70}, {20, 20}, {120, 20}, {120, 120}}; |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 985 | const char* labels[] = { "unknown", "convex", "concave" }; |
| 986 | for (SkScalar x : { 40, 100 } ) { |
| 987 | SkPath path; |
| 988 | quad[0].fX = x; |
| 989 | path.addPoly(quad, SK_ARRAY_COUNT(quad), true); |
| 990 | canvas->drawPath(path, paint); |
| 991 | canvas->drawString(labels[(int) path.getConvexity()], 30, 100, paint); |
| 992 | canvas->translate(100, 100); |
| 993 | } |
| 994 | } |
| 995 | ## |
| 996 | |
| 997 | #SeeAlso Contour Direction getConvexity getConvexityOrUnknown setConvexity isConvex |
| 998 | |
| 999 | #Enum Convexity ## |
| 1000 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1001 | #Method Convexity getConvexity() const |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1002 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1003 | #In Convexity |
| 1004 | #Line # returns geometry convexity, computing if necessary ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1005 | Computes Convexity if required, and returns stored value. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1006 | Convexity is computed if stored value is kUnknown_Convexity, |
| 1007 | or if Path has been altered since Convexity was computed or set. |
| 1008 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 1009 | #Return computed or stored Convexity ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1010 | |
| 1011 | #Example |
| 1012 | void draw(SkCanvas* canvas) { |
| 1013 | auto debugster = [](const char* prefix, const SkPath& path) -> void { |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1014 | SkDebugf("%s path convexity is %s\n", prefix, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1015 | SkPath::kUnknown_Convexity == path.getConvexity() ? "unknown" : |
| 1016 | SkPath::kConvex_Convexity == path.getConvexity() ? "convex" : "concave"); }; |
| 1017 | SkPath path; |
| 1018 | debugster("initial", path); |
| 1019 | path.lineTo(50, 0); |
| 1020 | debugster("first line", path); |
| 1021 | path.lineTo(50, 50); |
| 1022 | debugster("second line", path); |
| 1023 | path.lineTo(100, 50); |
| 1024 | debugster("third line", path); |
| 1025 | } |
| 1026 | ## |
| 1027 | |
| 1028 | #SeeAlso Convexity Contour Direction getConvexityOrUnknown setConvexity isConvex |
| 1029 | |
| 1030 | ## |
| 1031 | |
| 1032 | # ------------------------------------------------------------------------------ |
| 1033 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1034 | #Method Convexity getConvexityOrUnknown() const |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1035 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1036 | #In Convexity |
| 1037 | #Line # returns geometry convexity if known ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1038 | Returns last computed Convexity, or kUnknown_Convexity if |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1039 | Path has been altered since Convexity was computed or set. |
| 1040 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 1041 | #Return stored Convexity ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1042 | |
| 1043 | #Example |
| 1044 | #Description |
| 1045 | Convexity is unknown unless getConvexity is called without a subsequent call |
| 1046 | that alters the path. |
| 1047 | ## |
| 1048 | void draw(SkCanvas* canvas) { |
| 1049 | auto debugster = [](const char* prefix, const SkPath& path) -> void { |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1050 | SkDebugf("%s path convexity is %s\n", prefix, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1051 | SkPath::kUnknown_Convexity == path.getConvexityOrUnknown() ? "unknown" : |
| 1052 | SkPath::kConvex_Convexity == path.getConvexityOrUnknown() ? "convex" : "concave"); }; |
| 1053 | SkPath path; |
| 1054 | debugster("initial", path); |
| 1055 | path.lineTo(50, 0); |
| 1056 | debugster("first line", path); |
| 1057 | path.getConvexity(); |
| 1058 | path.lineTo(50, 50); |
| 1059 | debugster("second line", path); |
| 1060 | path.lineTo(100, 50); |
| 1061 | path.getConvexity(); |
| 1062 | debugster("third line", path); |
| 1063 | } |
| 1064 | ## |
| 1065 | |
| 1066 | #SeeAlso Convexity Contour Direction getConvexity setConvexity isConvex |
| 1067 | |
| 1068 | ## |
| 1069 | |
| 1070 | # ------------------------------------------------------------------------------ |
| 1071 | |
| 1072 | #Method void setConvexity(Convexity convexity) |
| 1073 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1074 | #In Convexity |
| 1075 | #Line # sets if geometry is convex to avoid future computation ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1076 | Stores convexity so that it is later returned by getConvexity or getConvexityOrUnknown. |
| 1077 | convexity may differ from getConvexity, although setting an incorrect value may |
| 1078 | cause incorrect or inefficient drawing. |
| 1079 | |
| 1080 | If convexity is kUnknown_Convexity: getConvexity will |
| 1081 | compute Convexity, and getConvexityOrUnknown will return kUnknown_Convexity. |
| 1082 | |
| 1083 | If convexity is kConvex_Convexity or kConcave_Convexity, getConvexity |
| 1084 | and getConvexityOrUnknown will return convexity until the path is |
| 1085 | altered. |
| 1086 | |
| 1087 | #Param convexity one of: kUnknown_Convexity, kConvex_Convexity, or kConcave_Convexity ## |
| 1088 | |
| 1089 | #Example |
| 1090 | void draw(SkCanvas* canvas) { |
| 1091 | auto debugster = [](const char* prefix, const SkPath& path) -> void { |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1092 | SkDebugf("%s path convexity is %s\n", prefix, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1093 | SkPath::kUnknown_Convexity == path.getConvexity() ? "unknown" : |
| 1094 | SkPath::kConvex_Convexity == path.getConvexity() ? "convex" : "concave"); }; |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1095 | SkPoint quad[] = {{70, 70}, {20, 20}, {120, 20}, {120, 120}}; |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1096 | SkPath path; |
| 1097 | path.addPoly(quad, SK_ARRAY_COUNT(quad), true); |
| 1098 | debugster("initial", path); |
| 1099 | path.setConvexity(SkPath::kConcave_Convexity); |
| 1100 | debugster("after forcing concave", path); |
| 1101 | path.setConvexity(SkPath::kUnknown_Convexity); |
| 1102 | debugster("after forcing unknown", path); |
| 1103 | } |
| 1104 | ## |
| 1105 | |
| 1106 | #SeeAlso Convexity Contour Direction getConvexity getConvexityOrUnknown isConvex |
| 1107 | |
| 1108 | ## |
| 1109 | |
| 1110 | # ------------------------------------------------------------------------------ |
| 1111 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1112 | #Method bool isConvex() const |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1113 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1114 | #In Convexity |
| 1115 | #Line # returns if geometry is convex ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1116 | Computes Convexity if required, and returns true if value is kConvex_Convexity. |
| 1117 | If setConvexity was called with kConvex_Convexity or kConcave_Convexity, and |
| 1118 | the path has not been altered, Convexity is not recomputed. |
| 1119 | |
| 1120 | #Return true if Convexity stored or computed is kConvex_Convexity ## |
| 1121 | |
| 1122 | #Example |
| 1123 | #Description |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1124 | Concave shape is erroneously considered convex after a forced call to |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1125 | setConvexity. |
| 1126 | ## |
| 1127 | void draw(SkCanvas* canvas) { |
| 1128 | SkPaint paint; |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1129 | SkPoint quad[] = {{70, 70}, {20, 20}, {120, 20}, {120, 120}}; |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1130 | for (SkScalar x : { 40, 100 } ) { |
| 1131 | SkPath path; |
| 1132 | quad[0].fX = x; |
| 1133 | path.addPoly(quad, SK_ARRAY_COUNT(quad), true); |
| 1134 | path.setConvexity(SkPath::kConvex_Convexity); |
| 1135 | canvas->drawPath(path, paint); |
| 1136 | canvas->drawString(path.isConvex() ? "convex" : "not convex", 30, 100, paint); |
| 1137 | canvas->translate(100, 100); |
| 1138 | } |
| 1139 | } |
| 1140 | ## |
| 1141 | |
| 1142 | #SeeAlso Convexity Contour Direction getConvexity getConvexityOrUnknown setConvexity |
| 1143 | |
| 1144 | ## |
| 1145 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1146 | #Subtopic Convexity ## |
| 1147 | |
| 1148 | # ------------------------------------------------------------------------------ |
| 1149 | |
Mike Reed | 0c3137c | 2018-02-20 13:57:05 -0500 | [diff] [blame] | 1150 | #Method bool isOval(SkRect* bounds) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1151 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1152 | #Line # returns if describes Oval ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1153 | |
Mike Reed | 0c3137c | 2018-02-20 13:57:05 -0500 | [diff] [blame] | 1154 | Returns true if this path is recognized as an oval or circle. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1155 | |
Mike Reed | 0c3137c | 2018-02-20 13:57:05 -0500 | [diff] [blame] | 1156 | bounds receives bounds of Oval. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1157 | |
Mike Reed | 0c3137c | 2018-02-20 13:57:05 -0500 | [diff] [blame] | 1158 | bounds is unmodified if Oval is not found. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1159 | |
Mike Reed | 0c3137c | 2018-02-20 13:57:05 -0500 | [diff] [blame] | 1160 | #Param bounds storage for bounding Rect of Oval; may be nullptr ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1161 | |
Mike Reed | 0c3137c | 2018-02-20 13:57:05 -0500 | [diff] [blame] | 1162 | #Return true if Path is recognized as an oval or circle ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1163 | |
| 1164 | #Example |
| 1165 | void draw(SkCanvas* canvas) { |
| 1166 | SkPaint paint; |
| 1167 | SkPath path; |
Mike Reed | 0c3137c | 2018-02-20 13:57:05 -0500 | [diff] [blame] | 1168 | path.addOval({20, 20, 220, 220}); |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1169 | SkRect bounds; |
Mike Reed | 0c3137c | 2018-02-20 13:57:05 -0500 | [diff] [blame] | 1170 | if (path.isOval(&bounds)) { |
| 1171 | paint.setColor(0xFF9FBFFF); |
| 1172 | canvas->drawRect(bounds, paint); |
| 1173 | } |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1174 | paint.setColor(0x3f000000); |
| 1175 | canvas->drawPath(path, paint); |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1176 | } |
| 1177 | ## |
| 1178 | |
| 1179 | #SeeAlso Oval addCircle addOval |
| 1180 | |
| 1181 | ## |
| 1182 | |
| 1183 | # ------------------------------------------------------------------------------ |
| 1184 | |
Mike Reed | 0c3137c | 2018-02-20 13:57:05 -0500 | [diff] [blame] | 1185 | #Method bool isRRect(SkRRect* rrect) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1186 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1187 | #Line # returns if describes Round_Rect ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1188 | |
Mike Reed | 0c3137c | 2018-02-20 13:57:05 -0500 | [diff] [blame] | 1189 | Returns true if this path is recognized as a SkRRect (but not an oval/circle or rect). |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1190 | |
| 1191 | rrect receives bounds of Round_Rect. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1192 | |
Mike Reed | 0c3137c | 2018-02-20 13:57:05 -0500 | [diff] [blame] | 1193 | rrect is unmodified if Round_Rect is not found. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1194 | |
| 1195 | #Param rrect storage for bounding Rect of Round_Rect; may be nullptr ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1196 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1197 | #Return true if Path contains only Round_Rect ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1198 | |
| 1199 | #Example |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1200 | #Description |
Mike Reed | 0c3137c | 2018-02-20 13:57:05 -0500 | [diff] [blame] | 1201 | Draw rounded rectangle and its bounds. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1202 | ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1203 | void draw(SkCanvas* canvas) { |
| 1204 | SkPaint paint; |
| 1205 | SkPath path; |
Mike Reed | 0c3137c | 2018-02-20 13:57:05 -0500 | [diff] [blame] | 1206 | path.addRRect(SkRRect::MakeRectXY({20, 20, 220, 220}, 30, 50)); |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1207 | SkRRect rrect; |
Mike Reed | 0c3137c | 2018-02-20 13:57:05 -0500 | [diff] [blame] | 1208 | if (path.isRRect(&rrect)) { |
| 1209 | const SkRect& bounds = rrect.rect(); |
| 1210 | paint.setColor(0xFF9FBFFF); |
| 1211 | canvas->drawRect(bounds, paint); |
| 1212 | } |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1213 | paint.setColor(0x3f000000); |
| 1214 | canvas->drawPath(path, paint); |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1215 | } |
| 1216 | ## |
| 1217 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1218 | #SeeAlso Round_Rect addRoundRect addRRect |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1219 | |
| 1220 | ## |
| 1221 | |
| 1222 | # ------------------------------------------------------------------------------ |
| 1223 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 1224 | #Method SkPath& reset() |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1225 | #In Constructor |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1226 | #Line # removes Verb_Array, Point_Array, and Weights; frees memory ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1227 | Sets Path to its initial state. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1228 | Removes Verb_Array, Point_Array, and Weights, and sets FillType to kWinding_FillType. |
| 1229 | Internal storage associated with Path is released. |
| 1230 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 1231 | #Return reference to Path ## |
| 1232 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1233 | #Example |
| 1234 | SkPath path1, path2; |
| 1235 | path1.setFillType(SkPath::kInverseWinding_FillType); |
| 1236 | path1.addRect({10, 20, 30, 40}); |
| 1237 | SkDebugf("path1 %c= path2\n", path1 == path2 ? '=' : '!'); |
| 1238 | path1.reset(); |
| 1239 | SkDebugf("path1 %c= path2\n", path1 == path2 ? '=' : '!'); |
| 1240 | ## |
| 1241 | |
| 1242 | #SeeAlso rewind() |
| 1243 | |
| 1244 | ## |
| 1245 | |
| 1246 | # ------------------------------------------------------------------------------ |
| 1247 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 1248 | #Method SkPath& rewind() |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1249 | #In Constructor |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1250 | #Line # removes Verb_Array, Point_Array, and Weights, keeping memory ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1251 | Sets Path to its initial state, preserving internal storage. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1252 | Removes Verb_Array, Point_Array, and Weights, and sets FillType to kWinding_FillType. |
| 1253 | Internal storage associated with Path is retained. |
| 1254 | |
| 1255 | Use rewind() instead of reset() if Path storage will be reused and performance |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1256 | is critical. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1257 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 1258 | #Return reference to Path ## |
| 1259 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1260 | #Example |
| 1261 | #Description |
| 1262 | Although path1 retains its internal storage, it is indistinguishable from |
| 1263 | a newly initialized path. |
| 1264 | ## |
| 1265 | SkPath path1, path2; |
| 1266 | path1.setFillType(SkPath::kInverseWinding_FillType); |
| 1267 | path1.addRect({10, 20, 30, 40}); |
| 1268 | SkDebugf("path1 %c= path2\n", path1 == path2 ? '=' : '!'); |
| 1269 | path1.rewind(); |
| 1270 | SkDebugf("path1 %c= path2\n", path1 == path2 ? '=' : '!'); |
| 1271 | ## |
| 1272 | |
| 1273 | #SeeAlso reset() |
| 1274 | |
| 1275 | ## |
| 1276 | |
| 1277 | # ------------------------------------------------------------------------------ |
| 1278 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1279 | #Method bool isEmpty() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1280 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1281 | #Line # returns if verb count is zero ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 1282 | Returns if Path is empty. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1283 | Empty Path may have FillType but has no SkPoint, Verb, or Conic_Weight. |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 1284 | SkPath() constructs empty Path; reset() and rewind() make Path empty. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1285 | |
| 1286 | #Return true if the path contains no Verb array ## |
| 1287 | |
| 1288 | #Example |
| 1289 | void draw(SkCanvas* canvas) { |
| 1290 | auto debugster = [](const char* prefix, const SkPath& path) -> void { |
| 1291 | SkDebugf("%s path is %s" "empty\n", prefix, path.isEmpty() ? "" : "not "); |
| 1292 | }; |
| 1293 | SkPath path; |
| 1294 | debugster("initial", path); |
| 1295 | path.moveTo(0, 0); |
| 1296 | debugster("after moveTo", path); |
| 1297 | path.rewind(); |
| 1298 | debugster("after rewind", path); |
| 1299 | path.lineTo(0, 0); |
| 1300 | debugster("after lineTo", path); |
| 1301 | path.reset(); |
| 1302 | debugster("after reset", path); |
| 1303 | } |
| 1304 | #StdOut |
| 1305 | initial path is empty |
| 1306 | after moveTo path is not empty |
| 1307 | after rewind path is empty |
| 1308 | after lineTo path is not empty |
| 1309 | after reset path is empty |
| 1310 | ## |
| 1311 | ## |
| 1312 | |
| 1313 | #SeeAlso SkPath() reset() rewind() |
| 1314 | |
| 1315 | ## |
| 1316 | |
| 1317 | # ------------------------------------------------------------------------------ |
| 1318 | |
| 1319 | #Method bool isLastContourClosed() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1320 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1321 | #Line # returns if final Contour forms a loop ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 1322 | Returns if Contour is closed. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1323 | Contour is closed if Path Verb array was last modified by close(). When stroked, |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1324 | closed Contour draws Paint_Stroke_Join instead of Paint_Stroke_Cap at first and last Point. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1325 | |
| 1326 | #Return true if the last Contour ends with a kClose_Verb ## |
| 1327 | |
| 1328 | #Example |
| 1329 | #Description |
| 1330 | close() has no effect if Path is empty; isLastContourClosed() returns |
| 1331 | false until Path has geometry followed by close(). |
| 1332 | ## |
| 1333 | void draw(SkCanvas* canvas) { |
| 1334 | auto debugster = [](const char* prefix, const SkPath& path) -> void { |
| 1335 | SkDebugf("%s last contour is %s" "closed\n", prefix, |
| 1336 | path.isLastContourClosed() ? "" : "not "); |
| 1337 | }; |
| 1338 | SkPath path; |
| 1339 | debugster("initial", path); |
| 1340 | path.close(); |
| 1341 | debugster("after close", path); |
| 1342 | path.lineTo(0, 0); |
| 1343 | debugster("after lineTo", path); |
| 1344 | path.close(); |
| 1345 | debugster("after close", path); |
| 1346 | } |
| 1347 | #StdOut |
| 1348 | initial last contour is not closed |
| 1349 | after close last contour is not closed |
| 1350 | after lineTo last contour is not closed |
| 1351 | after close last contour is closed |
| 1352 | ## |
| 1353 | ## |
| 1354 | |
| 1355 | #SeeAlso close() |
| 1356 | |
| 1357 | ## |
| 1358 | |
| 1359 | # ------------------------------------------------------------------------------ |
| 1360 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1361 | #Method bool isFinite() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1362 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1363 | #Line # returns if all Point values are finite ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1364 | Returns true for finite Point array values between negative SK_ScalarMax and |
| 1365 | positive SK_ScalarMax. Returns false for any Point array value of |
| 1366 | SK_ScalarInfinity, SK_ScalarNegativeInfinity, or SK_ScalarNaN. |
| 1367 | |
| 1368 | #Return true if all Point values are finite ## |
| 1369 | |
| 1370 | #Example |
| 1371 | void draw(SkCanvas* canvas) { |
| 1372 | auto debugster = [](const char* prefix, const SkPath& path) -> void { |
| 1373 | SkDebugf("%s path is %s" "finite\n", prefix, path.isFinite() ? "" : "not "); |
| 1374 | }; |
| 1375 | SkPath path; |
| 1376 | debugster("initial", path); |
| 1377 | path.lineTo(SK_ScalarMax, SK_ScalarMax); |
| 1378 | debugster("after line", path); |
| 1379 | SkMatrix matrix; |
| 1380 | matrix.setScale(2, 2); |
| 1381 | path.transform(matrix); |
| 1382 | debugster("after scale", path); |
| 1383 | } |
| 1384 | #StdOut |
| 1385 | initial path is finite |
| 1386 | after line path is finite |
| 1387 | after scale path is not finite |
| 1388 | ## |
| 1389 | ## |
| 1390 | |
| 1391 | #SeeAlso SkScalar |
| 1392 | ## |
| 1393 | |
| 1394 | # ------------------------------------------------------------------------------ |
| 1395 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1396 | #Method bool isVolatile() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1397 | #In Property |
| 1398 | #In Volatile |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1399 | #Line # returns if Device should not cache ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1400 | Returns true if the path is volatile; it will not be altered or discarded |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1401 | by the caller after it is drawn. Paths by default have volatile set false, allowing |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1402 | Surface to attach a cache of data which speeds repeated drawing. If true, Surface |
| 1403 | may not speed repeated drawing. |
| 1404 | |
| 1405 | #Return true if caller will alter Path after drawing ## |
| 1406 | |
| 1407 | #Example |
| 1408 | SkPath path; |
| 1409 | SkDebugf("volatile by default is %s\n", path.isVolatile() ? "true" : "false"); |
| 1410 | #StdOut |
| 1411 | volatile by default is false |
| 1412 | ## |
| 1413 | ## |
| 1414 | |
| 1415 | #SeeAlso setIsVolatile |
| 1416 | |
| 1417 | ## |
| 1418 | |
| 1419 | # ------------------------------------------------------------------------------ |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1420 | #Subtopic Volatile |
| 1421 | #Populate |
| 1422 | #Line # caching attribute ## |
| 1423 | ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1424 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1425 | #Method void setIsVolatile(bool isVolatile) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1426 | #In Volatile |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1427 | #Line # sets if Device should not cache ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 1428 | Specifies whether Path is volatile; whether it will be altered or discarded |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1429 | by the caller after it is drawn. Paths by default have volatile set false, allowing |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1430 | Device to attach a cache of data which speeds repeated drawing. |
| 1431 | |
| 1432 | Mark temporary paths, discarded or modified after use, as volatile |
| 1433 | to inform Device that the path need not be cached. |
| 1434 | |
| 1435 | Mark animating Path volatile to improve performance. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1436 | Mark unchanging Path non-volatile to improve repeated rendering. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1437 | |
| 1438 | Raster_Surface Path draws are affected by volatile for some shadows. |
| 1439 | GPU_Surface Path draws are affected by volatile for some shadows and concave geometries. |
| 1440 | |
| 1441 | #Param isVolatile true if caller will alter Path after drawing ## |
| 1442 | |
| 1443 | #Example |
| 1444 | #Height 50 |
| 1445 | #Width 50 |
| 1446 | SkPaint paint; |
| 1447 | paint.setStyle(SkPaint::kStroke_Style); |
| 1448 | SkPath path; |
| 1449 | path.setIsVolatile(true); |
| 1450 | path.lineTo(40, 40); |
| 1451 | canvas->drawPath(path, paint); |
| 1452 | path.rewind(); |
| 1453 | path.moveTo(0, 40); |
| 1454 | path.lineTo(40, 0); |
| 1455 | canvas->drawPath(path, paint); |
| 1456 | ## |
| 1457 | |
| 1458 | #ToDo tie example to bench to show how volatile affects speed or dm to show resource usage ## |
| 1459 | |
| 1460 | #SeeAlso isVolatile |
| 1461 | |
| 1462 | ## |
| 1463 | |
| 1464 | # ------------------------------------------------------------------------------ |
| 1465 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1466 | #Method static bool IsLineDegenerate(const SkPoint& p1, const SkPoint& p2, bool exact) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1467 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1468 | #Line # returns if Line is very small ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 1469 | Tests if Line between Point pair is degenerate. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1470 | Line with no length or that moves a very short distance is degenerate; it is |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1471 | treated as a point. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1472 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 1473 | exact changes the equality test. If true, returns true only if p1 equals p2. |
| 1474 | If false, returns true if p1 equals or nearly equals p2. |
| 1475 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1476 | #Param p1 line start point ## |
| 1477 | #Param p2 line end point ## |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 1478 | #Param exact if false, allow nearly equals ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1479 | |
| 1480 | #Return true if Line is degenerate; its length is effectively zero ## |
| 1481 | |
| 1482 | #Example |
| 1483 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1484 | As single precision floats, 100 and 100.000001 have the same bit representation, |
| 1485 | and are exactly equal. 100 and 100.0001 have different bit representations, and |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1486 | are not exactly equal, but are nearly equal. |
| 1487 | ## |
| 1488 | void draw(SkCanvas* canvas) { |
| 1489 | SkPoint points[] = { {100, 100}, {100.000001f, 100.000001f}, {100.0001f, 100.0001f} }; |
| 1490 | for (size_t i = 0; i < SK_ARRAY_COUNT(points) - 1; ++i) { |
| 1491 | for (bool exact : { false, true } ) { |
| 1492 | SkDebugf("line from (%1.8g,%1.8g) to (%1.8g,%1.8g) is %s" "degenerate, %s\n", |
| 1493 | points[i].fX, points[i].fY, points[i + 1].fX, points[i + 1].fY, |
| 1494 | SkPath::IsLineDegenerate(points[i], points[i + 1], exact) |
| 1495 | ? "" : "not ", exact ? "exactly" : "nearly"); |
| 1496 | } |
| 1497 | } |
| 1498 | } |
| 1499 | #StdOut |
| 1500 | line from (100,100) to (100,100) is degenerate, nearly |
| 1501 | line from (100,100) to (100,100) is degenerate, exactly |
| 1502 | line from (100,100) to (100.0001,100.0001) is degenerate, nearly |
| 1503 | line from (100,100) to (100.0001,100.0001) is not degenerate, exactly |
| 1504 | #StdOut ## |
| 1505 | ## |
| 1506 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1507 | #SeeAlso IsQuadDegenerate IsCubicDegenerate |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1508 | ## |
| 1509 | |
| 1510 | # ------------------------------------------------------------------------------ |
| 1511 | |
| 1512 | #Method static bool IsQuadDegenerate(const SkPoint& p1, const SkPoint& p2, |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1513 | const SkPoint& p3, bool exact) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1514 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1515 | #Line # returns if Quad is very small ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1516 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 1517 | Tests if Quad is degenerate. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1518 | Quad with no length or that moves a very short distance is degenerate; it is |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1519 | treated as a point. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1520 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1521 | #Param p1 Quad start point ## |
| 1522 | #Param p2 Quad control point ## |
| 1523 | #Param p3 Quad end point ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1524 | #Param exact if true, returns true only if p1, p2, and p3 are equal; |
| 1525 | if false, returns true if p1, p2, and p3 are equal or nearly equal |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1526 | ## |
| 1527 | |
| 1528 | #Return true if Quad is degenerate; its length is effectively zero ## |
| 1529 | |
| 1530 | #Example |
| 1531 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1532 | As single precision floats: 100, 100.00001, and 100.00002 have different bit representations |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1533 | but nearly the same value. Translating all three by 1000 gives them the same bit representation; |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1534 | the fractional portion of the number can not be represented by the float and is lost. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1535 | ## |
| 1536 | void draw(SkCanvas* canvas) { |
| 1537 | auto debugster = [](const SkPath& path, bool exact) -> void { |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1538 | SkDebugf("quad (%1.8g,%1.8g), (%1.8g,%1.8g), (%1.8g,%1.8g) is %s" "degenerate, %s\n", |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1539 | path.getPoint(0).fX, path.getPoint(0).fY, path.getPoint(1).fX, |
| 1540 | path.getPoint(1).fY, path.getPoint(2).fX, path.getPoint(2).fY, |
| 1541 | SkPath::IsQuadDegenerate(path.getPoint(0), path.getPoint(1), path.getPoint(2), exact) ? |
| 1542 | "" : "not ", exact ? "exactly" : "nearly"); |
| 1543 | }; |
| 1544 | SkPath path, offset; |
| 1545 | path.moveTo({100, 100}); |
| 1546 | path.quadTo({100.00001f, 100.00001f}, {100.00002f, 100.00002f}); |
| 1547 | offset.addPath(path, 1000, 1000); |
| 1548 | for (bool exact : { false, true } ) { |
| 1549 | debugster(path, exact); |
| 1550 | debugster(offset, exact); |
| 1551 | } |
| 1552 | } |
| 1553 | #StdOut |
| 1554 | quad (100,100), (100.00001,100.00001), (100.00002,100.00002) is degenerate, nearly |
| 1555 | quad (1100,1100), (1100,1100), (1100,1100) is degenerate, nearly |
| 1556 | quad (100,100), (100.00001,100.00001), (100.00002,100.00002) is not degenerate, exactly |
| 1557 | quad (1100,1100), (1100,1100), (1100,1100) is degenerate, exactly |
| 1558 | #StdOut ## |
| 1559 | ## |
| 1560 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1561 | #SeeAlso IsLineDegenerate IsCubicDegenerate |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1562 | ## |
| 1563 | |
| 1564 | # ------------------------------------------------------------------------------ |
| 1565 | |
| 1566 | #Method static bool IsCubicDegenerate(const SkPoint& p1, const SkPoint& p2, |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1567 | const SkPoint& p3, const SkPoint& p4, bool exact) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1568 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1569 | #Line # returns if Cubic is very small ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1570 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 1571 | Tests if Cubic is degenerate. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1572 | Cubic with no length or that moves a very short distance is degenerate; it is |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1573 | treated as a point. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1574 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1575 | #Param p1 Cubic start point ## |
| 1576 | #Param p2 Cubic control point 1 ## |
| 1577 | #Param p3 Cubic control point 2 ## |
| 1578 | #Param p4 Cubic end point ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1579 | #Param exact if true, returns true only if p1, p2, p3, and p4 are equal; |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1580 | if false, returns true if p1, p2, p3, and p4 are equal or nearly equal |
| 1581 | ## |
| 1582 | |
| 1583 | #Return true if Cubic is degenerate; its length is effectively zero ## |
| 1584 | |
| 1585 | #Example |
| 1586 | void draw(SkCanvas* canvas) { |
| 1587 | SkPoint points[] = {{1, 0}, {0, 0}, {0, 0}, {0, 0}}; |
| 1588 | SkScalar step = 1; |
Cary Clark | 75fd449 | 2018-06-20 12:45:16 -0400 | [diff] [blame] | 1589 | SkScalar prior, length = 0, degenerate = 0; |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1590 | do { |
| 1591 | prior = points[0].fX; |
| 1592 | step /= 2; |
| 1593 | if (SkPath::IsCubicDegenerate(points[0], points[1], points[2], points[3], false)) { |
| 1594 | degenerate = prior; |
| 1595 | points[0].fX += step; |
| 1596 | } else { |
| 1597 | length = prior; |
| 1598 | points[0].fX -= step; |
| 1599 | } |
| 1600 | } while (prior != points[0].fX); |
| 1601 | SkDebugf("%1.8g is degenerate\n", degenerate); |
| 1602 | SkDebugf("%1.8g is length\n", length); |
| 1603 | } |
| 1604 | #StdOut |
| 1605 | 0.00024414062 is degenerate |
| 1606 | 0.00024414065 is length |
| 1607 | #StdOut ## |
| 1608 | ## |
| 1609 | |
| 1610 | ## |
| 1611 | |
| 1612 | # ------------------------------------------------------------------------------ |
| 1613 | |
| 1614 | #Method bool isLine(SkPoint line[2]) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1615 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1616 | #Line # returns if describes Line ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1617 | Returns true if Path contains only one Line; |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1618 | Path_Verb array has two entries: kMove_Verb, kLine_Verb. |
| 1619 | If Path contains one Line and line is not nullptr, line is set to |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1620 | Line start point and Line end point. |
| 1621 | Returns false if Path is not one Line; line is unaltered. |
| 1622 | |
| 1623 | #Param line storage for Line. May be nullptr ## |
| 1624 | |
| 1625 | #Return true if Path contains exactly one Line ## |
| 1626 | |
| 1627 | #Example |
| 1628 | void draw(SkCanvas* canvas) { |
| 1629 | auto debugster = [](const char* prefix, const SkPath& path) -> void { |
| 1630 | SkPoint line[2]; |
| 1631 | if (path.isLine(line)) { |
| 1632 | SkDebugf("%s is line (%1.8g,%1.8g) (%1.8g,%1.8g)\n", prefix, |
| 1633 | line[0].fX, line[0].fY, line[1].fX, line[1].fY); |
| 1634 | } else { |
| 1635 | SkDebugf("%s is not line\n", prefix); |
| 1636 | } |
| 1637 | }; |
| 1638 | SkPath path; |
| 1639 | debugster("empty", path); |
| 1640 | path.lineTo(0, 0); |
| 1641 | debugster("zero line", path); |
| 1642 | path.rewind(); |
| 1643 | path.moveTo(10, 10); |
| 1644 | path.lineTo(20, 20); |
| 1645 | debugster("line", path); |
| 1646 | path.moveTo(20, 20); |
| 1647 | debugster("second move", path); |
| 1648 | } |
| 1649 | #StdOut |
| 1650 | empty is not line |
| 1651 | zero line is line (0,0) (0,0) |
| 1652 | line is line (10,10) (20,20) |
| 1653 | second move is not line |
| 1654 | ## |
| 1655 | ## |
| 1656 | |
| 1657 | ## |
| 1658 | |
| 1659 | # ------------------------------------------------------------------------------ |
| 1660 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1661 | #Subtopic Point_Array |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1662 | #Line # end points and control points for lines and curves ## |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1663 | #Substitute SkPoint array |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1664 | |
| 1665 | Point_Array contains Points satisfying the allocated Points for |
| 1666 | each Verb in Verb_Array. For instance, Path containing one Contour with Line |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1667 | and Quad is described by Verb_Array: Verb::kMoveTo, Verb::kLineTo, Verb::kQuadTo; and |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1668 | one Point for move, one Point for Line, two Points for Quad; totaling four Points. |
| 1669 | |
| 1670 | Point_Array may be read directly from Path with getPoints, or inspected with |
| 1671 | getPoint, with Iter, or with RawIter. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1672 | |
| 1673 | #Method int getPoints(SkPoint points[], int max) const |
| 1674 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1675 | #In Point_Array |
| 1676 | #Line # returns Point_Array ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1677 | Returns number of points in Path. Up to max points are copied. |
| 1678 | points may be nullptr; then, max must be zero. |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1679 | If max is greater than number of points, excess points storage is unaltered. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1680 | |
| 1681 | #Param points storage for Path Point array. May be nullptr ## |
| 1682 | #Param max maximum to copy; must be greater than or equal to zero ## |
| 1683 | |
| 1684 | #Return Path Point array length ## |
| 1685 | |
| 1686 | #Example |
| 1687 | void draw(SkCanvas* canvas) { |
| 1688 | auto debugster = [](const char* prefix, const SkPath& path, SkPoint* points, int max) -> void { |
| 1689 | int count = path.getPoints(points, max); |
| 1690 | SkDebugf("%s point count: %d ", prefix, count); |
| 1691 | for (int i = 0; i < SkTMin(count, max) && points; ++i) { |
| 1692 | SkDebugf("(%1.8g,%1.8g) ", points[i].fX, points[i].fY); |
| 1693 | } |
| 1694 | SkDebugf("\n"); |
| 1695 | }; |
| 1696 | SkPath path; |
| 1697 | path.lineTo(20, 20); |
| 1698 | path.lineTo(-10, -10); |
| 1699 | SkPoint points[3]; |
| 1700 | debugster("no points", path, nullptr, 0); |
| 1701 | debugster("zero max", path, points, 0); |
| 1702 | debugster("too small", path, points, 2); |
| 1703 | debugster("just right", path, points, path.countPoints()); |
| 1704 | } |
| 1705 | #StdOut |
| 1706 | no points point count: 3 |
| 1707 | zero max point count: 3 |
| 1708 | too small point count: 3 (0,0) (20,20) |
| 1709 | just right point count: 3 (0,0) (20,20) (-10,-10) |
| 1710 | ## |
| 1711 | ## |
| 1712 | |
| 1713 | #SeeAlso countPoints getPoint |
| 1714 | ## |
| 1715 | |
| 1716 | #Method int countPoints() const |
| 1717 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1718 | #In Point_Array |
| 1719 | #Line # returns Point_Array length ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1720 | Returns the number of points in Path. |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1721 | Point count is initially zero. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1722 | |
| 1723 | #Return Path Point array length ## |
| 1724 | |
| 1725 | #Example |
| 1726 | void draw(SkCanvas* canvas) { |
| 1727 | auto debugster = [](const char* prefix, const SkPath& path) -> void { |
| 1728 | SkDebugf("%s point count: %d\n", prefix, path.countPoints()); |
| 1729 | }; |
| 1730 | SkPath path; |
| 1731 | debugster("empty", path); |
| 1732 | path.lineTo(0, 0); |
| 1733 | debugster("zero line", path); |
| 1734 | path.rewind(); |
| 1735 | path.moveTo(10, 10); |
| 1736 | path.lineTo(20, 20); |
| 1737 | debugster("line", path); |
| 1738 | path.moveTo(20, 20); |
| 1739 | debugster("second move", path); |
| 1740 | } |
| 1741 | #StdOut |
| 1742 | empty point count: 0 |
| 1743 | zero line point count: 2 |
| 1744 | line point count: 2 |
| 1745 | second move point count: 3 |
| 1746 | ## |
| 1747 | ## |
| 1748 | |
| 1749 | #SeeAlso getPoints |
| 1750 | ## |
| 1751 | |
| 1752 | #Method SkPoint getPoint(int index) const |
| 1753 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1754 | #In Point_Array |
| 1755 | #Line # returns entry from Point_Array ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1756 | Returns Point at index in Point_Array. Valid range for index is |
| 1757 | 0 to countPoints - 1. |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1758 | Returns (0, 0) if index is out of range. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1759 | |
| 1760 | #Param index Point array element selector ## |
| 1761 | |
| 1762 | #Return Point array value or (0, 0) ## |
| 1763 | |
| 1764 | #Example |
| 1765 | void draw(SkCanvas* canvas) { |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1766 | SkPath path; |
| 1767 | path.lineTo(20, 20); |
| 1768 | path.offset(-10, -10); |
| 1769 | for (int i= 0; i < path.countPoints(); ++i) { |
| 1770 | SkDebugf("point %d: (%1.8g,%1.8g)\n", i, path.getPoint(i).fX, path.getPoint(i).fY); |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1771 | } |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1772 | } |
| 1773 | #StdOut |
| 1774 | point 0: (-10,-10) |
| 1775 | point 1: (10,10) |
| 1776 | ## |
| 1777 | ## |
| 1778 | |
| 1779 | #SeeAlso countPoints getPoints |
| 1780 | ## |
| 1781 | |
| 1782 | |
| 1783 | #Subtopic Point_Array ## |
| 1784 | |
| 1785 | # ------------------------------------------------------------------------------ |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1786 | #Subtopic Verb_Array |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1787 | #Line # line and curve type for points ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1788 | |
| 1789 | Verb_Array always starts with kMove_Verb. |
| 1790 | If kClose_Verb is not the last entry, it is always followed by kMove_Verb; |
| 1791 | the quantity of kMove_Verb equals the Contour count. |
| 1792 | Verb_Array does not include or count kDone_Verb; it is a convenience |
| 1793 | returned when iterating through Verb_Array. |
| 1794 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1795 | Verb_Array may be read directly from Path with getVerbs, or inspected with Iter, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1796 | or with RawIter. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1797 | |
| 1798 | #Method int countVerbs() const |
| 1799 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1800 | #In Verb_Array |
| 1801 | #Line # returns Verb_Array length ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1802 | Returns the number of Verbs: kMove_Verb, kLine_Verb, kQuad_Verb, kConic_Verb, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1803 | kCubic_Verb, and kClose_Verb; added to Path. |
| 1804 | |
| 1805 | #Return length of Verb_Array ## |
| 1806 | |
| 1807 | #Example |
| 1808 | SkPath path; |
| 1809 | SkDebugf("empty verb count: %d\n", path.countVerbs()); |
| 1810 | path.addRoundRect({10, 20, 30, 40}, 5, 5); |
| 1811 | SkDebugf("round rect verb count: %d\n", path.countVerbs()); |
| 1812 | #StdOut |
| 1813 | empty verb count: 0 |
| 1814 | round rect verb count: 10 |
| 1815 | ## |
| 1816 | ## |
| 1817 | |
| 1818 | #SeeAlso getVerbs Iter RawIter |
| 1819 | |
| 1820 | ## |
| 1821 | |
| 1822 | #Method int getVerbs(uint8_t verbs[], int max) const |
| 1823 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1824 | #In Verb_Array |
| 1825 | #Line # returns Verb_Array ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1826 | Returns the number of verbs in the path. Up to max verbs are copied. The |
| 1827 | verbs are copied as one byte per verb. |
| 1828 | |
| 1829 | #Param verbs storage for verbs, may be nullptr ## |
| 1830 | #Param max maximum number to copy into verbs ## |
| 1831 | |
| 1832 | #Return the actual number of verbs in the path ## |
| 1833 | |
| 1834 | #Example |
| 1835 | void draw(SkCanvas* canvas) { |
| 1836 | auto debugster = [](const char* prefix, const SkPath& path, uint8_t* verbs, int max) -> void { |
| 1837 | int count = path.getVerbs(verbs, max); |
| 1838 | SkDebugf("%s verb count: %d ", prefix, count); |
| 1839 | const char* verbStr[] = { "move", "line", "quad", "conic", "cubic", "close" }; |
| 1840 | for (int i = 0; i < SkTMin(count, max) && verbs; ++i) { |
| 1841 | SkDebugf("%s ", verbStr[verbs[i]]); |
| 1842 | } |
| 1843 | SkDebugf("\n"); |
| 1844 | }; |
| 1845 | SkPath path; |
| 1846 | path.lineTo(20, 20); |
| 1847 | path.lineTo(-10, -10); |
| 1848 | uint8_t verbs[3]; |
| 1849 | debugster("no verbs", path, nullptr, 0); |
| 1850 | debugster("zero max", path, verbs, 0); |
| 1851 | debugster("too small", path, verbs, 2); |
| 1852 | debugster("just right", path, verbs, path.countVerbs()); |
| 1853 | } |
| 1854 | #StdOut |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1855 | no verbs verb count: 3 |
| 1856 | zero max verb count: 3 |
| 1857 | too small verb count: 3 move line |
| 1858 | just right verb count: 3 move line line |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1859 | ## |
| 1860 | ## |
| 1861 | |
| 1862 | #SeeAlso countVerbs getPoints Iter RawIter |
| 1863 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1864 | |
| 1865 | #Subtopic Verb_Array ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1866 | |
| 1867 | # ------------------------------------------------------------------------------ |
| 1868 | |
| 1869 | #Method void swap(SkPath& other) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1870 | #In Operator |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1871 | #Line # exchanges Path pair ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1872 | Exchanges the Verb_Array, Point_Array, Weights, and Fill_Type with other. |
| 1873 | Cached state is also exchanged. swap() internally exchanges pointers, so |
| 1874 | it is lightweight and does not allocate memory. |
| 1875 | |
| 1876 | swap() usage has largely been replaced by operator=(const SkPath& path). |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1877 | Paths do not copy their content on assignment until they are written to, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1878 | making assignment as efficient as swap(). |
| 1879 | |
| 1880 | #Param other Path exchanged by value ## |
| 1881 | |
| 1882 | #Example |
| 1883 | SkPath path1, path2; |
| 1884 | path1.addRect({10, 20, 30, 40}); |
| 1885 | path1.swap(path2); |
| 1886 | const SkRect& b1 = path1.getBounds(); |
| 1887 | SkDebugf("path1 bounds = %g, %g, %g, %g\n", b1.fLeft, b1.fTop, b1.fRight, b1.fBottom); |
| 1888 | const SkRect& b2 = path2.getBounds(); |
| 1889 | SkDebugf("path2 bounds = %g, %g, %g, %g\n", b2.fLeft, b2.fTop, b2.fRight, b2.fBottom); |
| 1890 | #StdOut |
| 1891 | path1 bounds = 0, 0, 0, 0 |
| 1892 | path2 bounds = 10, 20, 30, 40 |
| 1893 | #StdOut ## |
| 1894 | ## |
| 1895 | |
| 1896 | #SeeAlso operator=(const SkPath& path) |
| 1897 | |
| 1898 | ## |
| 1899 | |
| 1900 | # ------------------------------------------------------------------------------ |
| 1901 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1902 | #Method const SkRect& getBounds() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1903 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1904 | #Line # returns maximum and minimum of Point_Array ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 1905 | Returns minimum and maximum axes values of Point_Array. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1906 | Returns (0, 0, 0, 0) if Path contains no points. Returned bounds width and height may |
| 1907 | be larger or smaller than area affected when Path is drawn. |
| 1908 | |
| 1909 | Rect returned includes all Points added to Path, including Points associated with |
| 1910 | kMove_Verb that define empty Contours. |
| 1911 | |
| 1912 | #Return bounds of all Points in Point_Array ## |
| 1913 | |
| 1914 | #Example |
| 1915 | #Description |
| 1916 | Bounds of upright Circle can be predicted from center and radius. |
| 1917 | Bounds of rotated Circle includes control Points outside of filled area. |
| 1918 | ## |
| 1919 | auto debugster = [](const char* prefix, const SkPath& path) -> void { |
| 1920 | const SkRect& bounds = path.getBounds(); |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1921 | SkDebugf("%s bounds = %g, %g, %g, %g\n", prefix, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1922 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
| 1923 | }; |
| 1924 | SkPath path; |
| 1925 | debugster("empty", path); |
| 1926 | path.addCircle(50, 45, 25); |
| 1927 | debugster("circle", path); |
| 1928 | SkMatrix matrix; |
| 1929 | matrix.setRotate(45, 50, 45); |
| 1930 | path.transform(matrix); |
| 1931 | debugster("rotated circle", path); |
| 1932 | #StdOut |
| 1933 | empty bounds = 0, 0, 0, 0 |
| 1934 | circle bounds = 25, 20, 75, 70 |
| 1935 | rotated circle bounds = 14.6447, 9.64466, 85.3553, 80.3553 |
| 1936 | ## |
| 1937 | ## |
| 1938 | |
| 1939 | #SeeAlso computeTightBounds updateBoundsCache |
| 1940 | |
| 1941 | ## |
| 1942 | |
| 1943 | # ------------------------------------------------------------------------------ |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1944 | #Subtopic Utility |
| 1945 | #Populate |
| 1946 | #Line # rarely called management functions ## |
| 1947 | ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1948 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1949 | #Method void updateBoundsCache() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1950 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1951 | #Line # refreshes result of getBounds ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 1952 | Updates internal bounds so that subsequent calls to getBounds are instantaneous. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1953 | Unaltered copies of Path may also access cached bounds through getBounds. |
| 1954 | |
| 1955 | For now, identical to calling getBounds and ignoring the returned value. |
| 1956 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1957 | Call to prepare Path subsequently drawn from multiple threads, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1958 | to avoid a race condition where each draw separately computes the bounds. |
| 1959 | |
| 1960 | #Example |
| 1961 | double times[2] = { 0, 0 }; |
| 1962 | for (int i = 0; i < 10000; ++i) { |
| 1963 | SkPath path; |
| 1964 | for (int j = 1; j < 100; ++ j) { |
| 1965 | path.addCircle(50 + j, 45 + j, 25 + j); |
| 1966 | } |
| 1967 | if (1 & i) { |
| 1968 | path.updateBoundsCache(); |
| 1969 | } |
| 1970 | double start = SkTime::GetNSecs(); |
| 1971 | (void) path.getBounds(); |
| 1972 | times[1 & i] += SkTime::GetNSecs() - start; |
| 1973 | } |
| 1974 | SkDebugf("uncached avg: %g ms\n", times[0] * 1e-6); |
| 1975 | SkDebugf("cached avg: %g ms\n", times[1] * 1e-6); |
| 1976 | #StdOut |
| 1977 | #Volatile |
| 1978 | uncached avg: 0.18048 ms |
| 1979 | cached avg: 0.182784 ms |
| 1980 | ## |
| 1981 | ## |
| 1982 | |
| 1983 | #SeeAlso getBounds |
| 1984 | #ToDo the results don't make sense, need to profile to figure this out ## |
| 1985 | |
| 1986 | ## |
| 1987 | |
| 1988 | # ------------------------------------------------------------------------------ |
| 1989 | |
| 1990 | #Method SkRect computeTightBounds() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1991 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1992 | #Line # returns extent of geometry ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 1993 | Returns minimum and maximum axes values of the lines and curves in Path. |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1994 | Returns (0, 0, 0, 0) if Path contains no points. |
| 1995 | Returned bounds width and height may be larger or smaller than area affected |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 1996 | when Path is drawn. |
| 1997 | |
| 1998 | Includes Points associated with kMove_Verb that define empty |
| 1999 | Contours. |
| 2000 | |
| 2001 | Behaves identically to getBounds when Path contains |
| 2002 | only lines. If Path contains curves, computed bounds includes |
| 2003 | the maximum extent of the Quad, Conic, or Cubic; is slower than getBounds; |
| 2004 | and unlike getBounds, does not cache the result. |
| 2005 | |
| 2006 | #Return tight bounds of curves in Path ## |
| 2007 | |
| 2008 | #Example |
| 2009 | auto debugster = [](const char* prefix, const SkPath& path) -> void { |
| 2010 | const SkRect& bounds = path.computeTightBounds(); |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2011 | SkDebugf("%s bounds = %g, %g, %g, %g\n", prefix, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2012 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
| 2013 | }; |
| 2014 | SkPath path; |
| 2015 | debugster("empty", path); |
| 2016 | path.addCircle(50, 45, 25); |
| 2017 | debugster("circle", path); |
| 2018 | SkMatrix matrix; |
| 2019 | matrix.setRotate(45, 50, 45); |
| 2020 | path.transform(matrix); |
| 2021 | debugster("rotated circle", path); |
| 2022 | #StdOut |
| 2023 | empty bounds = 0, 0, 0, 0 |
| 2024 | circle bounds = 25, 20, 75, 70 |
| 2025 | rotated circle bounds = 25, 20, 75, 70 |
| 2026 | ## |
| 2027 | ## |
| 2028 | |
| 2029 | #SeeAlso getBounds |
| 2030 | |
| 2031 | ## |
| 2032 | |
| 2033 | # ------------------------------------------------------------------------------ |
| 2034 | |
| 2035 | #Method bool conservativelyContainsRect(const SkRect& rect) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2036 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2037 | #Line # returns true if Rect may be inside ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2038 | Returns true if rect is contained by Path. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2039 | May return false when rect is contained by Path. |
| 2040 | |
| 2041 | For now, only returns true if Path has one Contour and is convex. |
| 2042 | rect may share points and edges with Path and be contained. |
| 2043 | Returns true if rect is empty, that is, it has zero width or height; and |
| 2044 | the Point or Line described by rect is contained by Path. |
| 2045 | |
| 2046 | #Param rect Rect, Line, or Point checked for containment ## |
| 2047 | |
| 2048 | #Return true if rect is contained ## |
| 2049 | |
| 2050 | #Example |
| 2051 | #Height 140 |
| 2052 | #Description |
| 2053 | Rect is drawn in blue if it is contained by red Path. |
| 2054 | ## |
| 2055 | void draw(SkCanvas* canvas) { |
| 2056 | SkPath path; |
| 2057 | path.addRoundRect({10, 20, 54, 120}, 10, 20); |
| 2058 | SkRect tests[] = { |
| 2059 | { 10, 40, 54, 80 }, |
| 2060 | { 25, 20, 39, 120 }, |
| 2061 | { 15, 25, 49, 115 }, |
| 2062 | { 13, 27, 51, 113 }, |
| 2063 | }; |
| 2064 | for (unsigned i = 0; i < SK_ARRAY_COUNT(tests); ++i) { |
| 2065 | SkPaint paint; |
| 2066 | paint.setColor(SK_ColorRED); |
| 2067 | canvas->drawPath(path, paint); |
| 2068 | bool rectInPath = path.conservativelyContainsRect(tests[i]); |
| 2069 | paint.setColor(rectInPath ? SK_ColorBLUE : SK_ColorBLACK); |
| 2070 | canvas->drawRect(tests[i], paint); |
| 2071 | canvas->translate(64, 0); |
| 2072 | } |
| 2073 | } |
| 2074 | ## |
| 2075 | |
| 2076 | #SeeAlso contains Op Rect Convexity |
| 2077 | |
| 2078 | ## |
| 2079 | |
| 2080 | # ------------------------------------------------------------------------------ |
| 2081 | |
| 2082 | #Method void incReserve(unsigned extraPtCount) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2083 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2084 | #Line # reserves space for additional data ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2085 | Grows Path Verb_Array and Point_Array to contain extraPtCount additional Points. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2086 | May improve performance and use less memory by |
| 2087 | reducing the number and size of allocations when creating Path. |
| 2088 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2089 | #Param extraPtCount number of additional Points to allocate ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2090 | |
| 2091 | #Example |
| 2092 | #Height 192 |
| 2093 | void draw(SkCanvas* canvas) { |
| 2094 | auto addPoly = [](int sides, SkScalar size, SkPath* path) -> void { |
| 2095 | path->moveTo(size, 0); |
| 2096 | for (int i = 1; i < sides; i++) { |
| 2097 | SkScalar c, s = SkScalarSinCos(SK_ScalarPI * 2 * i / sides, &c); |
| 2098 | path->lineTo(c * size, s * size); |
| 2099 | } |
| 2100 | path->close(); |
| 2101 | }; |
| 2102 | SkPath path; |
| 2103 | path.incReserve(3 + 4 + 5 + 6 + 7 + 8 + 9); |
| 2104 | for (int sides = 3; sides < 10; ++sides) { |
| 2105 | addPoly(sides, sides, &path); |
| 2106 | } |
| 2107 | SkMatrix matrix; |
| 2108 | matrix.setScale(10, 10, -10, -10); |
| 2109 | path.transform(matrix); |
| 2110 | SkPaint paint; |
| 2111 | paint.setStyle(SkPaint::kStroke_Style); |
| 2112 | canvas->drawPath(path, paint); |
| 2113 | } |
| 2114 | ## |
| 2115 | |
| 2116 | #SeeAlso Point_Array |
| 2117 | |
| 2118 | ## |
| 2119 | |
| 2120 | # ------------------------------------------------------------------------------ |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2121 | #Subtopic Build |
| 2122 | #Populate |
| 2123 | #Line # adds points and verbs to path ## |
| 2124 | ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2125 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2126 | #Method SkPath& moveTo(SkScalar x, SkScalar y) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2127 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2128 | #Line # starts Contour ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2129 | Adds beginning of Contour at Point (x, y). |
| 2130 | |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 2131 | #Param x x-axis value of Contour start ## |
| 2132 | #Param y y-axis value of Contour start ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2133 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2134 | #Return reference to Path ## |
| 2135 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2136 | #Example |
| 2137 | #Width 140 |
| 2138 | #Height 100 |
| 2139 | void draw(SkCanvas* canvas) { |
| 2140 | SkRect rect = { 20, 20, 120, 80 }; |
| 2141 | SkPath path; |
| 2142 | path.addRect(rect); |
| 2143 | path.moveTo(rect.fLeft, rect.fTop); |
| 2144 | path.lineTo(rect.fRight, rect.fBottom); |
| 2145 | path.moveTo(rect.fLeft, rect.fBottom); |
| 2146 | path.lineTo(rect.fRight, rect.fTop); |
| 2147 | SkPaint paint; |
| 2148 | paint.setStyle(SkPaint::kStroke_Style); |
| 2149 | canvas->drawPath(path, paint); |
| 2150 | } |
| 2151 | ## |
| 2152 | |
| 2153 | #SeeAlso Contour lineTo rMoveTo quadTo conicTo cubicTo close() |
| 2154 | |
| 2155 | ## |
| 2156 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2157 | #Method SkPath& moveTo(const SkPoint& p) |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2158 | |
| 2159 | Adds beginning of Contour at Point p. |
| 2160 | |
| 2161 | #Param p contour start ## |
| 2162 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2163 | #Return reference to Path ## |
| 2164 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2165 | #Example |
| 2166 | #Width 128 |
| 2167 | #Height 128 |
| 2168 | void draw(SkCanvas* canvas) { |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2169 | SkPoint data[][3] = {{{30,40},{60,60},{90,30}}, {{30,120},{60,100},{90,120}}, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2170 | {{60,100},{60,40},{70,30}}, {{60,40},{50,20},{70,30}}}; |
| 2171 | SkPath path; |
| 2172 | for (unsigned i = 0; i < SK_ARRAY_COUNT(data); ++i) { |
| 2173 | path.moveTo(data[i][0]); |
| 2174 | path.lineTo(data[i][1]); |
| 2175 | path.lineTo(data[i][2]); |
| 2176 | } |
| 2177 | SkPaint paint; |
| 2178 | paint.setStyle(SkPaint::kStroke_Style); |
| 2179 | canvas->drawPath(path, paint); |
| 2180 | } |
| 2181 | ## |
| 2182 | |
| 2183 | #SeeAlso Contour lineTo rMoveTo quadTo conicTo cubicTo close() |
| 2184 | |
| 2185 | ## |
| 2186 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2187 | #Method SkPath& rMoveTo(SkScalar dx, SkScalar dy) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2188 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2189 | #Line # starts Contour relative to Last_Point ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2190 | Adds beginning of Contour relative to Last_Point. |
| 2191 | If Path is empty, starts Contour at (dx, dy). |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2192 | Otherwise, start Contour at Last_Point offset by (dx, dy). |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2193 | Function name stands for "relative move to". |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2194 | |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 2195 | #Param dx offset from Last_Point to Contour start on x-axis ## |
| 2196 | #Param dy offset from Last_Point to Contour start on y-axis ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2197 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2198 | #Return reference to Path ## |
| 2199 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2200 | #Example |
| 2201 | #Height 100 |
| 2202 | SkPath path; |
| 2203 | path.addRect({20, 20, 80, 80}, SkPath::kCW_Direction, 2); |
| 2204 | path.rMoveTo(25, 2); |
| 2205 | SkVector arrow[] = {{0, -4}, {-20, 0}, {0, -3}, {-5, 5}, {5, 5}, {0, -3}, {20, 0}}; |
| 2206 | for (unsigned i = 0; i < SK_ARRAY_COUNT(arrow); ++i) { |
| 2207 | path.rLineTo(arrow[i].fX, arrow[i].fY); |
| 2208 | } |
| 2209 | SkPaint paint; |
| 2210 | canvas->drawPath(path, paint); |
| 2211 | SkPoint lastPt; |
| 2212 | path.getLastPt(&lastPt); |
| 2213 | canvas->drawString("start", lastPt.fX, lastPt.fY, paint); |
| 2214 | ## |
| 2215 | |
| 2216 | #SeeAlso Contour lineTo moveTo quadTo conicTo cubicTo close() |
| 2217 | |
| 2218 | ## |
| 2219 | |
| 2220 | # ------------------------------------------------------------------------------ |
| 2221 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2222 | #Method SkPath& lineTo(SkScalar x, SkScalar y) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2223 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2224 | #Line # appends Line ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2225 | Adds Line from Last_Point to (x, y). If Path is empty, or last Verb is |
| 2226 | kClose_Verb, Last_Point is set to (0, 0) before adding Line. |
| 2227 | |
| 2228 | lineTo appends kMove_Verb to Verb_Array and (0, 0) to Point_Array, if needed. |
| 2229 | lineTo then appends kLine_Verb to Verb_Array and (x, y) to Point_Array. |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2230 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2231 | #Param x end of added Line in x ## |
| 2232 | #Param y end of added Line in y ## |
| 2233 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2234 | #Return reference to Path ## |
| 2235 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2236 | #Example |
| 2237 | #Height 100 |
| 2238 | ###$ |
| 2239 | void draw(SkCanvas* canvas) { |
| 2240 | SkPaint paint; |
| 2241 | paint.setAntiAlias(true); |
| 2242 | paint.setTextSize(72); |
| 2243 | canvas->drawString("#", 120, 80, paint); |
| 2244 | paint.setStyle(SkPaint::kStroke_Style); |
| 2245 | paint.setStrokeWidth(5); |
| 2246 | SkPath path; |
| 2247 | SkPoint hash[] = {{58, 28}, {43, 80}, {37, 45}, {85, 45}}; |
| 2248 | SkVector offsets[] = {{0, 0}, {17, 0}, {0, 0}, {-5, 17}}; |
| 2249 | unsigned o = 0; |
| 2250 | for (unsigned i = 0; i < SK_ARRAY_COUNT(hash); i += 2) { |
| 2251 | for (unsigned j = 0; j < 2; o++, j++) { |
| 2252 | path.moveTo(hash[i].fX + offsets[o].fX, hash[i].fY + offsets[o].fY); |
| 2253 | path.lineTo(hash[i + 1].fX + offsets[o].fX, hash[i + 1].fY + offsets[o].fY); |
| 2254 | } |
| 2255 | } |
| 2256 | canvas->drawPath(path, paint); |
| 2257 | } |
| 2258 | $$$# |
| 2259 | ## |
| 2260 | |
| 2261 | #SeeAlso Contour moveTo rLineTo addRect |
| 2262 | |
| 2263 | ## |
| 2264 | |
| 2265 | # ------------------------------------------------------------------------------ |
| 2266 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2267 | #Method SkPath& lineTo(const SkPoint& p) |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2268 | |
| 2269 | Adds Line from Last_Point to Point p. If Path is empty, or last Verb is |
| 2270 | kClose_Verb, Last_Point is set to (0, 0) before adding Line. |
| 2271 | |
| 2272 | lineTo first appends kMove_Verb to Verb_Array and (0, 0) to Point_Array, if needed. |
| 2273 | lineTo then appends kLine_Verb to Verb_Array and Point p to Point_Array. |
| 2274 | |
| 2275 | #Param p end Point of added Line ## |
| 2276 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2277 | #Return reference to Path ## |
| 2278 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2279 | #Example |
| 2280 | #Height 100 |
| 2281 | SkPath path; |
| 2282 | SkVector oxo[] = {{25, 25}, {35, 35}, {25, 35}, {35, 25}, |
| 2283 | {40, 20}, {40, 80}, {60, 20}, {60, 80}, |
| 2284 | {20, 40}, {80, 40}, {20, 60}, {80, 60}}; |
| 2285 | for (unsigned i = 0; i < SK_ARRAY_COUNT(oxo); i += 2) { |
| 2286 | path.moveTo(oxo[i]); |
| 2287 | path.lineTo(oxo[i + 1]); |
| 2288 | } |
| 2289 | SkPaint paint; |
| 2290 | paint.setStyle(SkPaint::kStroke_Style); |
| 2291 | canvas->drawPath(path, paint); |
| 2292 | ## |
| 2293 | |
| 2294 | #SeeAlso Contour moveTo rLineTo addRect |
| 2295 | |
| 2296 | ## |
| 2297 | |
| 2298 | # ------------------------------------------------------------------------------ |
| 2299 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2300 | #Method SkPath& rLineTo(SkScalar dx, SkScalar dy) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2301 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2302 | #Line # appends Line relative to Last_Point ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2303 | Adds Line from Last_Point to Vector (dx, dy). If Path is empty, or last Verb is |
| 2304 | kClose_Verb, Last_Point is set to (0, 0) before adding Line. |
| 2305 | |
| 2306 | Appends kMove_Verb to Verb_Array and (0, 0) to Point_Array, if needed; |
| 2307 | then appends kLine_Verb to Verb_Array and Line end to Point_Array. |
| 2308 | Line end is Last_Point plus Vector (dx, dy). |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2309 | Function name stands for "relative line to". |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2310 | |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 2311 | #Param dx offset from Last_Point to Line end on x-axis ## |
| 2312 | #Param dy offset from Last_Point to Line end on y-axis ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2313 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2314 | #Return reference to Path ## |
| 2315 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2316 | #Example |
| 2317 | #Height 128 |
| 2318 | void draw(SkCanvas* canvas) { |
| 2319 | SkPaint paint; |
| 2320 | paint.setAntiAlias(true); |
| 2321 | paint.setStyle(SkPaint::kStroke_Style); |
| 2322 | SkPath path; |
| 2323 | path.moveTo(10, 98); |
| 2324 | SkScalar x = 0, y = 0; |
| 2325 | for (int i = 10; i < 100; i += 5) { |
| 2326 | x += i * ((i & 2) - 1); |
| 2327 | y += i * (((i + 1) & 2) - 1); |
| 2328 | path.rLineTo(x, y); |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2329 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2330 | } |
| 2331 | canvas->drawPath(path, paint); |
| 2332 | } |
| 2333 | ## |
| 2334 | |
| 2335 | #SeeAlso Contour moveTo lineTo addRect |
| 2336 | |
| 2337 | ## |
| 2338 | |
| 2339 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2340 | #Subtopic Quad |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 2341 | #Alias Quad ## |
| 2342 | #Alias Quads ## |
| 2343 | #Alias Quadratic_Bezier ## |
| 2344 | #Alias Quadratic_Beziers ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2345 | #Line # curve described by second-order polynomial ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2346 | |
| 2347 | Quad describes a quadratic Bezier, a second-order curve identical to a section |
| 2348 | of a parabola. Quad begins at a start Point, curves towards a control Point, |
| 2349 | and then curves to an end Point. |
| 2350 | |
| 2351 | #Example |
| 2352 | #Height 110 |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2353 | void draw(SkCanvas* canvas) { |
| 2354 | SkPaint paint; |
| 2355 | paint.setAntiAlias(true); |
| 2356 | paint.setStyle(SkPaint::kStroke_Style); |
| 2357 | SkPoint quadPts[] = {{20, 90}, {120, 10}, {220, 90}}; |
| 2358 | canvas->drawLine(quadPts[0], quadPts[1], paint); |
| 2359 | canvas->drawLine(quadPts[1], quadPts[2], paint); |
| 2360 | SkPath path; |
| 2361 | path.moveTo(quadPts[0]); |
| 2362 | path.quadTo(quadPts[1], quadPts[2]); |
| 2363 | paint.setStrokeWidth(3); |
| 2364 | canvas->drawPath(path, paint); |
| 2365 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2366 | ## |
| 2367 | |
| 2368 | Quad is a special case of Conic where Conic_Weight is set to one. |
| 2369 | |
| 2370 | Quad is always contained by the triangle connecting its three Points. Quad |
| 2371 | begins tangent to the line between start Point and control Point, and ends |
| 2372 | tangent to the line between control Point and end Point. |
| 2373 | |
| 2374 | #Example |
| 2375 | #Height 160 |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2376 | void draw(SkCanvas* canvas) { |
| 2377 | SkPaint paint; |
| 2378 | paint.setAntiAlias(true); |
| 2379 | paint.setStyle(SkPaint::kStroke_Style); |
| 2380 | SkPoint quadPts[] = {{20, 150}, {120, 10}, {220, 150}}; |
| 2381 | SkColor colors[] = { 0xff88ff00, 0xff0088bb, 0xff6600cc, 0xffbb3377 }; |
| 2382 | for (unsigned i = 0; i < SK_ARRAY_COUNT(colors); ++i) { |
| 2383 | paint.setColor(0x7fffffff & colors[i]); |
| 2384 | paint.setStrokeWidth(1); |
| 2385 | canvas->drawLine(quadPts[0], quadPts[1], paint); |
| 2386 | canvas->drawLine(quadPts[1], quadPts[2], paint); |
| 2387 | SkPath path; |
| 2388 | path.moveTo(quadPts[0]); |
| 2389 | path.quadTo(quadPts[1], quadPts[2]); |
| 2390 | paint.setStrokeWidth(3); |
| 2391 | paint.setColor(colors[i]); |
| 2392 | canvas->drawPath(path, paint); |
| 2393 | quadPts[1].fY += 30; |
| 2394 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2395 | } |
| 2396 | ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2397 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2398 | #Method SkPath& quadTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2399 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2400 | #In Quad |
| 2401 | #Line # appends Quad ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2402 | Adds Quad from Last_Point towards (x1, y1), to (x2, y2). |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2403 | If Path is empty, or last Verb is kClose_Verb, Last_Point is set to (0, 0) |
| 2404 | before adding Quad. |
| 2405 | |
| 2406 | Appends kMove_Verb to Verb_Array and (0, 0) to Point_Array, if needed; |
| 2407 | then appends kQuad_Verb to Verb_Array; and (x1, y1), (x2, y2) |
| 2408 | to Point_Array. |
| 2409 | |
| 2410 | #Param x1 control Point of Quad in x ## |
| 2411 | #Param y1 control Point of Quad in y ## |
| 2412 | #Param x2 end Point of Quad in x ## |
| 2413 | #Param y2 end Point of Quad in y ## |
| 2414 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2415 | #Return reference to Path ## |
| 2416 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2417 | #Example |
| 2418 | void draw(SkCanvas* canvas) { |
| 2419 | SkPaint paint; |
| 2420 | paint.setAntiAlias(true); |
| 2421 | paint.setStyle(SkPaint::kStroke_Style); |
| 2422 | SkPath path; |
| 2423 | path.moveTo(0, -10); |
| 2424 | for (int i = 0; i < 128; i += 16) { |
| 2425 | path.quadTo( 10 + i, -10 - i, 10 + i, 0); |
| 2426 | path.quadTo( 14 + i, 14 + i, 0, 14 + i); |
| 2427 | path.quadTo(-18 - i, 18 + i, -18 - i, 0); |
| 2428 | path.quadTo(-22 - i, -22 - i, 0, -22 - i); |
| 2429 | } |
| 2430 | path.offset(128, 128); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2431 | canvas->drawPath(path, paint); |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2432 | } |
| 2433 | ## |
| 2434 | |
| 2435 | #SeeAlso Contour moveTo conicTo rQuadTo |
| 2436 | |
| 2437 | ## |
| 2438 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2439 | #Method SkPath& quadTo(const SkPoint& p1, const SkPoint& p2) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2440 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2441 | #In Quad |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2442 | Adds Quad from Last_Point towards Point p1, to Point p2. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2443 | If Path is empty, or last Verb is kClose_Verb, Last_Point is set to (0, 0) |
| 2444 | before adding Quad. |
| 2445 | |
| 2446 | Appends kMove_Verb to Verb_Array and (0, 0) to Point_Array, if needed; |
| 2447 | then appends kQuad_Verb to Verb_Array; and Points p1, p2 |
| 2448 | to Point_Array. |
| 2449 | |
| 2450 | #Param p1 control Point of added Quad ## |
| 2451 | #Param p2 end Point of added Quad ## |
| 2452 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2453 | #Return reference to Path ## |
| 2454 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2455 | #Example |
| 2456 | void draw(SkCanvas* canvas) { |
| 2457 | SkPaint paint; |
| 2458 | paint.setStyle(SkPaint::kStroke_Style); |
| 2459 | paint.setAntiAlias(true); |
| 2460 | SkPath path; |
| 2461 | SkPoint pts[] = {{128, 10}, {10, 214}, {236, 214}}; |
| 2462 | path.moveTo(pts[1]); |
| 2463 | for (int i = 0; i < 3; ++i) { |
| 2464 | path.quadTo(pts[i % 3], pts[(i + 2) % 3]); |
| 2465 | } |
| 2466 | canvas->drawPath(path, paint); |
| 2467 | } |
| 2468 | ## |
| 2469 | |
| 2470 | #SeeAlso Contour moveTo conicTo rQuadTo |
| 2471 | |
| 2472 | ## |
| 2473 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2474 | #Method SkPath& rQuadTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2475 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2476 | #In Quad |
| 2477 | #Line # appends Quad relative to Last_Point ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2478 | Adds Quad from Last_Point towards Vector (dx1, dy1), to Vector (dx2, dy2). |
| 2479 | If Path is empty, or last Verb |
| 2480 | is kClose_Verb, Last_Point is set to (0, 0) before adding Quad. |
| 2481 | |
| 2482 | Appends kMove_Verb to Verb_Array and (0, 0) to Point_Array, |
| 2483 | if needed; then appends kQuad_Verb to Verb_Array; and appends Quad |
| 2484 | control and Quad end to Point_Array. |
| 2485 | Quad control is Last_Point plus Vector (dx1, dy1). |
| 2486 | Quad end is Last_Point plus Vector (dx2, dy2). |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2487 | Function name stands for "relative quad to". |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2488 | |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 2489 | #Param dx1 offset from Last_Point to Quad control on x-axis ## |
| 2490 | #Param dy1 offset from Last_Point to Quad control on y-axis ## |
| 2491 | #Param dx2 offset from Last_Point to Quad end on x-axis ## |
| 2492 | #Param dy2 offset from Last_Point to Quad end on y-axis ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2493 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2494 | #Return reference to Path ## |
| 2495 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2496 | #Example |
| 2497 | void draw(SkCanvas* canvas) { |
| 2498 | SkPaint paint; |
| 2499 | paint.setAntiAlias(true); |
| 2500 | SkPath path; |
| 2501 | path.moveTo(128, 20); |
| 2502 | path.rQuadTo(-6, 10, -7, 10); |
| 2503 | for (int i = 1; i < 32; i += 4) { |
| 2504 | path.rQuadTo(10 + i, 10 + i, 10 + i * 4, 10); |
| 2505 | path.rQuadTo(-10 - i, 10 + i, -10 - (i + 2) * 4, 10); |
| 2506 | } |
| 2507 | path.quadTo(92, 220, 128, 215); |
| 2508 | canvas->drawPath(path, paint); |
| 2509 | } |
| 2510 | ## |
| 2511 | |
| 2512 | #SeeAlso Contour moveTo conicTo quadTo |
| 2513 | |
| 2514 | ## |
| 2515 | |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2516 | #Subtopic Quad ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2517 | |
| 2518 | # ------------------------------------------------------------------------------ |
| 2519 | |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2520 | #Subtopic Conic |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2521 | #Line # conic section defined by three points and a weight ## |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 2522 | #Alias Conics ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2523 | |
| 2524 | Conic describes a conical section: a piece of an ellipse, or a piece of a |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2525 | parabola, or a piece of a hyperbola. Conic begins at a start Point, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2526 | curves towards a control Point, and then curves to an end Point. The influence |
| 2527 | of the control Point is determined by Conic_Weight. |
| 2528 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2529 | Each Conic in Path adds two Points and one Conic_Weight. Conic_Weights in Path |
| 2530 | may be inspected with Iter, or with RawIter. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2531 | |
| 2532 | #Subtopic Weight |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 2533 | #Alias Conic_Weights ## |
| 2534 | #Alias Weights ## |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2535 | #Line # strength of Conic control Point ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2536 | |
| 2537 | Weight determines both the strength of the control Point and the type of Conic. |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2538 | Weight varies from zero to infinity. At zero, Weight causes the control Point to |
| 2539 | have no effect; Conic is identical to a line segment from start Point to end |
| 2540 | point. If Weight is less than one, Conic follows an elliptical arc. |
| 2541 | If Weight is exactly one, then Conic is identical to Quad; Conic follows a |
| 2542 | parabolic arc. If Weight is greater than one, Conic follows a hyperbolic |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 2543 | arc. If Weight is infinity, Conic is identical to two line segments, connecting |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2544 | start Point to control Point, and control Point to end Point. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2545 | |
| 2546 | #Example |
| 2547 | #Description |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2548 | When Conic_Weight is one, Quad is added to path; the two are identical. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2549 | ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2550 | void draw(SkCanvas* canvas) { |
| 2551 | const char* verbNames[] = { "move", "line", "quad", "conic", "cubic", "close", "done" }; |
| 2552 | const int pointCount[] = { 1 , 2 , 3 , 3 , 4 , 1 , 0 }; |
| 2553 | SkPath path; |
| 2554 | path.conicTo(20, 30, 50, 60, 1); |
| 2555 | SkPath::Iter iter(path, false); |
| 2556 | SkPath::Verb verb; |
| 2557 | do { |
| 2558 | SkPoint points[4]; |
| 2559 | verb = iter.next(points); |
| 2560 | SkDebugf("%s ", verbNames[(int) verb]); |
| 2561 | for (int i = 0; i < pointCount[(int) verb]; ++i) { |
| 2562 | SkDebugf("{%g, %g}, ", points[i].fX, points[i].fY); |
| 2563 | } |
| 2564 | if (SkPath::kConic_Verb == verb) { |
| 2565 | SkDebugf("weight = %g", iter.conicWeight()); |
| 2566 | } |
| 2567 | SkDebugf("\n"); |
| 2568 | } while (SkPath::kDone_Verb != verb); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2569 | } |
| 2570 | #StdOut |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2571 | move {0, 0}, |
| 2572 | quad {0, 0}, {20, 30}, {50, 60}, |
| 2573 | done |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2574 | ## |
| 2575 | ## |
| 2576 | |
| 2577 | If weight is less than one, Conic is an elliptical segment. |
| 2578 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2579 | #Example |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2580 | #Description |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2581 | A 90 degree circular arc has the weight |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2582 | #Formula |
| 2583 | 1 / sqrt(2) |
| 2584 | ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 2585 | . |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2586 | ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2587 | void draw(SkCanvas* canvas) { |
| 2588 | const char* verbNames[] = { "move", "line", "quad", "conic", "cubic", "close", "done" }; |
| 2589 | const int pointCount[] = { 1 , 2 , 3 , 3 , 4 , 1 , 0 }; |
| 2590 | SkPath path; |
| 2591 | path.arcTo(20, 0, 20, 20, 20); |
| 2592 | SkPath::Iter iter(path, false); |
| 2593 | SkPath::Verb verb; |
| 2594 | do { |
| 2595 | SkPoint points[4]; |
| 2596 | verb = iter.next(points); |
| 2597 | SkDebugf("%s ", verbNames[(int) verb]); |
| 2598 | for (int i = 0; i < pointCount[(int) verb]; ++i) { |
| 2599 | SkDebugf("{%g, %g}, ", points[i].fX, points[i].fY); |
| 2600 | } |
| 2601 | if (SkPath::kConic_Verb == verb) { |
| 2602 | SkDebugf("weight = %g", iter.conicWeight()); |
| 2603 | } |
| 2604 | SkDebugf("\n"); |
| 2605 | } while (SkPath::kDone_Verb != verb); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2606 | } |
| 2607 | #StdOut |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2608 | move {0, 0}, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2609 | conic {0, 0}, {20, 0}, {20, 20}, weight = 0.707107 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2610 | done |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2611 | ## |
| 2612 | ## |
| 2613 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2614 | If weight is greater than one, Conic is a hyperbolic segment. As weight gets large, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2615 | a hyperbolic segment can be approximated by straight lines connecting the |
| 2616 | control Point with the end Points. |
| 2617 | |
| 2618 | #Example |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2619 | void draw(SkCanvas* canvas) { |
| 2620 | const char* verbNames[] = { "move", "line", "quad", "conic", "cubic", "close", "done" }; |
| 2621 | const int pointCount[] = { 1 , 2 , 3 , 3 , 4 , 1 , 0 }; |
| 2622 | SkPath path; |
| 2623 | path.conicTo(20, 0, 20, 20, SK_ScalarInfinity); |
| 2624 | SkPath::Iter iter(path, false); |
| 2625 | SkPath::Verb verb; |
| 2626 | do { |
| 2627 | SkPoint points[4]; |
| 2628 | verb = iter.next(points); |
| 2629 | SkDebugf("%s ", verbNames[(int) verb]); |
| 2630 | for (int i = 0; i < pointCount[(int) verb]; ++i) { |
| 2631 | SkDebugf("{%g, %g}, ", points[i].fX, points[i].fY); |
| 2632 | } |
| 2633 | if (SkPath::kConic_Verb == verb) { |
| 2634 | SkDebugf("weight = %g", iter.conicWeight()); |
| 2635 | } |
| 2636 | SkDebugf("\n"); |
| 2637 | } while (SkPath::kDone_Verb != verb); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2638 | } |
| 2639 | #StdOut |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2640 | move {0, 0}, |
| 2641 | line {0, 0}, {20, 0}, |
| 2642 | line {20, 0}, {20, 20}, |
| 2643 | done |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2644 | ## |
| 2645 | ## |
| 2646 | |
| 2647 | #Subtopic Weight ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2648 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2649 | #Method SkPath& conicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2650 | SkScalar w) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2651 | #In Conic |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2652 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2653 | #Line # appends Conic ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2654 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2655 | Adds Conic from Last_Point towards (x1, y1), to (x2, y2), weighted by w. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2656 | If Path is empty, or last Verb is kClose_Verb, Last_Point is set to (0, 0) |
| 2657 | before adding Conic. |
| 2658 | |
| 2659 | Appends kMove_Verb to Verb_Array and (0, 0) to Point_Array, if needed. |
| 2660 | |
| 2661 | If w is finite and not one, appends kConic_Verb to Verb_Array; |
| 2662 | and (x1, y1), (x2, y2) to Point_Array; and w to Conic_Weights. |
| 2663 | |
| 2664 | If w is one, appends kQuad_Verb to Verb_Array, and |
| 2665 | (x1, y1), (x2, y2) to Point_Array. |
| 2666 | |
| 2667 | If w is not finite, appends kLine_Verb twice to Verb_Array, and |
| 2668 | (x1, y1), (x2, y2) to Point_Array. |
| 2669 | |
| 2670 | #Param x1 control Point of Conic in x ## |
| 2671 | #Param y1 control Point of Conic in y ## |
| 2672 | #Param x2 end Point of Conic in x ## |
| 2673 | #Param y2 end Point of Conic in y ## |
| 2674 | #Param w weight of added Conic ## |
| 2675 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2676 | #Return reference to Path ## |
| 2677 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2678 | #Example |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2679 | #Height 160 |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2680 | #Description |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2681 | As weight increases, curve is pulled towards control point. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2682 | The bottom two curves are elliptical; the next is parabolic; the |
| 2683 | top curve is hyperbolic. |
| 2684 | ## |
| 2685 | void draw(SkCanvas* canvas) { |
| 2686 | SkPaint paint; |
| 2687 | paint.setAntiAlias(true); |
| 2688 | paint.setStyle(SkPaint::kStroke_Style); |
| 2689 | SkPoint conicPts[] = {{20, 150}, {120, 10}, {220, 150}}; |
| 2690 | canvas->drawLine(conicPts[0], conicPts[1], paint); |
| 2691 | canvas->drawLine(conicPts[1], conicPts[2], paint); |
| 2692 | SkColor colors[] = { 0xff88ff00, 0xff0088bb, 0xff6600cc, 0xffbb3377 }; |
| 2693 | paint.setStrokeWidth(3); |
| 2694 | SkScalar weight = 0.5f; |
| 2695 | for (unsigned i = 0; i < SK_ARRAY_COUNT(colors); ++i) { |
| 2696 | SkPath path; |
| 2697 | path.moveTo(conicPts[0]); |
| 2698 | path.conicTo(conicPts[1], conicPts[2], weight); |
| 2699 | paint.setColor(colors[i]); |
| 2700 | canvas->drawPath(path, paint); |
| 2701 | weight += 0.25f; |
| 2702 | } |
| 2703 | } |
| 2704 | ## |
| 2705 | |
| 2706 | #SeeAlso rConicTo arcTo addArc quadTo |
| 2707 | |
| 2708 | ## |
| 2709 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2710 | #Method SkPath& conicTo(const SkPoint& p1, const SkPoint& p2, SkScalar w) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2711 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2712 | #In Conic |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2713 | Adds Conic from Last_Point towards Point p1, to Point p2, weighted by w. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2714 | If Path is empty, or last Verb is kClose_Verb, Last_Point is set to (0, 0) |
| 2715 | before adding Conic. |
| 2716 | |
| 2717 | Appends kMove_Verb to Verb_Array and (0, 0) to Point_Array, if needed. |
| 2718 | |
| 2719 | If w is finite and not one, appends kConic_Verb to Verb_Array; |
| 2720 | and Points p1, p2 to Point_Array; and w to Conic_Weights. |
| 2721 | |
| 2722 | If w is one, appends kQuad_Verb to Verb_Array, and Points p1, p2 |
| 2723 | to Point_Array. |
| 2724 | |
| 2725 | If w is not finite, appends kLine_Verb twice to Verb_Array, and |
| 2726 | Points p1, p2 to Point_Array. |
| 2727 | |
| 2728 | #Param p1 control Point of added Conic ## |
| 2729 | #Param p2 end Point of added Conic ## |
| 2730 | #Param w weight of added Conic ## |
| 2731 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2732 | #Return reference to Path ## |
| 2733 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2734 | #Example |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2735 | #Height 128 |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2736 | #Description |
| 2737 | Conics and arcs use identical representations. As the arc sweep increases |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2738 | the Conic_Weight also increases, but remains smaller than one. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2739 | ## |
| 2740 | void draw(SkCanvas* canvas) { |
| 2741 | SkPaint paint; |
| 2742 | paint.setAntiAlias(true); |
| 2743 | paint.setStyle(SkPaint::kStroke_Style); |
| 2744 | SkRect oval = {0, 20, 120, 140}; |
| 2745 | SkPath path; |
| 2746 | for (int i = 0; i < 4; ++i) { |
| 2747 | path.moveTo(oval.centerX(), oval.fTop); |
| 2748 | path.arcTo(oval, -90, 90 - 20 * i, false); |
| 2749 | oval.inset(15, 15); |
| 2750 | } |
| 2751 | path.offset(100, 0); |
| 2752 | SkScalar conicWeights[] = { 0.707107f, 0.819152f, 0.906308f, 0.965926f }; |
| 2753 | SkPoint conicPts[][3] = { { {40, 20}, {100, 20}, {100, 80} }, |
| 2754 | { {40, 35}, {71.509f, 35}, {82.286f, 64.6091f} }, |
| 2755 | { {40, 50}, {53.9892f, 50}, {62.981f, 60.7164f} }, |
| 2756 | { {40, 65}, {44.0192f, 65}, {47.5f, 67.0096f} } }; |
| 2757 | for (int i = 0; i < 4; ++i) { |
| 2758 | path.moveTo(conicPts[i][0]); |
| 2759 | path.conicTo(conicPts[i][1], conicPts[i][2], conicWeights[i]); |
| 2760 | } |
| 2761 | canvas->drawPath(path, paint); |
| 2762 | } |
| 2763 | ## |
| 2764 | |
| 2765 | #SeeAlso rConicTo arcTo addArc quadTo |
| 2766 | |
| 2767 | ## |
| 2768 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2769 | #Method SkPath& rConicTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2770 | SkScalar w) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2771 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2772 | #In Conic |
| 2773 | #Line # appends Conic relative to Last_Point ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2774 | |
| 2775 | Adds Conic from Last_Point towards Vector (dx1, dy1), to Vector (dx2, dy2), |
| 2776 | weighted by w. If Path is empty, or last Verb |
| 2777 | is kClose_Verb, Last_Point is set to (0, 0) before adding Conic. |
| 2778 | |
| 2779 | Appends kMove_Verb to Verb_Array and (0, 0) to Point_Array, |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2780 | if needed. |
| 2781 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2782 | If w is finite and not one, next appends kConic_Verb to Verb_Array, |
| 2783 | and w is recorded as Conic_Weight; otherwise, if w is one, appends |
| 2784 | kQuad_Verb to Verb_Array; or if w is not finite, appends kLine_Verb |
| 2785 | twice to Verb_Array. |
| 2786 | |
| 2787 | In all cases appends Points control and end to Point_Array. |
| 2788 | control is Last_Point plus Vector (dx1, dy1). |
| 2789 | end is Last_Point plus Vector (dx2, dy2). |
| 2790 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2791 | Function name stands for "relative conic to". |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2792 | |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 2793 | #Param dx1 offset from Last_Point to Conic control on x-axis ## |
| 2794 | #Param dy1 offset from Last_Point to Conic control on y-axis ## |
| 2795 | #Param dx2 offset from Last_Point to Conic end on x-axis ## |
| 2796 | #Param dy2 offset from Last_Point to Conic end on y-axis ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2797 | #Param w weight of added Conic ## |
| 2798 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2799 | #Return reference to Path ## |
| 2800 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2801 | #Example |
| 2802 | #Height 140 |
| 2803 | void draw(SkCanvas* canvas) { |
| 2804 | SkPaint paint; |
| 2805 | paint.setAntiAlias(true); |
| 2806 | paint.setStyle(SkPaint::kStroke_Style); |
| 2807 | SkPath path; |
| 2808 | path.moveTo(20, 80); |
| 2809 | path.rConicTo( 60, 0, 60, 60, 0.707107f); |
| 2810 | path.rConicTo( 0, -60, 60, -60, 0.707107f); |
| 2811 | path.rConicTo(-60, 0, -60, -60, 0.707107f); |
| 2812 | path.rConicTo( 0, 60, -60, 60, 0.707107f); |
| 2813 | canvas->drawPath(path, paint); |
| 2814 | } |
| 2815 | ## |
| 2816 | |
| 2817 | #SeeAlso conicTo arcTo addArc quadTo |
| 2818 | |
| 2819 | ## |
| 2820 | |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2821 | #Subtopic Conic ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2822 | |
| 2823 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2824 | #Subtopic Cubic |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 2825 | #Alias Cubic ## |
| 2826 | #Alias Cubics ## |
| 2827 | #Alias Cubic_Bezier ## |
| 2828 | #Alias Cubic_Beziers ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2829 | #Line # curve described by third-order polynomial ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2830 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2831 | Cubic describes a Bezier_Curve segment described by a third-order polynomial. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2832 | Cubic begins at a start Point, curving towards the first control Point; |
| 2833 | and curves from the end Point towards the second control Point. |
| 2834 | |
| 2835 | #Example |
| 2836 | #Height 160 |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2837 | void draw(SkCanvas* canvas) { |
| 2838 | SkPaint paint; |
| 2839 | paint.setAntiAlias(true); |
| 2840 | paint.setStyle(SkPaint::kStroke_Style); |
| 2841 | SkPoint cubicPts[] = {{20, 150}, {90, 10}, {160, 150}, {230, 10}}; |
| 2842 | SkColor colors[] = { 0xff88ff00, 0xff0088bb, 0xff6600cc, 0xffbb3377 }; |
| 2843 | for (unsigned i = 0; i < SK_ARRAY_COUNT(colors); ++i) { |
| 2844 | paint.setColor(0x7fffffff & colors[i]); |
| 2845 | paint.setStrokeWidth(1); |
| 2846 | for (unsigned j = 0; j < 3; ++j) { |
| 2847 | canvas->drawLine(cubicPts[j], cubicPts[j + 1], paint); |
| 2848 | } |
| 2849 | SkPath path; |
| 2850 | path.moveTo(cubicPts[0]); |
| 2851 | path.cubicTo(cubicPts[1], cubicPts[2], cubicPts[3]); |
| 2852 | paint.setStrokeWidth(3); |
| 2853 | paint.setColor(colors[i]); |
| 2854 | canvas->drawPath(path, paint); |
| 2855 | cubicPts[1].fY += 30; |
| 2856 | cubicPts[2].fX += 30; |
| 2857 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2858 | } |
| 2859 | ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2860 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2861 | #Method SkPath& cubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2862 | SkScalar x3, SkScalar y3) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2863 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2864 | #In Cubic |
| 2865 | #Line # appends Cubic ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2866 | |
| 2867 | Adds Cubic from Last_Point towards (x1, y1), then towards (x2, y2), ending at |
| 2868 | (x3, y3). If Path is empty, or last Verb is kClose_Verb, Last_Point is set to |
| 2869 | (0, 0) before adding Cubic. |
| 2870 | |
| 2871 | Appends kMove_Verb to Verb_Array and (0, 0) to Point_Array, if needed; |
| 2872 | then appends kCubic_Verb to Verb_Array; and (x1, y1), (x2, y2), (x3, y3) |
| 2873 | to Point_Array. |
| 2874 | |
| 2875 | #Param x1 first control Point of Cubic in x ## |
| 2876 | #Param y1 first control Point of Cubic in y ## |
| 2877 | #Param x2 second control Point of Cubic in x ## |
| 2878 | #Param y2 second control Point of Cubic in y ## |
| 2879 | #Param x3 end Point of Cubic in x ## |
| 2880 | #Param y3 end Point of Cubic in y ## |
| 2881 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2882 | #Return reference to Path ## |
| 2883 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2884 | #Example |
| 2885 | void draw(SkCanvas* canvas) { |
| 2886 | SkPaint paint; |
| 2887 | paint.setAntiAlias(true); |
| 2888 | paint.setStyle(SkPaint::kStroke_Style); |
| 2889 | SkPath path; |
| 2890 | path.moveTo(0, -10); |
| 2891 | for (int i = 0; i < 128; i += 16) { |
| 2892 | SkScalar c = i * 0.5f; |
| 2893 | path.cubicTo( 10 + c, -10 - i, 10 + i, -10 - c, 10 + i, 0); |
| 2894 | path.cubicTo( 14 + i, 14 + c, 14 + c, 14 + i, 0, 14 + i); |
| 2895 | path.cubicTo(-18 - c, 18 + i, -18 - i, 18 + c, -18 - i, 0); |
| 2896 | path.cubicTo(-22 - i, -22 - c, -22 - c, -22 - i, 0, -22 - i); |
| 2897 | } |
| 2898 | path.offset(128, 128); |
| 2899 | canvas->drawPath(path, paint); |
| 2900 | } |
| 2901 | ## |
| 2902 | |
| 2903 | #SeeAlso Contour moveTo rCubicTo quadTo |
| 2904 | |
| 2905 | ## |
| 2906 | |
| 2907 | # ------------------------------------------------------------------------------ |
| 2908 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2909 | #Method SkPath& cubicTo(const SkPoint& p1, const SkPoint& p2, const SkPoint& p3) |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2910 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2911 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2912 | #In Cubic |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2913 | Adds Cubic from Last_Point towards Point p1, then towards Point p2, ending at |
| 2914 | Point p3. If Path is empty, or last Verb is kClose_Verb, Last_Point is set to |
| 2915 | (0, 0) before adding Cubic. |
| 2916 | |
| 2917 | Appends kMove_Verb to Verb_Array and (0, 0) to Point_Array, if needed; |
| 2918 | then appends kCubic_Verb to Verb_Array; and Points p1, p2, p3 |
| 2919 | to Point_Array. |
| 2920 | |
| 2921 | #Param p1 first control Point of Cubic ## |
| 2922 | #Param p2 second control Point of Cubic ## |
| 2923 | #Param p3 end Point of Cubic ## |
| 2924 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2925 | #Return reference to Path ## |
| 2926 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2927 | #Example |
| 2928 | #Height 84 |
| 2929 | SkPaint paint; |
| 2930 | paint.setAntiAlias(true); |
| 2931 | paint.setStyle(SkPaint::kStroke_Style); |
| 2932 | SkPoint pts[] = { {20, 20}, {300, 80}, {-140, 90}, {220, 10} }; |
| 2933 | SkPath path; |
| 2934 | path.moveTo(pts[0]); |
| 2935 | path.cubicTo(pts[1], pts[2], pts[3]); |
| 2936 | canvas->drawPath(path, paint); |
| 2937 | ## |
| 2938 | |
| 2939 | #SeeAlso Contour moveTo rCubicTo quadTo |
| 2940 | |
| 2941 | ## |
| 2942 | |
| 2943 | # ------------------------------------------------------------------------------ |
| 2944 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2945 | #Method SkPath& rCubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2946 | SkScalar x3, SkScalar y3) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2947 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2948 | #In Cubic |
| 2949 | #Line # appends Cubic relative to Last_Point ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2950 | |
| 2951 | Adds Cubic from Last_Point towards Vector (dx1, dy1), then towards |
| 2952 | Vector (dx2, dy2), to Vector (dx3, dy3). |
| 2953 | If Path is empty, or last Verb |
| 2954 | is kClose_Verb, Last_Point is set to (0, 0) before adding Cubic. |
| 2955 | |
| 2956 | Appends kMove_Verb to Verb_Array and (0, 0) to Point_Array, |
| 2957 | if needed; then appends kCubic_Verb to Verb_Array; and appends Cubic |
| 2958 | control and Cubic end to Point_Array. |
| 2959 | Cubic control is Last_Point plus Vector (dx1, dy1). |
| 2960 | Cubic end is Last_Point plus Vector (dx2, dy2). |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2961 | Function name stands for "relative cubic to". |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2962 | |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 2963 | #Param x1 offset from Last_Point to first Cubic control on x-axis ## |
| 2964 | #Param y1 offset from Last_Point to first Cubic control on y-axis ## |
| 2965 | #Param x2 offset from Last_Point to second Cubic control on x-axis ## |
| 2966 | #Param y2 offset from Last_Point to second Cubic control on y-axis ## |
| 2967 | #Param x3 offset from Last_Point to Cubic end on x-axis ## |
| 2968 | #Param y3 offset from Last_Point to Cubic end on y-axis ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2969 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 2970 | #Return reference to Path ## |
| 2971 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2972 | #Example |
| 2973 | void draw(SkCanvas* canvas) { |
| 2974 | SkPaint paint; |
| 2975 | paint.setAntiAlias(true); |
| 2976 | paint.setStyle(SkPaint::kStroke_Style); |
| 2977 | SkPath path; |
| 2978 | path.moveTo(24, 108); |
| 2979 | for (int i = 0; i < 16; i++) { |
| 2980 | SkScalar sx, sy; |
| 2981 | sx = SkScalarSinCos(i * SK_ScalarPI / 8, &sy); |
| 2982 | path.rCubicTo(40 * sx, 4 * sy, 4 * sx, 40 * sy, 40 * sx, 40 * sy); |
| 2983 | } |
| 2984 | canvas->drawPath(path, paint); |
| 2985 | } |
| 2986 | ## |
| 2987 | |
| 2988 | #SeeAlso Contour moveTo cubicTo quadTo |
| 2989 | |
| 2990 | ## |
| 2991 | |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2992 | #Subtopic Cubic ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2993 | |
| 2994 | # ------------------------------------------------------------------------------ |
| 2995 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2996 | #Subtopic Arc |
| 2997 | #Line # part of Oval or Circle ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2998 | Arc can be constructed in a number of ways. Arc may be described by part of Oval and angles, |
| 2999 | by start point and end point, and by radius and tangent lines. Each construction has advantages, |
| 3000 | and some constructions correspond to Arc drawing in graphics standards. |
| 3001 | |
| 3002 | All Arc draws are implemented by one or more Conic draws. When Conic_Weight is less than one, |
| 3003 | Conic describes an Arc of some Oval or Circle. |
| 3004 | |
| 3005 | arcTo(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, bool forceMoveTo) |
| 3006 | describes Arc as a piece of Oval, beginning at start angle, sweeping clockwise or counterclockwise, |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3007 | which may continue Contour or start a new one. This construction is similar to PostScript and |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3008 | HTML_Canvas arcs. Variation addArc always starts new Contour. Canvas::drawArc draws without |
| 3009 | requiring Path. |
| 3010 | |
| 3011 | arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar radius) |
| 3012 | describes Arc as tangent to the line (x0, y0), (x1, y1) and tangent to the line (x1, y1), (x2, y2) |
| 3013 | where (x0, y0) is the last Point added to Path. This construction is similar to PostScript and |
| 3014 | HTML_Canvas arcs. |
| 3015 | |
| 3016 | arcTo(SkScalar rx, SkScalar ry, SkScalar xAxisRotate, ArcSize largeArc, Direction sweep, |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3017 | SkScalar x, SkScalar y) |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3018 | describes Arc as part of Oval with radii (rx, ry), beginning at |
| 3019 | last Point added to Path and ending at (x, y). More than one Arc satisfies this criteria, |
| 3020 | so additional values choose a single solution. This construction is similar to SVG arcs. |
| 3021 | |
| 3022 | conicTo describes Arc of less than 180 degrees as a pair of tangent lines and Conic_Weight. |
| 3023 | conicTo can represent any Arc with a sweep less than 180 degrees at any rotation. All arcTo |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3024 | constructions are converted to Conic data when added to Path. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3025 | |
| 3026 | #ToDo allow example to hide source and not be exposed as fiddle since markdown / html can't |
| 3027 | do the kind of table shown in the illustration. |
| 3028 | example is spaced correctly on fiddle but spacing is too wide on pc |
| 3029 | ## |
| 3030 | |
| 3031 | #Example |
| 3032 | #Height 300 |
| 3033 | #Width 600 |
| 3034 | #Description |
| 3035 | #List |
| 3036 | # <sup>1</sup> arcTo(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, bool forceMoveTo) ## |
| 3037 | # <sup>2</sup> parameter sets force MoveTo ## |
Cary Clark | 5081eed | 2018-01-22 07:55:48 -0500 | [diff] [blame] | 3038 | # <sup>3</sup> start angle must be multiple of 90 degrees ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3039 | # <sup>4</sup> arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar radius) ## |
| 3040 | # <sup>5</sup> arcTo(SkScalar rx, SkScalar ry, SkScalar xAxisRotate, ArcSize largeArc, |
| 3041 | Direction sweep, SkScalar x, SkScalar y) ## |
| 3042 | #List ## |
| 3043 | #Description ## |
| 3044 | #Function |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 3045 | ###$ |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3046 | struct data { |
| 3047 | const char* name; |
| 3048 | char super; |
| 3049 | int yn[10]; |
| 3050 | }; |
| 3051 | |
| 3052 | const data dataSet[] = { |
| 3053 | { "arcTo sweep", '1', {1, 3, 1, 0, 0, 0, 0, 1, 0, 0 }}, |
| 3054 | { "drawArc", 0, {1, -1, 1, 1, 1, 1, 1, 0, 0, 0 }}, |
| 3055 | { "addArc", 0, {1, 1, 1, 4, 0, 1, 1, 1, 0, 0 }}, |
| 3056 | { "arcTo tangents", '4', {0, 0, 0, 0, 0, 0, 0, 1, 1, 0 }}, |
| 3057 | { "arcTo radii", '5', {1, 0, 1, 0, 0, 0, 0, 1, 1, 0 }}, |
| 3058 | { "conicTo", 0, {1, 1, 0, 0, 0, 0, 0, 1, 1, 1 }} |
| 3059 | }; |
| 3060 | |
| 3061 | #define __degree_symbol__ "\xC2" "\xB0" |
| 3062 | |
| 3063 | const char* headers[] = { |
| 3064 | "Oval part", |
| 3065 | "force moveTo", |
| 3066 | "can draw 180" __degree_symbol__, |
| 3067 | "can draw 360" __degree_symbol__, |
| 3068 | "can draw greater than 360" __degree_symbol__, |
| 3069 | "ignored if radius is zero", |
| 3070 | "ignored if sweep is zero", |
| 3071 | "requires Path", |
| 3072 | "describes rotation", |
| 3073 | "describes perspective", |
| 3074 | }; |
| 3075 | |
| 3076 | const char* yna[] = { |
| 3077 | "n/a", |
| 3078 | "no", |
| 3079 | "yes" |
| 3080 | }; |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 3081 | $$$# |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3082 | ## |
| 3083 | void draw(SkCanvas* canvas) { |
| 3084 | SkPaint lp; |
| 3085 | lp.setAntiAlias(true); |
| 3086 | SkPaint tp(lp); |
| 3087 | SkPaint sp(tp); |
| 3088 | SkPaint bp(tp); |
| 3089 | bp.setFakeBoldText(true); |
| 3090 | sp.setTextSize(10); |
| 3091 | lp.setColor(SK_ColorGRAY); |
| 3092 | canvas->translate(0, 32); |
| 3093 | const int tl = 115; |
| 3094 | for (unsigned col = 0; col <= SK_ARRAY_COUNT(headers); ++col) { |
| 3095 | canvas->drawLine(tl + col * 35, 100, tl + col * 35, 250, lp); |
| 3096 | if (0 == col) { |
| 3097 | continue; |
| 3098 | } |
| 3099 | canvas->drawLine(tl + col * 35, 100, tl + 100 + col * 35, 0, lp); |
| 3100 | SkPath path; |
| 3101 | path.moveTo(tl - 3 + col * 35, 103); |
| 3102 | path.lineTo(tl + 124 + col * 35, -24); |
| 3103 | canvas->drawTextOnPathHV(headers[col -1], strlen(headers[col -1]), path, 0, -9, bp); |
| 3104 | } |
| 3105 | for (unsigned row = 0; row <= SK_ARRAY_COUNT(dataSet); ++row) { |
| 3106 | if (0 == row) { |
| 3107 | canvas->drawLine(tl, 100, tl + 350, 100, lp); |
| 3108 | } else { |
| 3109 | canvas->drawLine(5, 100 + row * 25, tl + 350, 100 + row * 25, lp); |
| 3110 | } |
| 3111 | if (row == SK_ARRAY_COUNT(dataSet)) { |
| 3112 | break; |
| 3113 | } |
| 3114 | canvas->drawString(dataSet[row].name, 5, 117 + row * 25, bp); |
| 3115 | if (dataSet[row].super) { |
| 3116 | SkScalar width = bp.measureText(dataSet[row].name, strlen(dataSet[row].name)); |
| 3117 | canvas->drawText(&dataSet[row].super, 1, 8 + width, 112 + row * 25, sp); |
| 3118 | } |
| 3119 | for (unsigned col = 0; col < SK_ARRAY_COUNT(headers); ++col) { |
| 3120 | int val = dataSet[row].yn[col]; |
| 3121 | canvas->drawString(yna[SkTMin(2, val + 1)], tl + 5 + col * 35, 117 + row * 25, tp); |
| 3122 | if (val > 1) { |
| 3123 | char supe = '0' + val - 1; |
| 3124 | canvas->drawText(&supe, 1, tl + 25 + col * 35, 112 + row * 25, sp); |
| 3125 | } |
| 3126 | } |
| 3127 | } |
| 3128 | } |
| 3129 | #Example ## |
| 3130 | |
| 3131 | #Example |
| 3132 | #Height 128 |
| 3133 | #Description |
| 3134 | #ToDo make this a list or table ## |
| 3135 | 1 describes an arc from an oval, a starting angle, and a sweep angle. |
| 3136 | 2 is similar to 1, but does not require building a path to draw. |
| 3137 | 3 is similar to 1, but always begins new Contour. |
| 3138 | 4 describes an arc from a pair of tangent lines and a radius. |
| 3139 | 5 describes an arc from Oval center, arc start Point and arc end Point. |
| 3140 | 6 describes an arc from a pair of tangent lines and a Conic_Weight. |
| 3141 | ## |
| 3142 | void draw(SkCanvas* canvas) { |
| 3143 | SkRect oval = {8, 8, 56, 56}; |
| 3144 | SkPaint ovalPaint; |
| 3145 | ovalPaint.setAntiAlias(true); |
| 3146 | SkPaint textPaint(ovalPaint); |
| 3147 | ovalPaint.setStyle(SkPaint::kStroke_Style); |
| 3148 | SkPaint arcPaint(ovalPaint); |
| 3149 | arcPaint.setStrokeWidth(5); |
| 3150 | arcPaint.setColor(SK_ColorBLUE); |
| 3151 | canvas->translate(-64, 0); |
| 3152 | for (char arcStyle = '1'; arcStyle <= '6'; ++arcStyle) { |
| 3153 | '4' == arcStyle ? canvas->translate(-96, 55) : canvas->translate(64, 0); |
| 3154 | canvas->drawText(&arcStyle, 1, 30, 36, textPaint); |
| 3155 | canvas->drawOval(oval, ovalPaint); |
| 3156 | SkPath path; |
| 3157 | path.moveTo({56, 32}); |
| 3158 | switch (arcStyle) { |
| 3159 | case '1': |
| 3160 | path.arcTo(oval, 0, 90, false); |
| 3161 | break; |
| 3162 | case '2': |
| 3163 | canvas->drawArc(oval, 0, 90, false, arcPaint); |
| 3164 | continue; |
| 3165 | case '3': |
| 3166 | path.addArc(oval, 0, 90); |
| 3167 | break; |
| 3168 | case '4': |
| 3169 | path.arcTo({56, 56}, {32, 56}, 24); |
| 3170 | break; |
| 3171 | case '5': |
| 3172 | path.arcTo({24, 24}, 0, SkPath::kSmall_ArcSize, SkPath::kCW_Direction, {32, 56}); |
| 3173 | break; |
| 3174 | case '6': |
| 3175 | path.conicTo({56, 56}, {32, 56}, SK_ScalarRoot2Over2); |
| 3176 | break; |
| 3177 | } |
| 3178 | canvas->drawPath(path, arcPaint); |
| 3179 | } |
| 3180 | } |
| 3181 | #Example ## |
| 3182 | |
| 3183 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 3184 | #Method SkPath& arcTo(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, bool forceMoveTo) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3185 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3186 | #In Arc |
| 3187 | #Line # appends Arc ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3188 | Appends Arc to Path. Arc added is part of ellipse |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3189 | bounded by oval, from startAngle through sweepAngle. Both startAngle and |
| 3190 | sweepAngle are measured in degrees, where zero degrees is aligned with the |
| 3191 | positive x-axis, and positive sweeps extends Arc clockwise. |
| 3192 | |
| 3193 | arcTo adds Line connecting Path last Point to initial Arc Point if forceMoveTo |
| 3194 | is false and Path is not empty. Otherwise, added Contour begins with first point |
| 3195 | of Arc. Angles greater than -360 and less than 360 are treated modulo 360. |
| 3196 | |
| 3197 | #Param oval bounds of ellipse containing Arc ## |
| 3198 | #Param startAngle starting angle of Arc in degrees ## |
| 3199 | #Param sweepAngle sweep, in degrees. Positive is clockwise; treated modulo 360 ## |
| 3200 | #Param forceMoveTo true to start a new contour with Arc ## |
| 3201 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 3202 | #Return reference to Path ## |
| 3203 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3204 | #Example |
| 3205 | #Height 200 |
| 3206 | #Description |
| 3207 | arcTo continues a previous contour when forceMoveTo is false and when Path |
| 3208 | is not empty. |
| 3209 | ## |
| 3210 | void draw(SkCanvas* canvas) { |
| 3211 | SkPaint paint; |
| 3212 | SkPath path; |
| 3213 | paint.setStyle(SkPaint::kStroke_Style); |
| 3214 | paint.setStrokeWidth(4); |
| 3215 | path.moveTo(0, 0); |
| 3216 | path.arcTo({20, 20, 120, 120}, -90, 90, false); |
| 3217 | canvas->drawPath(path, paint); |
| 3218 | path.rewind(); |
| 3219 | path.arcTo({120, 20, 220, 120}, -90, 90, false); |
| 3220 | canvas->drawPath(path, paint); |
| 3221 | path.rewind(); |
| 3222 | path.moveTo(0, 0); |
| 3223 | path.arcTo({20, 120, 120, 220}, -90, 90, true); |
| 3224 | canvas->drawPath(path, paint); |
| 3225 | } |
| 3226 | ## |
| 3227 | |
| 3228 | #SeeAlso addArc SkCanvas::drawArc conicTo |
| 3229 | |
| 3230 | ## |
| 3231 | |
| 3232 | # ------------------------------------------------------------------------------ |
| 3233 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 3234 | #Method SkPath& arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar radius) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3235 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3236 | #In Arc |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3237 | Appends Arc to Path, after appending Line if needed. Arc is implemented by Conic |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3238 | weighted to describe part of Circle. Arc is contained by tangent from |
| 3239 | last Path point (x0, y0) to (x1, y1), and tangent from (x1, y1) to (x2, y2). Arc |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3240 | is part of Circle sized to radius, positioned so it touches both tangent lines. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3241 | |
| 3242 | #ToDo allow example to hide source and not be exposed as fiddle ## |
| 3243 | |
| 3244 | #Example |
| 3245 | #Height 226 |
| 3246 | void draw(SkCanvas* canvas) { |
| 3247 | SkPaint tangentPaint; |
| 3248 | tangentPaint.setAntiAlias(true); |
| 3249 | SkPaint textPaint(tangentPaint); |
| 3250 | tangentPaint.setStyle(SkPaint::kStroke_Style); |
| 3251 | tangentPaint.setColor(SK_ColorGRAY); |
| 3252 | SkPaint arcPaint(tangentPaint); |
| 3253 | arcPaint.setStrokeWidth(5); |
| 3254 | arcPaint.setColor(SK_ColorBLUE); |
| 3255 | SkPath path; |
| 3256 | SkPoint pts[] = { {56, 20}, {200, 20}, {90, 190} }; |
| 3257 | SkScalar radius = 50; |
| 3258 | path.moveTo(pts[0]); |
| 3259 | path.arcTo(pts[1], pts[2], radius); |
| 3260 | canvas->drawLine(pts[0], pts[1], tangentPaint); |
| 3261 | canvas->drawLine(pts[1], pts[2], tangentPaint); |
| 3262 | SkPoint lastPt; |
| 3263 | (void) path.getLastPt(&lastPt); |
| 3264 | SkVector radial = pts[2] - pts[1]; |
| 3265 | radial.setLength(radius); |
| 3266 | SkPoint center = { lastPt.fX - radial.fY, lastPt.fY + radial.fX }; |
| 3267 | canvas->drawCircle(center, radius, tangentPaint); |
| 3268 | canvas->drawLine(lastPt, center, tangentPaint); |
| 3269 | radial = pts[1] - pts[0]; |
| 3270 | radial.setLength(radius); |
| 3271 | SkPoint arcStart = { center.fX + radial.fY, center.fY - radial.fX }; |
| 3272 | canvas->drawLine(center, arcStart, tangentPaint); |
| 3273 | canvas->drawPath(path, arcPaint); |
| 3274 | textPaint.setTextAlign(SkPaint::kRight_Align); |
| 3275 | canvas->drawString("(x0, y0)", pts[0].fX - 5, pts[0].fY, textPaint); |
| 3276 | textPaint.setTextAlign(SkPaint::kLeft_Align); |
| 3277 | canvas->drawString("(x1, y1)", pts[1].fX + 5, pts[1].fY, textPaint); |
| 3278 | textPaint.setTextAlign(SkPaint::kCenter_Align); |
| 3279 | canvas->drawString("(x2, y2)", pts[2].fX, pts[2].fY + 15, textPaint); |
| 3280 | textPaint.setTextAlign(SkPaint::kRight_Align); |
| 3281 | canvas->drawString("radius", center.fX + 15, center.fY + 25, textPaint); |
| 3282 | canvas->drawString("radius", center.fX - 3, center.fY - 16, textPaint); |
| 3283 | } |
| 3284 | ## |
| 3285 | |
| 3286 | If last Path Point does not start Arc, arcTo appends connecting Line to Path. |
| 3287 | The length of Vector from (x1, y1) to (x2, y2) does not affect Arc. |
| 3288 | |
| 3289 | #Example |
| 3290 | #Height 128 |
| 3291 | void draw(SkCanvas* canvas) { |
| 3292 | SkPaint tangentPaint; |
| 3293 | tangentPaint.setAntiAlias(true); |
| 3294 | SkPaint textPaint(tangentPaint); |
| 3295 | tangentPaint.setStyle(SkPaint::kStroke_Style); |
| 3296 | tangentPaint.setColor(SK_ColorGRAY); |
| 3297 | SkPaint arcPaint(tangentPaint); |
| 3298 | arcPaint.setStrokeWidth(5); |
| 3299 | arcPaint.setColor(SK_ColorBLUE); |
| 3300 | SkPath path; |
| 3301 | SkPoint pts[] = { {156, 20}, {200, 20}, {170, 50} }; |
| 3302 | SkScalar radius = 50; |
| 3303 | path.moveTo(pts[0]); |
| 3304 | path.arcTo(pts[1], pts[2], radius); |
| 3305 | canvas->drawLine(pts[0], pts[1], tangentPaint); |
| 3306 | canvas->drawLine(pts[1], pts[2], tangentPaint); |
| 3307 | SkPoint lastPt; |
| 3308 | (void) path.getLastPt(&lastPt); |
| 3309 | SkVector radial = pts[2] - pts[1]; |
| 3310 | radial.setLength(radius); |
| 3311 | SkPoint center = { lastPt.fX - radial.fY, lastPt.fY + radial.fX }; |
| 3312 | canvas->drawLine(lastPt, center, tangentPaint); |
| 3313 | radial = pts[1] - pts[0]; |
| 3314 | radial.setLength(radius); |
| 3315 | SkPoint arcStart = { center.fX + radial.fY, center.fY - radial.fX }; |
| 3316 | canvas->drawLine(center, arcStart, tangentPaint); |
| 3317 | canvas->drawPath(path, arcPaint); |
| 3318 | textPaint.setTextAlign(SkPaint::kCenter_Align); |
| 3319 | canvas->drawString("(x0, y0)", pts[0].fX, pts[0].fY - 7, textPaint); |
| 3320 | textPaint.setTextAlign(SkPaint::kLeft_Align); |
| 3321 | canvas->drawString("(x1, y1)", pts[1].fX + 5, pts[1].fY, textPaint); |
| 3322 | textPaint.setTextAlign(SkPaint::kCenter_Align); |
| 3323 | canvas->drawString("(x2, y2)", pts[2].fX, pts[2].fY + 15, textPaint); |
| 3324 | textPaint.setTextAlign(SkPaint::kRight_Align); |
| 3325 | canvas->drawString("radius", center.fX + 15, center.fY + 25, textPaint); |
| 3326 | canvas->drawString("radius", center.fX - 5, center.fY - 20, textPaint); |
| 3327 | } |
| 3328 | ## |
| 3329 | |
| 3330 | Arc sweep is always less than 180 degrees. If radius is zero, or if |
| 3331 | tangents are nearly parallel, arcTo appends Line from last Path Point to (x1, y1). |
| 3332 | |
| 3333 | arcTo appends at most one Line and one Conic. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3334 | arcTo implements the functionality of PostScript_Arct and HTML_Canvas_ArcTo. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3335 | |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 3336 | #Param x1 x-axis value common to pair of tangents ## |
| 3337 | #Param y1 y-axis value common to pair of tangents ## |
| 3338 | #Param x2 x-axis value end of second tangent ## |
| 3339 | #Param y2 y-axis value end of second tangent ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3340 | #Param radius distance from Arc to Circle center ## |
| 3341 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 3342 | #Return reference to Path ## |
| 3343 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3344 | #Example |
| 3345 | #Description |
| 3346 | arcTo is represented by Line and circular Conic in Path. |
| 3347 | ## |
| 3348 | void draw(SkCanvas* canvas) { |
| 3349 | SkPath path; |
| 3350 | path.moveTo({156, 20}); |
| 3351 | path.arcTo(200, 20, 170, 50, 50); |
| 3352 | SkPath::Iter iter(path, false); |
| 3353 | SkPoint p[4]; |
| 3354 | SkPath::Verb verb; |
| 3355 | while (SkPath::kDone_Verb != (verb = iter.next(p))) { |
| 3356 | switch (verb) { |
| 3357 | case SkPath::kMove_Verb: |
| 3358 | SkDebugf("move to (%g,%g)\n", p[0].fX, p[0].fY); |
| 3359 | break; |
| 3360 | case SkPath::kLine_Verb: |
| 3361 | SkDebugf("line (%g,%g),(%g,%g)\n", p[0].fX, p[0].fY, p[1].fX, p[1].fY); |
| 3362 | break; |
| 3363 | case SkPath::kConic_Verb: |
| 3364 | SkDebugf("conic (%g,%g),(%g,%g),(%g,%g) weight %g\n", |
| 3365 | p[0].fX, p[0].fY, p[1].fX, p[1].fY, p[2].fX, p[2].fY, iter.conicWeight()); |
| 3366 | break; |
| 3367 | default: |
| 3368 | SkDebugf("unexpected verb\n"); |
| 3369 | } |
| 3370 | } |
| 3371 | } |
| 3372 | #StdOut |
| 3373 | move to (156,20) |
| 3374 | line (156,20),(79.2893,20) |
| 3375 | conic (79.2893,20),(200,20),(114.645,105.355) weight 0.382683 |
| 3376 | ## |
| 3377 | ## |
| 3378 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3379 | #SeeAlso conicTo |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3380 | |
| 3381 | ## |
| 3382 | |
| 3383 | # ------------------------------------------------------------------------------ |
| 3384 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 3385 | #Method SkPath& arcTo(const SkPoint p1, const SkPoint p2, SkScalar radius) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3386 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3387 | #In Arc |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3388 | Appends Arc to Path, after appending Line if needed. Arc is implemented by Conic |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3389 | weighted to describe part of Circle. Arc is contained by tangent from |
| 3390 | last Path point to p1, and tangent from p1 to p2. Arc |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3391 | is part of Circle sized to radius, positioned so it touches both tangent lines. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3392 | |
| 3393 | If last Path Point does not start Arc, arcTo appends connecting Line to Path. |
| 3394 | The length of Vector from p1 to p2 does not affect Arc. |
| 3395 | |
| 3396 | Arc sweep is always less than 180 degrees. If radius is zero, or if |
| 3397 | tangents are nearly parallel, arcTo appends Line from last Path Point to p1. |
| 3398 | |
| 3399 | arcTo appends at most one Line and one Conic. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3400 | arcTo implements the functionality of PostScript_Arct and HTML_Canvas_ArcTo. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3401 | |
| 3402 | #Param p1 Point common to pair of tangents ## |
| 3403 | #Param p2 end of second tangent ## |
| 3404 | #Param radius distance from Arc to Circle center ## |
| 3405 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 3406 | #Return reference to Path ## |
| 3407 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3408 | #Example |
| 3409 | #Description |
| 3410 | Because tangent lines are parallel, arcTo appends line from last Path Point to |
| 3411 | p1, but does not append a circular Conic. |
| 3412 | ## |
| 3413 | void draw(SkCanvas* canvas) { |
| 3414 | SkPath path; |
| 3415 | path.moveTo({156, 20}); |
| 3416 | path.arcTo({200, 20}, {170, 20}, 50); |
| 3417 | SkPath::Iter iter(path, false); |
| 3418 | SkPoint p[4]; |
| 3419 | SkPath::Verb verb; |
| 3420 | while (SkPath::kDone_Verb != (verb = iter.next(p))) { |
| 3421 | switch (verb) { |
| 3422 | case SkPath::kMove_Verb: |
| 3423 | SkDebugf("move to (%g,%g)\n", p[0].fX, p[0].fY); |
| 3424 | break; |
| 3425 | case SkPath::kLine_Verb: |
| 3426 | SkDebugf("line (%g,%g),(%g,%g)\n", p[0].fX, p[0].fY, p[1].fX, p[1].fY); |
| 3427 | break; |
| 3428 | case SkPath::kConic_Verb: |
| 3429 | SkDebugf("conic (%g,%g),(%g,%g),(%g,%g) weight %g\n", |
| 3430 | p[0].fX, p[0].fY, p[1].fX, p[1].fY, p[2].fX, p[2].fY, iter.conicWeight()); |
| 3431 | break; |
| 3432 | default: |
| 3433 | SkDebugf("unexpected verb\n"); |
| 3434 | } |
| 3435 | } |
| 3436 | } |
| 3437 | #StdOut |
| 3438 | move to (156,20) |
| 3439 | line (156,20),(200,20) |
| 3440 | ## |
| 3441 | ## |
| 3442 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3443 | #SeeAlso conicTo |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3444 | |
| 3445 | ## |
| 3446 | |
| 3447 | # ------------------------------------------------------------------------------ |
| 3448 | |
| 3449 | #Enum ArcSize |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3450 | #Line # used by arcTo variation ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3451 | |
| 3452 | #Code |
| 3453 | enum ArcSize { |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3454 | kSmall_ArcSize, |
| 3455 | kLarge_ArcSize, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3456 | }; |
| 3457 | ## |
| 3458 | |
| 3459 | Four Oval parts with radii (rx, ry) start at last Path Point and ends at (x, y). |
| 3460 | ArcSize and Direction select one of the four Oval parts. |
| 3461 | |
| 3462 | #Const kSmall_ArcSize 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3463 | #Line # smaller of Arc pair ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3464 | ## |
| 3465 | #Const kLarge_ArcSize 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3466 | #Line # larger of Arc pair ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3467 | ## |
| 3468 | |
| 3469 | #Example |
| 3470 | #Height 160 |
| 3471 | #Description |
| 3472 | Arc begins at top of Oval pair and ends at bottom. Arc can take four routes to get there. |
| 3473 | Two routes are large, and two routes are counterclockwise. The one route both large |
| 3474 | and counterclockwise is blue. |
| 3475 | ## |
| 3476 | void draw(SkCanvas* canvas) { |
| 3477 | SkPaint paint; |
| 3478 | paint.setAntiAlias(true); |
| 3479 | paint.setStyle(SkPaint::kStroke_Style); |
| 3480 | for (auto sweep: { SkPath::kCW_Direction, SkPath::kCCW_Direction } ) { |
| 3481 | for (auto arcSize : { SkPath::kSmall_ArcSize, SkPath::kLarge_ArcSize } ) { |
| 3482 | SkPath path; |
| 3483 | path.moveTo({120, 50}); |
| 3484 | path.arcTo(70, 40, 30, arcSize, sweep, 156, 100); |
| 3485 | if (SkPath::kCCW_Direction == sweep && SkPath::kLarge_ArcSize == arcSize) { |
| 3486 | paint.setColor(SK_ColorBLUE); |
| 3487 | paint.setStrokeWidth(3); |
| 3488 | } |
| 3489 | canvas->drawPath(path, paint); |
| 3490 | } |
| 3491 | } |
| 3492 | } |
| 3493 | ## |
| 3494 | |
| 3495 | #SeeAlso arcTo Direction |
| 3496 | |
| 3497 | ## |
| 3498 | |
| 3499 | # ------------------------------------------------------------------------------ |
| 3500 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 3501 | #Method SkPath& arcTo(SkScalar rx, SkScalar ry, SkScalar xAxisRotate, ArcSize largeArc, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3502 | Direction sweep, SkScalar x, SkScalar y) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3503 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3504 | #In Arc |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3505 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3506 | Appends Arc to Path. Arc is implemented by one or more Conics weighted to |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3507 | describe part of Oval with radii (rx, ry) rotated by xAxisRotate degrees. Arc |
| 3508 | curves from last Path Point to (x, y), choosing one of four possible routes: |
| 3509 | clockwise or counterclockwise, and smaller or larger. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3510 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3511 | Arc sweep is always less than 360 degrees. arcTo appends Line to (x, y) if |
| 3512 | either radii are zero, or if last Path Point equals (x, y). arcTo scales radii |
| 3513 | (rx, ry) to fit last Path Point and (x, y) if both are greater than zero but |
| 3514 | too small. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3515 | |
| 3516 | arcTo appends up to four Conic curves. |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3517 | arcTo implements the functionality of SVG_Arc, although SVG "sweep-flag" value |
| 3518 | is opposite the integer value of sweep; SVG "sweep-flag" uses 1 for clockwise, |
| 3519 | while kCW_Direction cast to int is zero. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3520 | |
| 3521 | #Param rx radius in x before x-axis rotation ## |
| 3522 | #Param ry radius in y before x-axis rotation ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3523 | #Param xAxisRotate x-axis rotation in degrees; positive values are clockwise ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3524 | #Param largeArc chooses smaller or larger Arc ## |
| 3525 | #Param sweep chooses clockwise or counterclockwise Arc ## |
| 3526 | #Param x end of Arc ## |
| 3527 | #Param y end of Arc ## |
| 3528 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 3529 | #Return reference to Path ## |
| 3530 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3531 | #Example |
| 3532 | #Height 160 |
| 3533 | void draw(SkCanvas* canvas) { |
| 3534 | SkPaint paint; |
| 3535 | paint.setAntiAlias(true); |
| 3536 | paint.setStyle(SkPaint::kStroke_Style); |
| 3537 | for (auto sweep: { SkPath::kCW_Direction, SkPath::kCCW_Direction } ) { |
| 3538 | for (auto arcSize : { SkPath::kSmall_ArcSize, SkPath::kLarge_ArcSize } ) { |
| 3539 | SkPath path; |
| 3540 | path.moveTo({120, 50}); |
| 3541 | path.arcTo(70, 40, 30, arcSize, sweep, 120.1, 50); |
| 3542 | if (SkPath::kCCW_Direction == sweep && SkPath::kLarge_ArcSize == arcSize) { |
| 3543 | paint.setColor(SK_ColorBLUE); |
| 3544 | paint.setStrokeWidth(3); |
| 3545 | } |
| 3546 | canvas->drawPath(path, paint); |
| 3547 | } |
| 3548 | } |
| 3549 | } |
| 3550 | ## |
| 3551 | |
| 3552 | #SeeAlso rArcTo ArcSize Direction |
| 3553 | |
| 3554 | ## |
| 3555 | |
| 3556 | # ------------------------------------------------------------------------------ |
| 3557 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 3558 | #Method SkPath& arcTo(const SkPoint r, SkScalar xAxisRotate, ArcSize largeArc, Direction sweep, |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3559 | const SkPoint xy) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3560 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3561 | #In Arc |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3562 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3563 | Appends Arc to Path. Arc is implemented by one or more Conic weighted to describe part of Oval |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3564 | with radii (r.fX, r.fY) rotated by xAxisRotate degrees. Arc curves from last Path Point to |
| 3565 | (xy.fX, xy.fY), choosing one of four possible routes: clockwise or counterclockwise, |
| 3566 | and smaller or larger. |
| 3567 | |
| 3568 | Arc sweep is always less than 360 degrees. arcTo appends Line to xy if either radii are zero, |
| 3569 | or if last Path Point equals (x, y). arcTo scales radii r to fit last Path Point and |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3570 | xy if both are greater than zero but too small to describe an arc. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3571 | |
| 3572 | arcTo appends up to four Conic curves. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3573 | arcTo implements the functionality of SVG_Arc, although SVG "sweep-flag" value is |
| 3574 | opposite the integer value of sweep; SVG "sweep-flag" uses 1 for clockwise, while |
| 3575 | kCW_Direction cast to int is zero. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3576 | |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 3577 | #Param r radii on axes before x-axis rotation ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3578 | #Param xAxisRotate x-axis rotation in degrees; positive values are clockwise ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3579 | #Param largeArc chooses smaller or larger Arc ## |
| 3580 | #Param sweep chooses clockwise or counterclockwise Arc ## |
| 3581 | #Param xy end of Arc ## |
| 3582 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 3583 | #Return reference to Path ## |
| 3584 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3585 | #Example |
| 3586 | #Height 108 |
| 3587 | void draw(SkCanvas* canvas) { |
| 3588 | SkPaint paint; |
| 3589 | SkPath path; |
| 3590 | const SkPoint starts[] = {{20, 20}, {120, 20}, {70, 60}}; |
| 3591 | for (auto start : starts) { |
| 3592 | path.moveTo(start.fX, start.fY); |
| 3593 | path.rArcTo(20, 20, 0, SkPath::kSmall_ArcSize, SkPath::kCCW_Direction, 60, 0); |
| 3594 | } |
| 3595 | canvas->drawPath(path, paint); |
| 3596 | } |
| 3597 | ## |
| 3598 | |
| 3599 | #SeeAlso rArcTo ArcSize Direction |
| 3600 | |
| 3601 | ## |
| 3602 | |
| 3603 | # ------------------------------------------------------------------------------ |
| 3604 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 3605 | #Method SkPath& rArcTo(SkScalar rx, SkScalar ry, SkScalar xAxisRotate, ArcSize largeArc, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3606 | Direction sweep, SkScalar dx, SkScalar dy) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3607 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3608 | #In Arc |
| 3609 | #Line # appends Arc relative to Last_Point ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3610 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3611 | Appends Arc to Path, relative to last Path Point. Arc is implemented by one or |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3612 | more Conic, weighted to describe part of Oval with radii (rx, ry) rotated by |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3613 | xAxisRotate degrees. Arc curves from last Path Point (x0, y0) to end Point: |
| 3614 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3615 | #Formula |
| 3616 | (x0 + dx, y0 + dy) |
| 3617 | ## |
| 3618 | , choosing one of four possible routes: clockwise or |
| 3619 | counterclockwise, and smaller or larger. If Path is empty, the start Arc Point |
| 3620 | is (0, 0). |
| 3621 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3622 | Arc sweep is always less than 360 degrees. arcTo appends Line to end Point |
| 3623 | if either radii are zero, or if last Path Point equals end Point. |
| 3624 | arcTo scales radii (rx, ry) to fit last Path Point and end Point if both are |
| 3625 | greater than zero but too small to describe an arc. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3626 | |
| 3627 | arcTo appends up to four Conic curves. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3628 | arcTo implements the functionality of SVG_Arc, although SVG "sweep-flag" value is |
| 3629 | opposite the integer value of sweep; SVG "sweep-flag" uses 1 for clockwise, while |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3630 | kCW_Direction cast to int is zero. |
| 3631 | |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 3632 | #Param rx radius before x-axis rotation ## |
| 3633 | #Param ry radius before x-axis rotation ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3634 | #Param xAxisRotate x-axis rotation in degrees; positive values are clockwise ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3635 | #Param largeArc chooses smaller or larger Arc ## |
| 3636 | #Param sweep chooses clockwise or counterclockwise Arc ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 3637 | #Param dx x-axis offset end of Arc from last Path Point ## |
| 3638 | #Param dy y-axis offset end of Arc from last Path Point ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3639 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 3640 | #Return reference to Path ## |
| 3641 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3642 | #Example |
| 3643 | #Height 108 |
| 3644 | void draw(SkCanvas* canvas) { |
| 3645 | SkPaint paint; |
| 3646 | SkPath path; |
| 3647 | const SkPoint starts[] = {{20, 20}, {120, 20}, {70, 60}}; |
| 3648 | for (auto start : starts) { |
| 3649 | path.moveTo(start.fX, start.fY); |
| 3650 | path.rArcTo(20, 20, 0, SkPath::kSmall_ArcSize, SkPath::kCCW_Direction, 60, 0); |
| 3651 | } |
| 3652 | canvas->drawPath(path, paint); |
| 3653 | } |
| 3654 | ## |
| 3655 | |
| 3656 | #SeeAlso arcTo ArcSize Direction |
| 3657 | |
| 3658 | ## |
| 3659 | |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3660 | #Subtopic Arc ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3661 | |
| 3662 | # ------------------------------------------------------------------------------ |
| 3663 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 3664 | #Method SkPath& close() |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3665 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3666 | #Line # makes last Contour a loop ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3667 | Appends kClose_Verb to Path. A closed Contour connects the first and last Point |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3668 | with Line, forming a continuous loop. Open and closed Contour draw the same |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3669 | with SkPaint::kFill_Style. With SkPaint::kStroke_Style, open Contour draws |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3670 | Paint_Stroke_Cap at Contour start and end; closed Contour draws |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3671 | Paint_Stroke_Join at Contour start and end. |
| 3672 | |
| 3673 | close() has no effect if Path is empty or last Path Verb is kClose_Verb. |
| 3674 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 3675 | #Return reference to Path ## |
| 3676 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3677 | #Example |
| 3678 | void draw(SkCanvas* canvas) { |
| 3679 | SkPaint paint; |
| 3680 | paint.setStrokeWidth(15); |
| 3681 | paint.setStrokeCap(SkPaint::kRound_Cap); |
| 3682 | SkPath path; |
| 3683 | const SkPoint points[] = {{20, 20}, {70, 20}, {40, 90}}; |
| 3684 | path.addPoly(points, SK_ARRAY_COUNT(points), false); |
| 3685 | for (int loop = 0; loop < 2; ++loop) { |
| 3686 | for (auto style : {SkPaint::kStroke_Style, SkPaint::kFill_Style, |
| 3687 | SkPaint::kStrokeAndFill_Style} ) { |
| 3688 | paint.setStyle(style); |
| 3689 | canvas->drawPath(path, paint); |
| 3690 | canvas->translate(85, 0); |
| 3691 | } |
| 3692 | path.close(); |
| 3693 | canvas->translate(-255, 128); |
| 3694 | } |
| 3695 | } |
| 3696 | ## |
| 3697 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3698 | #SeeAlso |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3699 | |
| 3700 | ## |
| 3701 | |
| 3702 | # ------------------------------------------------------------------------------ |
| 3703 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3704 | #Method static bool IsInverseFillType(FillType fill) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3705 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3706 | #Line # returns if Fill_Type represents outside geometry ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3707 | Returns true if fill is inverted and Path with fill represents area outside |
| 3708 | of its geometric bounds. |
| 3709 | |
| 3710 | #Table |
| 3711 | #Legend |
| 3712 | # FillType # is inverse ## |
| 3713 | ## |
| 3714 | # kWinding_FillType # false ## |
| 3715 | # kEvenOdd_FillType # false ## |
| 3716 | # kInverseWinding_FillType # true ## |
| 3717 | # kInverseEvenOdd_FillType # true ## |
| 3718 | ## |
| 3719 | |
| 3720 | #Param fill one of: kWinding_FillType, kEvenOdd_FillType, |
| 3721 | kInverseWinding_FillType, kInverseEvenOdd_FillType |
| 3722 | ## |
| 3723 | |
| 3724 | #Return true if Path fills outside its bounds ## |
| 3725 | |
| 3726 | #Example |
| 3727 | #Function |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 3728 | ###$ |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3729 | #define nameValue(fill) { SkPath::fill, #fill } |
| 3730 | |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 3731 | $$$# |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3732 | ## |
| 3733 | void draw(SkCanvas* canvas) { |
| 3734 | struct { |
| 3735 | SkPath::FillType fill; |
| 3736 | const char* name; |
| 3737 | } fills[] = { |
| 3738 | nameValue(kWinding_FillType), |
| 3739 | nameValue(kEvenOdd_FillType), |
| 3740 | nameValue(kInverseWinding_FillType), |
| 3741 | nameValue(kInverseEvenOdd_FillType), |
| 3742 | }; |
| 3743 | for (auto fill: fills ) { |
| 3744 | SkDebugf("IsInverseFillType(%s) == %s\n", fill.name, SkPath::IsInverseFillType(fill.fill) ? |
| 3745 | "true" : "false"); |
| 3746 | } |
| 3747 | } |
| 3748 | #StdOut |
| 3749 | IsInverseFillType(kWinding_FillType) == false |
| 3750 | IsInverseFillType(kEvenOdd_FillType) == false |
| 3751 | IsInverseFillType(kInverseWinding_FillType) == true |
| 3752 | IsInverseFillType(kInverseEvenOdd_FillType) == true |
| 3753 | ## |
| 3754 | ## |
| 3755 | |
| 3756 | #SeeAlso FillType getFillType setFillType ConvertToNonInverseFillType |
| 3757 | |
| 3758 | ## |
| 3759 | |
| 3760 | # ------------------------------------------------------------------------------ |
| 3761 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3762 | #Method static FillType ConvertToNonInverseFillType(FillType fill) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3763 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3764 | #Line # returns Fill_Type representing inside geometry ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3765 | Returns equivalent Fill_Type representing Path fill inside its bounds. |
| 3766 | . |
| 3767 | |
| 3768 | #Table |
| 3769 | #Legend |
| 3770 | # FillType # inside FillType ## |
| 3771 | ## |
| 3772 | # kWinding_FillType # kWinding_FillType ## |
| 3773 | # kEvenOdd_FillType # kEvenOdd_FillType ## |
| 3774 | # kInverseWinding_FillType # kWinding_FillType ## |
| 3775 | # kInverseEvenOdd_FillType # kEvenOdd_FillType ## |
| 3776 | ## |
| 3777 | |
| 3778 | #Param fill one of: kWinding_FillType, kEvenOdd_FillType, |
| 3779 | kInverseWinding_FillType, kInverseEvenOdd_FillType |
| 3780 | ## |
| 3781 | |
| 3782 | #Return fill, or kWinding_FillType or kEvenOdd_FillType if fill is inverted ## |
| 3783 | |
| 3784 | #Example |
| 3785 | #Function |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 3786 | ###$ |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3787 | #define nameValue(fill) { SkPath::fill, #fill } |
| 3788 | |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 3789 | $$$# |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3790 | ## |
| 3791 | void draw(SkCanvas* canvas) { |
| 3792 | struct { |
| 3793 | SkPath::FillType fill; |
| 3794 | const char* name; |
| 3795 | } fills[] = { |
| 3796 | nameValue(kWinding_FillType), |
| 3797 | nameValue(kEvenOdd_FillType), |
| 3798 | nameValue(kInverseWinding_FillType), |
| 3799 | nameValue(kInverseEvenOdd_FillType), |
| 3800 | }; |
| 3801 | for (unsigned i = 0; i < SK_ARRAY_COUNT(fills); ++i) { |
| 3802 | if (fills[i].fill != (SkPath::FillType) i) { |
| 3803 | SkDebugf("fills array order does not match FillType enum order"); |
| 3804 | break; |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3805 | } |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3806 | SkDebugf("ConvertToNonInverseFillType(%s) == %s\n", fills[i].name, |
| 3807 | fills[(int) SkPath::ConvertToNonInverseFillType(fills[i].fill)].name); |
| 3808 | } |
| 3809 | } |
| 3810 | #StdOut |
| 3811 | ConvertToNonInverseFillType(kWinding_FillType) == kWinding_FillType |
| 3812 | ConvertToNonInverseFillType(kEvenOdd_FillType) == kEvenOdd_FillType |
| 3813 | ConvertToNonInverseFillType(kInverseWinding_FillType) == kWinding_FillType |
| 3814 | ConvertToNonInverseFillType(kInverseEvenOdd_FillType) == kEvenOdd_FillType |
| 3815 | ## |
| 3816 | ## |
| 3817 | |
| 3818 | #SeeAlso FillType getFillType setFillType IsInverseFillType |
| 3819 | |
| 3820 | ## |
| 3821 | |
| 3822 | # ------------------------------------------------------------------------------ |
| 3823 | |
| 3824 | #Method static int ConvertConicToQuads(const SkPoint& p0, const SkPoint& p1, const SkPoint& p2, |
| 3825 | SkScalar w, SkPoint pts[], int pow2) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3826 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3827 | #Line # approximates Conic with Quad array ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3828 | |
| 3829 | Approximates Conic with Quad array. Conic is constructed from start Point p0, |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3830 | control Point p1, end Point p2, and weight w. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3831 | Quad array is stored in pts; this storage is supplied by caller. |
| 3832 | Maximum Quad count is 2 to the pow2. |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3833 | Every third point in array shares last Point of previous Quad and first Point of |
| 3834 | next Quad. Maximum pts storage size is given by: |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3835 | #Formula |
| 3836 | (1 + 2 * (1 << pow2)) * sizeof(SkPoint) |
| 3837 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3838 | . |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 3839 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3840 | Returns Quad count used the approximation, which may be smaller |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3841 | than the number requested. |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3842 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3843 | Conic_Weight determines the amount of influence Conic control point has on the curve. |
| 3844 | w less than one represents an elliptical section. w greater than one represents |
| 3845 | a hyperbolic section. w equal to one represents a parabolic section. |
| 3846 | |
| 3847 | Two Quad curves are sufficient to approximate an elliptical Conic with a sweep |
| 3848 | of up to 90 degrees; in this case, set pow2 to one. |
| 3849 | |
| 3850 | #Param p0 Conic start Point ## |
| 3851 | #Param p1 Conic control Point ## |
| 3852 | #Param p2 Conic end Point ## |
| 3853 | #Param w Conic weight ## |
| 3854 | #Param pts storage for Quad array ## |
| 3855 | #Param pow2 Quad count, as power of two, normally 0 to 5 (1 to 32 Quad curves) ## |
| 3856 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 3857 | #Return number of Quad curves written to pts ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3858 | |
| 3859 | #Example |
| 3860 | #Description |
| 3861 | A pair of Quad curves are drawn in red on top of the elliptical Conic curve in black. |
| 3862 | The middle curve is nearly circular. The top-right curve is parabolic, which can |
| 3863 | be drawn exactly with a single Quad. |
| 3864 | ## |
| 3865 | void draw(SkCanvas* canvas) { |
| 3866 | SkPaint conicPaint; |
| 3867 | conicPaint.setAntiAlias(true); |
| 3868 | conicPaint.setStyle(SkPaint::kStroke_Style); |
| 3869 | SkPaint quadPaint(conicPaint); |
| 3870 | quadPaint.setColor(SK_ColorRED); |
| 3871 | SkPoint conic[] = { {20, 170}, {80, 170}, {80, 230} }; |
| 3872 | for (auto weight : { .25f, .5f, .707f, .85f, 1.f } ) { |
| 3873 | SkPoint quads[5]; |
| 3874 | SkPath::ConvertConicToQuads(conic[0], conic[1], conic[2], weight, quads, 1); |
| 3875 | SkPath path; |
| 3876 | path.moveTo(conic[0]); |
| 3877 | path.conicTo(conic[1], conic[2], weight); |
| 3878 | canvas->drawPath(path, conicPaint); |
| 3879 | path.rewind(); |
| 3880 | path.moveTo(quads[0]); |
| 3881 | path.quadTo(quads[1], quads[2]); |
| 3882 | path.quadTo(quads[3], quads[4]); |
| 3883 | canvas->drawPath(path, quadPaint); |
| 3884 | canvas->translate(50, -50); |
| 3885 | } |
| 3886 | } |
| 3887 | ## |
| 3888 | |
| 3889 | #SeeAlso Conic Quad |
| 3890 | |
| 3891 | ## |
| 3892 | |
| 3893 | # ------------------------------------------------------------------------------ |
| 3894 | |
| 3895 | #Method bool isRect(SkRect* rect, bool* isClosed = nullptr, Direction* direction = nullptr) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3896 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3897 | #Line # returns if describes Rect ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3898 | Returns true if Path is equivalent to Rect when filled. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3899 | If false: rect, isClosed, and direction are unchanged. |
| 3900 | If true: rect, isClosed, and direction are written to if not nullptr. |
| 3901 | |
| 3902 | rect may be smaller than the Path bounds. Path bounds may include kMove_Verb points |
| 3903 | that do not alter the area drawn by the returned rect. |
| 3904 | |
| 3905 | #Param rect storage for bounds of Rect; may be nullptr ## |
| 3906 | #Param isClosed storage set to true if Path is closed; may be nullptr ## |
| 3907 | #Param direction storage set to Rect direction; may be nullptr ## |
| 3908 | |
| 3909 | #Return true if Path contains Rect ## |
| 3910 | |
| 3911 | #Example |
| 3912 | #Description |
| 3913 | After addRect, isRect returns true. Following moveTo permits isRect to return true, but |
| 3914 | following lineTo does not. addPoly returns true even though rect is not closed, and one |
| 3915 | side of rect is made up of consecutive line segments. |
| 3916 | ## |
| 3917 | void draw(SkCanvas* canvas) { |
| 3918 | auto debugster = [](const char* prefix, const SkPath& path) -> void { |
| 3919 | SkRect rect; |
| 3920 | SkPath::Direction direction; |
| 3921 | bool isClosed; |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3922 | path.isRect(&rect, &isClosed, &direction) ? |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3923 | SkDebugf("%s is rect (%g, %g, %g, %g); is %s" "closed; direction %s\n", prefix, |
| 3924 | rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, isClosed ? "" : "not ", |
| 3925 | SkPath::kCW_Direction == direction ? "CW" : "CCW") : |
| 3926 | SkDebugf("%s is not rect\n", prefix); |
| 3927 | }; |
| 3928 | SkPath path; |
| 3929 | debugster("empty", path); |
| 3930 | path.addRect({10, 20, 30, 40}); |
| 3931 | debugster("addRect", path); |
| 3932 | path.moveTo(60, 70); |
| 3933 | debugster("moveTo", path); |
| 3934 | path.lineTo(60, 70); |
| 3935 | debugster("lineTo", path); |
| 3936 | path.reset(); |
| 3937 | const SkPoint pts[] = { {0, 0}, {0, 80}, {80, 80}, {80, 0}, {40, 0}, {20, 0} }; |
| 3938 | path.addPoly(pts, SK_ARRAY_COUNT(pts), false); |
| 3939 | debugster("addPoly", path); |
| 3940 | } |
| 3941 | #StdOut |
| 3942 | empty is not rect |
| 3943 | addRect is rect (10, 20, 30, 40); is closed; direction CW |
| 3944 | moveTo is rect (10, 20, 30, 40); is closed; direction CW |
| 3945 | lineTo is not rect |
| 3946 | addPoly is rect (0, 0, 80, 80); is not closed; direction CCW |
| 3947 | ## |
| 3948 | ## |
| 3949 | |
| 3950 | #SeeAlso computeTightBounds conservativelyContainsRect getBounds isConvex isLastContourClosed isNestedFillRects |
| 3951 | |
| 3952 | ## |
| 3953 | |
| 3954 | # ------------------------------------------------------------------------------ |
| 3955 | |
| 3956 | #Method bool isNestedFillRects(SkRect rect[2], Direction dirs[2] = nullptr) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3957 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3958 | #Line # returns if describes Rect pair, one inside the other ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3959 | Returns true if Path is equivalent to nested Rect pair when filled. |
| 3960 | If false, rect and dirs are unchanged. |
| 3961 | If true, rect and dirs are written to if not nullptr: |
| 3962 | setting rect[0] to outer Rect, and rect[1] to inner Rect; |
| 3963 | setting dirs[0] to Direction of outer Rect, and dirs[1] to Direction of inner |
| 3964 | Rect. |
| 3965 | |
| 3966 | #Param rect storage for Rect pair; may be nullptr ## |
| 3967 | #Param dirs storage for Direction pair; may be nullptr ## |
| 3968 | |
| 3969 | #Return true if Path contains nested Rect pair ## |
| 3970 | |
| 3971 | #Example |
| 3972 | void draw(SkCanvas* canvas) { |
| 3973 | SkPaint paint; |
| 3974 | paint.setStyle(SkPaint::kStroke_Style); |
| 3975 | paint.setStrokeWidth(5); |
| 3976 | SkPath path; |
| 3977 | path.addRect({10, 20, 30, 40}); |
| 3978 | paint.getFillPath(path, &path); |
| 3979 | SkRect rects[2]; |
| 3980 | SkPath::Direction directions[2]; |
| 3981 | if (path.isNestedFillRects(rects, directions)) { |
| 3982 | for (int i = 0; i < 2; ++i) { |
| 3983 | SkDebugf("%s (%g, %g, %g, %g); direction %s\n", i ? "inner" : "outer", |
| 3984 | rects[i].fLeft, rects[i].fTop, rects[i].fRight, rects[i].fBottom, |
| 3985 | SkPath::kCW_Direction == directions[i] ? "CW" : "CCW"); |
| 3986 | } |
| 3987 | } else { |
| 3988 | SkDebugf("is not nested rectangles\n"); |
| 3989 | } |
| 3990 | } |
| 3991 | #StdOut |
| 3992 | outer (7.5, 17.5, 32.5, 42.5); direction CW |
| 3993 | inner (12.5, 22.5, 27.5, 37.5); direction CCW |
| 3994 | ## |
| 3995 | ## |
| 3996 | |
| 3997 | #SeeAlso computeTightBounds conservativelyContainsRect getBounds isConvex isLastContourClosed isRect |
| 3998 | |
| 3999 | ## |
| 4000 | |
| 4001 | # ------------------------------------------------------------------------------ |
| 4002 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4003 | #Method SkPath& addRect(const SkRect& rect, Direction dir = kCW_Direction) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4004 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4005 | #Line # adds one Contour containing Rect ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4006 | Adds Rect to Path, appending kMove_Verb, three kLine_Verb, and kClose_Verb, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4007 | starting with top-left corner of Rect; followed by top-right, bottom-right, |
| 4008 | and bottom-left if dir is kCW_Direction; or followed by bottom-left, |
| 4009 | bottom-right, and top-right if dir is kCCW_Direction. |
| 4010 | |
| 4011 | #Param rect Rect to add as a closed contour ## |
| 4012 | #Param dir Direction to wind added contour ## |
| 4013 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4014 | #Return reference to Path ## |
| 4015 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4016 | #Example |
| 4017 | #Description |
| 4018 | The left Rect dashes starting at the top-left corner, to the right. |
| 4019 | The right Rect dashes starting at the top-left corner, towards the bottom. |
| 4020 | ## |
| 4021 | #Height 128 |
| 4022 | void draw(SkCanvas* canvas) { |
| 4023 | SkPaint paint; |
| 4024 | paint.setStrokeWidth(15); |
| 4025 | paint.setStrokeCap(SkPaint::kSquare_Cap); |
| 4026 | float intervals[] = { 5, 21.75f }; |
| 4027 | paint.setStyle(SkPaint::kStroke_Style); |
| 4028 | paint.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 0)); |
| 4029 | SkPath path; |
| 4030 | path.addRect({20, 20, 100, 100}, SkPath::kCW_Direction); |
| 4031 | canvas->drawPath(path, paint); |
| 4032 | path.rewind(); |
| 4033 | path.addRect({140, 20, 220, 100}, SkPath::kCCW_Direction); |
| 4034 | canvas->drawPath(path, paint); |
| 4035 | } |
| 4036 | ## |
| 4037 | |
| 4038 | #SeeAlso SkCanvas::drawRect Direction |
| 4039 | |
| 4040 | ## |
| 4041 | |
| 4042 | # ------------------------------------------------------------------------------ |
| 4043 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4044 | #Method SkPath& addRect(const SkRect& rect, Direction dir, unsigned start) |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4045 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4046 | Adds Rect to Path, appending kMove_Verb, three kLine_Verb, and kClose_Verb. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4047 | If dir is kCW_Direction, Rect corners are added clockwise; if dir is |
| 4048 | kCCW_Direction, Rect corners are added counterclockwise. |
| 4049 | start determines the first corner added. |
| 4050 | |
| 4051 | #Table |
| 4052 | #Legend |
| 4053 | # start # first corner ## |
| 4054 | #Legend ## |
| 4055 | # 0 # top-left ## |
| 4056 | # 1 # top-right ## |
| 4057 | # 2 # bottom-right ## |
| 4058 | # 3 # bottom-left ## |
| 4059 | #Table ## |
| 4060 | |
| 4061 | #Param rect Rect to add as a closed contour ## |
| 4062 | #Param dir Direction to wind added contour ## |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 4063 | #Param start initial corner of Rect to add ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4064 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4065 | #Return reference to Path ## |
| 4066 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4067 | #Example |
| 4068 | #Height 128 |
| 4069 | #Description |
| 4070 | The arrow is just after the initial corner and points towards the next |
| 4071 | corner appended to Path. |
| 4072 | ## |
| 4073 | void draw(SkCanvas* canvas) { |
| 4074 | const SkPoint arrow[] = { {5, -5}, {15, -5}, {20, 0}, {15, 5}, {5, 5}, {10, 0} }; |
| 4075 | const SkRect rect = {10, 10, 54, 54}; |
| 4076 | SkPaint rectPaint; |
| 4077 | rectPaint.setAntiAlias(true); |
| 4078 | rectPaint.setStyle(SkPaint::kStroke_Style); |
| 4079 | SkPaint arrowPaint(rectPaint); |
| 4080 | SkPath arrowPath; |
| 4081 | arrowPath.addPoly(arrow, SK_ARRAY_COUNT(arrow), true); |
| 4082 | arrowPaint.setPathEffect(SkPath1DPathEffect::Make(arrowPath, 176, 0, |
| 4083 | SkPath1DPathEffect::kRotate_Style)); |
| 4084 | for (auto direction : { SkPath::kCW_Direction, SkPath::kCCW_Direction } ) { |
| 4085 | for (unsigned start : { 0, 1, 2, 3 } ) { |
| 4086 | SkPath path; |
| 4087 | path.addRect(rect, direction, start); |
| 4088 | canvas->drawPath(path, rectPaint); |
| 4089 | canvas->drawPath(path, arrowPaint); |
| 4090 | canvas->translate(64, 0); |
| 4091 | } |
| 4092 | canvas->translate(-256, 64); |
| 4093 | } |
| 4094 | } |
| 4095 | ## |
| 4096 | |
| 4097 | #SeeAlso SkCanvas::drawRect Direction |
| 4098 | |
| 4099 | ## |
| 4100 | |
| 4101 | # ------------------------------------------------------------------------------ |
| 4102 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4103 | #Method SkPath& addRect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4104 | Direction dir = kCW_Direction) |
| 4105 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4106 | Adds Rect (left, top, right, bottom) to Path, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4107 | appending kMove_Verb, three kLine_Verb, and kClose_Verb, |
| 4108 | starting with top-left corner of Rect; followed by top-right, bottom-right, |
| 4109 | and bottom-left if dir is kCW_Direction; or followed by bottom-left, |
| 4110 | bottom-right, and top-right if dir is kCCW_Direction. |
| 4111 | |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 4112 | #Param left smaller x-axis value of Rect ## |
| 4113 | #Param top smaller y-axis value of Rect ## |
| 4114 | #Param right larger x-axis value of Rect ## |
| 4115 | #Param bottom larger y-axis value of Rect ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4116 | #Param dir Direction to wind added contour ## |
| 4117 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4118 | #Return reference to Path ## |
| 4119 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4120 | #Example |
| 4121 | #Description |
| 4122 | The left Rect dashes start at the top-left corner, and continue to the right. |
| 4123 | The right Rect dashes start at the top-left corner, and continue down. |
| 4124 | ## |
| 4125 | #Height 128 |
| 4126 | void draw(SkCanvas* canvas) { |
| 4127 | SkPaint paint; |
| 4128 | paint.setStrokeWidth(15); |
| 4129 | paint.setStrokeCap(SkPaint::kSquare_Cap); |
| 4130 | float intervals[] = { 5, 21.75f }; |
| 4131 | paint.setStyle(SkPaint::kStroke_Style); |
| 4132 | paint.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 0)); |
| 4133 | for (auto direction : { SkPath::kCW_Direction, SkPath::kCCW_Direction } ) { |
| 4134 | SkPath path; |
| 4135 | path.addRect(20, 20, 100, 100, direction); |
| 4136 | canvas->drawPath(path, paint); |
| 4137 | canvas->translate(128, 0); |
| 4138 | } |
| 4139 | } |
| 4140 | ## |
| 4141 | |
| 4142 | #SeeAlso SkCanvas::drawRect Direction |
| 4143 | |
| 4144 | ## |
| 4145 | |
| 4146 | # ------------------------------------------------------------------------------ |
| 4147 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4148 | #Method SkPath& addOval(const SkRect& oval, Direction dir = kCW_Direction) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4149 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4150 | #Line # adds one Contour containing Oval ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4151 | Adds Oval to path, appending kMove_Verb, four kConic_Verb, and kClose_Verb. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4152 | Oval is upright ellipse bounded by Rect oval with radii equal to half oval width |
| 4153 | and half oval height. Oval begins at (oval.fRight, oval.centerY()) and continues |
| 4154 | clockwise if dir is kCW_Direction, counterclockwise if dir is kCCW_Direction. |
| 4155 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4156 | #Param oval bounds of ellipse added ## |
| 4157 | #Param dir Direction to wind ellipse ## |
| 4158 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4159 | #Return reference to Path ## |
| 4160 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4161 | #Example |
| 4162 | #Height 120 |
| 4163 | SkPaint paint; |
| 4164 | SkPath oval; |
| 4165 | oval.addOval({20, 20, 160, 80}); |
| 4166 | canvas->drawPath(oval, paint); |
| 4167 | ## |
| 4168 | |
| 4169 | #SeeAlso SkCanvas::drawOval Direction Oval |
| 4170 | |
| 4171 | ## |
| 4172 | |
| 4173 | # ------------------------------------------------------------------------------ |
| 4174 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4175 | #Method SkPath& addOval(const SkRect& oval, Direction dir, unsigned start) |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4176 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4177 | Adds Oval to Path, appending kMove_Verb, four kConic_Verb, and kClose_Verb. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4178 | Oval is upright ellipse bounded by Rect oval with radii equal to half oval width |
| 4179 | and half oval height. Oval begins at start and continues |
| 4180 | clockwise if dir is kCW_Direction, counterclockwise if dir is kCCW_Direction. |
| 4181 | |
| 4182 | #Table |
| 4183 | #Legend |
| 4184 | # start # Point ## |
| 4185 | #Legend ## |
| 4186 | # 0 # oval.centerX(), oval.fTop ## |
| 4187 | # 1 # oval.fRight, oval.centerY() ## |
| 4188 | # 2 # oval.centerX(), oval.fBottom ## |
| 4189 | # 3 # oval.fLeft, oval.centerY() ## |
| 4190 | #Table ## |
| 4191 | |
| 4192 | #Param oval bounds of ellipse added ## |
| 4193 | #Param dir Direction to wind ellipse ## |
| 4194 | #Param start index of initial point of ellipse ## |
| 4195 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4196 | #Return reference to Path ## |
| 4197 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4198 | #Example |
| 4199 | #Height 160 |
| 4200 | void draw(SkCanvas* canvas) { |
| 4201 | const SkPoint arrow[] = { {0, -5}, {10, 0}, {0, 5} }; |
| 4202 | const SkRect rect = {10, 10, 54, 54}; |
| 4203 | SkPaint ovalPaint; |
| 4204 | ovalPaint.setAntiAlias(true); |
| 4205 | SkPaint textPaint(ovalPaint); |
| 4206 | textPaint.setTextAlign(SkPaint::kCenter_Align); |
| 4207 | ovalPaint.setStyle(SkPaint::kStroke_Style); |
| 4208 | SkPaint arrowPaint(ovalPaint); |
| 4209 | SkPath arrowPath; |
| 4210 | arrowPath.addPoly(arrow, SK_ARRAY_COUNT(arrow), true); |
| 4211 | arrowPaint.setPathEffect(SkPath1DPathEffect::Make(arrowPath, 176, 0, |
| 4212 | SkPath1DPathEffect::kRotate_Style)); |
| 4213 | for (auto direction : { SkPath::kCW_Direction, SkPath::kCCW_Direction } ) { |
| 4214 | for (unsigned start : { 0, 1, 2, 3 } ) { |
| 4215 | SkPath path; |
| 4216 | path.addOval(rect, direction, start); |
| 4217 | canvas->drawPath(path, ovalPaint); |
| 4218 | canvas->drawPath(path, arrowPaint); |
| 4219 | canvas->drawText(&"0123"[start], 1, rect.centerX(), rect.centerY() + 5, textPaint); |
| 4220 | canvas->translate(64, 0); |
| 4221 | } |
| 4222 | canvas->translate(-256, 72); |
| 4223 | canvas->drawString(SkPath::kCW_Direction == direction ? "clockwise" : "counterclockwise", |
| 4224 | 128, 0, textPaint); |
| 4225 | } |
| 4226 | } |
| 4227 | ## |
| 4228 | |
| 4229 | #SeeAlso SkCanvas::drawOval Direction Oval |
| 4230 | |
| 4231 | ## |
| 4232 | |
| 4233 | # ------------------------------------------------------------------------------ |
| 4234 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4235 | #Method SkPath& addCircle(SkScalar x, SkScalar y, SkScalar radius, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4236 | Direction dir = kCW_Direction) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4237 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4238 | #Line # adds one Contour containing Circle ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4239 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4240 | Adds Circle centered at (x, y) of size radius to Path, appending kMove_Verb, |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4241 | four kConic_Verb, and kClose_Verb. Circle begins at: |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4242 | #Formula |
| 4243 | (x + radius, y) |
| 4244 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4245 | , continuing |
| 4246 | clockwise if dir is kCW_Direction, and counterclockwise if dir is kCCW_Direction. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4247 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 4248 | Has no effect if radius is zero or negative. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4249 | |
| 4250 | #Param x center of Circle ## |
| 4251 | #Param y center of Circle ## |
| 4252 | #Param radius distance from center to edge ## |
| 4253 | #Param dir Direction to wind Circle ## |
| 4254 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4255 | #Return reference to Path ## |
| 4256 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4257 | #Example |
| 4258 | void draw(SkCanvas* canvas) { |
| 4259 | SkPaint paint; |
| 4260 | paint.setAntiAlias(true); |
| 4261 | paint.setStyle(SkPaint::kStroke_Style); |
| 4262 | paint.setStrokeWidth(10); |
| 4263 | for (int size = 10; size < 300; size += 20) { |
| 4264 | SkPath path; |
| 4265 | path.addCircle(128, 128, size, SkPath::kCW_Direction); |
| 4266 | canvas->drawPath(path, paint); |
| 4267 | } |
| 4268 | } |
| 4269 | ## |
| 4270 | |
| 4271 | #SeeAlso SkCanvas::drawCircle Direction Circle |
| 4272 | |
| 4273 | ## |
| 4274 | |
| 4275 | # ------------------------------------------------------------------------------ |
| 4276 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4277 | #Method SkPath& addArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4278 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4279 | #Line # adds one Contour containing Arc ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4280 | Appends Arc to Path, as the start of new Contour. Arc added is part of ellipse |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4281 | bounded by oval, from startAngle through sweepAngle. Both startAngle and |
| 4282 | sweepAngle are measured in degrees, where zero degrees is aligned with the |
| 4283 | positive x-axis, and positive sweeps extends Arc clockwise. |
| 4284 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4285 | If sweepAngle <= -360, or sweepAngle >= 360; and startAngle modulo 90 is nearly |
| 4286 | zero, append Oval instead of Arc. Otherwise, sweepAngle values are treated |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4287 | modulo 360, and Arc may or may not draw depending on numeric rounding. |
| 4288 | |
| 4289 | #Param oval bounds of ellipse containing Arc ## |
| 4290 | #Param startAngle starting angle of Arc in degrees ## |
| 4291 | #Param sweepAngle sweep, in degrees. Positive is clockwise; treated modulo 360 ## |
| 4292 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4293 | #Return reference to Path ## |
| 4294 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4295 | #Example |
| 4296 | #Description |
| 4297 | The middle row of the left and right columns draw differently from the entries |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4298 | above and below because sweepAngle is outside of the range of +/-360, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4299 | and startAngle modulo 90 is not zero. |
| 4300 | ## |
| 4301 | void draw(SkCanvas* canvas) { |
| 4302 | SkPaint paint; |
| 4303 | for (auto start : { 0, 90, 135, 180, 270 } ) { |
| 4304 | for (auto sweep : { -450.f, -180.f, -90.f, 90.f, 180.f, 360.1f } ) { |
| 4305 | SkPath path; |
| 4306 | path.addArc({10, 10, 35, 45}, start, sweep); |
| 4307 | canvas->drawPath(path, paint); |
| 4308 | canvas->translate(252 / 6, 0); |
| 4309 | } |
| 4310 | canvas->translate(-252, 255 / 5); |
| 4311 | } |
| 4312 | } |
| 4313 | ## |
| 4314 | |
| 4315 | #SeeAlso Arc arcTo SkCanvas::drawArc |
| 4316 | |
| 4317 | ## |
| 4318 | |
| 4319 | # ------------------------------------------------------------------------------ |
| 4320 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4321 | #Method SkPath& addRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4322 | Direction dir = kCW_Direction) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4323 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4324 | #Line # adds one Contour containing Round_Rect with common corner radii ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4325 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4326 | Appends Round_Rect to Path, creating a new closed Contour. Round_Rect has bounds |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4327 | equal to rect; each corner is 90 degrees of an ellipse with radii (rx, ry). If |
| 4328 | dir is kCW_Direction, Round_Rect starts at top-left of the lower-left corner and |
| 4329 | winds clockwise. If dir is kCCW_Direction, Round_Rect starts at the bottom-left |
| 4330 | of the upper-left corner and winds counterclockwise. |
| 4331 | |
| 4332 | If either rx or ry is too large, rx and ry are scaled uniformly until the |
| 4333 | corners fit. If rx or ry is less than or equal to zero, addRoundRect appends |
| 4334 | Rect rect to Path. |
| 4335 | |
| 4336 | After appending, Path may be empty, or may contain: Rect, Oval, or RoundRect. |
| 4337 | |
| 4338 | #Param rect bounds of Round_Rect ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 4339 | #Param rx x-axis radius of rounded corners on the Round_Rect ## |
| 4340 | #Param ry y-axis radius of rounded corners on the Round_Rect ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4341 | #Param dir Direction to wind Round_Rect ## |
| 4342 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4343 | #Return reference to Path ## |
| 4344 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4345 | #Example |
| 4346 | #Description |
| 4347 | If either radius is zero, path contains Rect and is drawn red. |
| 4348 | If sides are only radii, path contains Oval and is drawn blue. |
| 4349 | All remaining path draws are convex, and are drawn in gray; no |
| 4350 | paths constructed from addRoundRect are concave, so none are |
| 4351 | drawn in green. |
| 4352 | ## |
| 4353 | void draw(SkCanvas* canvas) { |
| 4354 | SkPaint paint; |
| 4355 | paint.setAntiAlias(true); |
| 4356 | for (auto xradius : { 0, 7, 13, 20 } ) { |
| 4357 | for (auto yradius : { 0, 9, 18, 40 } ) { |
| 4358 | SkPath path; |
| 4359 | path.addRoundRect({10, 10, 36, 46}, xradius, yradius); |
| 4360 | paint.setColor(path.isRect(nullptr) ? SK_ColorRED : path.isOval(nullptr) ? |
| 4361 | SK_ColorBLUE : path.isConvex() ? SK_ColorGRAY : SK_ColorGREEN); |
| 4362 | canvas->drawPath(path, paint); |
| 4363 | canvas->translate(64, 0); |
| 4364 | } |
| 4365 | canvas->translate(-256, 64); |
| 4366 | } |
| 4367 | } |
| 4368 | ## |
| 4369 | |
| 4370 | #SeeAlso addRRect SkCanvas::drawRoundRect |
| 4371 | |
| 4372 | ## |
| 4373 | |
| 4374 | # ------------------------------------------------------------------------------ |
| 4375 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4376 | #Method SkPath& addRoundRect(const SkRect& rect, const SkScalar radii[], |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4377 | Direction dir = kCW_Direction) |
| 4378 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4379 | Appends Round_Rect to Path, creating a new closed Contour. Round_Rect has bounds |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4380 | equal to rect; each corner is 90 degrees of an ellipse with radii from the |
| 4381 | array. |
| 4382 | |
| 4383 | #Table |
| 4384 | #Legend |
| 4385 | # radii index # location ## |
| 4386 | #Legend ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 4387 | # 0 # x-axis radius of top-left corner ## |
| 4388 | # 1 # y-axis radius of top-left corner ## |
| 4389 | # 2 # x-axis radius of top-right corner ## |
| 4390 | # 3 # y-axis radius of top-right corner ## |
| 4391 | # 4 # x-axis radius of bottom-right corner ## |
| 4392 | # 5 # y-axis radius of bottom-right corner ## |
| 4393 | # 6 # x-axis radius of bottom-left corner ## |
| 4394 | # 7 # y-axis radius of bottom-left corner ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4395 | #Table ## |
| 4396 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4397 | If dir is kCW_Direction, Round_Rect starts at top-left of the lower-left corner |
| 4398 | and winds clockwise. If dir is kCCW_Direction, Round_Rect starts at the |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4399 | bottom-left of the upper-left corner and winds counterclockwise. |
| 4400 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4401 | If both radii on any side of rect exceed its length, all radii are scaled |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4402 | uniformly until the corners fit. If either radius of a corner is less than or |
| 4403 | equal to zero, both are treated as zero. |
| 4404 | |
| 4405 | After appending, Path may be empty, or may contain: Rect, Oval, or RoundRect. |
| 4406 | |
| 4407 | #Param rect bounds of Round_Rect ## |
| 4408 | #Param radii array of 8 SkScalar values, a radius pair for each corner ## |
| 4409 | #Param dir Direction to wind Round_Rect ## |
| 4410 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4411 | #Return reference to Path ## |
| 4412 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4413 | #Example |
| 4414 | void draw(SkCanvas* canvas) { |
| 4415 | SkPaint paint; |
| 4416 | paint.setAntiAlias(true); |
| 4417 | SkScalar radii[] = { 80, 100, 0, 0, 40, 60, 0, 0 }; |
| 4418 | SkPath path; |
| 4419 | SkMatrix rotate90; |
| 4420 | rotate90.setRotate(90, 128, 128); |
| 4421 | for (int i = 0; i < 4; ++i) { |
| 4422 | path.addRoundRect({10, 10, 110, 110}, radii); |
| 4423 | path.transform(rotate90); |
| 4424 | } |
| 4425 | canvas->drawPath(path, paint); |
| 4426 | } |
| 4427 | ## |
| 4428 | |
| 4429 | #SeeAlso addRRect SkCanvas::drawRoundRect |
| 4430 | |
| 4431 | ## |
| 4432 | |
| 4433 | # ------------------------------------------------------------------------------ |
| 4434 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4435 | #Method SkPath& addRRect(const SkRRect& rrect, Direction dir = kCW_Direction) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4436 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4437 | #Line # adds one Contour containing Round_Rect ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4438 | Adds rrect to Path, creating a new closed Contour. If |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4439 | dir is kCW_Direction, rrect starts at top-left of the lower-left corner and |
| 4440 | winds clockwise. If dir is kCCW_Direction, rrect starts at the bottom-left |
| 4441 | of the upper-left corner and winds counterclockwise. |
| 4442 | |
| 4443 | After appending, Path may be empty, or may contain: Rect, Oval, or Round_Rect. |
| 4444 | |
| 4445 | #Param rrect bounds and radii of rounded rectangle ## |
| 4446 | #Param dir Direction to wind Round_Rect ## |
| 4447 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4448 | #Return reference to Path ## |
| 4449 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4450 | #Example |
| 4451 | void draw(SkCanvas* canvas) { |
| 4452 | SkPaint paint; |
| 4453 | paint.setAntiAlias(true); |
| 4454 | SkRRect rrect; |
| 4455 | SkVector radii[] = {{50, 50}, {0, 0}, {0, 0}, {50, 50}}; |
| 4456 | rrect.setRectRadii({10, 10, 110, 110}, radii); |
| 4457 | SkPath path; |
| 4458 | SkMatrix rotate90; |
| 4459 | rotate90.setRotate(90, 128, 128); |
| 4460 | for (int i = 0; i < 4; ++i) { |
| 4461 | path.addRRect(rrect); |
| 4462 | path.transform(rotate90); |
| 4463 | } |
| 4464 | canvas->drawPath(path, paint); |
| 4465 | } |
| 4466 | ## |
| 4467 | |
| 4468 | #SeeAlso addRoundRect SkCanvas::drawRRect |
| 4469 | |
| 4470 | ## |
| 4471 | |
| 4472 | # ------------------------------------------------------------------------------ |
| 4473 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4474 | #Method SkPath& addRRect(const SkRRect& rrect, Direction dir, unsigned start) |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4475 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4476 | Adds rrect to Path, creating a new closed Contour. If dir is kCW_Direction, rrect |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4477 | winds clockwise; if dir is kCCW_Direction, rrect winds counterclockwise. |
| 4478 | start determines the first point of rrect to add. |
| 4479 | |
| 4480 | #Table |
| 4481 | #Legend |
| 4482 | # start # location ## |
| 4483 | #Legend ## |
| 4484 | # 0 # right of top-left corner ## |
| 4485 | # 1 # left of top-right corner ## |
| 4486 | # 2 # bottom of top-right corner ## |
| 4487 | # 3 # top of bottom-right corner ## |
| 4488 | # 4 # left of bottom-right corner ## |
| 4489 | # 5 # right of bottom-left corner ## |
| 4490 | # 6 # top of bottom-left corner ## |
| 4491 | # 7 # bottom of top-left corner ## |
| 4492 | #Table ## |
| 4493 | |
| 4494 | After appending, Path may be empty, or may contain: Rect, Oval, or Round_Rect. |
| 4495 | |
| 4496 | #Param rrect bounds and radii of rounded rectangle ## |
| 4497 | #Param dir Direction to wind Round_Rect ## |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 4498 | #Param start index of initial point of Round_Rect ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4499 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4500 | #Return reference to Path ## |
| 4501 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4502 | #Example |
| 4503 | void draw(SkCanvas* canvas) { |
| 4504 | SkPaint paint; |
| 4505 | paint.setAntiAlias(true); |
| 4506 | SkRRect rrect; |
| 4507 | rrect.setRectXY({40, 40, 215, 215}, 50, 50); |
| 4508 | SkPath path; |
| 4509 | path.addRRect(rrect); |
| 4510 | canvas->drawPath(path, paint); |
| 4511 | for (int start = 0; start < 8; ++start) { |
| 4512 | SkPath textPath; |
| 4513 | textPath.addRRect(rrect, SkPath::kCW_Direction, start); |
| 4514 | canvas->drawTextOnPathHV(&"01234567"[start], 1, textPath, 0, -5, paint); |
| 4515 | } |
| 4516 | } |
| 4517 | ## |
| 4518 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4519 | #SeeAlso addRoundRect SkCanvas::drawRRect |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4520 | |
| 4521 | ## |
| 4522 | |
| 4523 | # ------------------------------------------------------------------------------ |
| 4524 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4525 | #Method SkPath& addPoly(const SkPoint pts[], int count, bool close) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4526 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4527 | #Line # adds one Contour containing connected lines ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4528 | Adds Contour created from Line array, adding (count - 1) Line segments. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 4529 | Contour added starts at pts[0], then adds a line for every additional Point |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4530 | in pts array. If close is true, appends kClose_Verb to Path, connecting |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 4531 | pts[count - 1] and pts[0]. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4532 | |
| 4533 | If count is zero, append kMove_Verb to path. |
| 4534 | Has no effect if count is less than one. |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4535 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 4536 | #Param pts array of Line sharing end and start Point ## |
| 4537 | #Param count length of Point array ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4538 | #Param close true to add Line connecting Contour end and start ## |
| 4539 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4540 | #Return reference to Path ## |
| 4541 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4542 | #Example |
| 4543 | void draw(SkCanvas* canvas) { |
| 4544 | SkPaint paint; |
| 4545 | paint.setStrokeWidth(15); |
| 4546 | paint.setStrokeCap(SkPaint::kRound_Cap); |
| 4547 | const SkPoint points[] = {{20, 20}, {70, 20}, {40, 90}}; |
| 4548 | for (bool close : { false, true } ) { |
| 4549 | SkPath path; |
| 4550 | path.addPoly(points, SK_ARRAY_COUNT(points), close); |
| 4551 | for (auto style : {SkPaint::kStroke_Style, SkPaint::kFill_Style, |
| 4552 | SkPaint::kStrokeAndFill_Style} ) { |
| 4553 | paint.setStyle(style); |
| 4554 | canvas->drawPath(path, paint); |
| 4555 | canvas->translate(85, 0); |
| 4556 | } |
| 4557 | canvas->translate(-255, 128); |
| 4558 | } |
| 4559 | } |
| 4560 | ## |
| 4561 | |
| 4562 | #SeeAlso SkCanvas::drawPoints |
| 4563 | |
| 4564 | ## |
| 4565 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4566 | #Method SkPath& addPoly(const std::initializer_list<SkPoint>& list, bool close) |
| 4567 | |
| 4568 | Adds Contour created from list. Contour added starts at list[0], then adds a line |
| 4569 | for every additional Point in list. If close is true, appends kClose_Verb to Path, |
| 4570 | connecting last and first Point in list. |
| 4571 | |
| 4572 | If list is empty, append kMove_Verb to path. |
| 4573 | |
| 4574 | #Param list array of Points ## |
| 4575 | #Param close true to add Line connecting Contour end and start ## |
| 4576 | |
| 4577 | #Return reference to Path ## |
| 4578 | |
| 4579 | #Example |
| 4580 | void draw(SkCanvas* canvas) { |
| 4581 | SkPaint paint; |
| 4582 | paint.setStrokeWidth(15); |
| 4583 | paint.setStrokeCap(SkPaint::kRound_Cap); |
| 4584 | for (bool close : { false, true } ) { |
| 4585 | SkPath path; |
| 4586 | path.addPoly({{20, 20}, {70, 20}, {40, 90}}, close); |
| 4587 | for (auto style : {SkPaint::kStroke_Style, SkPaint::kFill_Style, |
| 4588 | SkPaint::kStrokeAndFill_Style} ) { |
| 4589 | paint.setStyle(style); |
| 4590 | canvas->drawPath(path, paint); |
| 4591 | canvas->translate(85, 0); |
| 4592 | } |
| 4593 | canvas->translate(-255, 128); |
| 4594 | } |
| 4595 | } |
| 4596 | ## |
| 4597 | |
| 4598 | #SeeAlso SkCanvas::drawPoints |
| 4599 | |
| 4600 | ## |
| 4601 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4602 | # ------------------------------------------------------------------------------ |
| 4603 | |
| 4604 | #Enum AddPathMode |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4605 | #Line # sets addPath options ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4606 | |
| 4607 | #Code |
| 4608 | enum AddPathMode { |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4609 | kAppend_AddPathMode, |
| 4610 | kExtend_AddPathMode, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4611 | }; |
| 4612 | ## |
| 4613 | |
| 4614 | AddPathMode chooses how addPath appends. Adding one Path to another can extend |
| 4615 | the last Contour or start a new Contour. |
| 4616 | |
| 4617 | #Const kAppend_AddPathMode |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4618 | #Line # appended to destination unaltered ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4619 | Path Verbs, Points, and Conic_Weights are appended to destination unaltered. |
| 4620 | Since Path Verb_Array begins with kMove_Verb if src is not empty, this |
| 4621 | starts a new Contour. |
| 4622 | ## |
| 4623 | #Const kExtend_AddPathMode |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4624 | #Line # add line if prior Contour is not closed ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4625 | If destination is closed or empty, start a new Contour. If destination |
| 4626 | is not empty, add Line from Last_Point to added Path first Point. Skip added |
| 4627 | Path initial kMove_Verb, then append remining Verbs, Points, and Conic_Weights. |
| 4628 | ## |
| 4629 | |
| 4630 | #Example |
| 4631 | #Description |
| 4632 | test is built from path, open on the top row, and closed on the bottom row. |
| 4633 | The left column uses kAppend_AddPathMode; the right uses kExtend_AddPathMode. |
| 4634 | The top right composition is made up of one contour; the other three have two. |
| 4635 | ## |
| 4636 | #Height 180 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4637 | SkPath path, path2; |
| 4638 | path.moveTo(20, 20); |
| 4639 | path.lineTo(20, 40); |
| 4640 | path.lineTo(40, 20); |
| 4641 | path2.moveTo(60, 60); |
| 4642 | path2.lineTo(80, 60); |
| 4643 | path2.lineTo(80, 40); |
| 4644 | SkPaint paint; |
| 4645 | paint.setStyle(SkPaint::kStroke_Style); |
| 4646 | for (int i = 0; i < 2; i++) { |
| 4647 | for (auto addPathMode : { SkPath::kAppend_AddPathMode, SkPath::kExtend_AddPathMode } ) { |
| 4648 | SkPath test(path); |
| 4649 | test.addPath(path2, addPathMode); |
| 4650 | canvas->drawPath(test, paint); |
| 4651 | canvas->translate(100, 0); |
| 4652 | } |
| 4653 | canvas->translate(-200, 100); |
| 4654 | path.close(); |
| 4655 | } |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4656 | ## |
| 4657 | |
| 4658 | #SeeAlso addPath reverseAddPath |
| 4659 | |
| 4660 | ## |
| 4661 | |
| 4662 | # ------------------------------------------------------------------------------ |
| 4663 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4664 | #Method SkPath& addPath(const SkPath& src, SkScalar dx, SkScalar dy, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4665 | AddPathMode mode = kAppend_AddPathMode) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4666 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4667 | #Line # adds contents of Path ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4668 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4669 | Appends src to Path, offset by (dx, dy). |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4670 | |
| 4671 | If mode is kAppend_AddPathMode, src Verb_Array, Point_Array, and Conic_Weights are |
| 4672 | added unaltered. If mode is kExtend_AddPathMode, add Line before appending |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4673 | Verbs, Points, and Conic_Weights. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4674 | |
| 4675 | #Param src Path Verbs, Points, and Conic_Weights to add ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 4676 | #Param dx offset added to src Point_Array x-axis coordinates ## |
| 4677 | #Param dy offset added to src Point_Array y-axis coordinates ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4678 | #Param mode kAppend_AddPathMode or kExtend_AddPathMode ## |
| 4679 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4680 | #Return reference to Path ## |
| 4681 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4682 | #Example |
| 4683 | #Height 180 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4684 | SkPaint paint; |
| 4685 | paint.setTextSize(128); |
| 4686 | paint.setFakeBoldText(true); |
| 4687 | SkPath dest, text; |
| 4688 | paint.getTextPath("O", 1, 50, 120, &text); |
| 4689 | for (int i = 0; i < 3; i++) { |
| 4690 | dest.addPath(text, i * 20, i * 20); |
| 4691 | } |
| 4692 | Simplify(dest, &dest); |
| 4693 | paint.setStyle(SkPaint::kStroke_Style); |
| 4694 | paint.setStrokeWidth(3); |
| 4695 | canvas->drawPath(dest, paint); |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4696 | ## |
| 4697 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4698 | #SeeAlso AddPathMode offset reverseAddPath |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4699 | |
| 4700 | ## |
| 4701 | |
| 4702 | # ------------------------------------------------------------------------------ |
| 4703 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4704 | #Method SkPath& addPath(const SkPath& src, AddPathMode mode = kAppend_AddPathMode) |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4705 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4706 | Appends src to Path. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4707 | |
| 4708 | If mode is kAppend_AddPathMode, src Verb_Array, Point_Array, and Conic_Weights are |
| 4709 | added unaltered. If mode is kExtend_AddPathMode, add Line before appending |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4710 | Verbs, Points, and Conic_Weights. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4711 | |
| 4712 | #Param src Path Verbs, Points, and Conic_Weights to add ## |
| 4713 | #Param mode kAppend_AddPathMode or kExtend_AddPathMode ## |
| 4714 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4715 | #Return reference to Path ## |
| 4716 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4717 | #Example |
| 4718 | #Height 80 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4719 | SkPaint paint; |
| 4720 | paint.setStyle(SkPaint::kStroke_Style); |
| 4721 | SkPath dest, path; |
| 4722 | path.addOval({-80, 20, 0, 60}, SkPath::kCW_Direction, 1); |
| 4723 | for (int i = 0; i < 2; i++) { |
| 4724 | dest.addPath(path, SkPath::kExtend_AddPathMode); |
| 4725 | dest.offset(100, 0); |
| 4726 | } |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4727 | canvas->drawPath(dest, paint); |
| 4728 | ## |
| 4729 | |
| 4730 | #SeeAlso AddPathMode reverseAddPath |
| 4731 | |
| 4732 | ## |
| 4733 | |
| 4734 | # ------------------------------------------------------------------------------ |
| 4735 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4736 | #Method SkPath& addPath(const SkPath& src, const SkMatrix& matrix, AddPathMode mode = kAppend_AddPathMode) |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4737 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4738 | Appends src to Path, transformed by matrix. Transformed curves may have different |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4739 | Verbs, Points, and Conic_Weights. |
| 4740 | |
| 4741 | If mode is kAppend_AddPathMode, src Verb_Array, Point_Array, and Conic_Weights are |
| 4742 | added unaltered. If mode is kExtend_AddPathMode, add Line before appending |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4743 | Verbs, Points, and Conic_Weights. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4744 | |
| 4745 | #Param src Path Verbs, Points, and Conic_Weights to add ## |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 4746 | #Param matrix transform applied to src ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4747 | #Param mode kAppend_AddPathMode or kExtend_AddPathMode ## |
| 4748 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4749 | #Return reference to Path ## |
| 4750 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4751 | #Example |
| 4752 | #Height 160 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4753 | SkPaint paint; |
| 4754 | paint.setStyle(SkPaint::kStroke_Style); |
| 4755 | SkPath dest, path; |
| 4756 | path.addOval({20, 20, 200, 120}, SkPath::kCW_Direction, 1); |
| 4757 | for (int i = 0; i < 6; i++) { |
| 4758 | SkMatrix matrix; |
| 4759 | matrix.reset(); |
| 4760 | matrix.setPerspX(i / 400.f); |
| 4761 | dest.addPath(path, matrix); |
| 4762 | } |
| 4763 | canvas->drawPath(dest, paint); |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4764 | ## |
| 4765 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4766 | #SeeAlso AddPathMode transform offset reverseAddPath |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4767 | |
| 4768 | ## |
| 4769 | |
| 4770 | # ------------------------------------------------------------------------------ |
| 4771 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4772 | #Method SkPath& reverseAddPath(const SkPath& src) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4773 | #In Build |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4774 | #Line # adds contents of Path back to front ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4775 | Appends src to Path, from back to front. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4776 | Reversed src always appends a new Contour to Path. |
| 4777 | |
| 4778 | #Param src Path Verbs, Points, and Conic_Weights to add ## |
| 4779 | |
Cary Clark | 0251b1b | 2018-08-15 15:14:55 -0400 | [diff] [blame] | 4780 | #Return reference to Path ## |
| 4781 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4782 | #Example |
| 4783 | #Height 200 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4784 | SkPath path; |
| 4785 | path.moveTo(20, 20); |
| 4786 | path.lineTo(20, 40); |
| 4787 | path.lineTo(40, 20); |
| 4788 | SkPaint paint; |
| 4789 | paint.setStyle(SkPaint::kStroke_Style); |
| 4790 | for (int i = 0; i < 2; i++) { |
| 4791 | SkPath path2; |
| 4792 | path2.moveTo(60, 60); |
| 4793 | path2.lineTo(80, 60); |
| 4794 | path2.lineTo(80, 40); |
| 4795 | for (int j = 0; j < 2; j++) { |
| 4796 | SkPath test(path); |
| 4797 | test.reverseAddPath(path2); |
| 4798 | canvas->drawPath(test, paint); |
| 4799 | canvas->translate(100, 0); |
| 4800 | path2.close(); |
| 4801 | } |
| 4802 | canvas->translate(-200, 100); |
| 4803 | path.close(); |
| 4804 | } |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4805 | ## |
| 4806 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4807 | #SeeAlso AddPathMode transform offset addPath |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4808 | |
| 4809 | ## |
| 4810 | |
| 4811 | # ------------------------------------------------------------------------------ |
| 4812 | |
| 4813 | #Method void offset(SkScalar dx, SkScalar dy, SkPath* dst) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4814 | #In Transform |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4815 | #Line # translates Point_Array ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4816 | Offsets Point_Array by (dx, dy). Offset Path replaces dst. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4817 | If dst is nullptr, Path is replaced by offset data. |
| 4818 | |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 4819 | #Param dx offset added to Point_Array x-axis coordinates ## |
| 4820 | #Param dy offset added to Point_Array y-axis coordinates ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4821 | #Param dst overwritten, translated copy of Path; may be nullptr ## |
| 4822 | |
| 4823 | #Example |
| 4824 | #Height 60 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4825 | SkPath pattern; |
| 4826 | pattern.moveTo(20, 20); |
| 4827 | pattern.lineTo(20, 40); |
| 4828 | pattern.lineTo(40, 20); |
| 4829 | SkPaint paint; |
| 4830 | paint.setStyle(SkPaint::kStroke_Style); |
| 4831 | for (int i = 0; i < 10; i++) { |
| 4832 | SkPath path; |
| 4833 | pattern.offset(20 * i, 0, &path); |
| 4834 | canvas->drawPath(path, paint); |
| 4835 | } |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4836 | ## |
| 4837 | |
| 4838 | #SeeAlso addPath transform |
| 4839 | |
| 4840 | ## |
| 4841 | |
| 4842 | # ------------------------------------------------------------------------------ |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4843 | #Subtopic Transform |
| 4844 | #Populate |
| 4845 | #Line # modify all points ## |
| 4846 | ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4847 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4848 | #Method void offset(SkScalar dx, SkScalar dy) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4849 | #In Transform |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4850 | Offsets Point_Array by (dx, dy). Path is replaced by offset data. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4851 | |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 4852 | #Param dx offset added to Point_Array x-axis coordinates ## |
| 4853 | #Param dy offset added to Point_Array y-axis coordinates ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4854 | |
| 4855 | #Example |
| 4856 | #Height 60 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4857 | SkPath path; |
| 4858 | path.moveTo(20, 20); |
| 4859 | path.lineTo(20, 40); |
| 4860 | path.lineTo(40, 20); |
| 4861 | SkPaint paint; |
| 4862 | paint.setStyle(SkPaint::kStroke_Style); |
| 4863 | for (int i = 0; i < 10; i++) { |
| 4864 | canvas->drawPath(path, paint); |
| 4865 | path.offset(20, 0); |
| 4866 | } |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4867 | ## |
| 4868 | |
| 4869 | #SeeAlso addPath transform SkCanvas::translate() |
| 4870 | |
| 4871 | ## |
| 4872 | |
| 4873 | # ------------------------------------------------------------------------------ |
| 4874 | |
| 4875 | #Method void transform(const SkMatrix& matrix, SkPath* dst) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4876 | #In Transform |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4877 | #Line # applies Matrix to Point_Array and Weights ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4878 | Transforms Verb_Array, Point_Array, and weight by matrix. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4879 | transform may change Verbs and increase their number. |
| 4880 | Transformed Path replaces dst; if dst is nullptr, original data |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4881 | is replaced. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4882 | |
| 4883 | #Param matrix Matrix to apply to Path ## |
| 4884 | #Param dst overwritten, transformed copy of Path; may be nullptr ## |
| 4885 | |
| 4886 | #Example |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4887 | #Height 200 |
| 4888 | SkPath pattern; |
| 4889 | pattern.moveTo(100, 100); |
| 4890 | pattern.lineTo(100, 20); |
| 4891 | pattern.lineTo(20, 100); |
| 4892 | SkPaint paint; |
| 4893 | paint.setStyle(SkPaint::kStroke_Style); |
| 4894 | for (int i = 0; i < 10; i++) { |
| 4895 | SkPath path; |
| 4896 | SkMatrix matrix; |
| 4897 | matrix.setRotate(36 * i, 100, 100); |
| 4898 | pattern.transform(matrix, &path); |
| 4899 | canvas->drawPath(path, paint); |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4900 | } |
| 4901 | ## |
| 4902 | |
| 4903 | #SeeAlso addPath offset SkCanvas::concat() SkMatrix |
| 4904 | |
| 4905 | ## |
| 4906 | |
| 4907 | # ------------------------------------------------------------------------------ |
| 4908 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4909 | #Method void transform(const SkMatrix& matrix) |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4910 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4911 | Transforms Verb_Array, Point_Array, and weight by matrix. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4912 | transform may change Verbs and increase their number. |
| 4913 | Path is replaced by transformed data. |
| 4914 | |
| 4915 | #Param matrix Matrix to apply to Path ## |
| 4916 | |
| 4917 | #Example |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4918 | #Height 200 |
| 4919 | SkPath path; |
| 4920 | path.moveTo(100, 100); |
| 4921 | path.quadTo(100, 20, 20, 100); |
| 4922 | SkPaint paint; |
| 4923 | paint.setStyle(SkPaint::kStroke_Style); |
| 4924 | for (int i = 0; i < 10; i++) { |
| 4925 | SkMatrix matrix; |
| 4926 | matrix.setRotate(36, 100, 100); |
| 4927 | path.transform(matrix); |
| 4928 | canvas->drawPath(path, paint); |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4929 | } |
| 4930 | ## |
| 4931 | |
| 4932 | #SeeAlso addPath offset SkCanvas::concat() SkMatrix |
| 4933 | |
| 4934 | ## |
| 4935 | |
| 4936 | # ------------------------------------------------------------------------------ |
| 4937 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4938 | #Subtopic Last_Point |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4939 | #Line # final Point in Contour ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4940 | |
| 4941 | Path is defined cumulatively, often by adding a segment to the end of last |
| 4942 | Contour. Last_Point of Contour is shared as first Point of added Line or Curve. |
| 4943 | Last_Point can be read and written directly with getLastPt and setLastPt. |
| 4944 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4945 | #Method bool getLastPt(SkPoint* lastPt) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4946 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4947 | #In Last_Point |
| 4948 | #Line # returns Last_Point ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4949 | Returns Last_Point on Path in lastPt. Returns false if Point_Array is empty, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4950 | storing (0, 0) if lastPt is not nullptr. |
| 4951 | |
| 4952 | #Param lastPt storage for final Point in Point_Array; may be nullptr ## |
| 4953 | |
| 4954 | #Return true if Point_Array contains one or more Points ## |
| 4955 | |
| 4956 | #Example |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4957 | SkPath path; |
| 4958 | path.moveTo(100, 100); |
| 4959 | path.quadTo(100, 20, 20, 100); |
| 4960 | SkMatrix matrix; |
| 4961 | matrix.setRotate(36, 100, 100); |
| 4962 | path.transform(matrix); |
| 4963 | SkPoint last; |
| 4964 | path.getLastPt(&last); |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4965 | SkDebugf("last point: %g, %g\n", last.fX, last.fY); |
| 4966 | #StdOut |
| 4967 | last point: 35.2786, 52.9772 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4968 | ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4969 | ## |
| 4970 | |
| 4971 | #SeeAlso setLastPt |
| 4972 | |
| 4973 | ## |
| 4974 | |
| 4975 | #Method void setLastPt(SkScalar x, SkScalar y) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4976 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4977 | #In Last_Point |
| 4978 | #Line # replaces Last_Point ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4979 | Sets Last_Point to (x, y). If Point_Array is empty, append kMove_Verb to |
Cary Clark | 186d08f | 2018-04-03 08:43:27 -0400 | [diff] [blame] | 4980 | Verb_Array and append (x, y) to Point_Array. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4981 | |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 4982 | #Param x set x-axis value of Last_Point ## |
| 4983 | #Param y set y-axis value of Last_Point ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4984 | |
| 4985 | #Example |
| 4986 | #Height 128 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4987 | SkPaint paint; |
| 4988 | paint.setTextSize(128); |
| 4989 | SkPath path; |
| 4990 | paint.getTextPath("@", 1, 60, 100, &path); |
| 4991 | path.setLastPt(20, 120); |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4992 | canvas->drawPath(path, paint); |
| 4993 | ## |
| 4994 | |
| 4995 | #SeeAlso getLastPt |
| 4996 | |
| 4997 | ## |
| 4998 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4999 | #Method void setLastPt(const SkPoint& p) |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5000 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5001 | Sets the last point on the path. If Point_Array is empty, append kMove_Verb to |
Cary Clark | 186d08f | 2018-04-03 08:43:27 -0400 | [diff] [blame] | 5002 | Verb_Array and append p to Point_Array. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5003 | |
| 5004 | #Param p set value of Last_Point ## |
| 5005 | |
| 5006 | #Example |
| 5007 | #Height 128 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5008 | SkPaint paint; |
| 5009 | paint.setTextSize(128); |
| 5010 | SkPath path, path2; |
| 5011 | paint.getTextPath("A", 1, 60, 100, &path); |
| 5012 | paint.getTextPath("Z", 1, 60, 100, &path2); |
| 5013 | SkPoint pt, pt2; |
| 5014 | path.getLastPt(&pt); |
| 5015 | path2.getLastPt(&pt2); |
| 5016 | path.setLastPt(pt2); |
| 5017 | path2.setLastPt(pt); |
| 5018 | canvas->drawPath(path, paint); |
| 5019 | canvas->drawPath(path2, paint); |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5020 | ## |
| 5021 | |
| 5022 | #SeeAlso getLastPt |
| 5023 | |
| 5024 | ## |
| 5025 | |
| 5026 | #Subtopic Last_Point ## |
| 5027 | |
| 5028 | # ------------------------------------------------------------------------------ |
| 5029 | |
| 5030 | #Enum SegmentMask |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 5031 | #Line # returns Verb types in Path ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5032 | |
| 5033 | #Code |
| 5034 | enum SegmentMask { |
| 5035 | kLine_SegmentMask = 1 << 0, |
| 5036 | kQuad_SegmentMask = 1 << 1, |
| 5037 | kConic_SegmentMask = 1 << 2, |
| 5038 | kCubic_SegmentMask = 1 << 3, |
| 5039 | }; |
| 5040 | ## |
| 5041 | |
| 5042 | SegmentMask constants correspond to each drawing Verb type in Path; for |
| 5043 | instance, if Path only contains Lines, only the kLine_SegmentMask bit is set. |
| 5044 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 5045 | #Bug 6785 |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5046 | #Const kLine_SegmentMask 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5047 | #Line # contains one or more Lines ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5048 | Set if Verb_Array contains kLine_Verb. |
| 5049 | ## |
| 5050 | #Const kQuad_SegmentMask 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5051 | #Line # contains one or more Quads ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5052 | Set if Verb_Array contains kQuad_Verb. Note that conicTo may add a Quad. |
| 5053 | ## |
| 5054 | #Const kConic_SegmentMask 4 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5055 | #Line # contains one or more Conics ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5056 | Set if Verb_Array contains kConic_Verb. |
| 5057 | ## |
| 5058 | #Const kCubic_SegmentMask 8 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5059 | #Line # contains one or more Cubics ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5060 | Set if Verb_Array contains kCubic_Verb. |
| 5061 | ## |
| 5062 | |
| 5063 | #Example |
| 5064 | #Description |
| 5065 | When conicTo has a weight of one, Quad is added to Path. |
| 5066 | ## |
| 5067 | SkPath path; |
| 5068 | path.conicTo(10, 10, 20, 30, 1); |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5069 | SkDebugf("Path kConic_SegmentMask is %s\n", path.getSegmentMasks() & |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5070 | SkPath::kConic_SegmentMask ? "set" : "clear"); |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5071 | SkDebugf("Path kQuad_SegmentMask is %s\n", path.getSegmentMasks() & |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5072 | SkPath::kQuad_SegmentMask ? "set" : "clear"); |
| 5073 | #StdOut |
| 5074 | Path kConic_SegmentMask is clear |
| 5075 | Path kQuad_SegmentMask is set |
| 5076 | ## |
| 5077 | ## |
| 5078 | |
| 5079 | #SeeAlso getSegmentMasks Verb |
| 5080 | |
| 5081 | ## |
| 5082 | |
| 5083 | # ------------------------------------------------------------------------------ |
| 5084 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5085 | #Method uint32_t getSegmentMasks() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 5086 | #In Utility |
| 5087 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5088 | #Line # returns types in Verb_Array ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5089 | Returns a mask, where each set bit corresponds to a SegmentMask constant |
| 5090 | if Path contains one or more Verbs of that type. |
| 5091 | Returns zero if Path contains no Lines, or Curves: Quads, Conics, or Cubics. |
| 5092 | |
| 5093 | getSegmentMasks() returns a cached result; it is very fast. |
| 5094 | |
| 5095 | #Return SegmentMask bits or zero ## |
| 5096 | |
| 5097 | #Example |
| 5098 | SkPath path; |
| 5099 | path.quadTo(20, 30, 40, 50); |
| 5100 | path.close(); |
| 5101 | const char* masks[] = { "line", "quad", "conic", "cubic" }; |
| 5102 | int index = 0; |
| 5103 | for (auto mask : { SkPath::kLine_SegmentMask, SkPath::kQuad_SegmentMask, |
| 5104 | SkPath::kConic_SegmentMask, SkPath::kCubic_SegmentMask } ) { |
| 5105 | if (mask & path.getSegmentMasks()) { |
| 5106 | SkDebugf("mask %s set\n", masks[index]); |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5107 | } |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5108 | ++index; |
| 5109 | } |
| 5110 | #StdOut |
| 5111 | mask quad set |
| 5112 | ## |
| 5113 | ## |
| 5114 | |
| 5115 | #SeeAlso getSegmentMasks Verb |
| 5116 | |
| 5117 | ## |
| 5118 | |
| 5119 | # ------------------------------------------------------------------------------ |
| 5120 | |
| 5121 | #Method bool contains(SkScalar x, SkScalar y) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 5122 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5123 | #Line # returns if Point is in fill area ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5124 | Returns true if the point (x, y) is contained by Path, taking into |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5125 | account FillType. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5126 | |
| 5127 | #Table |
| 5128 | #Legend |
| 5129 | # FillType # contains() returns true if Point is enclosed by ## |
| 5130 | ## |
| 5131 | # kWinding_FillType # a non-zero sum of Contour Directions. ## |
| 5132 | # kEvenOdd_FillType # an odd number of Contours. ## |
| 5133 | # kInverseWinding_FillType # a zero sum of Contour Directions. ## |
| 5134 | # kInverseEvenOdd_FillType # and even number of Contours. ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5135 | ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5136 | |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 5137 | #Param x x-axis value of containment test ## |
| 5138 | #Param y y-axis value of containment test ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5139 | |
| 5140 | #Return true if Point is in Path ## |
| 5141 | |
| 5142 | #Example |
| 5143 | SkPath path; |
| 5144 | SkPaint paint; |
| 5145 | paint.setTextSize(256); |
| 5146 | paint.getTextPath("&", 1, 30, 220, &path); |
| 5147 | for (int y = 2; y < 256; y += 9) { |
| 5148 | for (int x = 2; x < 256; x += 9) { |
| 5149 | int coverage = 0; |
| 5150 | for (int iy = -4; iy <= 4; iy += 2) { |
| 5151 | for (int ix = -4; ix <= 4; ix += 2) { |
| 5152 | coverage += path.contains(x + ix, y + iy); |
| 5153 | } |
| 5154 | } |
| 5155 | paint.setColor(SkColorSetARGB(0x5f, 0xff * coverage / 25, 0, 0xff * (25 - coverage) / 25)); |
| 5156 | canvas->drawCircle(x, y, 8, paint); |
| 5157 | } |
| 5158 | } |
| 5159 | ## |
| 5160 | |
| 5161 | #SeeAlso conservativelyContainsRect Fill_Type Op |
| 5162 | |
| 5163 | ## |
| 5164 | |
| 5165 | # ------------------------------------------------------------------------------ |
| 5166 | |
| 5167 | #Method void dump(SkWStream* stream, bool forceClose, bool dumpAsHex) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 5168 | #In Utility |
Cary Clark | 53498e9 | 2018-06-28 19:13:56 -0400 | [diff] [blame] | 5169 | #Line # sends text representation to stream ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 5170 | Writes text representation of Path to stream. If stream is nullptr, writes to |
| 5171 | standard output. Set forceClose to true to get edges used to fill Path. |
| 5172 | Set dumpAsHex true to generate exact binary representations |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5173 | of floating point numbers used in Point_Array and Conic_Weights. |
| 5174 | |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 5175 | #Param stream writable WStream receiving Path text representation; may be nullptr ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5176 | #Param forceClose true if missing kClose_Verb is output ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5177 | #Param dumpAsHex true if SkScalar values are written as hexadecimal ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5178 | |
| 5179 | #Example |
| 5180 | SkPath path; |
| 5181 | path.quadTo(20, 30, 40, 50); |
| 5182 | for (bool forceClose : { false, true } ) { |
| 5183 | for (bool dumpAsHex : { false, true } ) { |
| 5184 | path.dump(nullptr, forceClose, dumpAsHex); |
| 5185 | SkDebugf("\n"); |
| 5186 | } |
| 5187 | } |
| 5188 | #StdOut |
| 5189 | path.setFillType(SkPath::kWinding_FillType); |
| 5190 | path.moveTo(0, 0); |
| 5191 | path.quadTo(20, 30, 40, 50); |
| 5192 | |
| 5193 | path.setFillType(SkPath::kWinding_FillType); |
| 5194 | path.moveTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0 |
| 5195 | path.quadTo(SkBits2Float(0x41a00000), SkBits2Float(0x41f00000), SkBits2Float(0x42200000), SkBits2Float(0x42480000)); // 20, 30, 40, 50 |
| 5196 | |
| 5197 | path.setFillType(SkPath::kWinding_FillType); |
| 5198 | path.moveTo(0, 0); |
| 5199 | path.quadTo(20, 30, 40, 50); |
| 5200 | path.lineTo(0, 0); |
| 5201 | path.close(); |
| 5202 | |
| 5203 | path.setFillType(SkPath::kWinding_FillType); |
| 5204 | path.moveTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0 |
| 5205 | path.quadTo(SkBits2Float(0x41a00000), SkBits2Float(0x41f00000), SkBits2Float(0x42200000), SkBits2Float(0x42480000)); // 20, 30, 40, 50 |
| 5206 | path.lineTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0 |
| 5207 | path.close(); |
| 5208 | ## |
| 5209 | ## |
| 5210 | |
Cary Clark | 53498e9 | 2018-06-28 19:13:56 -0400 | [diff] [blame] | 5211 | #SeeAlso dumpHex SkRect::dump() SkRRect::dump() SkPathMeasure::dump() |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5212 | |
| 5213 | ## |
| 5214 | |
| 5215 | # ------------------------------------------------------------------------------ |
| 5216 | |
| 5217 | #Method void dump() const |
| 5218 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5219 | Writes text representation of Path to standard output. The representation may be |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5220 | directly compiled as C++ code. Floating point values are written |
| 5221 | with limited precision; it may not be possible to reconstruct original Path |
| 5222 | from output. |
| 5223 | |
| 5224 | #Example |
| 5225 | SkPath path, copy; |
| 5226 | path.lineTo(6.f / 7, 2.f / 3); |
| 5227 | path.dump(); |
| 5228 | copy.setFillType(SkPath::kWinding_FillType); |
| 5229 | copy.moveTo(0, 0); |
| 5230 | copy.lineTo(0.857143f, 0.666667f); |
| 5231 | SkDebugf("path is " "%s" "equal to copy\n", path == copy ? "" : "not "); |
| 5232 | #StdOut |
| 5233 | path.setFillType(SkPath::kWinding_FillType); |
| 5234 | path.moveTo(0, 0); |
| 5235 | path.lineTo(0.857143f, 0.666667f); |
| 5236 | path is not equal to copy |
| 5237 | ## |
| 5238 | ## |
| 5239 | |
| 5240 | #SeeAlso dumpHex SkRect::dump() SkRRect::dump() SkPathMeasure::dump() writeToMemory |
| 5241 | |
| 5242 | ## |
| 5243 | |
| 5244 | # ------------------------------------------------------------------------------ |
| 5245 | |
| 5246 | #Method void dumpHex() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 5247 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5248 | #Line # sends text representation using hexadecimal to standard output ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5249 | Writes text representation of Path to standard output. The representation may be |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5250 | directly compiled as C++ code. Floating point values are written |
| 5251 | in hexadecimal to preserve their exact bit pattern. The output reconstructs the |
| 5252 | original Path. |
| 5253 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5254 | Use instead of dump() when submitting |
| 5255 | #A bug reports against Skia # https://bug.skia.org ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 5256 | . |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5257 | |
| 5258 | #Example |
| 5259 | SkPath path, copy; |
| 5260 | path.lineTo(6.f / 7, 2.f / 3); |
| 5261 | path.dumpHex(); |
| 5262 | copy.setFillType(SkPath::kWinding_FillType); |
| 5263 | copy.moveTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0 |
| 5264 | copy.lineTo(SkBits2Float(0x3f5b6db7), SkBits2Float(0x3f2aaaab)); // 0.857143f, 0.666667f |
| 5265 | SkDebugf("path is " "%s" "equal to copy\n", path == copy ? "" : "not "); |
| 5266 | #StdOut |
| 5267 | path.setFillType(SkPath::kWinding_FillType); |
| 5268 | path.moveTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0 |
| 5269 | path.lineTo(SkBits2Float(0x3f5b6db7), SkBits2Float(0x3f2aaaab)); // 0.857143f, 0.666667f |
| 5270 | path is equal to copy |
| 5271 | ## |
| 5272 | ## |
| 5273 | |
Cary Clark | 186d08f | 2018-04-03 08:43:27 -0400 | [diff] [blame] | 5274 | #SeeAlso dump SkRect::dumpHex SkRRect::dumpHex writeToMemory |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5275 | |
| 5276 | ## |
| 5277 | |
| 5278 | # ------------------------------------------------------------------------------ |
| 5279 | |
| 5280 | #Method size_t writeToMemory(void* buffer) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 5281 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5282 | #Line # copies data to buffer ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5283 | Writes Path to buffer, returning the number of bytes written. |
| 5284 | Pass nullptr to obtain the storage size. |
| 5285 | |
| 5286 | Writes Fill_Type, Verb_Array, Point_Array, Conic_Weight, and |
| 5287 | additionally writes computed information like Convexity and bounds. |
| 5288 | |
| 5289 | Use only be used in concert with readFromMemory; |
| 5290 | the format used for Path in memory is not guaranteed. |
| 5291 | |
| 5292 | #Param buffer storage for Path; may be nullptr ## |
| 5293 | |
| 5294 | #Return size of storage required for Path; always a multiple of 4 ## |
| 5295 | |
| 5296 | #Example |
| 5297 | void draw(SkCanvas* canvas) { |
| 5298 | SkPath path, copy; |
| 5299 | path.lineTo(6.f / 7, 2.f / 3); |
| 5300 | size_t size = path.writeToMemory(nullptr); |
| 5301 | SkTDArray<char> storage; |
| 5302 | storage.setCount(size); |
| 5303 | path.writeToMemory(storage.begin()); |
| 5304 | copy.readFromMemory(storage.begin(), size); |
| 5305 | SkDebugf("path is " "%s" "equal to copy\n", path == copy ? "" : "not "); |
| 5306 | } |
| 5307 | #StdOut |
| 5308 | path is equal to copy |
| 5309 | ## |
| 5310 | ## |
| 5311 | |
| 5312 | #SeeAlso serialize readFromMemory dump dumpHex |
| 5313 | |
| 5314 | ## |
| 5315 | |
| 5316 | #Method sk_sp<SkData> serialize() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 5317 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5318 | #Line # copies data to buffer ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5319 | Writes Path to buffer, returning the buffer written to, wrapped in Data. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5320 | |
| 5321 | serialize() writes Fill_Type, Verb_Array, Point_Array, Conic_Weight, and |
| 5322 | additionally writes computed information like Convexity and bounds. |
| 5323 | |
| 5324 | serialize() should only be used in concert with readFromMemory. |
| 5325 | The format used for Path in memory is not guaranteed. |
| 5326 | |
| 5327 | #Return Path data wrapped in Data buffer ## |
| 5328 | |
| 5329 | #Example |
| 5330 | void draw(SkCanvas* canvas) { |
| 5331 | SkPath path, copy; |
| 5332 | path.lineTo(6.f / 7, 2.f / 3); |
| 5333 | sk_sp<SkData> data = path.serialize(); |
| 5334 | copy.readFromMemory(data->data(), data->size()); |
| 5335 | SkDebugf("path is " "%s" "equal to copy\n", path == copy ? "" : "not "); |
| 5336 | } |
| 5337 | #StdOut |
| 5338 | path is equal to copy |
| 5339 | ## |
| 5340 | ## |
| 5341 | |
| 5342 | #SeeAlso writeToMemory readFromMemory dump dumpHex |
| 5343 | ## |
| 5344 | |
| 5345 | # ------------------------------------------------------------------------------ |
| 5346 | |
| 5347 | #Method size_t readFromMemory(const void* buffer, size_t length) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 5348 | #In Utility |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5349 | #Line # initializes from buffer ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5350 | Initializes Path from buffer of size length. Returns zero if the buffer is |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5351 | data is inconsistent, or the length is too small. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5352 | |
| 5353 | Reads Fill_Type, Verb_Array, Point_Array, Conic_Weight, and |
| 5354 | additionally reads computed information like Convexity and bounds. |
| 5355 | |
| 5356 | Used only in concert with writeToMemory; |
| 5357 | the format used for Path in memory is not guaranteed. |
| 5358 | |
| 5359 | #Param buffer storage for Path ## |
| 5360 | #Param length buffer size in bytes; must be multiple of 4 ## |
| 5361 | |
| 5362 | #Return number of bytes read, or zero on failure ## |
| 5363 | |
| 5364 | #Example |
| 5365 | void draw(SkCanvas* canvas) { |
| 5366 | SkPath path, copy; |
| 5367 | path.lineTo(6.f / 7, 2.f / 3); |
| 5368 | size_t size = path.writeToMemory(nullptr); |
| 5369 | SkTDArray<char> storage; |
| 5370 | storage.setCount(size); |
| 5371 | path.writeToMemory(storage.begin()); |
| 5372 | size_t wrongSize = size - 4; |
| 5373 | size_t bytesRead = copy.readFromMemory(storage.begin(), wrongSize); |
| 5374 | SkDebugf("length = %u; returned by readFromMemory = %u\n", wrongSize, bytesRead); |
| 5375 | size_t largerSize = size + 4; |
| 5376 | bytesRead = copy.readFromMemory(storage.begin(), largerSize); |
| 5377 | SkDebugf("length = %u; returned by readFromMemory = %u\n", largerSize, bytesRead); |
| 5378 | } |
| 5379 | #StdOut |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5380 | length = 32; returned by readFromMemory = 0 |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 5381 | length = 40; returned by readFromMemory = 36 |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5382 | ## |
| 5383 | ## |
| 5384 | |
| 5385 | #SeeAlso writeToMemory |
| 5386 | |
| 5387 | ## |
| 5388 | |
| 5389 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5390 | #Subtopic Generation_ID |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 5391 | #Alias Generation_IDs ## |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 5392 | #Line # value reflecting contents change ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5393 | Generation_ID provides a quick way to check if Verb_Array, Point_Array, or |
| 5394 | Conic_Weight has changed. Generation_ID is not a hash; identical Paths will |
| 5395 | not necessarily have matching Generation_IDs. |
| 5396 | |
| 5397 | Empty Paths have a Generation_ID of one. |
| 5398 | |
| 5399 | #Method uint32_t getGenerationID() const |
| 5400 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5401 | #In Generation_ID |
| 5402 | #Line # returns unique ID ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5403 | Returns a non-zero, globally unique value. A different value is returned |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5404 | if Verb_Array, Point_Array, or Conic_Weight changes. |
| 5405 | |
| 5406 | Setting Fill_Type does not change Generation_ID. |
| 5407 | |
| 5408 | Each time the path is modified, a different Generation_ID will be returned. |
| 5409 | |
| 5410 | #Bug 1762 |
| 5411 | Fill_Type does affect Generation_ID on Android framework. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5412 | |
| 5413 | #Return non-zero, globally unique value ## |
| 5414 | |
| 5415 | #Example |
| 5416 | SkPath path; |
| 5417 | SkDebugf("empty genID = %u\n", path.getGenerationID()); |
| 5418 | path.lineTo(1, 2); |
| 5419 | SkDebugf("1st lineTo genID = %u\n", path.getGenerationID()); |
| 5420 | path.rewind(); |
| 5421 | SkDebugf("empty genID = %u\n", path.getGenerationID()); |
| 5422 | path.lineTo(1, 2); |
| 5423 | SkDebugf("2nd lineTo genID = %u\n", path.getGenerationID()); |
| 5424 | #StdOut |
| 5425 | empty genID = 1 |
| 5426 | 1st lineTo genID = 2 |
| 5427 | empty genID = 1 |
| 5428 | 2nd lineTo genID = 3 |
| 5429 | ## |
| 5430 | ## |
| 5431 | |
| 5432 | #SeeAlso operator==(const SkPath& a, const SkPath& b) |
| 5433 | |
| 5434 | ## |
| 5435 | |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5436 | #Subtopic ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5437 | |
| 5438 | # ------------------------------------------------------------------------------ |
| 5439 | |
| 5440 | #Method bool isValid() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 5441 | #In Property |
| 5442 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5443 | #Line # returns if data is internally consistent ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5444 | Returns if Path data is consistent. Corrupt Path data is detected if |
| 5445 | internal values are out of range or internal storage does not match |
| 5446 | array dimensions. |
| 5447 | |
| 5448 | #Return true if Path data is consistent ## |
| 5449 | |
| 5450 | #NoExample |
| 5451 | ## |
| 5452 | |
| 5453 | ## |
| 5454 | |
| 5455 | #Method bool pathRefIsValid() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 5456 | #Deprecated soon |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5457 | ## |
| 5458 | |
| 5459 | # ------------------------------------------------------------------------------ |
| 5460 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5461 | #Class Iter |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5462 | #Line # data iterator ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5463 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5464 | #Code |
| 5465 | class Iter { |
| 5466 | public: |
| 5467 | Iter(); |
| 5468 | Iter(const SkPath& path, bool forceClose); |
| 5469 | void setPath(const SkPath& path, bool forceClose); |
| 5470 | Verb next(SkPoint pts[4], bool doConsumeDegenerates = true, bool exact = false); |
| 5471 | SkScalar conicWeight() const; |
| 5472 | bool isCloseLine() const; |
| 5473 | bool isClosedContour() const; |
| 5474 | }; |
| 5475 | ## |
| 5476 | |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 5477 | Iterates through Verb_Array, and associated Point_Array and Conic_Weight. |
| 5478 | Provides options to treat open Contours as closed, and to ignore |
| 5479 | degenerate data. |
| 5480 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5481 | #Example |
| 5482 | #Height 128 |
| 5483 | #Description |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5484 | Ignoring the actual Verbs and replacing them with Quads rounds the |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5485 | path of the glyph. |
| 5486 | ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5487 | void draw(SkCanvas* canvas) { |
| 5488 | SkPaint paint; |
| 5489 | paint.setAntiAlias(true); |
| 5490 | paint.setTextSize(256); |
| 5491 | SkPath asterisk, path; |
| 5492 | paint.getTextPath("*", 1, 50, 192, &asterisk); |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5493 | SkPath::Iter iter(asterisk, true); |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5494 | SkPoint start[4], pts[4]; |
| 5495 | iter.next(start); // skip moveTo |
| 5496 | iter.next(start); // first quadTo |
| 5497 | path.moveTo((start[0] + start[1]) * 0.5f); |
| 5498 | while (SkPath::kClose_Verb != iter.next(pts)) { |
| 5499 | path.quadTo(pts[0], (pts[0] + pts[1]) * 0.5f); |
| 5500 | } |
| 5501 | path.quadTo(start[0], (start[0] + start[1]) * 0.5f); |
| 5502 | canvas->drawPath(path, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5503 | } |
| 5504 | ## |
| 5505 | |
| 5506 | #SeeAlso RawIter |
| 5507 | |
| 5508 | #Method Iter() |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5509 | #Line # constructs Path iterator ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5510 | Initializes Iter with an empty Path. next() on Iter returns kDone_Verb. |
| 5511 | Call setPath to initialize Iter at a later time. |
| 5512 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5513 | #Return Iter of empty Path ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5514 | |
| 5515 | #Example |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5516 | void draw(SkCanvas* canvas) { |
| 5517 | SkPath::Iter iter; |
| 5518 | SkPoint points[4]; |
| 5519 | SkDebugf("iter is " "%s" "done\n", SkPath::kDone_Verb == iter.next(points) ? "" : "not "); |
| 5520 | SkPath path; |
| 5521 | iter.setPath(path, false); |
| 5522 | SkDebugf("iter is " "%s" "done\n", SkPath::kDone_Verb == iter.next(points) ? "" : "not "); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5523 | } |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5524 | #StdOut |
| 5525 | iter is done |
| 5526 | iter is done |
| 5527 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5528 | ## |
| 5529 | |
| 5530 | #SeeAlso setPath |
| 5531 | |
| 5532 | ## |
| 5533 | |
| 5534 | #Method Iter(const SkPath& path, bool forceClose) |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 5535 | #Line # constructs Path iterator ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5536 | |
| 5537 | Sets Iter to return elements of Verb_Array, Point_Array, and Conic_Weight in path. |
| 5538 | If forceClose is true, Iter will add kLine_Verb and kClose_Verb after each |
| 5539 | open Contour. path is not altered. |
| 5540 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5541 | #Param path Path to iterate ## |
| 5542 | #Param forceClose true if open Contours generate kClose_Verb ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5543 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5544 | #Return Iter of path ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5545 | |
| 5546 | #Example |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5547 | void draw(SkCanvas* canvas) { |
| 5548 | auto debugster = [](const char* prefix, SkPath::Iter& iter) -> void { |
| 5549 | SkDebugf("%s:\n", prefix); |
| 5550 | const char* verbStr[] = { "Move", "Line", "Quad", "Conic", "Cubic", "Close", "Done" }; |
| 5551 | const int pointCount[] = { 1 , 2 , 3 , 3 , 4 , 1 , 0 }; |
| 5552 | SkPath::Verb verb; |
| 5553 | do { |
| 5554 | SkPoint points[4]; |
| 5555 | verb = iter.next(points); |
| 5556 | SkDebugf("k%s_Verb ", verbStr[(int) verb]); |
| 5557 | for (int i = 0; i < pointCount[(int) verb]; ++i) { |
| 5558 | SkDebugf("{%g, %g}, ", points[i].fX, points[i].fY); |
| 5559 | } |
| 5560 | if (SkPath::kConic_Verb == verb) { |
| 5561 | SkDebugf("weight = %g", iter.conicWeight()); |
| 5562 | } |
| 5563 | SkDebugf("\n"); |
| 5564 | } while (SkPath::kDone_Verb != verb); |
| 5565 | SkDebugf("\n"); |
| 5566 | }; |
| 5567 | |
| 5568 | SkPath path; |
| 5569 | path.quadTo(10, 20, 30, 40); |
| 5570 | SkPath::Iter openIter(path, false); |
| 5571 | debugster("open", openIter); |
| 5572 | SkPath::Iter closedIter(path, true); |
| 5573 | debugster("closed", closedIter); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5574 | } |
| 5575 | #StdOut |
| 5576 | open: |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5577 | kMove_Verb {0, 0}, |
| 5578 | kQuad_Verb {0, 0}, {10, 20}, {30, 40}, |
| 5579 | kDone_Verb |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5580 | |
| 5581 | closed: |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5582 | kMove_Verb {0, 0}, |
| 5583 | kQuad_Verb {0, 0}, {10, 20}, {30, 40}, |
| 5584 | kLine_Verb {30, 40}, {0, 0}, |
| 5585 | kClose_Verb {0, 0}, |
| 5586 | kDone_Verb |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5587 | ## |
| 5588 | ## |
| 5589 | |
| 5590 | #SeeAlso setPath |
| 5591 | |
| 5592 | ## |
| 5593 | |
| 5594 | #Method void setPath(const SkPath& path, bool forceClose) |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 5595 | #Line # resets Iter to Path ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5596 | Sets Iter to return elements of Verb_Array, Point_Array, and Conic_Weight in path. |
| 5597 | If forceClose is true, Iter will add kLine_Verb and kClose_Verb after each |
| 5598 | open Contour. path is not altered. |
| 5599 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5600 | #Param path Path to iterate ## |
| 5601 | #Param forceClose true if open Contours generate kClose_Verb ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5602 | |
| 5603 | #Example |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5604 | void draw(SkCanvas* canvas) { |
| 5605 | auto debugster = [](const char* prefix, SkPath::Iter& iter) -> void { |
| 5606 | SkDebugf("%s:\n", prefix); |
| 5607 | const char* verbStr[] = { "Move", "Line", "Quad", "Conic", "Cubic", "Close", "Done" }; |
| 5608 | const int pointCount[] = { 1 , 2 , 3 , 3 , 4 , 1 , 0 }; |
| 5609 | SkPath::Verb verb; |
| 5610 | do { |
| 5611 | SkPoint points[4]; |
| 5612 | verb = iter.next(points); |
| 5613 | SkDebugf("k%s_Verb ", verbStr[(int) verb]); |
| 5614 | for (int i = 0; i < pointCount[(int) verb]; ++i) { |
| 5615 | SkDebugf("{%g, %g}, ", points[i].fX, points[i].fY); |
| 5616 | } |
| 5617 | if (SkPath::kConic_Verb == verb) { |
| 5618 | SkDebugf("weight = %g", iter.conicWeight()); |
| 5619 | } |
| 5620 | SkDebugf("\n"); |
| 5621 | } while (SkPath::kDone_Verb != verb); |
| 5622 | SkDebugf("\n"); |
| 5623 | }; |
| 5624 | |
| 5625 | SkPath path; |
| 5626 | path.quadTo(10, 20, 30, 40); |
| 5627 | SkPath::Iter iter(path, false); |
| 5628 | debugster("quad open", iter); |
| 5629 | SkPath path2; |
| 5630 | path2.conicTo(1, 2, 3, 4, .5f); |
| 5631 | iter.setPath(path2, true); |
| 5632 | debugster("conic closed", iter); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5633 | } |
| 5634 | #StdOut |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5635 | quad open: |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5636 | kMove_Verb {0, 0}, |
| 5637 | kQuad_Verb {0, 0}, {10, 20}, {30, 40}, |
| 5638 | kDone_Verb |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5639 | |
| 5640 | conic closed: |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5641 | kMove_Verb {0, 0}, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5642 | kConic_Verb {0, 0}, {1, 2}, {3, 4}, weight = 0.5 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5643 | kLine_Verb {3, 4}, {0, 0}, |
| 5644 | kClose_Verb {0, 0}, |
| 5645 | kDone_Verb |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5646 | ## |
| 5647 | ## |
| 5648 | |
| 5649 | #SeeAlso Iter(const SkPath& path, bool forceClose) |
| 5650 | |
| 5651 | ## |
| 5652 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5653 | #Method Verb next(SkPoint pts[4], bool doConsumeDegenerates = true, bool exact = false) |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 5654 | #Line # returns next Verb ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5655 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 5656 | Returns next Verb in Verb_Array, and advances Iter. |
| 5657 | When Verb_Array is exhausted, returns kDone_Verb. |
| 5658 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5659 | Zero to four Points are stored in pts, depending on the returned Verb. |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 5660 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5661 | If doConsumeDegenerates is true, skip consecutive kMove_Verb entries, returning |
| 5662 | only the last in the series; and skip very small Lines, Quads, and Conics; and |
| 5663 | skip kClose_Verb following kMove_Verb. |
| 5664 | if doConsumeDegenerates is true and exact is true, only skip Lines, Quads, and |
| 5665 | Conics with zero lengths. |
| 5666 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 5667 | #Param pts storage for Point data describing returned Verb ## |
| 5668 | #Param doConsumeDegenerates if true, skip degenerate Verbs ## |
| 5669 | #Param exact skip zero length curves ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5670 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5671 | #Return next Verb from Verb_Array ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5672 | |
| 5673 | #Example |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5674 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5675 | skip degenerate skips the first in a kMove_Verb pair, the kMove_Verb |
| 5676 | followed by the kClose_Verb, the zero length Line and the very small Line. |
| 5677 | |
| 5678 | skip degenerate if exact skips the same as skip degenerate, but shows |
| 5679 | the very small Line. |
| 5680 | |
| 5681 | skip none shows all of the Verbs and Points in Path. |
| 5682 | ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5683 | void draw(SkCanvas* canvas) { |
| 5684 | auto debugster = [](const char* prefix, const SkPath& path, bool degen, bool exact) -> void { |
| 5685 | SkPath::Iter iter(path, false); |
| 5686 | SkDebugf("%s:\n", prefix); |
| 5687 | const char* verbStr[] = { "Move", "Line", "Quad", "Conic", "Cubic", "Close", "Done" }; |
| 5688 | const int pointCount[] = { 1 , 2 , 3 , 3 , 4 , 1 , 0 }; |
| 5689 | SkPath::Verb verb; |
| 5690 | do { |
| 5691 | SkPoint points[4]; |
| 5692 | verb = iter.next(points, degen, exact); |
| 5693 | SkDebugf("k%s_Verb ", verbStr[(int) verb]); |
| 5694 | for (int i = 0; i < pointCount[(int) verb]; ++i) { |
| 5695 | SkDebugf("{%1.8g, %1.8g}, ", points[i].fX, points[i].fY); |
| 5696 | } |
| 5697 | SkDebugf("\n"); |
| 5698 | } while (SkPath::kDone_Verb != verb); |
| 5699 | SkDebugf("\n"); |
| 5700 | }; |
| 5701 | |
| 5702 | SkPath path; |
| 5703 | path.moveTo(10, 10); |
| 5704 | path.moveTo(20, 20); |
| 5705 | path.quadTo(10, 20, 30, 40); |
| 5706 | path.moveTo(1, 1); |
| 5707 | path.close(); |
| 5708 | path.moveTo(30, 30); |
| 5709 | path.lineTo(30, 30); |
| 5710 | path.moveTo(30, 30); |
| 5711 | path.lineTo(30.00001f, 30); |
| 5712 | debugster("skip degenerate", path, true, false); |
| 5713 | debugster("skip degenerate if exact", path, true, true); |
| 5714 | debugster("skip none", path, false, false); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5715 | } |
| 5716 | #StdOut |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5717 | skip degenerate: |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5718 | kMove_Verb {20, 20}, |
| 5719 | kQuad_Verb {20, 20}, {10, 20}, {30, 40}, |
| 5720 | kDone_Verb |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5721 | |
| 5722 | skip degenerate if exact: |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5723 | kMove_Verb {20, 20}, |
| 5724 | kQuad_Verb {20, 20}, {10, 20}, {30, 40}, |
| 5725 | kMove_Verb {30, 30}, |
| 5726 | kLine_Verb {30, 30}, {30.00001, 30}, |
| 5727 | kDone_Verb |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5728 | |
| 5729 | skip none: |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5730 | kMove_Verb {10, 10}, |
| 5731 | kMove_Verb {20, 20}, |
| 5732 | kQuad_Verb {20, 20}, {10, 20}, {30, 40}, |
| 5733 | kMove_Verb {1, 1}, |
| 5734 | kClose_Verb {1, 1}, |
| 5735 | kMove_Verb {30, 30}, |
| 5736 | kLine_Verb {30, 30}, {30, 30}, |
| 5737 | kMove_Verb {30, 30}, |
| 5738 | kLine_Verb {30, 30}, {30.00001, 30}, |
| 5739 | kDone_Verb |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5740 | ## |
| 5741 | ## |
| 5742 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5743 | #SeeAlso Verb IsLineDegenerate IsCubicDegenerate IsQuadDegenerate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5744 | |
| 5745 | ## |
| 5746 | |
| 5747 | #Method SkScalar conicWeight() const |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 5748 | #Line # returns Conic_Weight ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5749 | Returns Conic_Weight if next() returned kConic_Verb. |
| 5750 | |
| 5751 | If next() has not been called, or next() did not return kConic_Verb, |
| 5752 | result is undefined. |
| 5753 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5754 | #Return Conic_Weight for Conic Points returned by next() ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5755 | |
| 5756 | #Example |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5757 | void draw(SkCanvas* canvas) { |
| 5758 | SkPath path; |
| 5759 | path.conicTo(1, 2, 3, 4, .5f); |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5760 | SkPath::Iter iter(path, false); |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5761 | SkPoint p[4]; |
| 5762 | SkDebugf("first verb is " "%s" "move\n", SkPath::kMove_Verb == iter.next(p) ? "" : "not "); |
| 5763 | SkDebugf("next verb is " "%s" "conic\n", SkPath::kConic_Verb == iter.next(p) ? "" : "not "); |
| 5764 | SkDebugf("conic points: {%g,%g}, {%g,%g}, {%g,%g}\n", p[0].fX, p[0].fY, p[1].fX, p[1].fY, |
| 5765 | p[2].fX, p[2].fY); |
| 5766 | SkDebugf("conic weight: %g\n", iter.conicWeight()); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5767 | } |
| 5768 | #StdOut |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5769 | first verb is move |
| 5770 | next verb is conic |
| 5771 | conic points: {0,0}, {1,2}, {3,4} |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5772 | conic weight: 0.5 |
| 5773 | ## |
| 5774 | ## |
| 5775 | |
| 5776 | #SeeAlso Conic_Weight |
| 5777 | |
| 5778 | ## |
| 5779 | |
| 5780 | #Method bool isCloseLine() const |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5781 | #Line # returns if Line was generated by kClose_Verb ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5782 | Returns true if last kLine_Verb returned by next() was generated |
| 5783 | by kClose_Verb. When true, the end point returned by next() is |
| 5784 | also the start point of Contour. |
| 5785 | |
| 5786 | If next() has not been called, or next() did not return kLine_Verb, |
| 5787 | result is undefined. |
| 5788 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5789 | #Return true if last kLine_Verb was generated by kClose_Verb ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5790 | |
| 5791 | #Example |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5792 | void draw(SkCanvas* canvas) { |
| 5793 | SkPath path; |
| 5794 | path.moveTo(6, 7); |
| 5795 | path.conicTo(1, 2, 3, 4, .5f); |
| 5796 | path.close(); |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5797 | SkPath::Iter iter(path, false); |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5798 | SkPoint p[4]; |
| 5799 | SkDebugf("1st verb is " "%s" "move\n", SkPath::kMove_Verb == iter.next(p) ? "" : "not "); |
| 5800 | SkDebugf("moveTo point: {%g,%g}\n", p[0].fX, p[0].fY); |
| 5801 | SkDebugf("2nd verb is " "%s" "conic\n", SkPath::kConic_Verb == iter.next(p) ? "" : "not "); |
| 5802 | SkDebugf("3rd verb is " "%s" "line\n", SkPath::kLine_Verb == iter.next(p) ? "" : "not "); |
| 5803 | SkDebugf("line points: {%g,%g}, {%g,%g}\n", p[0].fX, p[0].fY, p[1].fX, p[1].fY); |
| 5804 | SkDebugf("line " "%s" "generated by close\n", iter.isCloseLine() ? "" : "not "); |
| 5805 | SkDebugf("4th verb is " "%s" "close\n", SkPath::kClose_Verb == iter.next(p) ? "" : "not "); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5806 | } |
| 5807 | #StdOut |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5808 | 1st verb is move |
| 5809 | moveTo point: {6,7} |
| 5810 | 2nd verb is conic |
| 5811 | 3rd verb is line |
| 5812 | line points: {3,4}, {6,7} |
| 5813 | line generated by close |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5814 | 4th verb is close |
| 5815 | ## |
| 5816 | ## |
| 5817 | |
| 5818 | #SeeAlso close() |
| 5819 | ## |
| 5820 | |
| 5821 | #Method bool isClosedContour() const |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5822 | #Line # returns if Contour has kClose_Verb ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5823 | Returns true if subsequent calls to next() return kClose_Verb before returning |
| 5824 | kMove_Verb. if true, Contour Iter is processing may end with kClose_Verb, or |
| 5825 | Iter may have been initialized with force close set to true. |
| 5826 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5827 | #Return true if Contour is closed ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5828 | |
| 5829 | #Example |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5830 | void draw(SkCanvas* canvas) { |
| 5831 | for (bool forceClose : { false, true } ) { |
| 5832 | SkPath path; |
| 5833 | path.conicTo(1, 2, 3, 4, .5f); |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5834 | SkPath::Iter iter(path, forceClose); |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5835 | SkDebugf("without close(), forceClose is %s: isClosedContour returns %s\n", |
| 5836 | forceClose ? "true " : "false", iter.isClosedContour() ? "true" : "false"); |
| 5837 | path.close(); |
| 5838 | iter.setPath(path, forceClose); |
| 5839 | SkDebugf("with close(), forceClose is %s: isClosedContour returns %s\n", |
| 5840 | forceClose ? "true " : "false", iter.isClosedContour() ? "true" : "false"); |
| 5841 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5842 | } |
| 5843 | #StdOut |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5844 | without close(), forceClose is false: isClosedContour returns false |
| 5845 | with close(), forceClose is false: isClosedContour returns true |
| 5846 | without close(), forceClose is true : isClosedContour returns true |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5847 | with close(), forceClose is true : isClosedContour returns true |
| 5848 | ## |
| 5849 | ## |
| 5850 | |
| 5851 | #SeeAlso Iter(const SkPath& path, bool forceClose) |
| 5852 | |
| 5853 | ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5854 | |
| 5855 | #Class Iter ## |
| 5856 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5857 | #Class RawIter |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5858 | #Line # raw data iterator ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5859 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5860 | #Code |
| 5861 | class RawIter { |
| 5862 | public: |
| 5863 | RawIter(); |
| 5864 | RawIter(const SkPath& path); |
| 5865 | void setPath(const SkPath& path); |
| 5866 | Verb next(SkPoint pts[4]); |
| 5867 | Verb peek() const; |
| 5868 | SkScalar conicWeight() const; |
| 5869 | } |
| 5870 | ## |
| 5871 | |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 5872 | Iterates through Verb_Array, and associated Point_Array and Conic_Weight. |
| 5873 | Verb_Array, Point_Array, and Conic_Weight are returned unaltered. |
| 5874 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5875 | #Method RawIter() |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5876 | #Line # constructs empty Path iterator ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5877 | |
| 5878 | Initializes RawIter with an empty Path. next() on RawIter returns kDone_Verb. |
Cary Clark | 78c110e | 2018-02-09 16:49:09 -0500 | [diff] [blame] | 5879 | Call setPath to initialize SkPath::Iter at a later time. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5880 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5881 | #Return RawIter of empty Path ## |
| 5882 | |
| 5883 | #NoExample |
| 5884 | ## |
| 5885 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5886 | |
| 5887 | #Method RawIter(const SkPath& path) |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5888 | #Line # constructs with Path to iterate over ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5889 | |
| 5890 | |
| 5891 | Sets RawIter to return elements of Verb_Array, Point_Array, and Conic_Weight in path. |
| 5892 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5893 | #Param path Path to iterate ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5894 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5895 | #Return RawIter of path ## |
| 5896 | |
| 5897 | #NoExample |
| 5898 | ## |
| 5899 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5900 | |
| 5901 | #Method void setPath(const SkPath& path) |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5902 | #Line # sets Path to iterate over ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5903 | |
Cary Clark | 78c110e | 2018-02-09 16:49:09 -0500 | [diff] [blame] | 5904 | Sets SkPath::Iter to return elements of Verb_Array, Point_Array, and Conic_Weight in path. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5905 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5906 | #Param path Path to iterate ## |
| 5907 | |
| 5908 | #NoExample |
| 5909 | ## |
| 5910 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5911 | |
| 5912 | #Method Verb next(SkPoint pts[4]) |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5913 | #Line # returns next Verb and associated Points ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5914 | Returns next Verb in Verb_Array, and advances RawIter. |
| 5915 | When Verb_Array is exhausted, returns kDone_Verb. |
| 5916 | Zero to four Points are stored in pts, depending on the returned Verb. |
| 5917 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 5918 | #Param pts storage for Point data describing returned Verb ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5919 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5920 | #Return next Verb from Verb_Array ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5921 | |
| 5922 | #Example |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5923 | void draw(SkCanvas* canvas) { |
| 5924 | SkPath path; |
| 5925 | path.moveTo(50, 60); |
| 5926 | path.quadTo(10, 20, 30, 40); |
| 5927 | path.close(); |
| 5928 | path.lineTo(30, 30); |
| 5929 | path.conicTo(1, 2, 3, 4, .5f); |
| 5930 | path.cubicTo(-1, -2, -3, -4, -5, -6); |
| 5931 | SkPath::RawIter iter(path); |
| 5932 | const char* verbStr[] = { "Move", "Line", "Quad", "Conic", "Cubic", "Close", "Done" }; |
| 5933 | const int pointCount[] = { 1 , 2 , 3 , 3 , 4 , 1 , 0 }; |
| 5934 | SkPath::Verb verb; |
| 5935 | do { |
| 5936 | SkPoint points[4]; |
| 5937 | verb = iter.next(points); |
| 5938 | SkDebugf("k%s_Verb ", verbStr[(int) verb]); |
| 5939 | for (int i = 0; i < pointCount[(int) verb]; ++i) { |
| 5940 | SkDebugf("{%1.8g, %1.8g}, ", points[i].fX, points[i].fY); |
| 5941 | } |
| 5942 | if (SkPath::kConic_Verb == verb) { |
| 5943 | SkDebugf("weight = %g", iter.conicWeight()); |
| 5944 | } |
| 5945 | SkDebugf("\n"); |
| 5946 | } while (SkPath::kDone_Verb != verb); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5947 | } |
| 5948 | #StdOut |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5949 | kMove_Verb {50, 60}, |
| 5950 | kQuad_Verb {50, 60}, {10, 20}, {30, 40}, |
| 5951 | kClose_Verb {50, 60}, |
| 5952 | kMove_Verb {50, 60}, |
| 5953 | kLine_Verb {50, 60}, {30, 30}, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5954 | kConic_Verb {30, 30}, {1, 2}, {3, 4}, weight = 0.5 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5955 | kCubic_Verb {3, 4}, {-1, -2}, {-3, -4}, {-5, -6}, |
| 5956 | kDone_Verb |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5957 | ## |
| 5958 | ## |
| 5959 | |
| 5960 | #SeeAlso peek() |
| 5961 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5962 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5963 | |
| 5964 | #Method Verb peek() const |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5965 | #Line # returns next Verb ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5966 | Returns next Verb, but does not advance RawIter. |
| 5967 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5968 | #Return next Verb from Verb_Array ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5969 | |
| 5970 | #Example |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5971 | SkPath path; |
| 5972 | path.quadTo(10, 20, 30, 40); |
| 5973 | path.conicTo(1, 2, 3, 4, .5f); |
| 5974 | path.cubicTo(1, 2, 3, 4, .5, 6); |
| 5975 | SkPath::RawIter iter(path); |
| 5976 | SkPath::Verb verb, peek = iter.peek(); |
| 5977 | const char* verbStr[] = { "Move", "Line", "Quad", "Conic", "Cubic", "Close", "Done" }; |
| 5978 | do { |
| 5979 | SkPoint points[4]; |
| 5980 | verb = iter.next(points); |
| 5981 | SkDebugf("peek %s %c= verb %s\n", verbStr[peek], peek == verb ? '=' : '!', verbStr[verb]); |
| 5982 | peek = iter.peek(); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5983 | } while (SkPath::kDone_Verb != verb); |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 5984 | SkDebugf("peek %s %c= verb %s\n", verbStr[peek], peek == verb ? '=' : '!', verbStr[verb]); |
| 5985 | #StdOut |
| 5986 | #Volatile |
| 5987 | peek Move == verb Move |
| 5988 | peek Quad == verb Quad |
| 5989 | peek Conic == verb Conic |
| 5990 | peek Cubic == verb Cubic |
| 5991 | peek Done == verb Done |
| 5992 | peek Done == verb Done |
| 5993 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5994 | ## |
| 5995 | |
| 5996 | #Bug 6832 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5997 | StdOut is not really volatile, it just produces the wrong result. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5998 | A simple fix changes the output of hairlines and needs to be |
| 5999 | investigated to see if the change is correct or not. |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 6000 | see change 21340 (abandoned for now) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6001 | |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 6002 | #SeeAlso next |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6003 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 6004 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6005 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 6006 | #Method SkScalar conicWeight() const |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 6007 | #Line # returns Conic_Weight ## |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 6008 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6009 | Returns Conic_Weight if next() returned kConic_Verb. |
| 6010 | |
| 6011 | If next() has not been called, or next() did not return kConic_Verb, |
| 6012 | result is undefined. |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 6013 | |
| 6014 | #Return Conic_Weight for Conic Points returned by next() ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6015 | |
| 6016 | #Example |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 6017 | void draw(SkCanvas* canvas) { |
| 6018 | SkPath path; |
| 6019 | path.conicTo(1, 2, 3, 4, .5f); |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 6020 | SkPath::RawIter iter(path); |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 6021 | SkPoint p[4]; |
| 6022 | SkDebugf("first verb is " "%s" "move\n", SkPath::kMove_Verb == iter.next(p) ? "" : "not "); |
| 6023 | SkDebugf("next verb is " "%s" "conic\n", SkPath::kConic_Verb == iter.next(p) ? "" : "not "); |
| 6024 | SkDebugf("conic points: {%g,%g}, {%g,%g}, {%g,%g}\n", p[0].fX, p[0].fY, p[1].fX, p[1].fY, |
| 6025 | p[2].fX, p[2].fY); |
| 6026 | SkDebugf("conic weight: %g\n", iter.conicWeight()); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6027 | } |
| 6028 | #StdOut |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 6029 | first verb is move |
| 6030 | next verb is conic |
| 6031 | conic points: {0,0}, {1,2}, {3,4} |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6032 | conic weight: 0.5 |
| 6033 | ## |
| 6034 | ## |
| 6035 | |
| 6036 | #SeeAlso Conic_Weight |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 6037 | |
| 6038 | ## |
| 6039 | |
| 6040 | #Class RawIter ## |
| 6041 | |
| 6042 | #Class SkPath ## |
| 6043 | |
| 6044 | #Topic Path ## |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 6045 | |