OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
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 #ifndef SkPathWriter_DEFINED | 7 #ifndef SkPathWriter_DEFINED |
8 #define SkPathWriter_DEFINED | 8 #define SkPathWriter_DEFINED |
9 | 9 |
10 #include "SkPath.h" | 10 #include "SkPath.h" |
| 11 #include "SkTArray.h" |
| 12 #include "SkTDArray.h" |
| 13 |
| 14 class SkOpPtT; |
| 15 |
| 16 // Construct the path one contour at a time. |
| 17 // If the contour is closed, copy it to the final output. |
| 18 // Otherwise, keep the partial contour for later assembly. |
11 | 19 |
12 class SkPathWriter { | 20 class SkPathWriter { |
13 public: | 21 public: |
14 SkPathWriter(SkPath& path); | 22 SkPathWriter(SkPath& path); |
15 void close(); | 23 void assemble(); |
16 void conicTo(const SkPoint& pt1, const SkPoint& pt2, SkScalar weight); | 24 void conicTo(const SkPoint& pt1, const SkOpPtT* pt2, SkScalar weight); |
17 void cubicTo(const SkPoint& pt1, const SkPoint& pt2, const SkPoint& pt3); | 25 void cubicTo(const SkPoint& pt1, const SkPoint& pt2, const SkOpPtT* pt3); |
18 void deferredLine(const SkPoint& pt); | 26 void deferredLine(const SkOpPtT* pt); |
19 void deferredMove(const SkPoint& pt); | 27 void deferredMove(const SkOpPtT* pt); |
20 void deferredMoveLine(const SkPoint& pt); | 28 void finishContour(); |
21 bool hasMove() const; | 29 bool hasMove() const { return !fFirstPtT; } |
22 void init(); | 30 void init(); |
23 bool isClosed() const; | 31 bool isClosed() const; |
24 bool isEmpty() const { return fEmpty; } | 32 const SkPath* nativePath() const { return fPathPtr; } |
25 void lineTo(); | 33 void quadTo(const SkPoint& pt1, const SkOpPtT* pt2); |
26 const SkPath* nativePath() const; | |
27 void nudge(); | |
28 void quadTo(const SkPoint& pt1, const SkPoint& pt2); | |
29 bool someAssemblyRequired() const; | |
30 | 34 |
31 private: | 35 private: |
32 bool changedSlopes(const SkPoint& pt) const; | 36 bool changedSlopes(const SkOpPtT* pt) const; |
| 37 void close(); |
| 38 const SkTDArray<const SkOpPtT*>& endPtTs() const { return fEndPtTs; } |
| 39 void lineTo(); |
| 40 bool matchedLast(const SkOpPtT*) const; |
33 void moveTo(); | 41 void moveTo(); |
| 42 const SkTArray<SkPath>& partials() const { return fPartials; } |
| 43 bool someAssemblyRequired(); |
| 44 void update(const SkOpPtT* pt); |
34 | 45 |
35 SkPath* fPathPtr; | 46 SkPath fCurrent; // contour under construction |
36 SkPoint fDefer[2]; | 47 SkTArray<SkPath> fPartials; // contours with mismatched starts and ends |
37 SkPoint fFirstPt; | 48 SkTDArray<const SkOpPtT*> fEndPtTs; // possible pt values for partial start
s and ends |
38 int fCloses; | 49 SkPath* fPathPtr; // closed contours are written here |
39 int fMoves; | 50 const SkOpPtT* fDefer[2]; // [0] deferred move, [1] deferred line |
40 bool fEmpty; | 51 const SkOpPtT* fFirstPtT; // first in current contour |
41 bool fHasMove; | |
42 bool fMoved; | |
43 }; | 52 }; |
44 | 53 |
45 #endif /* defined(__PathOps__SkPathWriter__) */ | 54 #endif /* defined(__PathOps__SkPathWriter__) */ |
OLD | NEW |