code style
git-svn-id: http://skia.googlecode.com/svn/trunk@1160 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/effects/SkDashPathEffect.cpp b/src/effects/SkDashPathEffect.cpp
index 48581b5..82f357c 100644
--- a/src/effects/SkDashPathEffect.cpp
+++ b/src/effects/SkDashPathEffect.cpp
@@ -19,24 +19,24 @@
#include "SkBuffer.h"
#include "SkPathMeasure.h"
-static inline int is_even(int x)
-{
+static inline int is_even(int x) {
return (~x) << 31;
}
-static SkScalar FindFirstInterval(const SkScalar intervals[], SkScalar phase, int32_t* index)
-{
+static SkScalar FindFirstInterval(const SkScalar intervals[], SkScalar phase,
+ int32_t* index) {
int i;
- for (i = 0; phase > intervals[i]; i++)
+ for (i = 0; phase > intervals[i]; i++) {
phase -= intervals[i];
+ }
*index = i;
return intervals[i] - phase;
}
-SkDashPathEffect::SkDashPathEffect(const SkScalar intervals[], int count, SkScalar phase, bool scaleToFit)
- : fScaleToFit(scaleToFit)
-{
+SkDashPathEffect::SkDashPathEffect(const SkScalar intervals[], int count,
+ SkScalar phase, bool scaleToFit)
+ : fScaleToFit(scaleToFit) {
SkASSERT(intervals);
SkASSERT(count > 1 && SkAlign2(count) == count);
@@ -44,46 +44,44 @@
fCount = count;
SkScalar len = 0;
- for (int i = 0; i < count; i++)
- {
+ for (int i = 0; i < count; i++) {
SkASSERT(intervals[i] >= 0);
fIntervals[i] = intervals[i];
len += intervals[i];
}
fIntervalLength = len;
- if (len > 0) // we don't handle 0 length dash arrays
- {
- if (phase < 0)
- {
+ if (len > 0) { // we don't handle 0 length dash arrays
+ if (phase < 0) {
phase = -phase;
- if (phase > len)
+ if (phase > len) {
phase = SkScalarMod(phase, len);
+ }
phase = len - phase;
- }
- else if (phase >= len)
+ } else if (phase >= len) {
phase = SkScalarMod(phase, len);
+ }
SkASSERT(phase >= 0 && phase < len);
fInitialDashLength = FindFirstInterval(intervals, phase, &fInitialDashIndex);
SkASSERT(fInitialDashLength >= 0);
SkASSERT(fInitialDashIndex >= 0 && fInitialDashIndex < fCount);
- }
- else
+ } else {
fInitialDashLength = -1; // signal bad dash intervals
+ }
}
-SkDashPathEffect::~SkDashPathEffect()
-{
+SkDashPathEffect::~SkDashPathEffect() {
sk_free(fIntervals);
}
-bool SkDashPathEffect::filterPath(SkPath* dst, const SkPath& src, SkScalar* width)
-{
+bool SkDashPathEffect::filterPath(SkPath* dst, const SkPath& src,
+ SkScalar* width) {
// we do nothing if the src wants to be filled, or if our dashlength is 0
- if (*width < 0 || fInitialDashLength < 0)
+ if (*width < 0 || fInitialDashLength < 0) {
return false;
+ }
SkPathMeasure meas(src, false);
const SkScalar* intervals = fIntervals;
@@ -95,12 +93,10 @@
int index = fInitialDashIndex;
SkScalar scale = SK_Scalar1;
- if (fScaleToFit)
- {
- if (fIntervalLength >= length)
+ if (fScaleToFit) {
+ if (fIntervalLength >= length) {
scale = SkScalarDiv(length, fIntervalLength);
- else
- {
+ } else {
SkScalar div = SkScalarDiv(length, fIntervalLength);
int n = SkScalarFloor(div);
scale = SkScalarDiv(length, n * fIntervalLength);
@@ -110,12 +106,10 @@
SkScalar distance = 0;
SkScalar dlen = SkScalarMul(fInitialDashLength, scale);
- while (distance < length)
- {
+ while (distance < length) {
SkASSERT(dlen >= 0);
addedSegment = false;
- if (is_even(index) && dlen > 0 && !skipFirstSegment)
- {
+ if (is_even(index) && dlen > 0 && !skipFirstSegment) {
addedSegment = true;
meas.getSegment(distance, distance + dlen, dst, true);
}
@@ -127,27 +121,28 @@
// wrap around our intervals array if necessary
index += 1;
SkASSERT(index <= fCount);
- if (index == fCount)
+ if (index == fCount) {
index = 0;
+ }
// fetch our next dlen
dlen = SkScalarMul(intervals[index], scale);
}
// extend if we ended on a segment and we need to join up with the (skipped) initial segment
- if (meas.isClosed() && is_even(fInitialDashIndex) && fInitialDashLength > 0)
+ if (meas.isClosed() && is_even(fInitialDashIndex) &&
+ fInitialDashLength > 0) {
meas.getSegment(0, SkScalarMul(fInitialDashLength, scale), dst, !addedSegment);
+ }
} while (meas.nextContour());
return true;
}
-SkFlattenable::Factory SkDashPathEffect::getFactory()
-{
+SkFlattenable::Factory SkDashPathEffect::getFactory() {
return fInitialDashLength < 0 ? NULL : CreateProc;
}
-void SkDashPathEffect::flatten(SkFlattenableWriteBuffer& buffer)
-{
+void SkDashPathEffect::flatten(SkFlattenableWriteBuffer& buffer) {
SkASSERT(fInitialDashLength >= 0);
buffer.write32(fCount);
@@ -158,13 +153,11 @@
buffer.writeMul4(fIntervals, fCount * sizeof(fIntervals[0]));
}
-SkFlattenable* SkDashPathEffect::CreateProc(SkFlattenableReadBuffer& buffer)
-{
+SkFlattenable* SkDashPathEffect::CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkDashPathEffect, (buffer));
}
-SkDashPathEffect::SkDashPathEffect(SkFlattenableReadBuffer& buffer)
-{
+SkDashPathEffect::SkDashPathEffect(SkFlattenableReadBuffer& buffer) {
fCount = buffer.readS32();
fInitialDashIndex = buffer.readS32();
fInitialDashLength = buffer.readScalar();