diff options
-rw-r--r-- | include/core/SkPathMeasure.h | 10 | ||||
-rw-r--r-- | src/effects/Sk1DPathEffect.cpp | 32 | ||||
-rw-r--r-- | src/effects/SkDiscretePathEffect.cpp | 15 |
3 files changed, 36 insertions, 21 deletions
diff --git a/include/core/SkPathMeasure.h b/include/core/SkPathMeasure.h index 6fb4482ad9..3419e6683f 100644 --- a/include/core/SkPathMeasure.h +++ b/include/core/SkPathMeasure.h @@ -29,7 +29,7 @@ public: a different path (or null), since the measure object keeps a pointer to the path object (does not copy its data). */ - void setPath(const SkPath*, bool forceClosed); + void setPath(const SkPath*, bool forceClosed); /** Return the total length of the current contour, or 0 if no path is associated (e.g. resetPath(null)) @@ -41,19 +41,23 @@ public: Returns false if there is no path, or a zero-length path was specified, in which case position and tangent are unchanged. */ - bool getPosTan(SkScalar distance, SkPoint* position, SkVector* tangent); + bool SK_WARN_UNUSED_RESULT getPosTan(SkScalar distance, SkPoint* position, + SkVector* tangent); enum MatrixFlags { kGetPosition_MatrixFlag = 0x01, kGetTangent_MatrixFlag = 0x02, kGetPosAndTan_MatrixFlag = kGetPosition_MatrixFlag | kGetTangent_MatrixFlag }; + /** Pins distance to 0 <= distance <= getLength(), and then computes the corresponding matrix (by calling getPosTan). Returns false if there is no path, or a zero-length path was specified, in which case matrix is unchanged. */ - bool getMatrix(SkScalar distance, SkMatrix* matrix, MatrixFlags flags = kGetPosAndTan_MatrixFlag); + bool SK_WARN_UNUSED_RESULT getMatrix(SkScalar distance, SkMatrix* matrix, + MatrixFlags flags = kGetPosAndTan_MatrixFlag); + /** Given a start and stop distance, return in dst the intervening segment(s). If the segment is zero-length, return false, else return true. startD and stopD are pinned to legal values (0..getLength()). If startD <= stopD diff --git a/src/effects/Sk1DPathEffect.cpp b/src/effects/Sk1DPathEffect.cpp index 108653846a..09e8d135b6 100644 --- a/src/effects/Sk1DPathEffect.cpp +++ b/src/effects/Sk1DPathEffect.cpp @@ -75,7 +75,7 @@ bool SkPath1DPathEffect::filterPath(SkPath* dst, const SkPath& src, return false; } -static void morphpoints(SkPoint dst[], const SkPoint src[], int count, +static bool morphpoints(SkPoint dst[], const SkPoint src[], int count, SkPathMeasure& meas, SkScalar dist) { for (int i = 0; i < count; i++) { SkPoint pos; @@ -84,7 +84,9 @@ static void morphpoints(SkPoint dst[], const SkPoint src[], int count, SkScalar sx = src[i].fX; SkScalar sy = src[i].fY; - meas.getPosTan(dist + sx, &pos, &tangent); + if (!meas.getPosTan(dist + sx, &pos, &tangent)) { + return false; + } SkMatrix matrix; SkPoint pt; @@ -95,6 +97,7 @@ static void morphpoints(SkPoint dst[], const SkPoint src[], int count, matrix.postTranslate(pos.fX, pos.fY); matrix.mapPoints(&dst[i], &pt, 1); } + return true; } /* TODO @@ -112,8 +115,9 @@ static void morphpath(SkPath* dst, const SkPath& src, SkPathMeasure& meas, while ((verb = iter.next(srcP)) != SkPath::kDone_Verb) { switch (verb) { case SkPath::kMove_Verb: - morphpoints(dstP, srcP, 1, meas, dist); - dst->moveTo(dstP[0]); + if (morphpoints(dstP, srcP, 1, meas, dist)) { + dst->moveTo(dstP[0]); + } break; case SkPath::kLine_Verb: srcP[2] = srcP[1]; @@ -121,12 +125,14 @@ static void morphpath(SkPath* dst, const SkPath& src, SkPathMeasure& meas, SkScalarAve(srcP[0].fY, srcP[2].fY)); // fall through to quad case SkPath::kQuad_Verb: - morphpoints(dstP, &srcP[1], 2, meas, dist); - dst->quadTo(dstP[0], dstP[1]); + if (morphpoints(dstP, &srcP[1], 2, meas, dist)) { + dst->quadTo(dstP[0], dstP[1]); + } break; case SkPath::kCubic_Verb: - morphpoints(dstP, &srcP[1], 3, meas, dist); - dst->cubicTo(dstP[0], dstP[1], dstP[2]); + if (morphpoints(dstP, &srcP[1], 3, meas, dist)) { + dst->cubicTo(dstP[0], dstP[1], dstP[2]); + } break; case SkPath::kClose_Verb: dst->close(); @@ -171,13 +177,15 @@ SkScalar SkPath1DPathEffect::next(SkPath* dst, SkScalar distance, switch (fStyle) { case kTranslate_Style: { SkPoint pos; - meas.getPosTan(distance, &pos, NULL); - dst->addPath(fPath, pos.fX, pos.fY); + if (meas.getPosTan(distance, &pos, NULL)) { + dst->addPath(fPath, pos.fX, pos.fY); + } } break; case kRotate_Style: { SkMatrix matrix; - meas.getMatrix(distance, &matrix); - dst->addPath(fPath, matrix); + if (meas.getMatrix(distance, &matrix)) { + dst->addPath(fPath, matrix); + } } break; case kMorph_Style: morphpath(dst, fPath, meas, distance); diff --git a/src/effects/SkDiscretePathEffect.cpp b/src/effects/SkDiscretePathEffect.cpp index e8c0ec9ad2..06b9d19c68 100644 --- a/src/effects/SkDiscretePathEffect.cpp +++ b/src/effects/SkDiscretePathEffect.cpp @@ -50,14 +50,17 @@ bool SkDiscretePathEffect::filterPath(SkPath* dst, const SkPath& src, n -= 1; distance += delta/2; } - meas.getPosTan(distance, &p, &v); - Perterb(&p, v, SkScalarMul(rand.nextSScalar1(), scale)); - dst->moveTo(p); + + if (meas.getPosTan(distance, &p, &v)) { + Perterb(&p, v, SkScalarMul(rand.nextSScalar1(), scale)); + dst->moveTo(p); + } while (--n >= 0) { distance += delta; - meas.getPosTan(distance, &p, &v); - Perterb(&p, v, SkScalarMul(rand.nextSScalar1(), scale)); - dst->lineTo(p); + if (meas.getPosTan(distance, &p, &v)) { + Perterb(&p, v, SkScalarMul(rand.nextSScalar1(), scale)); + dst->lineTo(p); + } } if (meas.isClosed()) { dst->close(); |