1 /* 2 * Copyright 2012 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 #ifndef SkPathWriter_DEFINED 8 #define SkPathWriter_DEFINED 9 10 #include "include/core/SkPath.h" 11 #include "include/core/SkPoint.h" 12 #include "include/core/SkScalar.h" 13 #include "include/private/base/SkTArray.h" 14 #include "include/private/base/SkTDArray.h" 15 16 class SkOpPtT; 17 18 // Construct the path one contour at a time. 19 // If the contour is closed, copy it to the final output. 20 // Otherwise, keep the partial contour for later assembly. 21 22 class SkPathWriter { 23 public: 24 SkPathWriter(SkPath& path); 25 void assemble(); 26 void conicTo(const SkPoint& pt1, const SkOpPtT* pt2, SkScalar weight); 27 void cubicTo(const SkPoint& pt1, const SkPoint& pt2, const SkOpPtT* pt3); 28 bool deferredLine(const SkOpPtT* pt); 29 void deferredMove(const SkOpPtT* pt); 30 void finishContour(); hasMove()31 bool hasMove() const { return !fFirstPtT; } 32 void init(); 33 bool isClosed() const; nativePath()34 const SkPath* nativePath() const { return fPathPtr; } 35 void quadTo(const SkPoint& pt1, const SkOpPtT* pt2); 36 37 private: 38 bool changedSlopes(const SkOpPtT* pt) const; 39 void close(); endPtTs()40 const SkTDArray<const SkOpPtT*>& endPtTs() const { return fEndPtTs; } 41 void lineTo(); 42 bool matchedLast(const SkOpPtT*) const; 43 void moveTo(); partials()44 const SkTArray<SkPath>& partials() const { return fPartials; } 45 bool someAssemblyRequired(); 46 SkPoint update(const SkOpPtT* pt); 47 48 SkPath fCurrent; // contour under construction 49 SkTArray<SkPath> fPartials; // contours with mismatched starts and ends 50 SkTDArray<const SkOpPtT*> fEndPtTs; // possible pt values for partial starts and ends 51 SkPath* fPathPtr; // closed contours are written here 52 const SkOpPtT* fDefer[2]; // [0] deferred move, [1] deferred line 53 const SkOpPtT* fFirstPtT; // first in current contour 54 }; 55 56 #endif /* defined(__PathOps__SkPathWriter__) */ 57