reformatting to match coding style -- no logic changes
git-svn-id: http://skia.googlecode.com/svn/trunk@778 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index 0fb2254..55f16af 100644
--- a/src/core/SkPaint.cpp
+++ b/src/core/SkPaint.cpp
@@ -67,8 +67,7 @@
fHinting = kNormal_Hinting;
}
-SkPaint::SkPaint(const SkPaint& src)
-{
+SkPaint::SkPaint(const SkPaint& src) {
memcpy(this, &src, sizeof(src));
SkSafeRef(fTypeface);
@@ -81,8 +80,7 @@
SkSafeRef(fLooper);
}
-SkPaint::~SkPaint()
-{
+SkPaint::~SkPaint() {
SkSafeUnref(fTypeface);
SkSafeUnref(fPathEffect);
SkSafeUnref(fShader);
@@ -93,8 +91,7 @@
SkSafeUnref(fLooper);
}
-SkPaint& SkPaint::operator=(const SkPaint& src)
-{
+SkPaint& SkPaint::operator=(const SkPaint& src) {
SkASSERT(&src);
SkSafeRef(src.fTypeface);
@@ -120,206 +117,177 @@
return *this;
}
-int operator==(const SkPaint& a, const SkPaint& b)
-{
+int operator==(const SkPaint& a, const SkPaint& b) {
return memcmp(&a, &b, sizeof(a)) == 0;
}
-void SkPaint::reset()
-{
+void SkPaint::reset() {
SkPaint init;
*this = init;
}
-void SkPaint::setFlags(uint32_t flags)
-{
+void SkPaint::setFlags(uint32_t flags) {
fFlags = flags;
}
-void SkPaint::setAntiAlias(bool doAA)
-{
+void SkPaint::setAntiAlias(bool doAA) {
this->setFlags(SkSetClearMask(fFlags, doAA, kAntiAlias_Flag));
}
-void SkPaint::setDither(bool doDither)
-{
+void SkPaint::setDither(bool doDither) {
this->setFlags(SkSetClearMask(fFlags, doDither, kDither_Flag));
}
-void SkPaint::setSubpixelText(bool doSubpixel)
-{
+void SkPaint::setSubpixelText(bool doSubpixel) {
this->setFlags(SkSetClearMask(fFlags, doSubpixel, kSubpixelText_Flag));
}
-void SkPaint::setLCDRenderText(bool doLCDRender)
-{
+void SkPaint::setLCDRenderText(bool doLCDRender) {
this->setFlags(SkSetClearMask(fFlags, doLCDRender, kLCDRenderText_Flag));
}
-void SkPaint::setEmbeddedBitmapText(bool doEmbeddedBitmapText)
-{
+void SkPaint::setEmbeddedBitmapText(bool doEmbeddedBitmapText) {
this->setFlags(SkSetClearMask(fFlags, doEmbeddedBitmapText, kEmbeddedBitmapText_Flag));
}
-void SkPaint::setAutohinted(bool useAutohinter)
-{
+void SkPaint::setAutohinted(bool useAutohinter) {
this->setFlags(SkSetClearMask(fFlags, useAutohinter, kAutoHinting_Flag));
}
-void SkPaint::setLinearText(bool doLinearText)
-{
+void SkPaint::setLinearText(bool doLinearText) {
this->setFlags(SkSetClearMask(fFlags, doLinearText, kLinearText_Flag));
}
-void SkPaint::setUnderlineText(bool doUnderline)
-{
+void SkPaint::setUnderlineText(bool doUnderline) {
this->setFlags(SkSetClearMask(fFlags, doUnderline, kUnderlineText_Flag));
}
-void SkPaint::setStrikeThruText(bool doStrikeThru)
-{
+void SkPaint::setStrikeThruText(bool doStrikeThru) {
this->setFlags(SkSetClearMask(fFlags, doStrikeThru, kStrikeThruText_Flag));
}
-void SkPaint::setFakeBoldText(bool doFakeBold)
-{
+void SkPaint::setFakeBoldText(bool doFakeBold) {
this->setFlags(SkSetClearMask(fFlags, doFakeBold, kFakeBoldText_Flag));
}
-void SkPaint::setDevKernText(bool doDevKern)
-{
+void SkPaint::setDevKernText(bool doDevKern) {
this->setFlags(SkSetClearMask(fFlags, doDevKern, kDevKernText_Flag));
}
-void SkPaint::setFilterBitmap(bool doFilter)
-{
+void SkPaint::setFilterBitmap(bool doFilter) {
this->setFlags(SkSetClearMask(fFlags, doFilter, kFilterBitmap_Flag));
}
-void SkPaint::setStyle(Style style)
-{
- if ((unsigned)style < kStyleCount)
+void SkPaint::setStyle(Style style) {
+ if ((unsigned)style < kStyleCount) {
fStyle = style;
+ }
#ifdef SK_DEBUG
- else
+ else {
SkDebugf("SkPaint::setStyle(%d) out of range\n", style);
+ }
#endif
}
-void SkPaint::setColor(SkColor color)
-{
+void SkPaint::setColor(SkColor color) {
fColor = color;
}
-void SkPaint::setAlpha(U8CPU a)
-{
- fColor = SkColorSetARGB(a, SkColorGetR(fColor), SkColorGetG(fColor), SkColorGetB(fColor));
+void SkPaint::setAlpha(U8CPU a) {
+ fColor = SkColorSetARGB(a, SkColorGetR(fColor),
+ SkColorGetG(fColor), SkColorGetB(fColor));
}
-void SkPaint::setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
-{
+void SkPaint::setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) {
fColor = SkColorSetARGB(a, r, g, b);
}
-void SkPaint::setStrokeWidth(SkScalar width)
-{
- if (width >= 0)
+void SkPaint::setStrokeWidth(SkScalar width) {
+ if (width >= 0) {
fWidth = width;
+ }
#ifdef SK_DEBUG
- else
+ else {
SkDebugf("SkPaint::setStrokeWidth() called with negative value\n");
+ }
#endif
}
-void SkPaint::setStrokeMiter(SkScalar limit)
-{
- if (limit >= 0)
+void SkPaint::setStrokeMiter(SkScalar limit) {
+ if (limit >= 0) {
fMiterLimit = limit;
+ }
#ifdef SK_DEBUG
- else
+ else {
SkDebugf("SkPaint::setStrokeMiter() called with negative value\n");
+ }
#endif
}
-void SkPaint::setStrokeCap(Cap ct)
-{
- if ((unsigned)ct < kCapCount)
+void SkPaint::setStrokeCap(Cap ct) {
+ if ((unsigned)ct < kCapCount) {
fCapType = SkToU8(ct);
-#ifdef SK_DEBUG
- else
- SkDebugf("SkPaint::setStrokeCap(%d) out of range\n", ct);
-#endif
+ } else {
+ SkDEBUGCODE(SkDebugf("SkPaint::setStrokeCap(%d) out of range\n", ct);)
+ }
}
-void SkPaint::setStrokeJoin(Join jt)
-{
- if ((unsigned)jt < kJoinCount)
+void SkPaint::setStrokeJoin(Join jt) {
+ if ((unsigned)jt < kJoinCount) {
fJoinType = SkToU8(jt);
-#ifdef SK_DEBUG
- else
- SkDebugf("SkPaint::setStrokeJoin(%d) out of range\n", jt);
-#endif
+ } else {
+ SkDEBUGCODE(SkDebugf("SkPaint::setStrokeJoin(%d) out of range\n", jt);)
+ }
}
-//////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
-void SkPaint::setTextAlign(Align align)
-{
- if ((unsigned)align < kAlignCount)
+void SkPaint::setTextAlign(Align align) {
+ if ((unsigned)align < kAlignCount) {
fTextAlign = SkToU8(align);
-#ifdef SK_DEBUG
- else
- SkDebugf("SkPaint::setTextAlign(%d) out of range\n", align);
-#endif
+ } else {
+ SkDEBUGCODE(SkDebugf("SkPaint::setTextAlign(%d) out of range\n", align);)
+ }
}
-void SkPaint::setTextSize(SkScalar ts)
-{
- if (ts >= 0)
+void SkPaint::setTextSize(SkScalar ts) {
+ if (ts >= 0) {
fTextSize = ts;
-#ifdef SK_DEBUG
- else
- SkDebugf("SkPaint::setTextSize() called with negative value\n");
-#endif
+ } else {
+ SkDEBUGCODE(SkDebugf("SkPaint::setTextSize() called with negative value\n");)
+ }
}
-void SkPaint::setTextScaleX(SkScalar scaleX)
-{
+void SkPaint::setTextScaleX(SkScalar scaleX) {
fTextScaleX = scaleX;
}
-void SkPaint::setTextSkewX(SkScalar skewX)
-{
+void SkPaint::setTextSkewX(SkScalar skewX) {
fTextSkewX = skewX;
}
-void SkPaint::setTextEncoding(TextEncoding encoding)
-{
- if ((unsigned)encoding <= kGlyphID_TextEncoding)
+void SkPaint::setTextEncoding(TextEncoding encoding) {
+ if ((unsigned)encoding <= kGlyphID_TextEncoding) {
fTextEncoding = encoding;
-#ifdef SK_DEBUG
- else
- SkDebugf("SkPaint::setTextEncoding(%d) out of range\n", encoding);
-#endif
+ } else {
+ SkDEBUGCODE(SkDebugf("SkPaint::setTextEncoding(%d) out of range\n", encoding);)
+ }
}
-///////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
-SkTypeface* SkPaint::setTypeface(SkTypeface* font)
-{
+SkTypeface* SkPaint::setTypeface(SkTypeface* font) {
SkRefCnt_SafeAssign(fTypeface, font);
return font;
}
-SkRasterizer* SkPaint::setRasterizer(SkRasterizer* r)
-{
+SkRasterizer* SkPaint::setRasterizer(SkRasterizer* r) {
SkRefCnt_SafeAssign(fRasterizer, r);
return r;
}
-SkDrawLooper* SkPaint::setLooper(SkDrawLooper* looper)
-{
+SkDrawLooper* SkPaint::setLooper(SkDrawLooper* looper) {
SkRefCnt_SafeAssign(fLooper, looper);
return looper;
}
@@ -457,40 +425,40 @@
///////////////////////////////////////////////////////////////////////////////
-static const SkGlyph& sk_getMetrics_utf8_next(SkGlyphCache* cache, const char** text)
-{
+static const SkGlyph& sk_getMetrics_utf8_next(SkGlyphCache* cache,
+ const char** text) {
SkASSERT(cache != NULL);
SkASSERT(text != NULL);
return cache->getUnicharMetrics(SkUTF8_NextUnichar(text));
}
-static const SkGlyph& sk_getMetrics_utf8_prev(SkGlyphCache* cache, const char** text)
-{
+static const SkGlyph& sk_getMetrics_utf8_prev(SkGlyphCache* cache,
+ const char** text) {
SkASSERT(cache != NULL);
SkASSERT(text != NULL);
return cache->getUnicharMetrics(SkUTF8_PrevUnichar(text));
}
-static const SkGlyph& sk_getMetrics_utf16_next(SkGlyphCache* cache, const char** text)
-{
+static const SkGlyph& sk_getMetrics_utf16_next(SkGlyphCache* cache,
+ const char** text) {
SkASSERT(cache != NULL);
SkASSERT(text != NULL);
return cache->getUnicharMetrics(SkUTF16_NextUnichar((const uint16_t**)text));
}
-static const SkGlyph& sk_getMetrics_utf16_prev(SkGlyphCache* cache, const char** text)
-{
+static const SkGlyph& sk_getMetrics_utf16_prev(SkGlyphCache* cache,
+ const char** text) {
SkASSERT(cache != NULL);
SkASSERT(text != NULL);
return cache->getUnicharMetrics(SkUTF16_PrevUnichar((const uint16_t**)text));
}
-static const SkGlyph& sk_getMetrics_glyph_next(SkGlyphCache* cache, const char** text)
-{
+static const SkGlyph& sk_getMetrics_glyph_next(SkGlyphCache* cache,
+ const char** text) {
SkASSERT(cache != NULL);
SkASSERT(text != NULL);
@@ -501,8 +469,8 @@
return cache->getGlyphIDMetrics(glyphID);
}
-static const SkGlyph& sk_getMetrics_glyph_prev(SkGlyphCache* cache, const char** text)
-{
+static const SkGlyph& sk_getMetrics_glyph_prev(SkGlyphCache* cache,
+ const char** text) {
SkASSERT(cache != NULL);
SkASSERT(text != NULL);
@@ -513,42 +481,40 @@
return cache->getGlyphIDMetrics(glyphID);
}
-///
-
-static const SkGlyph& sk_getAdvance_utf8_next(SkGlyphCache* cache, const char** text)
-{
+static const SkGlyph& sk_getAdvance_utf8_next(SkGlyphCache* cache,
+ const char** text) {
SkASSERT(cache != NULL);
SkASSERT(text != NULL);
return cache->getUnicharAdvance(SkUTF8_NextUnichar(text));
}
-static const SkGlyph& sk_getAdvance_utf8_prev(SkGlyphCache* cache, const char** text)
-{
+static const SkGlyph& sk_getAdvance_utf8_prev(SkGlyphCache* cache,
+ const char** text) {
SkASSERT(cache != NULL);
SkASSERT(text != NULL);
return cache->getUnicharAdvance(SkUTF8_PrevUnichar(text));
}
-static const SkGlyph& sk_getAdvance_utf16_next(SkGlyphCache* cache, const char** text)
-{
+static const SkGlyph& sk_getAdvance_utf16_next(SkGlyphCache* cache,
+ const char** text) {
SkASSERT(cache != NULL);
SkASSERT(text != NULL);
return cache->getUnicharAdvance(SkUTF16_NextUnichar((const uint16_t**)text));
}
-static const SkGlyph& sk_getAdvance_utf16_prev(SkGlyphCache* cache, const char** text)
-{
+static const SkGlyph& sk_getAdvance_utf16_prev(SkGlyphCache* cache,
+ const char** text) {
SkASSERT(cache != NULL);
SkASSERT(text != NULL);
return cache->getUnicharAdvance(SkUTF16_PrevUnichar((const uint16_t**)text));
}
-static const SkGlyph& sk_getAdvance_glyph_next(SkGlyphCache* cache, const char** text)
-{
+static const SkGlyph& sk_getAdvance_glyph_next(SkGlyphCache* cache,
+ const char** text) {
SkASSERT(cache != NULL);
SkASSERT(text != NULL);
@@ -559,8 +525,8 @@
return cache->getGlyphIDAdvance(glyphID);
}
-static const SkGlyph& sk_getAdvance_glyph_prev(SkGlyphCache* cache, const char** text)
-{
+static const SkGlyph& sk_getAdvance_glyph_prev(SkGlyphCache* cache,
+ const char** text) {
SkASSERT(cache != NULL);
SkASSERT(text != NULL);
@@ -572,8 +538,7 @@
}
SkMeasureCacheProc SkPaint::getMeasureCacheProc(TextBufferDirection tbd,
- bool needFullMetrics) const
-{
+ bool needFullMetrics) const {
static const SkMeasureCacheProc gMeasureCacheProcs[] = {
sk_getMetrics_utf8_next,
sk_getMetrics_utf16_next,
@@ -594,10 +559,12 @@
unsigned index = this->getTextEncoding();
- if (kBackward_TextBufferDirection == tbd)
+ if (kBackward_TextBufferDirection == tbd) {
index += 3;
- if (!needFullMetrics && !this->isDevKernText())
+ }
+ if (!needFullMetrics && !this->isDevKernText()) {
index += 6;
+ }
SkASSERT(index < SK_ARRAY_COUNT(gMeasureCacheProcs));
return gMeasureCacheProcs[index];
@@ -606,8 +573,7 @@
///////////////////////////////////////////////////////////////////////////////
static const SkGlyph& sk_getMetrics_utf8_00(SkGlyphCache* cache,
- const char** text, SkFixed, SkFixed)
-{
+ const char** text, SkFixed, SkFixed) {
SkASSERT(cache != NULL);
SkASSERT(text != NULL);
@@ -615,17 +581,15 @@
}
static const SkGlyph& sk_getMetrics_utf8_xy(SkGlyphCache* cache,
- const char** text, SkFixed x, SkFixed y)
-{
+ const char** text, SkFixed x, SkFixed y) {
SkASSERT(cache != NULL);
SkASSERT(text != NULL);
return cache->getUnicharMetrics(SkUTF8_NextUnichar(text), x, y);
}
-static const SkGlyph& sk_getMetrics_utf16_00(SkGlyphCache* cache, const char** text,
- SkFixed, SkFixed)
-{
+static const SkGlyph& sk_getMetrics_utf16_00(SkGlyphCache* cache,
+ const char** text, SkFixed, SkFixed) {
SkASSERT(cache != NULL);
SkASSERT(text != NULL);
@@ -633,8 +597,7 @@
}
static const SkGlyph& sk_getMetrics_utf16_xy(SkGlyphCache* cache,
- const char** text, SkFixed x, SkFixed y)
-{
+ const char** text, SkFixed x, SkFixed y) {
SkASSERT(cache != NULL);
SkASSERT(text != NULL);
@@ -642,9 +605,8 @@
x, y);
}
-static const SkGlyph& sk_getMetrics_glyph_00(SkGlyphCache* cache, const char** text,
- SkFixed, SkFixed)
-{
+static const SkGlyph& sk_getMetrics_glyph_00(SkGlyphCache* cache,
+ const char** text, SkFixed, SkFixed) {
SkASSERT(cache != NULL);
SkASSERT(text != NULL);
@@ -656,8 +618,7 @@
}
static const SkGlyph& sk_getMetrics_glyph_xy(SkGlyphCache* cache,
- const char** text, SkFixed x, SkFixed y)
-{
+ const char** text, SkFixed x, SkFixed y) {
SkASSERT(cache != NULL);
SkASSERT(text != NULL);
@@ -668,8 +629,7 @@
return cache->getGlyphIDMetrics(glyphID, x, y);
}
-SkDrawCacheProc SkPaint::getDrawCacheProc() const
-{
+SkDrawCacheProc SkPaint::getDrawCacheProc() const {
static const SkDrawCacheProc gDrawCacheProcs[] = {
sk_getMetrics_utf8_00,
sk_getMetrics_utf16_00,
@@ -681,8 +641,9 @@
};
unsigned index = this->getTextEncoding();
- if (fFlags & kSubpixelText_Flag)
+ if (fFlags & kSubpixelText_Flag) {
index += 3;
+ }
SkASSERT(index < SK_ARRAY_COUNT(gDrawCacheProcs));
return gDrawCacheProcs[index];
@@ -692,14 +653,14 @@
class SkAutoRestorePaintTextSizeAndFrame {
public:
- SkAutoRestorePaintTextSizeAndFrame(const SkPaint* paint) : fPaint((SkPaint*)paint)
- {
+ SkAutoRestorePaintTextSizeAndFrame(const SkPaint* paint)
+ : fPaint((SkPaint*)paint) {
fTextSize = paint->getTextSize();
fStyle = paint->getStyle();
fPaint->setStyle(SkPaint::kFill_Style);
}
- ~SkAutoRestorePaintTextSizeAndFrame()
- {
+
+ ~SkAutoRestorePaintTextSizeAndFrame() {
fPaint->setStyle(fStyle);
fPaint->setTextSize(fTextSize);
}
@@ -710,8 +671,7 @@
SkPaint::Style fStyle;
};
-static void set_bounds(const SkGlyph& g, SkRect* bounds)
-{
+static void set_bounds(const SkGlyph& g, SkRect* bounds) {
bounds->set(SkIntToScalar(g.fLeft),
SkIntToScalar(g.fTop),
SkIntToScalar(g.fLeft + g.fWidth),
@@ -733,8 +693,7 @@
}
#endif
-static void join_bounds(const SkGlyph& g, SkRect* bounds, Sk48Dot16 dx)
-{
+static void join_bounds(const SkGlyph& g, SkRect* bounds, Sk48Dot16 dx) {
SkScalar sx = Sk48Dot16ToScalar(dx);
bounds->join(SkIntToScalar(g.fLeft) + sx,
SkIntToScalar(g.fTop),
@@ -744,14 +703,13 @@
SkScalar SkPaint::measure_text(SkGlyphCache* cache,
const char* text, size_t byteLength,
- int* count, SkRect* bounds) const
-{
+ int* count, SkRect* bounds) const {
SkASSERT(count);
- if (byteLength == 0)
- {
+ if (byteLength == 0) {
*count = 0;
- if (bounds)
+ if (bounds) {
bounds->setEmpty();
+ }
return 0;
}
@@ -769,29 +727,22 @@
SkAutoKern autokern;
- if (NULL == bounds)
- {
- if (this->isDevKernText())
- {
+ if (NULL == bounds) {
+ if (this->isDevKernText()) {
int rsb;
for (; text < stop; n++) {
rsb = g->fRsbDelta;
g = &glyphCacheProc(cache, &text);
x += SkAutoKern_AdjustF(rsb, g->fLsbDelta) + g->fAdvanceX;
}
- }
- else
- {
+ } else {
for (; text < stop; n++) {
x += glyphCacheProc(cache, &text).fAdvanceX;
}
}
- }
- else
- {
+ } else {
set_bounds(*g, bounds);
- if (this->isDevKernText())
- {
+ if (this->isDevKernText()) {
int rsb;
for (; text < stop; n++) {
rsb = g->fRsbDelta;
@@ -800,9 +751,7 @@
join_bounds(*g, bounds, x);
x += g->fAdvanceX;
}
- }
- else
- {
+ } else {
for (; text < stop; n++) {
g = &glyphCacheProc(cache, &text);
join_bounds(*g, bounds, x);
@@ -817,24 +766,21 @@
}
SkScalar SkPaint::measureText(const void* textData, size_t length,
- SkRect* bounds, SkScalar zoom) const
-{
+ SkRect* bounds, SkScalar zoom) const {
const char* text = (const char*)textData;
SkASSERT(text != NULL || length == 0);
SkScalar scale = 0;
SkAutoRestorePaintTextSizeAndFrame restore(this);
- if (this->isLinearText())
- {
+ if (this->isLinearText()) {
scale = fTextSize / kCanonicalTextSizeForPaths;
// this gets restored by restore
((SkPaint*)this)->setTextSize(SkIntToScalar(kCanonicalTextSizeForPaths));
}
- SkMatrix zoomMatrix, *zoomPtr = NULL;
- if (zoom)
- {
+ SkMatrix zoomMatrix, *zoomPtr = NULL;
+ if (zoom) {
zoomMatrix.setScale(zoom, zoom);
zoomPtr = &zoomMatrix;
}
@@ -844,16 +790,13 @@
SkScalar width = 0;
- if (length > 0)
- {
+ if (length > 0) {
int tempCount;
width = this->measure_text(cache, text, length, &tempCount, bounds);
- if (scale)
- {
+ if (scale) {
width = SkScalarMul(width, scale);
- if (bounds)
- {
+ if (bounds) {
bounds->fLeft = SkScalarMul(bounds->fLeft, scale);
bounds->fTop = SkScalarMul(bounds->fTop, scale);
bounds->fRight = SkScalarMul(bounds->fRight, scale);
@@ -866,26 +809,21 @@
typedef bool (*SkTextBufferPred)(const char* text, const char* stop);
-static bool forward_textBufferPred(const char* text, const char* stop)
-{
+static bool forward_textBufferPred(const char* text, const char* stop) {
return text < stop;
}
-static bool backward_textBufferPred(const char* text, const char* stop)
-{
+static bool backward_textBufferPred(const char* text, const char* stop) {
return text > stop;
}
static SkTextBufferPred chooseTextBufferPred(SkPaint::TextBufferDirection tbd,
- const char** text, size_t length, const char** stop)
-{
- if (SkPaint::kForward_TextBufferDirection == tbd)
- {
+ const char** text, size_t length,
+ const char** stop) {
+ if (SkPaint::kForward_TextBufferDirection == tbd) {
*stop = *text + length;
return forward_textBufferPred;
- }
- else
- {
+ } else {
// text should point to the end of the buffer, and stop to the beginning
*stop = *text;
*text += length;
@@ -895,12 +833,11 @@
size_t SkPaint::breakText(const void* textD, size_t length, SkScalar maxWidth,
SkScalar* measuredWidth,
- TextBufferDirection tbd) const
-{
- if (0 == length || 0 >= maxWidth)
- {
- if (measuredWidth)
+ TextBufferDirection tbd) const {
+ if (0 == length || 0 >= maxWidth) {
+ if (measuredWidth) {
*measuredWidth = 0;
+ }
return 0;
}
@@ -910,8 +847,7 @@
SkScalar scale = 0;
SkAutoRestorePaintTextSizeAndFrame restore(this);
- if (this->isLinearText())
- {
+ if (this->isLinearText()) {
scale = fTextSize / kCanonicalTextSizeForPaths;
maxWidth = SkScalarMulDiv(maxWidth, kCanonicalTextSizeForPaths, fTextSize);
// this gets restored by restore
@@ -930,31 +866,24 @@
SkAutoKern autokern;
- if (this->isDevKernText())
- {
+ if (this->isDevKernText()) {
int rsb = 0;
- while (pred(text, stop))
- {
+ while (pred(text, stop)) {
const char* curr = text;
const SkGlyph& g = glyphCacheProc(cache, &text);
SkFixed x = SkAutoKern_AdjustF(rsb, g.fLsbDelta) + g.fAdvanceX;
- if ((width += x) > max)
- {
+ if ((width += x) > max) {
width -= x;
text = curr;
break;
}
rsb = g.fRsbDelta;
}
- }
- else
- {
- while (pred(text, stop))
- {
+ } else {
+ while (pred(text, stop)) {
const char* curr = text;
SkFixed x = glyphCacheProc(cache, &text).fAdvanceX;
- if ((width += x) > max)
- {
+ if ((width += x) > max) {
width -= x;
text = curr;
break;
@@ -962,12 +891,11 @@
}
}
- if (measuredWidth)
- {
-
+ if (measuredWidth) {
SkScalar scalarWidth = Sk48Dot16ToScalar(width);
- if (scale)
+ if (scale) {
scalarWidth = SkScalarMul(scalarWidth, scale);
+ }
*measuredWidth = scalarWidth;
}
@@ -978,32 +906,27 @@
///////////////////////////////////////////////////////////////////////////////
-static bool FontMetricsCacheProc(const SkGlyphCache* cache, void* context)
-{
+static bool FontMetricsCacheProc(const SkGlyphCache* cache, void* context) {
*(SkPaint::FontMetrics*)context = cache->getFontMetricsY();
return false; // don't detach the cache
}
-static void FontMetricsDescProc(const SkDescriptor* desc, void* context)
-{
+static void FontMetricsDescProc(const SkDescriptor* desc, void* context) {
SkGlyphCache::VisitCache(desc, FontMetricsCacheProc, context);
}
-SkScalar SkPaint::getFontMetrics(FontMetrics* metrics, SkScalar zoom) const
-{
+SkScalar SkPaint::getFontMetrics(FontMetrics* metrics, SkScalar zoom) const {
SkScalar scale = 0;
SkAutoRestorePaintTextSizeAndFrame restore(this);
- if (this->isLinearText())
- {
+ if (this->isLinearText()) {
scale = fTextSize / kCanonicalTextSizeForPaths;
// this gets restored by restore
((SkPaint*)this)->setTextSize(SkIntToScalar(kCanonicalTextSizeForPaths));
}
- SkMatrix zoomMatrix, *zoomPtr = NULL;
- if (zoom)
- {
+ SkMatrix zoomMatrix, *zoomPtr = NULL;
+ if (zoom) {
zoomMatrix.setScale(zoom, zoom);
zoomPtr = &zoomMatrix;
}
@@ -1014,13 +937,13 @@
const FontMetrics& my = cache->getFontMetricsY();
#endif
FontMetrics storage;
- if (NULL == metrics)
+ if (NULL == metrics) {
metrics = &storage;
+ }
this->descriptorProc(zoomPtr, FontMetricsDescProc, metrics);
- if (scale)
- {
+ if (scale) {
metrics->fTop = SkScalarMul(metrics->fTop, scale);
metrics->fAscent = SkScalarMul(metrics->fAscent, scale);
metrics->fDescent = SkScalarMul(metrics->fDescent, scale);
@@ -1030,32 +953,31 @@
return metrics->fDescent - metrics->fAscent + metrics->fLeading;
}
-////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
-static void set_bounds(const SkGlyph& g, SkRect* bounds, SkScalar scale)
-{
+static void set_bounds(const SkGlyph& g, SkRect* bounds, SkScalar scale) {
bounds->set(g.fLeft * scale,
g.fTop * scale,
(g.fLeft + g.fWidth) * scale,
(g.fTop + g.fHeight) * scale);
}
-int SkPaint::getTextWidths(const void* textData, size_t byteLength, SkScalar widths[],
- SkRect bounds[]) const
-{
- if (0 == byteLength)
+int SkPaint::getTextWidths(const void* textData, size_t byteLength,
+ SkScalar widths[], SkRect bounds[]) const {
+ if (0 == byteLength) {
return 0;
+ }
SkASSERT(NULL != textData);
- if (NULL == widths && NULL == bounds)
+ if (NULL == widths && NULL == bounds) {
return this->countText(textData, byteLength);
+ }
SkAutoRestorePaintTextSizeAndFrame restore(this);
SkScalar scale = 0;
- if (this->isLinearText())
- {
+ if (this->isLinearText()) {
scale = fTextSize / kCanonicalTextSizeForPaths;
// this gets restored by restore
((SkPaint*)this)->setTextSize(SkIntToScalar(kCanonicalTextSizeForPaths));
@@ -1071,8 +993,7 @@
const char* stop = text + byteLength;
int count = 0;
- if (this->isDevKernText())
- {
+ if (this->isDevKernText()) {
// we adjust the widths returned here through auto-kerning
SkAutoKern autokern;
SkFixed prevWidth = 0;
@@ -1148,16 +1069,18 @@
return count;
}
-////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
#include "SkDraw.h"
-void SkPaint::getTextPath(const void* textData, size_t length, SkScalar x, SkScalar y, SkPath* path) const
-{
+void SkPaint::getTextPath(const void* textData, size_t length,
+ SkScalar x, SkScalar y, SkPath* path) const {
+ SkASSERT(length == 0 || textData != NULL);
+
const char* text = (const char*)textData;
- SkASSERT(length == 0 || text != NULL);
- if (text == NULL || length == 0 || path == NULL)
+ if (text == NULL || length == 0 || path == NULL) {
return;
+ }
SkTextToPathIter iter(text, length, *this, false, true);
SkMatrix matrix;
@@ -1169,8 +1092,7 @@
SkScalar xpos;
const SkPath* iterPath;
- while ((iterPath = iter.next(&xpos)) != NULL)
- {
+ while ((iterPath = iter.next(&xpos)) != NULL) {
matrix.postTranslate(xpos - prevXPos, 0);
path->addPath(*iterPath, matrix);
prevXPos = xpos;
@@ -1182,8 +1104,7 @@
buffer->flatten(desc->addEntry(tag, buffer->size(), NULL));
}
-static SkMask::Format computeMaskFormat(const SkPaint& paint)
-{
+static SkMask::Format computeMaskFormat(const SkPaint& paint) {
uint32_t flags = paint.getFlags();
// Antialiasing being disabled trumps all other settings.
@@ -1191,9 +1112,10 @@
return SkMask::kBW_Format;
#if defined(SK_SUPPORT_LCDTEXT)
- if (flags & SkPaint::kLCDRenderText_Flag)
+ if (flags & SkPaint::kLCDRenderText_Flag) {
return SkFontHost::GetSubpixelOrientation() == SkFontHost::kHorizontal_LCDOrientation ?
SkMask::kHorizontalLCD_Format : SkMask::kVerticalLCD_Format;
+ }
#endif
return SkMask::kA8_Format;
@@ -1225,8 +1147,7 @@
}
void SkScalerContext::MakeRec(const SkPaint& paint,
- const SkMatrix* deviceMatrix, Rec* rec)
-{
+ const SkMatrix* deviceMatrix, Rec* rec) {
SkASSERT(deviceMatrix == NULL ||
(deviceMatrix->getType() & SkMatrix::kPerspective_Mask) == 0);
@@ -1235,15 +1156,12 @@
rec->fPreScaleX = paint.getTextScaleX();
rec->fPreSkewX = paint.getTextSkewX();
- if (deviceMatrix)
- {
+ if (deviceMatrix) {
rec->fPost2x2[0][0] = sk_relax(deviceMatrix->getScaleX());
rec->fPost2x2[0][1] = sk_relax(deviceMatrix->getSkewX());
rec->fPost2x2[1][0] = sk_relax(deviceMatrix->getSkewY());
rec->fPost2x2[1][1] = sk_relax(deviceMatrix->getScaleY());
- }
- else
- {
+ } else {
rec->fPost2x2[0][0] = rec->fPost2x2[1][1] = SK_Scalar1;
rec->fPost2x2[0][1] = rec->fPost2x2[1][0] = 0;
}
@@ -1253,8 +1171,7 @@
unsigned flags = SkFontHost::ComputeGammaFlag(paint);
- if (paint.isFakeBoldText())
- {
+ if (paint.isFakeBoldText()) {
#ifdef SK_USE_FREETYPE_EMBOLDEN
flags |= SkScalerContext::kEmbolden_Flag;
#else
@@ -1264,30 +1181,28 @@
kStdFakeBoldInterpLength);
SkScalar extra = SkScalarMul(paint.getTextSize(), fakeBoldScale);
- if (style == SkPaint::kFill_Style)
- {
+ if (style == SkPaint::kFill_Style) {
style = SkPaint::kStrokeAndFill_Style;
strokeWidth = extra; // ignore paint's strokeWidth if it was "fill"
- }
- else
+ } else {
strokeWidth += extra;
+ }
#endif
}
- if (paint.isDevKernText())
+ if (paint.isDevKernText()) {
flags |= SkScalerContext::kDevKernText_Flag;
+ }
- if (style != SkPaint::kFill_Style && strokeWidth > 0)
- {
+ if (style != SkPaint::kFill_Style && strokeWidth > 0) {
rec->fFrameWidth = strokeWidth;
rec->fMiterLimit = paint.getStrokeMiter();
rec->fStrokeJoin = SkToU8(paint.getStrokeJoin());
- if (style == SkPaint::kStrokeAndFill_Style)
+ if (style == SkPaint::kStrokeAndFill_Style) {
flags |= SkScalerContext::kFrameAndFill_Flag;
- }
- else
- {
+ }
+ } else {
rec->fFrameWidth = 0;
rec->fMiterLimit = 0;
rec->fStrokeJoin = 0;
@@ -1296,12 +1211,15 @@
rec->fMaskFormat = SkToU8(computeMaskFormat(paint));
rec->fFlags = SkToU8(flags);
rec->setHinting(computeHinting(paint));
- if (paint.isEmbeddedBitmapText())
+ if (paint.isEmbeddedBitmapText()) {
rec->fFlags |= SkScalerContext::kEmbeddedBitmapText_Flag;
- if (paint.isSubpixelText())
+ }
+ if (paint.isSubpixelText()) {
rec->fFlags |= SkScalerContext::kSubpixelPositioning_Flag;
- if (paint.isAutohinted())
+ }
+ if (paint.isAutohinted()) {
rec->fFlags |= SkScalerContext::kAutohinting_Flag;
+ }
/* Allow the fonthost to modify our rec before we use it as a key into the
cache. This way if we're asking for something that they will ignore,
@@ -1315,8 +1233,7 @@
void SkPaint::descriptorProc(const SkMatrix* deviceMatrix,
void (*proc)(const SkDescriptor*, void*),
- void* context) const
-{
+ void* context) const {
SkScalerContext::Rec rec;
SkScalerContext::MakeRec(*this, deviceMatrix, &rec);
@@ -1374,13 +1291,11 @@
proc(desc, context);
}
-static void DetachDescProc(const SkDescriptor* desc, void* context)
-{
+static void DetachDescProc(const SkDescriptor* desc, void* context) {
*((SkGlyphCache**)context) = SkGlyphCache::DetachCache(desc);
}
-SkGlyphCache* SkPaint::detachCache(const SkMatrix* deviceMatrix) const
-{
+SkGlyphCache* SkPaint::detachCache(const SkMatrix* deviceMatrix) const {
SkGlyphCache* cache;
this->descriptorProc(deviceMatrix, DetachDescProc, &cache);
return cache;
@@ -1564,58 +1479,57 @@
///////////////////////////////////////////////////////////////////////////////
-bool SkPaint::getFillPath(const SkPath& src, SkPath* dst) const
-{
+bool SkPaint::getFillPath(const SkPath& src, SkPath* dst) const {
SkPath effectPath, strokePath;
const SkPath* path = &src;
SkScalar width = this->getStrokeWidth();
switch (this->getStyle()) {
- case SkPaint::kFill_Style:
- width = -1; // mark it as no-stroke
- break;
- case SkPaint::kStrokeAndFill_Style:
- if (width == 0)
+ case SkPaint::kFill_Style:
width = -1; // mark it as no-stroke
- break;
- case SkPaint::kStroke_Style:
- break;
- default:
- SkASSERT(!"unknown paint style");
+ break;
+ case SkPaint::kStrokeAndFill_Style:
+ if (width == 0) {
+ width = -1; // mark it as no-stroke
+ }
+ break;
+ case SkPaint::kStroke_Style:
+ break;
+ default:
+ SkASSERT(!"unknown paint style");
}
- if (this->getPathEffect())
- {
+ if (this->getPathEffect()) {
// lie to the pathEffect if our style is strokeandfill, so that it treats us as just fill
- if (this->getStyle() == SkPaint::kStrokeAndFill_Style)
+ if (this->getStyle() == SkPaint::kStrokeAndFill_Style) {
width = -1; // mark it as no-stroke
+ }
- if (this->getPathEffect()->filterPath(&effectPath, src, &width))
+ if (this->getPathEffect()->filterPath(&effectPath, src, &width)) {
path = &effectPath;
+ }
// restore the width if we earlier had to lie, and if we're still set to no-stroke
// note: if we're now stroke (width >= 0), then the pathEffect asked for that change
// and we want to respect that (i.e. don't overwrite their setting for width)
- if (this->getStyle() == SkPaint::kStrokeAndFill_Style && width < 0)
- {
+ if (this->getStyle() == SkPaint::kStrokeAndFill_Style && width < 0) {
width = this->getStrokeWidth();
- if (width == 0)
+ if (width == 0) {
width = -1;
+ }
}
}
- if (width > 0 && !path->isEmpty())
- {
+ if (width > 0 && !path->isEmpty()) {
SkStroke stroker(*this, width);
stroker.strokePath(*path, &strokePath);
path = &strokePath;
}
- if (path == &src)
+ if (path == &src) {
*dst = src;
- else
- {
+ } else {
SkASSERT(path == &effectPath || path == &strokePath);
dst->swap(*(SkPath*)path);
}
@@ -1643,40 +1557,38 @@
return *storage;
}
-////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
-static bool has_thick_frame(const SkPaint& paint)
-{
- return paint.getStrokeWidth() > 0 && paint.getStyle() != SkPaint::kFill_Style;
+static bool has_thick_frame(const SkPaint& paint) {
+ return paint.getStrokeWidth() > 0 &&
+ paint.getStyle() != SkPaint::kFill_Style;
}
SkTextToPathIter::SkTextToPathIter( const char text[], size_t length,
const SkPaint& paint,
bool applyStrokeAndPathEffects,
- bool forceLinearTextOn)
- : fPaint(paint) /* make a copy of the paint */
-{
+ bool forceLinearTextOn) : fPaint(paint) {
fGlyphCacheProc = paint.getMeasureCacheProc(SkPaint::kForward_TextBufferDirection,
true);
- if (forceLinearTextOn)
+ if (forceLinearTextOn) {
fPaint.setLinearText(true);
+ }
fPaint.setMaskFilter(NULL); // don't want this affecting our path-cache lookup
- if (fPaint.getPathEffect() == NULL && !has_thick_frame(fPaint))
+ if (fPaint.getPathEffect() == NULL && !has_thick_frame(fPaint)) {
applyStrokeAndPathEffects = false;
+ }
// can't use our canonical size if we need to apply patheffects/strokes
- if (fPaint.isLinearText() && !applyStrokeAndPathEffects)
- {
+ if (fPaint.isLinearText() && !applyStrokeAndPathEffects) {
fPaint.setTextSize(SkIntToScalar(SkPaint::kCanonicalTextSizeForPaths));
fScale = paint.getTextSize() / SkPaint::kCanonicalTextSizeForPaths;
- }
- else
+ } else {
fScale = SK_Scalar1;
+ }
- if (!applyStrokeAndPathEffects)
- {
+ if (!applyStrokeAndPathEffects) {
fPaint.setStyle(SkPaint::kFill_Style);
fPaint.setPathEffect(NULL);
}
@@ -1686,8 +1598,7 @@
SkPaint::Style style = SkPaint::kFill_Style;
SkPathEffect* pe = NULL;
- if (!applyStrokeAndPathEffects)
- {
+ if (!applyStrokeAndPathEffects) {
style = paint.getStyle(); // restore
pe = paint.getPathEffect(); // restore
}
@@ -1698,12 +1609,13 @@
// now compute fXOffset if needed
SkScalar xOffset = 0;
- if (paint.getTextAlign() != SkPaint::kLeft_Align) // need to measure first
- {
+ if (paint.getTextAlign() != SkPaint::kLeft_Align) { // need to measure first
int count;
- SkScalar width = SkScalarMul(fPaint.measure_text(fCache, text, length, &count, NULL), fScale);
- if (paint.getTextAlign() == SkPaint::kCenter_Align)
+ SkScalar width = SkScalarMul(fPaint.measure_text(fCache, text, length,
+ &count, NULL), fScale);
+ if (paint.getTextAlign() == SkPaint::kCenter_Align) {
width = SkScalarHalf(width);
+ }
xOffset = -width;
}
fXPos = xOffset;
@@ -1713,26 +1625,24 @@
fStop = text + length;
}
-SkTextToPathIter::~SkTextToPathIter()
-{
+SkTextToPathIter::~SkTextToPathIter() {
SkGlyphCache::AttachCache(fCache);
}
-const SkPath* SkTextToPathIter::next(SkScalar* xpos)
-{
- while (fText < fStop)
- {
+const SkPath* SkTextToPathIter::next(SkScalar* xpos) {
+ while (fText < fStop) {
const SkGlyph& glyph = fGlyphCacheProc(fCache, &fText);
fXPos += SkScalarMul(SkFixedToScalar(fPrevAdvance + fAutoKern.adjust(glyph)), fScale);
fPrevAdvance = glyph.fAdvanceX; // + fPaint.getTextTracking();
- if (glyph.fWidth)
- {
- if (xpos)
+ if (glyph.fWidth) {
+ if (xpos) {
*xpos = fXPos;
+ }
return fCache->findPath(glyph);
}
}
return NULL;
}
+