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" |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 // Determine the language. | 488 // Determine the language. |
489 const uint16_t languageID = SkEndian_SwapBE16(nameRecord->languageID.languag
eTagID); | 489 const uint16_t languageID = SkEndian_SwapBE16(nameRecord->languageID.languag
eTagID); |
490 | 490 |
491 // Handle format 1 languages. | 491 // Handle format 1 languages. |
492 if (SkOTTableName::format_1 == fName.format && languageID >= 0x8000) { | 492 if (SkOTTableName::format_1 == fName.format && languageID >= 0x8000) { |
493 const uint16_t languageTagRecordIndex = languageID - 0x8000; | 493 const uint16_t languageTagRecordIndex = languageID - 0x8000; |
494 | 494 |
495 const SkOTTableName::Format1Ext* format1ext = | 495 const SkOTTableName::Format1Ext* format1ext = |
496 SkTAfter<const SkOTTableName::Format1Ext>(nameRecords, nameRecordsCo
unt); | 496 SkTAfter<const SkOTTableName::Format1Ext>(nameRecords, nameRecordsCo
unt); |
497 | 497 |
498 if (languageTagRecordIndex < format1ext->langTagCount) { | 498 if (languageTagRecordIndex < SkEndian_SwapBE16(format1ext->langTagCount)
) { |
499 const SkOTTableName::Format1Ext::LangTagRecord* languageTagRecord = | 499 const SkOTTableName::Format1Ext::LangTagRecord* languageTagRecord = |
500 SkTAfter<const SkOTTableName::Format1Ext::LangTagRecord>(format1
ext); | 500 SkTAfter<const SkOTTableName::Format1Ext::LangTagRecord>(format1
ext); |
501 | 501 |
502 uint16_t offset = SkEndian_SwapBE16(languageTagRecord[languageTagRec
ordIndex].offset); | 502 uint16_t offset = SkEndian_SwapBE16(languageTagRecord[languageTagRec
ordIndex].offset); |
503 uint16_t length = SkEndian_SwapBE16(languageTagRecord[languageTagRec
ordIndex].length); | 503 uint16_t length = SkEndian_SwapBE16(languageTagRecord[languageTagRec
ordIndex].length); |
504 const uint16_t* string = SkTAddOffset<const uint16_t>(stringTable, o
ffset); | 504 const uint16_t* string = SkTAddOffset<const uint16_t>(stringTable, o
ffset); |
505 SkStringFromUTF16BE(string, length, record.language); | 505 SkStringFromUTF16BE(string, length, record.language); |
506 return true; | 506 return true; |
507 } | 507 } |
508 } | 508 } |
509 | 509 |
510 // Handle format 0 languages, translating them into BCP 47. | 510 // Handle format 0 languages, translating them into BCP 47. |
511 const BCP47FromLanguageId target = { languageID, "" }; | 511 const BCP47FromLanguageId target = { languageID, "" }; |
512 int languageIndex = SkTSearch<BCP47FromLanguageId, BCP47FromLanguageIdLess>( | 512 int languageIndex = SkTSearch<BCP47FromLanguageId, BCP47FromLanguageIdLess>( |
513 BCP47FromLanguageID, SK_ARRAY_COUNT(BCP47FromLanguageID), target, sizeof
(target)); | 513 BCP47FromLanguageID, SK_ARRAY_COUNT(BCP47FromLanguageID), target, sizeof
(target)); |
514 if (languageIndex >= 0) { | 514 if (languageIndex >= 0) { |
515 record.language = BCP47FromLanguageID[languageIndex].bcp47; | 515 record.language = BCP47FromLanguageID[languageIndex].bcp47; |
516 return true; | 516 return true; |
517 } | 517 } |
518 | 518 |
519 // Unknown language, return the BCP 47 code 'und' for 'undetermined'. | 519 // Unknown language, return the BCP 47 code 'und' for 'undetermined'. |
520 SkASSERT(false); | 520 SkASSERT(false); |
521 record.language = "und"; | 521 record.language = "und"; |
522 return true; | 522 return true; |
523 } | 523 } |
OLD | NEW |