| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkPath_DEFINED | 8 #ifndef SkPath_DEFINED |
| 9 #define SkPath_DEFINED | 9 #define SkPath_DEFINED |
| 10 | 10 |
| 11 #include "SkMatrix.h" | 11 #include "SkMatrix.h" |
| 12 #include "SkPathRef.h" | 12 #include "SkPathRef.h" |
| 13 #include "SkRefCnt.h" | 13 #include "SkRefCnt.h" |
| 14 | 14 |
| 15 class SkReader32; | 15 class SkReader32; |
| 16 class SkWriter32; | 16 class SkWriter32; |
| 17 class SkAutoPathBoundsUpdate; | 17 class SkAutoPathBoundsUpdate; |
| 18 class SkString; | 18 class SkString; |
| 19 class SkRRect; | 19 class SkRRect; |
| 20 class SkWStream; | 20 class SkWStream; |
| 21 | 21 |
| 22 /** \class SkPath | 22 /** \class SkPath |
| 23 | 23 |
| 24 The SkPath class encapsulates compound (multiple contour) geometric paths | 24 The SkPath class encapsulates compound (multiple contour) geometric paths |
| 25 consisting of straight line segments, quadratic curves, and cubic curves. | 25 consisting of straight line segments, quadratic curves, and cubic curves. |
| 26 */ | 26 */ |
| 27 class SK_API SkPath { | 27 class SK_API SkPath { |
| 28 public: | 28 public: |
| 29 enum Direction { |
| 30 /** clockwise direction for adding closed contours */ |
| 31 kCW_Direction, |
| 32 /** counter-clockwise direction for adding closed contours */ |
| 33 kCCW_Direction, |
| 34 }; |
| 35 |
| 29 SkPath(); | 36 SkPath(); |
| 30 SkPath(const SkPath&); | 37 SkPath(const SkPath&); |
| 31 ~SkPath(); | 38 ~SkPath(); |
| 32 | 39 |
| 33 SkPath& operator=(const SkPath&); | 40 SkPath& operator=(const SkPath&); |
| 34 friend SK_API bool operator==(const SkPath&, const SkPath&); | 41 friend SK_API bool operator==(const SkPath&, const SkPath&); |
| 35 friend bool operator!=(const SkPath& a, const SkPath& b) { | 42 friend bool operator!=(const SkPath& a, const SkPath& b) { |
| 36 return !(a == b); | 43 return !(a == b); |
| 37 } | 44 } |
| 38 | 45 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 */ | 166 */ |
| 160 SK_ATTR_DEPRECATED("use setConvexity") | 167 SK_ATTR_DEPRECATED("use setConvexity") |
| 161 void setIsConvex(bool isConvex) { | 168 void setIsConvex(bool isConvex) { |
| 162 this->setConvexity(isConvex ? kConvex_Convexity : kConcave_Convexity); | 169 this->setConvexity(isConvex ? kConvex_Convexity : kConcave_Convexity); |
| 163 } | 170 } |
| 164 | 171 |
| 165 /** Returns true if the path is an oval. | 172 /** Returns true if the path is an oval. |
| 166 * | 173 * |
| 167 * @param rect returns the bounding rect of this oval. It's a circle | 174 * @param rect returns the bounding rect of this oval. It's a circle |
| 168 * if the height and width are the same. | 175 * if the height and width are the same. |
| 169 * | 176 * @param dir is the oval CCW (or CW if false). |
| 177 * @param start indicates where the contour starts on the oval (see |
| 178 * SkPath::addOval for intepretation of the index). |
| 170 * @return true if this path is an oval. | 179 * @return true if this path is an oval. |
| 171 * Tracking whether a path is an oval is considered an | 180 * Tracking whether a path is an oval is considered an |
| 172 * optimization for performance and so some paths that are in | 181 * optimization for performance and so some paths that are in |
| 173 * fact ovals can report false. | 182 * fact ovals can report false. |
| 174 */ | 183 */ |
| 175 bool isOval(SkRect* rect) const { return fPathRef->isOval(rect); } | 184 bool isOval(SkRect* rect, Direction* dir = nullptr, |
| 185 unsigned* start = nullptr) const { |
| 186 bool isCCW; |
| 187 bool result = fPathRef->isOval(rect, &isCCW, start); |
| 188 if (dir && result) { |
| 189 *dir = isCCW ? kCCW_Direction : kCW_Direction; |
| 190 } |
| 191 return result; |
| 192 } |
| 176 | 193 |
| 177 /** Returns true if the path is a round rect. | 194 /** Returns true if the path is a round rect. |
| 178 * | 195 * |
| 179 * @param rrect Returns the bounding rect and radii of this round rect. | 196 * @param rrect Returns the bounding rect and radii of this round rect. |
| 197 * @param dir is the rrect CCW (or CW if false). |
| 198 * @param start indicates where the contour starts on the rrect (see |
| 199 * SkPath::addRRect for intepretation of the index). |
| 180 * | 200 * |
| 181 * @return true if this path is a round rect. | 201 * @return true if this path is a round rect. |
| 182 * Tracking whether a path is a round rect is considered an | 202 * Tracking whether a path is a round rect is considered an |
| 183 * optimization for performance and so some paths that are in | 203 * optimization for performance and so some paths that are in |
| 184 * fact round rects can report false. | 204 * fact round rects can report false. |
| 185 */ | 205 */ |
| 186 bool isRRect(SkRRect* rrect) const { return fPathRef->isRRect(rrect); } | 206 bool isRRect(SkRRect* rrect, Direction* dir = nullptr, |
| 207 unsigned* start = nullptr) const { |
| 208 bool isCCW; |
| 209 bool result = fPathRef->isRRect(rrect, &isCCW, start); |
| 210 if (dir && result) { |
| 211 *dir = isCCW ? kCCW_Direction : kCW_Direction; |
| 212 } |
| 213 return result; |
| 214 } |
| 187 | 215 |
| 188 /** Clear any lines and curves from the path, making it empty. This frees up | 216 /** Clear any lines and curves from the path, making it empty. This frees up |
| 189 internal storage associated with those segments. | 217 internal storage associated with those segments. |
| 190 On Android, does not change fSourcePath. | 218 On Android, does not change fSourcePath. |
| 191 */ | 219 */ |
| 192 void reset(); | 220 void reset(); |
| 193 | 221 |
| 194 /** Similar to reset(), in that all lines and curves are removed from the | 222 /** Similar to reset(), in that all lines and curves are removed from the |
| 195 path. However, any internal storage for those lines/curves is retained, | 223 path. However, any internal storage for those lines/curves is retained, |
| 196 making reuse of the path potentially faster. | 224 making reuse of the path potentially faster. |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 this->arcTo(p1.fX, p1.fY, p2.fX, p2.fY, radius); | 547 this->arcTo(p1.fX, p1.fY, p2.fX, p2.fY, radius); |
| 520 } | 548 } |
| 521 | 549 |
| 522 enum ArcSize { | 550 enum ArcSize { |
| 523 /** the smaller of the two possible SVG arcs. */ | 551 /** the smaller of the two possible SVG arcs. */ |
| 524 kSmall_ArcSize, | 552 kSmall_ArcSize, |
| 525 /** the larger of the two possible SVG arcs. */ | 553 /** the larger of the two possible SVG arcs. */ |
| 526 kLarge_ArcSize, | 554 kLarge_ArcSize, |
| 527 }; | 555 }; |
| 528 | 556 |
| 529 enum Direction { | |
| 530 /** clockwise direction for adding closed contours */ | |
| 531 kCW_Direction, | |
| 532 /** counter-clockwise direction for adding closed contours */ | |
| 533 kCCW_Direction, | |
| 534 }; | |
| 535 | |
| 536 /** | 557 /** |
| 537 * Append an elliptical arc from the current point in the format used by SV
G. | 558 * Append an elliptical arc from the current point in the format used by SV
G. |
| 538 * The center of the ellipse is computed to satisfy the constraints below. | 559 * The center of the ellipse is computed to satisfy the constraints below. |
| 539 * | 560 * |
| 540 * @param rx,ry The radii in the x and y directions respectively. | 561 * @param rx,ry The radii in the x and y directions respectively. |
| 541 * @param xAxisRotate The angle in degrees relative to the x-axis. | 562 * @param xAxisRotate The angle in degrees relative to the x-axis. |
| 542 * @param largeArc Determines whether the smallest or largest arc possible | 563 * @param largeArc Determines whether the smallest or largest arc possible |
| 543 * is drawn. | 564 * is drawn. |
| 544 * @param sweep Determines if the arc should be swept in an anti-clockwise
or | 565 * @param sweep Determines if the arc should be swept in an anti-clockwise
or |
| 545 * clockwise direction. Note that this enum value is opposite the SV
G | 566 * clockwise direction. Note that this enum value is opposite the SV
G |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 * -*- | 731 * -*- |
| 711 * | | | 732 * | | |
| 712 * 3 * * 1 | 733 * 3 * * 1 |
| 713 * | | | 734 * | | |
| 714 * -*- | 735 * -*- |
| 715 * 2 | 736 * 2 |
| 716 */ | 737 */ |
| 717 void addOval(const SkRect& oval, Direction dir, unsigned start); | 738 void addOval(const SkRect& oval, Direction dir, unsigned start); |
| 718 | 739 |
| 719 /** | 740 /** |
| 720 * Add a closed circle contour to the path | 741 * Add a closed circle contour to the path. The circle contour begins at |
| 742 * the right-most point (as though 1 were passed to addOval's 'start' param
). |
| 721 * | 743 * |
| 722 * @param x The x-coordinate of the center of a circle to add as a | 744 * @param x The x-coordinate of the center of a circle to add as a |
| 723 * closed contour to the path | 745 * closed contour to the path |
| 724 * @param y The y-coordinate of the center of a circle to add as a | 746 * @param y The y-coordinate of the center of a circle to add as a |
| 725 * closed contour to the path | 747 * closed contour to the path |
| 726 * @param radius The radius of a circle to add as a closed contour to the | 748 * @param radius The radius of a circle to add as a closed contour to the |
| 727 * path | 749 * path |
| 728 * @param dir The direction to wind the circle's contour. | 750 * @param dir The direction to wind the circle's contour. |
| 729 */ | 751 */ |
| 730 void addCircle(SkScalar x, SkScalar y, SkScalar radius, | 752 void addCircle(SkScalar x, SkScalar y, SkScalar radius, |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1167 | 1189 |
| 1168 friend class SkAutoPathBoundsUpdate; | 1190 friend class SkAutoPathBoundsUpdate; |
| 1169 friend class SkAutoDisableOvalCheck; | 1191 friend class SkAutoDisableOvalCheck; |
| 1170 friend class SkAutoDisableDirectionCheck; | 1192 friend class SkAutoDisableDirectionCheck; |
| 1171 friend class SkBench_AddPathTest; // perf test reversePathTo | 1193 friend class SkBench_AddPathTest; // perf test reversePathTo |
| 1172 friend class PathTest_Private; // unit test reversePathTo | 1194 friend class PathTest_Private; // unit test reversePathTo |
| 1173 friend class ForceIsRRect_Private; // unit test isRRect | 1195 friend class ForceIsRRect_Private; // unit test isRRect |
| 1174 }; | 1196 }; |
| 1175 | 1197 |
| 1176 #endif | 1198 #endif |
| OLD | NEW |