chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkObjectParser.h" |
humper@google.com | f515ffc | 2013-01-07 15:48:19 +0000 | [diff] [blame] | 9 | #include "SkData.h" |
| 10 | #include "SkFontDescriptor.h" |
robertphillips | 80af645 | 2015-08-24 08:27:38 -0700 | [diff] [blame] | 11 | #include "SkImage.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 12 | #include "SkPath.h" |
robertphillips@google.com | 4991b8f | 2013-01-28 20:21:59 +0000 | [diff] [blame] | 13 | #include "SkRRect.h" |
| 14 | #include "SkShader.h" |
| 15 | #include "SkStream.h" |
| 16 | #include "SkStringUtils.h" |
| 17 | #include "SkTypeface.h" |
bungeman@google.com | 428fc4a | 2013-03-07 20:30:32 +0000 | [diff] [blame] | 18 | #include "SkUtils.h" |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 19 | |
| 20 | /* TODO(chudy): Replace all std::strings with char */ |
| 21 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 22 | SkString* SkObjectParser::BitmapToString(const SkBitmap& bitmap) { |
robertphillips@google.com | 195952f | 2012-10-23 12:13:35 +0000 | [diff] [blame] | 23 | SkString* mBitmap = new SkString("SkBitmap: "); |
| 24 | mBitmap->append("W: "); |
| 25 | mBitmap->appendS32(bitmap.width()); |
| 26 | mBitmap->append(" H: "); |
| 27 | mBitmap->appendS32(bitmap.height()); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 28 | |
reed | c77392e | 2014-06-02 13:07:26 -0700 | [diff] [blame] | 29 | const char* gColorTypeStrings[] = { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 30 | "None", "A8", "565", "4444", "RGBA", "BGRA", "Index8", "G8", "RGBAf16" |
robertphillips@google.com | 195952f | 2012-10-23 12:13:35 +0000 | [diff] [blame] | 31 | }; |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 32 | static_assert(kLastEnum_SkColorType + 1 == SK_ARRAY_COUNT(gColorTypeStrings), |
| 33 | "colortype names do not match colortype enum"); |
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 | fe8d5f6 | 2015-10-29 09:45:27 -0700 | [diff] [blame] | 137 | SkString* mPath = new SkString; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 138 | |
robertphillips | fe8d5f6 | 2015-10-29 09:45:27 -0700 | [diff] [blame] | 139 | mPath->appendf("Path (%d) (", path.getGenerationID()); |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 140 | |
robertphillips@google.com | 51185fe | 2012-12-05 19:34:33 +0000 | [diff] [blame] | 141 | static const char* gFillStrings[] = { |
| 142 | "Winding", "EvenOdd", "InverseWinding", "InverseEvenOdd" |
| 143 | }; |
| 144 | |
| 145 | mPath->append(gFillStrings[path.getFillType()]); |
| 146 | mPath->append(", "); |
| 147 | |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 148 | static const char* gConvexityStrings[] = { |
skia.committer@gmail.com | 6a748ad | 2012-10-19 02:01:19 +0000 | [diff] [blame] | 149 | "Unknown", "Convex", "Concave" |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 150 | }; |
| 151 | SkASSERT(SkPath::kConcave_Convexity == 2); |
| 152 | |
| 153 | mPath->append(gConvexityStrings[path.getConvexity()]); |
| 154 | mPath->append(", "); |
| 155 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 156 | if (path.isRect(nullptr)) { |
robertphillips@google.com | 195952f | 2012-10-23 12:13:35 +0000 | [diff] [blame] | 157 | mPath->append("isRect, "); |
| 158 | } else { |
| 159 | mPath->append("isNotRect, "); |
| 160 | } |
| 161 | |
robertphillips | 3d2e654 | 2015-11-24 06:34:50 -0800 | [diff] [blame] | 162 | if (path.isOval(nullptr)) { |
| 163 | mPath->append("isOval, "); |
| 164 | } else { |
| 165 | mPath->append("isNotOval, "); |
| 166 | } |
| 167 | |
| 168 | SkRRect rrect; |
| 169 | if (path.isRRect(&rrect)) { |
| 170 | mPath->append("isRRect, "); |
| 171 | } else { |
| 172 | mPath->append("isNotRRect, "); |
| 173 | } |
| 174 | |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 175 | mPath->appendS32(path.countVerbs()); |
| 176 | mPath->append("V, "); |
| 177 | mPath->appendS32(path.countPoints()); |
| 178 | mPath->append("P): "); |
| 179 | |
| 180 | static const char* gVerbStrings[] = { |
commit-bot@chromium.org | 4a3ca94 | 2013-06-04 21:51:06 +0000 | [diff] [blame] | 181 | "Move", "Line", "Quad", "Conic", "Cubic", "Close", "Done" |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 182 | }; |
commit-bot@chromium.org | 4a3ca94 | 2013-06-04 21:51:06 +0000 | [diff] [blame] | 183 | static const int gPtsPerVerb[] = { 1, 1, 2, 2, 3, 0, 0 }; |
| 184 | static const int gPtOffsetPerVerb[] = { 0, 1, 1, 1, 1, 0, 0 }; |
| 185 | SkASSERT(SkPath::kDone_Verb == 6); |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 186 | |
| 187 | SkPath::Iter iter(const_cast<SkPath&>(path), false); |
| 188 | SkPath::Verb verb; |
| 189 | SkPoint points[4]; |
| 190 | |
skia.committer@gmail.com | 6a748ad | 2012-10-19 02:01:19 +0000 | [diff] [blame] | 191 | for(verb = iter.next(points, false); |
| 192 | verb != SkPath::kDone_Verb; |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 193 | verb = iter.next(points, false)) { |
| 194 | |
| 195 | mPath->append(gVerbStrings[verb]); |
| 196 | mPath->append(" "); |
| 197 | |
| 198 | for (int i = 0; i < gPtsPerVerb[verb]; ++i) { |
| 199 | mPath->append("("); |
| 200 | mPath->appendScalar(points[gPtOffsetPerVerb[verb]+i].fX); |
| 201 | mPath->append(", "); |
| 202 | mPath->appendScalar(points[gPtOffsetPerVerb[verb]+i].fY); |
commit-bot@chromium.org | 4a3ca94 | 2013-06-04 21:51:06 +0000 | [diff] [blame] | 203 | mPath->append(")"); |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 204 | } |
commit-bot@chromium.org | 4a3ca94 | 2013-06-04 21:51:06 +0000 | [diff] [blame] | 205 | |
| 206 | if (SkPath::kConic_Verb == verb) { |
| 207 | mPath->append("("); |
| 208 | mPath->appendScalar(iter.conicWeight()); |
| 209 | mPath->append(")"); |
| 210 | } |
| 211 | |
| 212 | mPath->append(" "); |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 213 | } |
robertphillips@google.com | 8720176 | 2012-10-18 13:30:18 +0000 | [diff] [blame] | 214 | |
robertphillips@google.com | 30d35f2 | 2012-11-06 16:45:36 +0000 | [diff] [blame] | 215 | SkString* boundStr = SkObjectParser::RectToString(path.getBounds(), " Bound: "); |
| 216 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 217 | if (boundStr) { |
robertphillips@google.com | 30d35f2 | 2012-11-06 16:45:36 +0000 | [diff] [blame] | 218 | mPath->append(*boundStr); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 219 | delete boundStr; |
robertphillips@google.com | 30d35f2 | 2012-11-06 16:45:36 +0000 | [diff] [blame] | 220 | } |
| 221 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 222 | return mPath; |
| 223 | } |
| 224 | |
| 225 | SkString* SkObjectParser::PointsToString(const SkPoint pts[], size_t count) { |
| 226 | SkString* mPoints = new SkString("SkPoints pts[]: "); |
| 227 | for (unsigned int i = 0; i < count; i++) { |
| 228 | mPoints->append("("); |
| 229 | mPoints->appendScalar(pts[i].fX); |
| 230 | mPoints->append(","); |
| 231 | mPoints->appendScalar(pts[i].fY); |
| 232 | mPoints->append(")"); |
| 233 | } |
| 234 | return mPoints; |
| 235 | } |
| 236 | |
| 237 | SkString* SkObjectParser::PointModeToString(SkCanvas::PointMode mode) { |
| 238 | SkString* mMode = new SkString("SkCanvas::PointMode: "); |
| 239 | if (mode == SkCanvas::kPoints_PointMode) { |
| 240 | mMode->append("kPoints_PointMode"); |
| 241 | } else if (mode == SkCanvas::kLines_PointMode) { |
| 242 | mMode->append("kLines_Mode"); |
| 243 | } else if (mode == SkCanvas::kPolygon_PointMode) { |
| 244 | mMode->append("kPolygon_PointMode"); |
| 245 | } |
| 246 | return mMode; |
| 247 | } |
| 248 | |
robertphillips@google.com | 30d35f2 | 2012-11-06 16:45:36 +0000 | [diff] [blame] | 249 | SkString* SkObjectParser::RectToString(const SkRect& rect, const char* title) { |
| 250 | |
| 251 | SkString* mRect = new SkString; |
skia.committer@gmail.com | 72b2e6f | 2012-11-08 02:03:56 +0000 | [diff] [blame] | 252 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 253 | if (nullptr == title) { |
robertphillips@google.com | 30d35f2 | 2012-11-06 16:45:36 +0000 | [diff] [blame] | 254 | mRect->append("SkRect: "); |
| 255 | } else { |
| 256 | mRect->append(title); |
| 257 | } |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 258 | mRect->append("("); |
| 259 | mRect->appendScalar(rect.left()); |
| 260 | mRect->append(", "); |
| 261 | mRect->appendScalar(rect.top()); |
| 262 | mRect->append(", "); |
| 263 | mRect->appendScalar(rect.right()); |
| 264 | mRect->append(", "); |
| 265 | mRect->appendScalar(rect.bottom()); |
| 266 | mRect->append(")"); |
| 267 | return mRect; |
| 268 | } |
| 269 | |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 270 | SkString* SkObjectParser::RRectToString(const SkRRect& rrect, const char* title) { |
| 271 | |
| 272 | SkString* mRRect = new SkString; |
| 273 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 274 | if (nullptr == title) { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 275 | mRRect->append("SkRRect ("); |
| 276 | if (rrect.isEmpty()) { |
| 277 | mRRect->append("empty"); |
| 278 | } else if (rrect.isRect()) { |
| 279 | mRRect->append("rect"); |
| 280 | } else if (rrect.isOval()) { |
| 281 | mRRect->append("oval"); |
| 282 | } else if (rrect.isSimple()) { |
| 283 | mRRect->append("simple"); |
commit-bot@chromium.org | f338d7c | 2014-03-17 21:17:30 +0000 | [diff] [blame] | 284 | } else if (rrect.isNinePatch()) { |
| 285 | mRRect->append("nine-patch"); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 286 | } else { |
| 287 | SkASSERT(rrect.isComplex()); |
| 288 | mRRect->append("complex"); |
| 289 | } |
| 290 | mRRect->append("): "); |
| 291 | } else { |
| 292 | mRRect->append(title); |
| 293 | } |
| 294 | mRRect->append("("); |
| 295 | mRRect->appendScalar(rrect.rect().left()); |
| 296 | mRRect->append(", "); |
| 297 | mRRect->appendScalar(rrect.rect().top()); |
| 298 | mRRect->append(", "); |
| 299 | mRRect->appendScalar(rrect.rect().right()); |
| 300 | mRRect->append(", "); |
| 301 | mRRect->appendScalar(rrect.rect().bottom()); |
| 302 | mRRect->append(") radii: ("); |
| 303 | for (int i = 0; i < 4; ++i) { |
| 304 | const SkVector& radii = rrect.radii((SkRRect::Corner) i); |
| 305 | mRRect->appendScalar(radii.fX); |
| 306 | mRRect->append(", "); |
| 307 | mRRect->appendScalar(radii.fY); |
| 308 | if (i < 3) { |
| 309 | mRRect->append(", "); |
| 310 | } |
| 311 | } |
| 312 | mRRect->append(")"); |
| 313 | return mRRect; |
| 314 | } |
| 315 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 316 | SkString* SkObjectParser::RegionOpToString(SkRegion::Op op) { |
| 317 | SkString* mOp = new SkString("SkRegion::Op: "); |
| 318 | if (op == SkRegion::kDifference_Op) { |
| 319 | mOp->append("kDifference_Op"); |
| 320 | } else if (op == SkRegion::kIntersect_Op) { |
| 321 | mOp->append("kIntersect_Op"); |
| 322 | } else if (op == SkRegion::kUnion_Op) { |
| 323 | mOp->append("kUnion_Op"); |
| 324 | } else if (op == SkRegion::kXOR_Op) { |
| 325 | mOp->append("kXOR_Op"); |
| 326 | } else if (op == SkRegion::kReverseDifference_Op) { |
| 327 | mOp->append("kReverseDifference_Op"); |
| 328 | } else if (op == SkRegion::kReplace_Op) { |
| 329 | mOp->append("kReplace_Op"); |
| 330 | } else { |
| 331 | mOp->append("Unknown Type"); |
| 332 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 333 | return mOp; |
| 334 | } |
| 335 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 336 | SkString* SkObjectParser::RegionToString(const SkRegion& region) { |
| 337 | SkString* mRegion = new SkString("SkRegion: Data unavailable."); |
| 338 | return mRegion; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 339 | } |
| 340 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 341 | SkString* SkObjectParser::SaveLayerFlagsToString(SkCanvas::SaveLayerFlags saveLayerFlags) { |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 342 | SkString* mFlags = new SkString("SkCanvas::SaveFlags: "); |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 343 | if (saveLayerFlags & SkCanvas::kIsOpaque_SaveLayerFlag) { |
| 344 | mFlags->append("kIsOpaque_SaveLayerFlag "); |
fmalita@google.com | d3ae1d6 | 2013-07-11 16:25:55 +0000 | [diff] [blame] | 345 | } |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 346 | if (saveLayerFlags & SkCanvas::kPreserveLCDText_SaveLayerFlag) { |
| 347 | mFlags->append("kPreserveLCDText_SaveLayerFlag "); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 348 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 349 | return mFlags; |
| 350 | } |
| 351 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 352 | SkString* SkObjectParser::ScalarToString(SkScalar x, const char* text) { |
| 353 | SkString* mScalar = new SkString(text); |
| 354 | mScalar->append(" "); |
| 355 | mScalar->appendScalar(x); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 356 | return mScalar; |
| 357 | } |
| 358 | |
bungeman@google.com | 428fc4a | 2013-03-07 20:30:32 +0000 | [diff] [blame] | 359 | SkString* SkObjectParser::TextToString(const void* text, size_t byteLength, |
| 360 | SkPaint::TextEncoding encoding) { |
| 361 | |
| 362 | SkString* decodedText = new SkString(); |
| 363 | switch (encoding) { |
| 364 | case SkPaint::kUTF8_TextEncoding: { |
| 365 | decodedText->append("UTF-8: "); |
| 366 | decodedText->append((const char*)text, byteLength); |
| 367 | break; |
| 368 | } |
| 369 | case SkPaint::kUTF16_TextEncoding: { |
| 370 | decodedText->append("UTF-16: "); |
skia.committer@gmail.com | f61ebc0 | 2013-11-22 07:02:24 +0000 | [diff] [blame] | 371 | size_t sizeNeeded = SkUTF16_ToUTF8((uint16_t*)text, |
| 372 | SkToS32(byteLength / 2), |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 373 | nullptr); |
scroggo@google.com | b9050d7 | 2013-08-26 21:20:04 +0000 | [diff] [blame] | 374 | SkAutoSTMalloc<0x100, char> utf8(sizeNeeded); |
robertphillips@google.com | a466286 | 2013-11-21 14:24:16 +0000 | [diff] [blame] | 375 | SkUTF16_ToUTF8((uint16_t*)text, SkToS32(byteLength / 2), utf8); |
bungeman@google.com | 428fc4a | 2013-03-07 20:30:32 +0000 | [diff] [blame] | 376 | decodedText->append(utf8, sizeNeeded); |
bungeman@google.com | 428fc4a | 2013-03-07 20:30:32 +0000 | [diff] [blame] | 377 | break; |
| 378 | } |
| 379 | case SkPaint::kUTF32_TextEncoding: { |
| 380 | decodedText->append("UTF-32: "); |
| 381 | const SkUnichar* begin = (const SkUnichar*)text; |
| 382 | const SkUnichar* end = (const SkUnichar*)((const char*)text + byteLength); |
| 383 | for (const SkUnichar* unichar = begin; unichar < end; ++unichar) { |
| 384 | decodedText->appendUnichar(*unichar); |
| 385 | } |
| 386 | break; |
| 387 | } |
| 388 | case SkPaint::kGlyphID_TextEncoding: { |
| 389 | decodedText->append("GlyphID: "); |
| 390 | const uint16_t* begin = (const uint16_t*)text; |
| 391 | const uint16_t* end = (const uint16_t*)((const char*)text + byteLength); |
| 392 | for (const uint16_t* glyph = begin; glyph < end; ++glyph) { |
| 393 | decodedText->append("0x"); |
| 394 | decodedText->appendHex(*glyph); |
| 395 | decodedText->append(" "); |
| 396 | } |
| 397 | break; |
| 398 | } |
| 399 | default: |
| 400 | decodedText->append("Unknown text encoding."); |
| 401 | break; |
| 402 | } |
| 403 | |
| 404 | return decodedText; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 405 | } |