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