From f515ffc3d44975a09755276e572448061df3e2fe Mon Sep 17 00:00:00 2001 From: "humper@google.com" Date: Mon, 7 Jan 2013 15:48:19 +0000 Subject: [PATCH] Show the paint's typeface information in the details pane of the debugger. Also add a convenience constructor for SkMemoryStream that takes the SkData directly (instead of having to construct an empty one and call setData). Review URL: https://codereview.appspot.com/7065045 git-svn-id: http://skia.googlecode.com/svn/trunk@7048 2bbb7eff-a529-9590-31e7-b0007b416f81 --- debugger/SkObjectParser.cpp | 27 ++++++++++++++++++++++++++- gyp/debugger.gyp | 1 + include/core/SkStream.h | 1 + src/core/SkStream.cpp | 5 +++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/debugger/SkObjectParser.cpp b/debugger/SkObjectParser.cpp index 018a86babd..b327c0b090 100644 --- a/debugger/SkObjectParser.cpp +++ b/debugger/SkObjectParser.cpp @@ -8,6 +8,10 @@ #include "SkObjectParser.h" #include "SkRRect.h" +#include "SkTypeface.h" +#include "SkStream.h" +#include "SkData.h" +#include "SkFontDescriptor.h" /* TODO(chudy): Replace all std::strings with char */ @@ -98,8 +102,29 @@ SkString* SkObjectParser::MatrixToString(const SkMatrix& matrix) { SkString* SkObjectParser::PaintToString(const SkPaint& paint) { SkColor color = paint.getColor(); - SkString* mPaint = new SkString("SkPaint: Color: 0x"); + SkString* mPaint = new SkString("
SkPaint:
Color:
0x"); mPaint->appendHex(color); + mPaint->append("
"); + + SkTypeface *typeface = paint.getTypeface(); + if (typeface) { + SkDynamicMemoryWStream ostream; + typeface->serialize(&ostream); + SkData *data = SkAutoTUnref(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("
"); + } return mPaint; } diff --git a/gyp/debugger.gyp b/gyp/debugger.gyp index 5c760db12a..40ce090306 100644 --- a/gyp/debugger.gyp +++ b/gyp/debugger.gyp @@ -81,6 +81,7 @@ '../debugger', # To pull SkDebugger.h '../debugger/QT', # For all the QT UI Goodies '../src/gpu', # To pull gl/GrGLUtil.h + '../src/ports', # To pull SkFontDescriptor.h '../bench', '../tools', '<@(qt_includes)', diff --git a/include/core/SkStream.h b/include/core/SkStream.h index 08d087815b..8f0548e606 100644 --- a/include/core/SkStream.h +++ b/include/core/SkStream.h @@ -188,6 +188,7 @@ public: /** if copyData is true, the stream makes a private copy of the data */ SkMemoryStream(const void* data, size_t length, bool copyData = false); + SkMemoryStream(SkData *data); virtual ~SkMemoryStream(); /** Resets the stream to the specified data and length, diff --git a/src/core/SkStream.cpp b/src/core/SkStream.cpp index f7b1fb4f65..2851e5fec3 100644 --- a/src/core/SkStream.cpp +++ b/src/core/SkStream.cpp @@ -299,6 +299,11 @@ SkMemoryStream::SkMemoryStream(const void* src, size_t size, bool copyData) { fOffset = 0; } +SkMemoryStream::SkMemoryStream(SkData *data) { + fData = SkSafeRef(data); + fOffset = 0; +} + SkMemoryStream::~SkMemoryStream() { fData->unref(); }