#include "Sk1DPathEffect.h"
#include "SkPathMeasure.h"
-bool Sk1DPathEffect::filterPath(SkPath* dst, const SkPath& src, SkScalar* width)
-{
+bool Sk1DPathEffect::filterPath(SkPath* dst, const SkPath& src, SkScalar* width) {
SkPathMeasure meas(src, false);
do {
SkScalar length = meas.getLength();
SkScalar distance = this->begin(length);
- while (distance < length)
- {
+ while (distance < length) {
SkScalar delta = this->next(dst, distance, meas);
- if (delta <= 0)
+ if (delta <= 0) {
break;
+ }
distance += delta;
}
} while (meas.nextContour());
return true;
}
-///////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
SkPath1DPathEffect::SkPath1DPathEffect(const SkPath& path, SkScalar advance,
SkScalar phase, Style style) : fPath(path)
{
- if (advance <= 0 || path.isEmpty())
- {
+ if (advance <= 0 || path.isEmpty()) {
SkDEBUGF(("SkPath1DPathEffect can't use advance <= 0\n"));
fAdvance = 0; // signals we can't draw anything
- }
- else
- {
+ } else {
// cleanup their phase parameter, inverting it so that it becomes an
// offset along the path (to match the interpretation in PostScript)
- if (phase < 0)
- {
+ if (phase < 0) {
phase = -phase;
- if (phase > advance)
+ if (phase > advance) {
phase = SkScalarMod(phase, advance);
- }
- else
- {
- if (phase > advance)
+ }
+ } else {
+ if (phase > advance) {
phase = SkScalarMod(phase, advance);
+ }
phase = advance - phase;
}
// now catch the edge case where phase == advance (within epsilon)
- if (phase >= advance)
+ if (phase >= advance) {
phase = 0;
+ }
SkASSERT(phase >= 0);
fAdvance = advance;
}
}
-bool SkPath1DPathEffect::filterPath(SkPath* dst, const SkPath& src, SkScalar* width)
-{
- if (fAdvance > 0)
- {
+bool SkPath1DPathEffect::filterPath(SkPath* dst, const SkPath& src,
+ SkScalar* width) {
+ if (fAdvance > 0) {
*width = -1;
return this->INHERITED::filterPath(dst, src, width);
}
}
static void morphpoints(SkPoint dst[], const SkPoint src[], int count,
- SkPathMeasure& meas, SkScalar dist)
-{
- for (int i = 0; i < count; i++)
- {
+ SkPathMeasure& meas, SkScalar dist) {
+ for (int i = 0; i < count; i++) {
SkPoint pos;
SkVector tangent;
determine that, but we need it. I guess a cheap answer is let the caller tell us,
but that seems like a cop-out. Another answer is to get Rob Johnson to figure it out.
*/
-static void morphpath(SkPath* dst, const SkPath& src, SkPathMeasure& meas, SkScalar dist)
-{
+static void morphpath(SkPath* dst, const SkPath& src, SkPathMeasure& meas,
+ SkScalar dist) {
SkPath::Iter iter(src, false);
SkPoint srcP[4], dstP[3];
SkPath::Verb verb;
-
- while ((verb = iter.next(srcP)) != SkPath::kDone_Verb)
- {
+
+ while ((verb = iter.next(srcP)) != SkPath::kDone_Verb) {
switch (verb) {
case SkPath::kMove_Verb:
morphpoints(dstP, srcP, 1, meas, dist);
}
}
-SkPath1DPathEffect::SkPath1DPathEffect(SkFlattenableReadBuffer& buffer)
-{
+SkPath1DPathEffect::SkPath1DPathEffect(SkFlattenableReadBuffer& buffer) {
fAdvance = buffer.readScalar();
if (fAdvance > 0) {
fPath.unflatten(buffer);
}
}
-SkScalar SkPath1DPathEffect::begin(SkScalar contourLength)
-{
+SkScalar SkPath1DPathEffect::begin(SkScalar contourLength) {
return fInitialOffset;
}
-void SkPath1DPathEffect::flatten(SkFlattenableWriteBuffer& buffer)
-{
+void SkPath1DPathEffect::flatten(SkFlattenableWriteBuffer& buffer) {
buffer.writeScalar(fAdvance);
if (fAdvance > 0) {
fPath.flatten(buffer);
}
}
-SkScalar SkPath1DPathEffect::next(SkPath* dst, SkScalar distance, SkPathMeasure& meas)
-{
+SkScalar SkPath1DPathEffect::next(SkPath* dst, SkScalar distance,
+ SkPathMeasure& meas) {
switch (fStyle) {
- case kTranslate_Style:
- {
+ case kTranslate_Style: {
SkPoint pos;
meas.getPosTan(distance, &pos, NULL);
dst->addPath(fPath, pos.fX, pos.fY);
- }
- break;
- case kRotate_Style:
- {
+ } break;
+ case kRotate_Style: {
SkMatrix matrix;
meas.getMatrix(distance, &matrix);
dst->addPath(fPath, matrix);
- }
- break;
+ } break;
case kMorph_Style:
morphpath(dst, fPath, meas, distance);
break;