Make debugger 'text' output less useless.
https://codereview.appspot.com/7588043/


git-svn-id: http://skia.googlecode.com/svn/trunk@8029 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/debugger/SkDrawCommand.cpp b/debugger/SkDrawCommand.cpp
index ef1e1ec..8ffcb4b 100644
--- a/debugger/SkDrawCommand.cpp
+++ b/debugger/SkDrawCommand.cpp
@@ -348,7 +348,7 @@
     this->fPaint = &paint;
     this->fDrawType = DRAW_POS_TEXT;
 
-    this->fInfo.push(SkObjectParser::TextToString(text, byteLength));
+    this->fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
     // TODO(chudy): Test that this works.
     this->fInfo.push(SkObjectParser::PointsToString(pos, 1));
     this->fInfo.push(SkObjectParser::PaintToString(paint));
@@ -368,7 +368,7 @@
     this->fPaint = &paint;
     this->fDrawType = DRAW_POS_TEXT_H;
 
-    this->fInfo.push(SkObjectParser::TextToString(text, byteLength));
+    this->fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
     this->fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
     this->fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
     this->fInfo.push(SkObjectParser::PaintToString(paint));
@@ -436,7 +436,7 @@
     this->fPaint = &paint;
     this->fDrawType = DRAW_TEXT;
 
-    this->fInfo.push(SkObjectParser::TextToString(text, byteLength));
+    this->fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
     this->fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
     this->fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
     this->fInfo.push(SkObjectParser::PaintToString(paint));
@@ -455,7 +455,7 @@
     this->fPaint = &paint;
     this->fDrawType = DRAW_TEXT_ON_PATH;
 
-    this->fInfo.push(SkObjectParser::TextToString(text, byteLength));
+    this->fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
     this->fInfo.push(SkObjectParser::PathToString(path));
     if (matrix) this->fInfo.push(SkObjectParser::MatrixToString(*matrix));
     this->fInfo.push(SkObjectParser::PaintToString(paint));
diff --git a/debugger/SkObjectParser.cpp b/debugger/SkObjectParser.cpp
index a3738db..2d1f140 100644
--- a/debugger/SkObjectParser.cpp
+++ b/debugger/SkObjectParser.cpp
@@ -14,6 +14,7 @@
 #include "SkStream.h"
 #include "SkStringUtils.h"
 #include "SkTypeface.h"
+#include "SkUtils.h"
 
 /* TODO(chudy): Replace all std::strings with char */
 
@@ -318,9 +319,49 @@
     return mScalar;
 }
 
-SkString* SkObjectParser::TextToString(const void* text, size_t byteLength) {
-    SkString* mText = new SkString(6+byteLength+1);
-    mText->append("Text: ");
-    mText->append((char*) text, byteLength);
-    return mText;
+SkString* SkObjectParser::TextToString(const void* text, size_t byteLength,
+                                       SkPaint::TextEncoding encoding) {
+
+    SkString* decodedText = new SkString();
+    switch (encoding) {
+        case SkPaint::kUTF8_TextEncoding: {
+            decodedText->append("UTF-8: ");
+            decodedText->append((const char*)text, byteLength);
+            break;
+        }
+        case SkPaint::kUTF16_TextEncoding: {
+            decodedText->append("UTF-16: ");
+            size_t sizeNeeded = SkUTF16_ToUTF8((uint16_t*)text, byteLength / 2, NULL);
+            char* utf8 = new char[sizeNeeded];
+            SkUTF16_ToUTF8((uint16_t*)text, byteLength / 2, utf8);
+            decodedText->append(utf8, sizeNeeded);
+            delete utf8;
+            break;
+        }
+        case SkPaint::kUTF32_TextEncoding: {
+            decodedText->append("UTF-32: ");
+            const SkUnichar* begin = (const SkUnichar*)text;
+            const SkUnichar* end = (const SkUnichar*)((const char*)text + byteLength);
+            for (const SkUnichar* unichar = begin; unichar < end; ++unichar) {
+                decodedText->appendUnichar(*unichar);
+            }
+            break;
+        }
+        case SkPaint::kGlyphID_TextEncoding: {
+            decodedText->append("GlyphID: ");
+            const uint16_t* begin = (const uint16_t*)text;
+            const uint16_t* end = (const uint16_t*)((const char*)text + byteLength);
+            for (const uint16_t* glyph = begin; glyph < end; ++glyph) {
+                decodedText->append("0x");
+                decodedText->appendHex(*glyph);
+                decodedText->append(" ");
+            }
+            break;
+        }
+        default:
+            decodedText->append("Unknown text encoding.");
+            break;
+    }
+
+    return decodedText;
 }
diff --git a/debugger/SkObjectParser.h b/debugger/SkObjectParser.h
index ff22069..911b778 100644
--- a/debugger/SkObjectParser.h
+++ b/debugger/SkObjectParser.h
@@ -121,7 +121,8 @@
         Returns a string representation of the char pointer passed in.
         @param text  const void* that will be cast to a char*
      */
-    static SkString* TextToString(const void* text, size_t byteLength);
+    static SkString* TextToString(const void* text, size_t byteLength,
+                                  SkPaint::TextEncoding encoding);
 };
 
 #endif