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
diff --git a/debugger/SkObjectParser.cpp b/debugger/SkObjectParser.cpp
index 018a86b..b327c0b 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::PaintToString(const SkPaint& paint) {
SkColor color = paint.getColor();
- SkString* mPaint = new SkString("SkPaint: Color: 0x");
+ SkString* mPaint = new SkString("<dl><dt>SkPaint:</dt><dd><dl><dt>Color:</dt><dd>0x");
mPaint->appendHex(color);
+ mPaint->append("</dd>");
+
+ SkTypeface *typeface = paint.getTypeface();
+ if (typeface) {
+ SkDynamicMemoryWStream ostream;
+ typeface->serialize(&ostream);
+ SkData *data = SkAutoTUnref<SkData>(ostream.copyToData());
+
+ SkMemoryStream stream(data);
+ SkFontDescriptor descriptor(&stream);
+
+ mPaint->append("<dt>Font Family Name:</dt><dd>");
+ mPaint->append(descriptor.getFamilyName());
+ mPaint->append("</dd><dt>Font Full Name:</dt><dd>");
+ mPaint->append(descriptor.getFullName());
+ mPaint->append("</dd><dt>Font PS Name:</dt><dd>");
+ mPaint->append(descriptor.getPostscriptName());
+ mPaint->append("</dd><dt>Font File Name:</dt><dd>");
+ mPaint->append(descriptor.getFontFileName());
+ mPaint->append("</dd></dl></dl>");
+ }
return mPaint;
}
diff --git a/gyp/debugger.gyp b/gyp/debugger.gyp
index 5c760db..40ce090 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 08d0878..8f0548e 100644
--- a/include/core/SkStream.h
+++ b/include/core/SkStream.h
@@ -188,6 +188,7 @@
/** 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 f7b1fb4..2851e5f 100644
--- a/src/core/SkStream.cpp
+++ b/src/core/SkStream.cpp
@@ -299,6 +299,11 @@
fOffset = 0;
}
+SkMemoryStream::SkMemoryStream(SkData *data) {
+ fData = SkSafeRef(data);
+ fOffset = 0;
+}
+
SkMemoryStream::~SkMemoryStream() {
fData->unref();
}