OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkObjectParser.h" | 9 #include "SkObjectParser.h" |
10 #include "SkData.h" | 10 #include "SkData.h" |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 SkString* decodedText = new SkString(); | 329 SkString* decodedText = new SkString(); |
330 switch (encoding) { | 330 switch (encoding) { |
331 case SkPaint::kUTF8_TextEncoding: { | 331 case SkPaint::kUTF8_TextEncoding: { |
332 decodedText->append("UTF-8: "); | 332 decodedText->append("UTF-8: "); |
333 decodedText->append((const char*)text, byteLength); | 333 decodedText->append((const char*)text, byteLength); |
334 break; | 334 break; |
335 } | 335 } |
336 case SkPaint::kUTF16_TextEncoding: { | 336 case SkPaint::kUTF16_TextEncoding: { |
337 decodedText->append("UTF-16: "); | 337 decodedText->append("UTF-16: "); |
338 size_t sizeNeeded = SkUTF16_ToUTF8((uint16_t*)text, byteLength / 2, NULL); | 338 size_t sizeNeeded = SkUTF16_ToUTF8((uint16_t*)text, byteLength / 2, NULL); |
339 char* utf8 = new char[sizeNeeded]; | 339 SkAutoTArray<char> autoArray(sizeNeeded); |
340 char* utf8 = autoArray.get(); | |
bungeman-skia
2013/08/22 20:03:09
I like
SkAutoSTMalloc<0x100, char> utf8(sizeNeede
| |
340 SkUTF16_ToUTF8((uint16_t*)text, byteLength / 2, utf8); | 341 SkUTF16_ToUTF8((uint16_t*)text, byteLength / 2, utf8); |
341 decodedText->append(utf8, sizeNeeded); | 342 decodedText->append(utf8, sizeNeeded); |
342 delete utf8; | |
343 break; | 343 break; |
344 } | 344 } |
345 case SkPaint::kUTF32_TextEncoding: { | 345 case SkPaint::kUTF32_TextEncoding: { |
346 decodedText->append("UTF-32: "); | 346 decodedText->append("UTF-32: "); |
347 const SkUnichar* begin = (const SkUnichar*)text; | 347 const SkUnichar* begin = (const SkUnichar*)text; |
348 const SkUnichar* end = (const SkUnichar*)((const char*)text + byteLe ngth); | 348 const SkUnichar* end = (const SkUnichar*)((const char*)text + byteLe ngth); |
349 for (const SkUnichar* unichar = begin; unichar < end; ++unichar) { | 349 for (const SkUnichar* unichar = begin; unichar < end; ++unichar) { |
350 decodedText->appendUnichar(*unichar); | 350 decodedText->appendUnichar(*unichar); |
351 } | 351 } |
352 break; | 352 break; |
353 } | 353 } |
354 case SkPaint::kGlyphID_TextEncoding: { | 354 case SkPaint::kGlyphID_TextEncoding: { |
355 decodedText->append("GlyphID: "); | 355 decodedText->append("GlyphID: "); |
356 const uint16_t* begin = (const uint16_t*)text; | 356 const uint16_t* begin = (const uint16_t*)text; |
357 const uint16_t* end = (const uint16_t*)((const char*)text + byteLeng th); | 357 const uint16_t* end = (const uint16_t*)((const char*)text + byteLeng th); |
358 for (const uint16_t* glyph = begin; glyph < end; ++glyph) { | 358 for (const uint16_t* glyph = begin; glyph < end; ++glyph) { |
359 decodedText->append("0x"); | 359 decodedText->append("0x"); |
360 decodedText->appendHex(*glyph); | 360 decodedText->appendHex(*glyph); |
361 decodedText->append(" "); | 361 decodedText->append(" "); |
362 } | 362 } |
363 break; | 363 break; |
364 } | 364 } |
365 default: | 365 default: |
366 decodedText->append("Unknown text encoding."); | 366 decodedText->append("Unknown text encoding."); |
367 break; | 367 break; |
368 } | 368 } |
369 | 369 |
370 return decodedText; | 370 return decodedText; |
371 } | 371 } |
OLD | NEW |