SkPathWriter.h 1.8 KB

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