From 791f12e6cf558e0dd1689fbb0a6b5eddac9f42ad Mon Sep 17 00:00:00 2001 From: "robertphillips@google.com" Date: Thu, 14 Feb 2013 13:53:53 +0000 Subject: [PATCH] Move SkPaint::toString from debugger to SkPaint https://codereview.appspot.com/7314092/ git-svn-id: http://skia.googlecode.com/svn/trunk@7732 2bbb7eff-a529-9590-31e7-b0007b416f81 --- debugger/SkObjectParser.cpp | 174 +--------------------------- include/core/SkPaint.h | 2 + src/core/SkComposeShader.cpp | 2 +- src/core/SkPaint.cpp | 181 +++++++++++++++++++++++++++++- src/effects/SkLayerDrawLooper.cpp | 2 +- 5 files changed, 185 insertions(+), 176 deletions(-) diff --git a/debugger/SkObjectParser.cpp b/debugger/SkObjectParser.cpp index c53d3b5a31..a15a3207d3 100644 --- a/debugger/SkObjectParser.cpp +++ b/debugger/SkObjectParser.cpp @@ -92,177 +92,15 @@ SkString* SkObjectParser::IRectToString(const SkIRect& rect) { } SkString* SkObjectParser::MatrixToString(const SkMatrix& matrix) { - SkString* mMatrix = new SkString("SkMatrix: ("); - for (int i = 0; i < 8; i++) { - mMatrix->appendScalar(matrix.get(i)); - mMatrix->append("), ("); - } - mMatrix->appendScalar(matrix.get(8)); - mMatrix->append(")"); - return mMatrix; + SkString* str = new SkString("SkMatrix: "); + matrix.toString(str); + return str; } SkString* SkObjectParser::PaintToString(const SkPaint& paint) { - SkString* mPaint = new SkString("
SkPaint:
"); - - SkTypeface* typeface = paint.getTypeface(); - if (NULL != typeface) { - SkDynamicMemoryWStream ostream; - typeface->serialize(&ostream); - SkAutoTUnref data(ostream.copyToData()); - - SkMemoryStream stream(data); - SkFontDescriptor descriptor(&stream); - - mPaint->append("
Font Family Name:
"); - mPaint->append(descriptor.getFamilyName()); - mPaint->append("
Font Full Name:
"); - mPaint->append(descriptor.getFullName()); - mPaint->append("
Font PS Name:
"); - mPaint->append(descriptor.getPostscriptName()); - mPaint->append("
Font File Name:
"); - mPaint->append(descriptor.getFontFileName()); - mPaint->append("
"); - } - - mPaint->append("
TextSize:
"); - mPaint->appendScalar(paint.getTextSize()); - mPaint->append("
"); - - mPaint->append("
TextScaleX:
"); - mPaint->appendScalar(paint.getTextScaleX()); - mPaint->append("
"); - - mPaint->append("
TextSkewX:
"); - mPaint->appendScalar(paint.getTextSkewX()); - mPaint->append("
"); - - SkPathEffect* pathEffect = paint.getPathEffect(); - if (NULL != pathEffect) { - mPaint->append("
PathEffect:
"); - mPaint->append("
"); - } - - SkShader* shader = paint.getShader(); - if (NULL != shader) { - mPaint->append("
Shader:
"); - SkDEVCODE(shader->toString(mPaint);) - mPaint->append("
"); - } - - SkXfermode* xfer = paint.getXfermode(); - if (NULL != xfer) { - mPaint->append("
Xfermode:
"); - SkDEVCODE(xfer->toString(mPaint);) - mPaint->append("
"); - } - - SkMaskFilter* maskFilter = paint.getMaskFilter(); - if (NULL != maskFilter) { - mPaint->append("
MaskFilter:
"); - mPaint->append("
"); - } - - SkColorFilter* colorFilter = paint.getColorFilter(); - if (NULL != colorFilter) { - mPaint->append("
ColorFilter:
"); - mPaint->append("
"); - } - - SkRasterizer* rasterizer = paint.getRasterizer(); - if (NULL != rasterizer) { - mPaint->append("
Rasterizer:
"); - mPaint->append("
"); - } - - SkDrawLooper* looper = paint.getLooper(); - if (NULL != looper) { - mPaint->append("
DrawLooper:
"); - SkDEVCODE(looper->toString(mPaint);) - mPaint->append("
"); - } - - SkImageFilter* imageFilter = paint.getImageFilter(); - if (NULL != imageFilter) { - mPaint->append("
ImageFilter:
"); - mPaint->append("
"); - } - - SkAnnotation* annotation = paint.getAnnotation(); - if (NULL != annotation) { - mPaint->append("
Annotation:
"); - mPaint->append("
"); - } - - mPaint->append("
Color:
0x"); - SkColor color = paint.getColor(); - mPaint->appendHex(color); - mPaint->append("
"); - - mPaint->append("
Stroke Width:
"); - mPaint->appendScalar(paint.getStrokeWidth()); - mPaint->append("
"); - - mPaint->append("
Stroke Miter:
"); - mPaint->appendScalar(paint.getStrokeMiter()); - mPaint->append("
"); - - mPaint->append("
Flags:
("); - if (paint.getFlags()) { - bool needSeparator = false; - SkAddFlagToString(mPaint, paint.isAntiAlias(), "AntiAlias", &needSeparator); - SkAddFlagToString(mPaint, paint.isFilterBitmap(), "FilterBitmap", &needSeparator); - SkAddFlagToString(mPaint, paint.isDither(), "Dither", &needSeparator); - SkAddFlagToString(mPaint, paint.isUnderlineText(), "UnderlineText", &needSeparator); - SkAddFlagToString(mPaint, paint.isStrikeThruText(), "StrikeThruText", &needSeparator); - SkAddFlagToString(mPaint, paint.isFakeBoldText(), "FakeBoldText", &needSeparator); - SkAddFlagToString(mPaint, paint.isLinearText(), "LinearText", &needSeparator); - SkAddFlagToString(mPaint, paint.isSubpixelText(), "SubpixelText", &needSeparator); - SkAddFlagToString(mPaint, paint.isDevKernText(), "DevKernText", &needSeparator); - SkAddFlagToString(mPaint, paint.isLCDRenderText(), "LCDRenderText", &needSeparator); - SkAddFlagToString(mPaint, paint.isEmbeddedBitmapText(), - "EmbeddedBitmapText", &needSeparator); - SkAddFlagToString(mPaint, paint.isAutohinted(), "Autohinted", &needSeparator); - SkAddFlagToString(mPaint, paint.isVerticalText(), "VerticalText", &needSeparator); - SkAddFlagToString(mPaint, SkToBool(paint.getFlags() & SkPaint::kGenA8FromLCD_Flag), - "GenA8FromLCD", &needSeparator); - } else { - mPaint->append("None"); - } - mPaint->append(")
"); - - mPaint->append("
TextAlign:
"); - static const char* gTextAlignStrings[SkPaint::kAlignCount] = { "Left", "Center", "Right" }; - mPaint->append(gTextAlignStrings[paint.getTextAlign()]); - mPaint->append("
"); - - mPaint->append("
CapType:
"); - static const char* gStrokeCapStrings[SkPaint::kCapCount] = { "Butt", "Round", "Square" }; - mPaint->append(gStrokeCapStrings[paint.getStrokeCap()]); - mPaint->append("
"); - - mPaint->append("
JoinType:
"); - static const char* gJoinStrings[SkPaint::kJoinCount] = { "Miter", "Round", "Bevel" }; - mPaint->append(gJoinStrings[paint.getStrokeJoin()]); - mPaint->append("
"); - - mPaint->append("
Style:
"); - static const char* gStyleStrings[SkPaint::kStyleCount] = { "Fill", "Stroke", "StrokeAndFill" }; - mPaint->append(gStyleStrings[paint.getStyle()]); - mPaint->append("
"); - - mPaint->append("
TextEncoding:
"); - static const char* gTextEncodingStrings[] = { "UTF8", "UTF16", "UTF32", "GlyphID" }; - mPaint->append(gTextEncodingStrings[paint.getTextEncoding()]); - mPaint->append("
"); - - mPaint->append("
Hinting:
"); - static const char* gHintingStrings[] = { "None", "Slight", "Normal", "Full" }; - mPaint->append(gHintingStrings[paint.getHinting()]); - mPaint->append("
"); - - mPaint->append("
"); - return mPaint; + SkString* str = new SkString; + paint.toString(str); + return str; } SkString* SkObjectParser::PathToString(const SkPath& path) { diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h index b63845982f..35ce3e60c4 100644 --- a/include/core/SkPaint.h +++ b/include/core/SkPaint.h @@ -925,6 +925,8 @@ public: const SkRect& doComputeFastBounds(const SkRect& orig, SkRect* storage, Style) const; + SkDEVCODE(void toString(SkString*) const;) + private: SkTypeface* fTypeface; SkScalar fTextSize; diff --git a/src/core/SkComposeShader.cpp b/src/core/SkComposeShader.cpp index fd3b21e2ac..de0ffdb24a 100644 --- a/src/core/SkComposeShader.cpp +++ b/src/core/SkComposeShader.cpp @@ -183,7 +183,7 @@ void SkComposeShader::toString(SkString* str) const { str->append(" ShaderB: "); fShaderB->toString(str); str->append(" Xfermode: "); - // TODO: add "fMode->toString(str);" once SkXfermode::toString is added + fMode->toString(str); this->INHERITED::toString(str); diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index 8acdd8db28..b715524a42 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -8,27 +8,31 @@ #include "SkPaint.h" #include "SkAnnotation.h" +#include "SkAutoKern.h" #include "SkColorFilter.h" +#include "SkData.h" #include "SkDeviceProperties.h" +#include "SkFontDescriptor.h" #include "SkFontHost.h" +#include "SkGlyphCache.h" #include "SkImageFilter.h" #include "SkMaskFilter.h" #include "SkMaskGamma.h" +#include "SkOrderedReadBuffer.h" +#include "SkOrderedWriteBuffer.h" +#include "SkPaintDefaults.h" #include "SkPathEffect.h" #include "SkRasterizer.h" -#include "SkShader.h" #include "SkScalar.h" #include "SkScalerContext.h" +#include "SkShader.h" +#include "SkStringUtils.h" #include "SkStroke.h" #include "SkTextFormatParams.h" #include "SkTextToPathIter.h" #include "SkTypeface.h" #include "SkXfermode.h" -#include "SkAutoKern.h" -#include "SkGlyphCache.h" -#include "SkPaintDefaults.h" -#include "SkOrderedReadBuffer.h" -#include "SkOrderedWriteBuffer.h" + // define this to get a printf for out-of-range parameter in setters // e.g. setTextSize(-1) @@ -2213,6 +2217,171 @@ const SkRect& SkPaint::doComputeFastBounds(const SkRect& origSrc, return *storage; } +#ifdef SK_DEVELOPER +void SkPaint::toString(SkString* str) const { + str->append("
SkPaint:
"); + + SkTypeface* typeface = this->getTypeface(); + if (NULL != typeface) { + SkDynamicMemoryWStream ostream; + typeface->serialize(&ostream); + SkAutoTUnref data(ostream.copyToData()); + + SkMemoryStream stream(data); + SkFontDescriptor descriptor(&stream); + + str->append("
Font Family Name:
"); + str->append(descriptor.getFamilyName()); + str->append("
Font Full Name:
"); + str->append(descriptor.getFullName()); + str->append("
Font PS Name:
"); + str->append(descriptor.getPostscriptName()); + str->append("
Font File Name:
"); + str->append(descriptor.getFontFileName()); + str->append("
"); + } + + str->append("
TextSize:
"); + str->appendScalar(this->getTextSize()); + str->append("
"); + + str->append("
TextScaleX:
"); + str->appendScalar(this->getTextScaleX()); + str->append("
"); + + str->append("
TextSkewX:
"); + str->appendScalar(this->getTextSkewX()); + str->append("
"); + + SkPathEffect* pathEffect = this->getPathEffect(); + if (NULL != pathEffect) { + str->append("
PathEffect:
"); + str->append("
"); + } + + SkShader* shader = this->getShader(); + if (NULL != shader) { + str->append("
Shader:
"); + SkDEVCODE(shader->toString(str);) + str->append("
"); + } + + SkXfermode* xfer = this->getXfermode(); + if (NULL != xfer) { + str->append("
Xfermode:
"); + SkDEVCODE(xfer->toString(str);) + str->append("
"); + } + + SkMaskFilter* maskFilter = this->getMaskFilter(); + if (NULL != maskFilter) { + str->append("
MaskFilter:
"); + str->append("
"); + } + + SkColorFilter* colorFilter = this->getColorFilter(); + if (NULL != colorFilter) { + str->append("
ColorFilter:
"); + str->append("
"); + } + + SkRasterizer* rasterizer = this->getRasterizer(); + if (NULL != rasterizer) { + str->append("
Rasterizer:
"); + str->append("
"); + } + + SkDrawLooper* looper = this->getLooper(); + if (NULL != looper) { + str->append("
DrawLooper:
"); + SkDEVCODE(looper->toString(str);) + str->append("
"); + } + + SkImageFilter* imageFilter = this->getImageFilter(); + if (NULL != imageFilter) { + str->append("
ImageFilter:
"); + str->append("
"); + } + + SkAnnotation* annotation = this->getAnnotation(); + if (NULL != annotation) { + str->append("
Annotation:
"); + str->append("
"); + } + + str->append("
Color:
0x"); + SkColor color = this->getColor(); + str->appendHex(color); + str->append("
"); + + str->append("
Stroke Width:
"); + str->appendScalar(this->getStrokeWidth()); + str->append("
"); + + str->append("
Stroke Miter:
"); + str->appendScalar(this->getStrokeMiter()); + str->append("
"); + + str->append("
Flags:
("); + if (this->getFlags()) { + bool needSeparator = false; + SkAddFlagToString(str, this->isAntiAlias(), "AntiAlias", &needSeparator); + SkAddFlagToString(str, this->isFilterBitmap(), "FilterBitmap", &needSeparator); + SkAddFlagToString(str, this->isDither(), "Dither", &needSeparator); + SkAddFlagToString(str, this->isUnderlineText(), "UnderlineText", &needSeparator); + SkAddFlagToString(str, this->isStrikeThruText(), "StrikeThruText", &needSeparator); + SkAddFlagToString(str, this->isFakeBoldText(), "FakeBoldText", &needSeparator); + SkAddFlagToString(str, this->isLinearText(), "LinearText", &needSeparator); + SkAddFlagToString(str, this->isSubpixelText(), "SubpixelText", &needSeparator); + SkAddFlagToString(str, this->isDevKernText(), "DevKernText", &needSeparator); + SkAddFlagToString(str, this->isLCDRenderText(), "LCDRenderText", &needSeparator); + SkAddFlagToString(str, this->isEmbeddedBitmapText(), + "EmbeddedBitmapText", &needSeparator); + SkAddFlagToString(str, this->isAutohinted(), "Autohinted", &needSeparator); + SkAddFlagToString(str, this->isVerticalText(), "VerticalText", &needSeparator); + SkAddFlagToString(str, SkToBool(this->getFlags() & SkPaint::kGenA8FromLCD_Flag), + "GenA8FromLCD", &needSeparator); + } else { + str->append("None"); + } + str->append(")
"); + + str->append("
TextAlign:
"); + static const char* gTextAlignStrings[SkPaint::kAlignCount] = { "Left", "Center", "Right" }; + str->append(gTextAlignStrings[this->getTextAlign()]); + str->append("
"); + + str->append("
CapType:
"); + static const char* gStrokeCapStrings[SkPaint::kCapCount] = { "Butt", "Round", "Square" }; + str->append(gStrokeCapStrings[this->getStrokeCap()]); + str->append("
"); + + str->append("
JoinType:
"); + static const char* gJoinStrings[SkPaint::kJoinCount] = { "Miter", "Round", "Bevel" }; + str->append(gJoinStrings[this->getStrokeJoin()]); + str->append("
"); + + str->append("
Style:
"); + static const char* gStyleStrings[SkPaint::kStyleCount] = { "Fill", "Stroke", "StrokeAndFill" }; + str->append(gStyleStrings[this->getStyle()]); + str->append("
"); + + str->append("
TextEncoding:
"); + static const char* gTextEncodingStrings[] = { "UTF8", "UTF16", "UTF32", "GlyphID" }; + str->append(gTextEncodingStrings[this->getTextEncoding()]); + str->append("
"); + + str->append("
Hinting:
"); + static const char* gHintingStrings[] = { "None", "Slight", "Normal", "Full" }; + str->append(gHintingStrings[this->getHinting()]); + str->append("
"); + + str->append("
"); +} +#endif + + /////////////////////////////////////////////////////////////////////////////// static bool has_thick_frame(const SkPaint& paint) { diff --git a/src/effects/SkLayerDrawLooper.cpp b/src/effects/SkLayerDrawLooper.cpp index 0ffc08ecf6..ddd73083ad 100644 --- a/src/effects/SkLayerDrawLooper.cpp +++ b/src/effects/SkLayerDrawLooper.cpp @@ -338,7 +338,7 @@ void SkLayerDrawLooper::toString(SkString* str) const { str->append("false "); } - // TODO: add "rec->fPaint.toString(str);" when SkPaint::toString is added + rec->fPaint.toString(str); rec = rec->fNext; } }