diff --git a/include/core/SkPath.h b/include/core/SkPath.h index 16cc1f46d..98c79a644 100644 --- a/include/core/SkPath.h +++ b/include/core/SkPath.h @@ -623,11 +623,17 @@ public: /** Iterate through all of the segments (lines, quadratics, cubics) of each contours in a path. + + The iterator cleans up the segments along the way, removing degenerate + segments and adding close verbs where necessary. When the forceClose + argument is provided, each contour (as defined by a new starting + move command) will be completed with a close verb regardless of the + contour's contents. */ class SK_API Iter { public: - Iter(); - Iter(const SkPath&, bool forceClose); + Iter(); + Iter(const SkPath&, bool forceClose); void setPath(const SkPath&, bool forceClose); diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp index 7e6ac8c22..22860bf61 100644 --- a/src/core/SkPath.cpp +++ b/src/core/SkPath.cpp @@ -1185,9 +1185,10 @@ void SkPath::Iter::setPath(const SkPath& path, bool forceClose) { fVerbs = path.fVerbs.begin(); fVerbStop = path.fVerbs.end(); fLastPt.fX = fLastPt.fY = 0; + fMoveTo.fX = fMoveTo.fY = 0; fForceClose = SkToU8(forceClose); fNeedClose = false; - fSegmentState = kAfterPrimitive_SegmentState; + fSegmentState = kAfterClose_SegmentState; } bool SkPath::Iter::isClosedContour() const { @@ -1279,10 +1280,6 @@ void SkPath::Iter::consumeDegenerateSegments() { unsigned verb = *fVerbs; switch (verb) { case kMove_Verb: - // Set state for the next method. - fSegmentState = kAfterMove_SegmentState; - fMoveTo = fPts[0]; - // Keep a record of this most recent move lastMoveVerb = fVerbs; lastMovePt = fPts; @@ -1385,16 +1382,13 @@ SkPath::Verb SkPath::Iter::next(SkPoint pts[4]) { if (fVerbs == fVerbStop) { // might be a trailing moveto return kDone_Verb; } -#ifdef SK_OLD_EMPTY_PATH_BEHAVIOR fMoveTo = *srcPts; -#endif if (pts) { pts[0] = *srcPts; } srcPts += 1; -#ifdef SK_OLD_EMPTY_PATH_BEHAVIOR fSegmentState = kAfterMove_SegmentState; -#else +#ifndef SK_OLD_EMPTY_PATH_BEHAVIOR fLastPt = fMoveTo; #endif fNeedClose = fForceClose;