chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | #include "SkObjectParser.h" |
humper@google.com | f515ffc | 2013-01-07 15:48:19 +0000 | [diff] [blame] | 10 | #include "SkData.h" |
| 11 | #include "SkFontDescriptor.h" |
robertphillips@google.com | 4991b8f | 2013-01-28 20:21:59 +0000 | [diff] [blame] | 12 | #include "SkRRect.h" |
| 13 | #include "SkShader.h" |
| 14 | #include "SkStream.h" |
| 15 | #include "SkStringUtils.h" |
| 16 | #include "SkTypeface.h" |
bungeman@google.com | 428fc4a | 2013-03-07 20:30:32 +0000 | [diff] [blame] | 17 | #include "SkUtils.h" |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 18 | |
| 19 | /* TODO(chudy): Replace all std::strings with char */ |
| 20 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 21 | SkString* SkObjectParser::BitmapToString(const SkBitmap& bitmap) { |
robertphillips@google.com | 195952f | 2012-10-23 12:13:35 +0000 | [diff] [blame] | 22 | SkString* mBitmap = new SkString("SkBitmap: "); |
| 23 | mBitmap->append("W: "); |
| 24 | mBitmap->appendS32(bitmap.width()); |
| 25 | mBitmap->append(" H: "); |
| 26 | mBitmap->appendS32(bitmap.height()); |
| 27 | |
| 28 | const char* gConfigStrings[] = { |
reed@google.com | 2a1f446 | 2013-11-25 18:58:29 +0000 | [diff] [blame] | 29 | "None", "A8", "Index8", "RGB565", "ARGB4444", "ARGB8888" |
robertphillips@google.com | 195952f | 2012-10-23 12:13:35 +0000 | [diff] [blame] | 30 | }; |
reed@google.com | 2a1f446 | 2013-11-25 18:58:29 +0000 | [diff] [blame] | 31 | SkASSERT(SkBitmap::kConfigCount == SK_ARRAY_COUNT(gConfigStrings)); |
robertphillips@google.com | 195952f | 2012-10-23 12:13:35 +0000 | [diff] [blame] | 32 | |
| 33 | mBitmap->append(" Config: "); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 34 | mBitmap->append(gConfigStrings[bitmap.config()]); |
robertphillips@google.com | 195952f | 2012-10-23 12:13:35 +0000 | [diff] [blame] | 35 | |
| 36 | if (bitmap.isOpaque()) { |
| 37 | mBitmap->append(" opaque"); |
| 38 | } else { |
| 39 | mBitmap->append(" not-opaque"); |
| 40 | } |
| 41 | |
| 42 | if (bitmap.isImmutable()) { |
| 43 | mBitmap->append(" immutable"); |
| 44 | } else { |
| 45 | mBitmap->append(" not-immutable"); |
| 46 | } |
| 47 | |
| 48 | if (bitmap.isVolatile()) { |
| 49 | mBitmap->append(" volatile"); |
| 50 | } else { |
| 51 | mBitmap->append(" not-volatile"); |
| 52 | } |
| 53 | |
| 54 | mBitmap->append(" genID: "); |
| 55 | mBitmap->appendS32(bitmap.getGenerationID()); |
| 56 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 57 | return mBitmap; |
| 58 | } |
| 59 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 60 | SkString* SkObjectParser::BoolToString(bool doAA) { |
| 61 | SkString* mBool = new SkString("Bool doAA: "); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 62 | if (doAA) { |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 63 | mBool->append("True"); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 64 | } else { |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 65 | mBool->append("False"); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 66 | } |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 67 | return mBool; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 68 | } |
| 69 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 70 | SkString* SkObjectParser::CustomTextToString(const char* text) { |
| 71 | SkString* mText = new SkString(text); |
| 72 | return mText; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 73 | } |
| 74 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 75 | SkString* SkObjectParser::IntToString(int x, const char* text) { |
| 76 | SkString* mInt = new SkString(text); |
| 77 | mInt->append(" "); |
| 78 | mInt->appendScalar(SkIntToScalar(x)); |
| 79 | return mInt; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 80 | } |
| 81 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 82 | SkString* SkObjectParser::IRectToString(const SkIRect& rect) { |
| 83 | SkString* mRect = new SkString("SkIRect: "); |
| 84 | mRect->append("L: "); |
robertphillips@google.com | 195952f | 2012-10-23 12:13:35 +0000 | [diff] [blame] | 85 | mRect->appendS32(rect.left()); |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 86 | mRect->append(", T: "); |
robertphillips@google.com | 195952f | 2012-10-23 12:13:35 +0000 | [diff] [blame] | 87 | mRect->appendS32(rect.top()); |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 88 | mRect->append(", R: "); |
robertphillips@google.com | 195952f | 2012-10-23 12:13:35 +0000 | [diff] [blame] | 89 | mRect->appendS32(rect.right()); |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 90 | mRect->append(", B: "); |
robertphillips@google.com | 195952f | 2012-10-23 12:13:35 +0000 | [diff] [blame] | 91 | mRect->appendS32(rect.bottom()); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 92 | return mRect; |
| 93 | } |
| 94 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 95 | SkString* SkObjectParser::MatrixToString(const SkMatrix& matrix) { |
robertphillips@google.com | 791f12e | 2013-02-14 13:53:53 +0000 | [diff] [blame] | 96 | SkString* str = new SkString("SkMatrix: "); |
robertphillips@google.com | 37a2b39 | 2013-02-14 14:40:27 +0000 | [diff] [blame] | 97 | #ifdef SK_DEVELOPER |
robertphillips@google.com | 791f12e | 2013-02-14 13:53:53 +0000 | [diff] [blame] | 98 | matrix.toString(str); |
robertphillips@google.com | 37a2b39 | 2013-02-14 14:40:27 +0000 | [diff] [blame] | 99 | #endif |
robertphillips@google.com | 791f12e | 2013-02-14 13:53:53 +0000 | [diff] [blame] | 100 | return str; |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 101 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 102 | |
robertphillips@google.com | 735edb0 | 2013-01-10 18:54:11 +0000 | [diff] [blame] | 103 | SkString* SkObjectParser::PaintToString(const SkPaint& paint) { |
robertphillips@google.com | 791f12e | 2013-02-14 13:53:53 +0000 | [diff] [blame] | 104 | SkString* str = new SkString; |
robertphillips@google.com | 37a2b39 | 2013-02-14 14:40:27 +0000 | [diff] [blame] | 105 | #ifdef SK_DEVELOPER |
robertphillips@google.com | 791f12e | 2013-02-14 13:53:53 +0000 | [diff] [blame] | 106 | paint.toString(str); |
robertphillips@google.com | 37a2b39 | 2013-02-14 14:40:27 +0000 | [diff] [blame] | 107 | #endif |
robertphillips@google.com | 791f12e | 2013-02-14 13:53:53 +0000 | [diff] [blame] | 108 | return str; |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | SkString* SkObjectParser::PathToString(const SkPath& path) { |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 112 | SkString* mPath = new SkString("Path ("); |
| 113 | |
robertphillips@google.com | 51185fe | 2012-12-05 19:34:33 +0000 | [diff] [blame] | 114 | static const char* gFillStrings[] = { |
| 115 | "Winding", "EvenOdd", "InverseWinding", "InverseEvenOdd" |
| 116 | }; |
| 117 | |
| 118 | mPath->append(gFillStrings[path.getFillType()]); |
| 119 | mPath->append(", "); |
| 120 | |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 121 | static const char* gConvexityStrings[] = { |
skia.committer@gmail.com | 6a748ad | 2012-10-19 02:01:19 +0000 | [diff] [blame] | 122 | "Unknown", "Convex", "Concave" |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 123 | }; |
| 124 | SkASSERT(SkPath::kConcave_Convexity == 2); |
| 125 | |
| 126 | mPath->append(gConvexityStrings[path.getConvexity()]); |
| 127 | mPath->append(", "); |
| 128 | |
robertphillips@google.com | 195952f | 2012-10-23 12:13:35 +0000 | [diff] [blame] | 129 | if (path.isRect(NULL)) { |
| 130 | mPath->append("isRect, "); |
| 131 | } else { |
| 132 | mPath->append("isNotRect, "); |
| 133 | } |
| 134 | |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 135 | mPath->appendS32(path.countVerbs()); |
| 136 | mPath->append("V, "); |
| 137 | mPath->appendS32(path.countPoints()); |
| 138 | mPath->append("P): "); |
| 139 | |
| 140 | static const char* gVerbStrings[] = { |
commit-bot@chromium.org | 4a3ca94 | 2013-06-04 21:51:06 +0000 | [diff] [blame] | 141 | "Move", "Line", "Quad", "Conic", "Cubic", "Close", "Done" |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 142 | }; |
commit-bot@chromium.org | 4a3ca94 | 2013-06-04 21:51:06 +0000 | [diff] [blame] | 143 | static const int gPtsPerVerb[] = { 1, 1, 2, 2, 3, 0, 0 }; |
| 144 | static const int gPtOffsetPerVerb[] = { 0, 1, 1, 1, 1, 0, 0 }; |
| 145 | SkASSERT(SkPath::kDone_Verb == 6); |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 146 | |
| 147 | SkPath::Iter iter(const_cast<SkPath&>(path), false); |
| 148 | SkPath::Verb verb; |
| 149 | SkPoint points[4]; |
| 150 | |
skia.committer@gmail.com | 6a748ad | 2012-10-19 02:01:19 +0000 | [diff] [blame] | 151 | for(verb = iter.next(points, false); |
| 152 | verb != SkPath::kDone_Verb; |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 153 | verb = iter.next(points, false)) { |
| 154 | |
| 155 | mPath->append(gVerbStrings[verb]); |
| 156 | mPath->append(" "); |
| 157 | |
| 158 | for (int i = 0; i < gPtsPerVerb[verb]; ++i) { |
| 159 | mPath->append("("); |
| 160 | mPath->appendScalar(points[gPtOffsetPerVerb[verb]+i].fX); |
| 161 | mPath->append(", "); |
| 162 | mPath->appendScalar(points[gPtOffsetPerVerb[verb]+i].fY); |
commit-bot@chromium.org | 4a3ca94 | 2013-06-04 21:51:06 +0000 | [diff] [blame] | 163 | mPath->append(")"); |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 164 | } |
commit-bot@chromium.org | 4a3ca94 | 2013-06-04 21:51:06 +0000 | [diff] [blame] | 165 | |
| 166 | if (SkPath::kConic_Verb == verb) { |
| 167 | mPath->append("("); |
| 168 | mPath->appendScalar(iter.conicWeight()); |
| 169 | mPath->append(")"); |
| 170 | } |
| 171 | |
| 172 | mPath->append(" "); |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 173 | } |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 174 | |
robertphillips@google.com | 30d35f2 | 2012-11-06 16:45:36 +0000 | [diff] [blame] | 175 | SkString* boundStr = SkObjectParser::RectToString(path.getBounds(), " Bound: "); |
| 176 | |
| 177 | if (NULL != boundStr) { |
| 178 | mPath->append(*boundStr); |
| 179 | SkDELETE(boundStr); |
| 180 | } |
| 181 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 182 | return mPath; |
| 183 | } |
| 184 | |
| 185 | SkString* SkObjectParser::PointsToString(const SkPoint pts[], size_t count) { |
| 186 | SkString* mPoints = new SkString("SkPoints pts[]: "); |
| 187 | for (unsigned int i = 0; i < count; i++) { |
| 188 | mPoints->append("("); |
| 189 | mPoints->appendScalar(pts[i].fX); |
| 190 | mPoints->append(","); |
| 191 | mPoints->appendScalar(pts[i].fY); |
| 192 | mPoints->append(")"); |
| 193 | } |
| 194 | return mPoints; |
| 195 | } |
| 196 | |
| 197 | SkString* SkObjectParser::PointModeToString(SkCanvas::PointMode mode) { |
| 198 | SkString* mMode = new SkString("SkCanvas::PointMode: "); |
| 199 | if (mode == SkCanvas::kPoints_PointMode) { |
| 200 | mMode->append("kPoints_PointMode"); |
| 201 | } else if (mode == SkCanvas::kLines_PointMode) { |
| 202 | mMode->append("kLines_Mode"); |
| 203 | } else if (mode == SkCanvas::kPolygon_PointMode) { |
| 204 | mMode->append("kPolygon_PointMode"); |
| 205 | } |
| 206 | return mMode; |
| 207 | } |
| 208 | |
robertphillips@google.com | 30d35f2 | 2012-11-06 16:45:36 +0000 | [diff] [blame] | 209 | SkString* SkObjectParser::RectToString(const SkRect& rect, const char* title) { |
| 210 | |
| 211 | SkString* mRect = new SkString; |
skia.committer@gmail.com | 72b2e6f | 2012-11-08 02:03:56 +0000 | [diff] [blame] | 212 | |
robertphillips@google.com | 30d35f2 | 2012-11-06 16:45:36 +0000 | [diff] [blame] | 213 | if (NULL == title) { |
| 214 | mRect->append("SkRect: "); |
| 215 | } else { |
| 216 | mRect->append(title); |
| 217 | } |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 218 | mRect->append("("); |
| 219 | mRect->appendScalar(rect.left()); |
| 220 | mRect->append(", "); |
| 221 | mRect->appendScalar(rect.top()); |
| 222 | mRect->append(", "); |
| 223 | mRect->appendScalar(rect.right()); |
| 224 | mRect->append(", "); |
| 225 | mRect->appendScalar(rect.bottom()); |
| 226 | mRect->append(")"); |
| 227 | return mRect; |
| 228 | } |
| 229 | |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 230 | SkString* SkObjectParser::RRectToString(const SkRRect& rrect, const char* title) { |
| 231 | |
| 232 | SkString* mRRect = new SkString; |
| 233 | |
| 234 | if (NULL == title) { |
| 235 | mRRect->append("SkRRect ("); |
| 236 | if (rrect.isEmpty()) { |
| 237 | mRRect->append("empty"); |
| 238 | } else if (rrect.isRect()) { |
| 239 | mRRect->append("rect"); |
| 240 | } else if (rrect.isOval()) { |
| 241 | mRRect->append("oval"); |
| 242 | } else if (rrect.isSimple()) { |
| 243 | mRRect->append("simple"); |
| 244 | } else { |
| 245 | SkASSERT(rrect.isComplex()); |
| 246 | mRRect->append("complex"); |
| 247 | } |
| 248 | mRRect->append("): "); |
| 249 | } else { |
| 250 | mRRect->append(title); |
| 251 | } |
| 252 | mRRect->append("("); |
| 253 | mRRect->appendScalar(rrect.rect().left()); |
| 254 | mRRect->append(", "); |
| 255 | mRRect->appendScalar(rrect.rect().top()); |
| 256 | mRRect->append(", "); |
| 257 | mRRect->appendScalar(rrect.rect().right()); |
| 258 | mRRect->append(", "); |
| 259 | mRRect->appendScalar(rrect.rect().bottom()); |
| 260 | mRRect->append(") radii: ("); |
| 261 | for (int i = 0; i < 4; ++i) { |
| 262 | const SkVector& radii = rrect.radii((SkRRect::Corner) i); |
| 263 | mRRect->appendScalar(radii.fX); |
| 264 | mRRect->append(", "); |
| 265 | mRRect->appendScalar(radii.fY); |
| 266 | if (i < 3) { |
| 267 | mRRect->append(", "); |
| 268 | } |
| 269 | } |
| 270 | mRRect->append(")"); |
| 271 | return mRRect; |
| 272 | } |
| 273 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 274 | SkString* SkObjectParser::RegionOpToString(SkRegion::Op op) { |
| 275 | SkString* mOp = new SkString("SkRegion::Op: "); |
| 276 | if (op == SkRegion::kDifference_Op) { |
| 277 | mOp->append("kDifference_Op"); |
| 278 | } else if (op == SkRegion::kIntersect_Op) { |
| 279 | mOp->append("kIntersect_Op"); |
| 280 | } else if (op == SkRegion::kUnion_Op) { |
| 281 | mOp->append("kUnion_Op"); |
| 282 | } else if (op == SkRegion::kXOR_Op) { |
| 283 | mOp->append("kXOR_Op"); |
| 284 | } else if (op == SkRegion::kReverseDifference_Op) { |
| 285 | mOp->append("kReverseDifference_Op"); |
| 286 | } else if (op == SkRegion::kReplace_Op) { |
| 287 | mOp->append("kReplace_Op"); |
| 288 | } else { |
| 289 | mOp->append("Unknown Type"); |
| 290 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 291 | return mOp; |
| 292 | } |
| 293 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 294 | SkString* SkObjectParser::RegionToString(const SkRegion& region) { |
| 295 | SkString* mRegion = new SkString("SkRegion: Data unavailable."); |
| 296 | return mRegion; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 297 | } |
| 298 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 299 | SkString* SkObjectParser::SaveFlagsToString(SkCanvas::SaveFlags flags) { |
| 300 | SkString* mFlags = new SkString("SkCanvas::SaveFlags: "); |
fmalita@google.com | d3ae1d6 | 2013-07-11 16:25:55 +0000 | [diff] [blame] | 301 | if (flags & SkCanvas::kMatrix_SaveFlag) { |
| 302 | mFlags->append("kMatrix_SaveFlag "); |
| 303 | } |
| 304 | if (flags & SkCanvas::kClip_SaveFlag) { |
| 305 | mFlags->append("kClip_SaveFlag "); |
| 306 | } |
| 307 | if (flags & SkCanvas::kHasAlphaLayer_SaveFlag) { |
| 308 | mFlags->append("kHasAlphaLayer_SaveFlag "); |
| 309 | } |
| 310 | if (flags & SkCanvas::kFullColorLayer_SaveFlag) { |
| 311 | mFlags->append("kFullColorLayer_SaveFlag "); |
| 312 | } |
| 313 | if (flags & SkCanvas::kClipToLayer_SaveFlag) { |
| 314 | mFlags->append("kClipToLayer_SaveFlag "); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 315 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 316 | return mFlags; |
| 317 | } |
| 318 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 319 | SkString* SkObjectParser::ScalarToString(SkScalar x, const char* text) { |
| 320 | SkString* mScalar = new SkString(text); |
| 321 | mScalar->append(" "); |
| 322 | mScalar->appendScalar(x); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 323 | return mScalar; |
| 324 | } |
| 325 | |
bungeman@google.com | 428fc4a | 2013-03-07 20:30:32 +0000 | [diff] [blame] | 326 | SkString* SkObjectParser::TextToString(const void* text, size_t byteLength, |
| 327 | SkPaint::TextEncoding encoding) { |
| 328 | |
| 329 | SkString* decodedText = new SkString(); |
| 330 | switch (encoding) { |
| 331 | case SkPaint::kUTF8_TextEncoding: { |
| 332 | decodedText->append("UTF-8: "); |
| 333 | decodedText->append((const char*)text, byteLength); |
| 334 | break; |
| 335 | } |
| 336 | case SkPaint::kUTF16_TextEncoding: { |
| 337 | decodedText->append("UTF-16: "); |
skia.committer@gmail.com | f61ebc0 | 2013-11-22 07:02:24 +0000 | [diff] [blame] | 338 | size_t sizeNeeded = SkUTF16_ToUTF8((uint16_t*)text, |
| 339 | SkToS32(byteLength / 2), |
robertphillips@google.com | a466286 | 2013-11-21 14:24:16 +0000 | [diff] [blame] | 340 | NULL); |
scroggo@google.com | b9050d7 | 2013-08-26 21:20:04 +0000 | [diff] [blame] | 341 | SkAutoSTMalloc<0x100, char> utf8(sizeNeeded); |
robertphillips@google.com | a466286 | 2013-11-21 14:24:16 +0000 | [diff] [blame] | 342 | SkUTF16_ToUTF8((uint16_t*)text, SkToS32(byteLength / 2), utf8); |
bungeman@google.com | 428fc4a | 2013-03-07 20:30:32 +0000 | [diff] [blame] | 343 | decodedText->append(utf8, sizeNeeded); |
bungeman@google.com | 428fc4a | 2013-03-07 20:30:32 +0000 | [diff] [blame] | 344 | break; |
| 345 | } |
| 346 | case SkPaint::kUTF32_TextEncoding: { |
| 347 | decodedText->append("UTF-32: "); |
| 348 | const SkUnichar* begin = (const SkUnichar*)text; |
| 349 | const SkUnichar* end = (const SkUnichar*)((const char*)text + byteLength); |
| 350 | for (const SkUnichar* unichar = begin; unichar < end; ++unichar) { |
| 351 | decodedText->appendUnichar(*unichar); |
| 352 | } |
| 353 | break; |
| 354 | } |
| 355 | case SkPaint::kGlyphID_TextEncoding: { |
| 356 | decodedText->append("GlyphID: "); |
| 357 | const uint16_t* begin = (const uint16_t*)text; |
| 358 | const uint16_t* end = (const uint16_t*)((const char*)text + byteLength); |
| 359 | for (const uint16_t* glyph = begin; glyph < end; ++glyph) { |
| 360 | decodedText->append("0x"); |
| 361 | decodedText->appendHex(*glyph); |
| 362 | decodedText->append(" "); |
| 363 | } |
| 364 | break; |
| 365 | } |
| 366 | default: |
| 367 | decodedText->append("Unknown text encoding."); |
| 368 | break; |
| 369 | } |
| 370 | |
| 371 | return decodedText; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 372 | } |