| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkOTTable_name.h" | 8 #include "SkOTTable_name.h" |
| 9 | 9 |
| 10 #include "SkEndian.h" | 10 #include "SkEndian.h" |
| 11 #include "SkString.h" | 11 #include "SkString.h" |
| 12 #include "SkTSearch.h" | 12 #include "SkTSearch.h" |
| 13 #include "SkTemplates.h" |
| 13 #include "SkUtils.h" | 14 #include "SkUtils.h" |
| 14 | 15 |
| 15 static SkUnichar SkUTF16BE_NextUnichar(const uint16_t** srcPtr) { | 16 static SkUnichar SkUTF16BE_NextUnichar(const uint16_t** srcPtr) { |
| 16 SkASSERT(srcPtr && *srcPtr); | 17 SkASSERT(srcPtr && *srcPtr); |
| 17 | 18 |
| 18 const uint16_t* src = *srcPtr; | 19 const uint16_t* src = *srcPtr; |
| 19 SkUnichar c = SkEndian_SwapBE16(*src++); | 20 SkUnichar c = SkEndian_SwapBE16(*src++); |
| 20 | 21 |
| 21 SkASSERT(!SkUTF16_IsLowSurrogate(c)); | 22 SkASSERT(!SkUTF16_IsLowSurrogate(c)); |
| 22 if (SkUTF16_IsHighSurrogate(c)) { | 23 if (SkUTF16_IsHighSurrogate(c)) { |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 { 0x500a, "es-PR" }, //Spanish | 429 { 0x500a, "es-PR" }, //Spanish |
| 429 { 0x540a, "es-US" }, //Spanish | 430 { 0x540a, "es-US" }, //Spanish |
| 430 }; | 431 }; |
| 431 | 432 |
| 432 namespace { | 433 namespace { |
| 433 int BCP47FromLanguageIdCompare(const BCP47FromLanguageId* a, const BCP47FromLang
uageId* b) { | 434 int BCP47FromLanguageIdCompare(const BCP47FromLanguageId* a, const BCP47FromLang
uageId* b) { |
| 434 return a->languageID - b->languageID; | 435 return a->languageID - b->languageID; |
| 435 } | 436 } |
| 436 } | 437 } |
| 437 | 438 |
| 438 template <typename D, typename S> static D* SkTAfter(S const * const ptr, size_t
count = 1) { | |
| 439 return (D*)(ptr + count); | |
| 440 } | |
| 441 | |
| 442 template <typename D, typename S> static D* SkTAddOffset(S const * const ptr, si
ze_t byteOffset) { | |
| 443 return (D*)((char*)ptr + byteOffset); | |
| 444 } | |
| 445 | |
| 446 bool SkOTTableName::Iterator::next(SkOTTableName::Iterator::Record& record) { | 439 bool SkOTTableName::Iterator::next(SkOTTableName::Iterator::Record& record) { |
| 447 const size_t nameRecordsCount = SkEndian_SwapBE16(fName.count); | 440 const size_t nameRecordsCount = SkEndian_SwapBE16(fName.count); |
| 448 const SkOTTableName::Record* nameRecords = SkTAfter<const SkOTTableName::Rec
ord>(&fName); | 441 const SkOTTableName::Record* nameRecords = SkTAfter<const SkOTTableName::Rec
ord>(&fName); |
| 449 const SkOTTableName::Record* nameRecord; | 442 const SkOTTableName::Record* nameRecord; |
| 450 | 443 |
| 451 // Find the next record which matches the requested type. | 444 // Find the next record which matches the requested type. |
| 452 do { | 445 do { |
| 453 if (fIndex >= nameRecordsCount) { | 446 if (fIndex >= nameRecordsCount) { |
| 454 return false; | 447 return false; |
| 455 } | 448 } |
| 456 | 449 |
| 457 nameRecord = &nameRecords[fIndex]; | 450 nameRecord = &nameRecords[fIndex]; |
| 458 ++fIndex; | 451 ++fIndex; |
| 459 } while (fType != -1 && nameRecord->nameID.fontSpecific != fType); | 452 } while (fType != -1 && nameRecord->nameID.fontSpecific != fType); |
| 460 | 453 |
| 461 const uint16_t stringTableOffset = SkEndian_SwapBE16(fName.stringOffset); | 454 const uint16_t stringTableOffset = SkEndian_SwapBE16(fName.stringOffset); |
| 462 const char* stringTable = SkTAddOffset<char>(&fName, stringTableOffset); | 455 const char* stringTable = SkTAddOffset<const char>(&fName, stringTableOffset
); |
| 463 | 456 |
| 464 // Decode the name into UTF-8. | 457 // Decode the name into UTF-8. |
| 465 const uint16_t nameOffset = SkEndian_SwapBE16(nameRecord->offset); | 458 const uint16_t nameOffset = SkEndian_SwapBE16(nameRecord->offset); |
| 466 const uint16_t nameLength = SkEndian_SwapBE16(nameRecord->length); | 459 const uint16_t nameLength = SkEndian_SwapBE16(nameRecord->length); |
| 467 const char* nameString = SkTAddOffset<char>(stringTable, nameOffset); | 460 const char* nameString = SkTAddOffset<const char>(stringTable, nameOffset); |
| 468 switch (nameRecord->platformID.value) { | 461 switch (nameRecord->platformID.value) { |
| 469 case SkOTTableName::Record::PlatformID::Windows: | 462 case SkOTTableName::Record::PlatformID::Windows: |
| 470 SkASSERT(SkOTTableName::Record::EncodingID::Windows::UnicodeBMPUCS2 | 463 SkASSERT(SkOTTableName::Record::EncodingID::Windows::UnicodeBMPUCS2 |
| 471 == nameRecord->encodingID.windows.value | 464 == nameRecord->encodingID.windows.value |
| 472 || SkOTTableName::Record::EncodingID::Windows::UnicodeUCS4 | 465 || SkOTTableName::Record::EncodingID::Windows::UnicodeUCS4 |
| 473 == nameRecord->encodingID.windows.value | 466 == nameRecord->encodingID.windows.value |
| 474 || SkOTTableName::Record::EncodingID::Windows::Symbol | 467 || SkOTTableName::Record::EncodingID::Windows::Symbol |
| 475 == nameRecord->encodingID.windows.value); | 468 == nameRecord->encodingID.windows.value); |
| 476 case SkOTTableName::Record::PlatformID::Unicode: | 469 case SkOTTableName::Record::PlatformID::Unicode: |
| 477 case SkOTTableName::Record::PlatformID::ISO: | 470 case SkOTTableName::Record::PlatformID::ISO: |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 if (languageIndex >= 0) { | 514 if (languageIndex >= 0) { |
| 522 record.language = BCP47FromLanguageID[languageIndex].bcp47; | 515 record.language = BCP47FromLanguageID[languageIndex].bcp47; |
| 523 return true; | 516 return true; |
| 524 } | 517 } |
| 525 | 518 |
| 526 // Unknown language, return the BCP 47 code 'und' for 'undetermined'. | 519 // Unknown language, return the BCP 47 code 'und' for 'undetermined'. |
| 527 SkASSERT(false); | 520 SkASSERT(false); |
| 528 record.language = "und"; | 521 record.language = "und"; |
| 529 return true; | 522 return true; |
| 530 } | 523 } |
| OLD | NEW |