• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "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.
19 
20 class SkPathWriter {
21 public:
22     SkPathWriter(SkPath& path);
23     void assemble();
24     void conicTo(const SkPoint& pt1, const SkOpPtT* pt2, SkScalar weight);
25     void cubicTo(const SkPoint& pt1, const SkPoint& pt2, const SkOpPtT* pt3);
26     bool deferredLine(const SkOpPtT* pt);
27     void deferredMove(const SkOpPtT* pt);
28     void finishContour();
hasMove()29     bool hasMove() const { return !fFirstPtT; }
30     void init();
31     bool isClosed() const;
nativePath()32     const SkPath* nativePath() const { return fPathPtr; }
33     void quadTo(const SkPoint& pt1, const SkOpPtT* pt2);
34 
35 private:
36     bool changedSlopes(const SkOpPtT* pt) const;
37     void close();
endPtTs()38     const SkTDArray<const SkOpPtT*>& endPtTs() const { return fEndPtTs; }
39     void lineTo();
40     bool matchedLast(const SkOpPtT*) const;
41     void moveTo();
partials()42     const SkTArray<SkPath>& partials() const { return fPartials; }
43     bool someAssemblyRequired();
44     SkPoint update(const SkOpPtT* pt);
45 
46     SkPath fCurrent;  // contour under construction
47     SkTArray<SkPath> fPartials;   // contours with mismatched starts and ends
48     SkTDArray<const SkOpPtT*> fEndPtTs;  // possible pt values for partial starts and ends
49     SkPath* fPathPtr;  // closed contours are written here
50     const SkOpPtT* fDefer[2];  // [0] deferred move, [1] deferred line
51     const SkOpPtT* fFirstPtT;  // first in current contour
52 };
53 
54 #endif /* defined(__PathOps__SkPathWriter__) */
55