Chromium Code Reviews| Index: src/utils/SkWhitelistTypefaces.cpp |
| diff --git a/src/utils/SkWhitelistTypefaces.cpp b/src/utils/SkWhitelistTypefaces.cpp |
| index 99f3644a97f6ef6376739ae761e039fe9ef4c5b6..4219423b2ad1117f608c26f23338db758773f621 100644 |
| --- a/src/utils/SkWhitelistTypefaces.cpp |
| +++ b/src/utils/SkWhitelistTypefaces.cpp |
| @@ -11,6 +11,7 @@ |
| #include "SkString.h" |
| #include "SkTypeface.h" |
| #include "SkUtils.h" |
| +#include "../sfnt/SkOTUtils.h" |
| #include "SkWhitelistChecksums.cpp" |
| @@ -25,28 +26,8 @@ extern bool GenerateChecksums(); |
| static bool timesNewRomanSerializedNameOnly = false; |
| #endif |
| -struct NameRecord { |
| - unsigned short fPlatformID; |
| - unsigned short fEncodingID; |
| - unsigned short fLanguageID; |
| - unsigned short fNameID; |
| - unsigned short fLength; |
| - unsigned short fOffset; |
| -}; |
| - |
| -struct NameTable { |
| - unsigned short fFormat; |
| - unsigned short fCount; |
| - unsigned short fStringOffset; |
| - NameRecord fRecord[1]; |
| -}; |
| - |
| #define SUBNAME_PREFIX "sk_" |
| -static unsigned short swizzle(unsigned short x) { |
| - return x << 8 | (x >> 8 & 0xff); |
| -} |
| - |
| static bool font_name_is_local(const char* fontName, SkTypeface::Style style) { |
| if (!strcmp(fontName, "DejaVu Sans")) { |
| return true; |
| @@ -56,76 +37,28 @@ static bool font_name_is_local(const char* fontName, SkTypeface::Style style) { |
| return defaultFace != foundFace; |
| } |
| -static int name_table(const NameTable* nameTable, int tableIndex, const char** stringLocPtr) { |
| - int nameTableCount = swizzle(nameTable->fCount); |
| - for (int i = 0; i < nameTableCount; ++i) { |
| - const NameRecord* nameRecord = &nameTable->fRecord[i]; |
| - int recordNameID = swizzle(nameRecord->fNameID); |
| - if (recordNameID != tableIndex) { |
| - continue; |
| - } |
| - int stringLen = swizzle(nameRecord->fLength); |
| - if (!stringLen) { |
| - break; |
| - } |
| - int recordOffset = swizzle(nameRecord->fOffset); |
| - const char* stringLoc = (const char* ) nameTable + swizzle(nameTable->fStringOffset); |
| - stringLoc += recordOffset; |
| - *stringLocPtr = stringLoc; |
| - return stringLen; |
| - } |
| - return -1; |
| -} |
| - |
| static int whitelist_name_index(const SkTypeface* tf) { |
| - static const SkFontTableTag nameTag = SkSetFourByteTag('n', 'a', 'm', 'e'); |
| - size_t nameSize = tf->getTableSize(nameTag); |
| - if (!nameSize) { |
| - return -1; |
| - } |
| - SkTDArray<char> name; |
| - name.setCount((int) nameSize); |
| - tf->getTableData(nameTag, 0, nameSize, name.begin()); |
| - const NameTable* nameTable = (const NameTable* ) name.begin(); |
| - const char* stringLoc; |
| - int stringLen = name_table(nameTable, 1, &stringLoc); |
| - if (stringLen < 0) { |
| - stringLen = name_table(nameTable, 16, &stringLoc); |
| - } |
| - if (stringLen < 0) { |
| - stringLen = name_table(nameTable, 21, &stringLoc); |
| - } |
| - if (stringLen < 0) { |
| - return -1; |
| - } |
| + |
| SkString fontNameStr; |
| - if (!*stringLoc) { |
| - stringLen /= 2; |
| - for (int i = 0; i < stringLen; ++i) { |
| - fontNameStr.appendUnichar(swizzle(((const uint16_t*) stringLoc)[i])); |
| - } |
| - } else { |
| - fontNameStr.resize(stringLen); |
| - strncpy(fontNameStr.writable_str(), stringLoc, stringLen); |
| - } |
| - // check against permissible list of names |
| - for (int i = 0; i < whitelistCount; ++i) { |
| - if (fontNameStr.equals(whitelist[i].fFontName)) { |
| - return i; |
| + SkTypeface::LocalizedStrings* nameIter = |
|
bungeman-skia
2015/09/01 20:47:51
I think this might be better as
SkAutoTUref<SkTyp
caryclark
2015/09/02 11:45:15
Done.
|
| + SkOTUtils::LocalizedStrings_NameTable::CreateForFamilyNames(*tf); |
| + SkTypeface::LocalizedString familyNameLocalized; |
| + while (nameIter->next(&familyNameLocalized)) { |
| + fontNameStr = familyNameLocalized.fString.c_str(); |
|
bungeman-skia
2015/09/01 20:47:51
Is there a reason for the '.c_str()'? It seems
fo
caryclark
2015/09/02 11:45:15
Done.
|
| + // check against permissible list of names |
| + for (int i = 0; i < whitelistCount; ++i) { |
| + if (fontNameStr.equals(whitelist[i].fFontName)) { |
| + return i; |
| + } |
| } |
| } |
| - for (int i = 0; i < whitelistCount; ++i) { |
| - if (fontNameStr.startsWith(whitelist[i].fFontName)) { |
| + nameIter = SkOTUtils::LocalizedStrings_NameTable::CreateForFamilyNames(*tf); |
|
bungeman-skia
2015/09/01 20:47:51
Does all of this (down to the '}') belong in the '
caryclark
2015/09/02 11:45:15
Done.
|
| + while (nameIter->next(&familyNameLocalized)) { |
| + fontNameStr = familyNameLocalized.fString.c_str(); |
| #if WHITELIST_DEBUG |
| - SkDebugf("partial match whitelist=\"%s\" fontName=\"%s\"\n", whitelist[i].fFontName, |
| - fontNameStr.c_str()); |
| + SkDebugf("no match fontName=\"%s\"\n", fontNameStr.c_str()); |
| #endif |
| - return -1; |
| - } |
| } |
| -#if WHITELIST_DEBUG |
| - SkDebugf("no match fontName=\"%s\"\n", fontNameStr.c_str()); |
| -#endif |
| return -1; |
| } |
| @@ -263,7 +196,7 @@ SkTypeface* WhitelistDeserializeTypeface(SkStream* stream) { |
| if (!strncmp(SUBNAME_PREFIX, familyName, sizeof(SUBNAME_PREFIX) - 1)) { |
| familyName += sizeof(SUBNAME_PREFIX) - 1; |
| } |
| - return SkTypeface::CreateFromName(desc.getFamilyName(), desc.getStyle()); |
| + return SkTypeface::CreateFromName(familyName, desc.getStyle()); |
| } |
| bool CheckChecksums() { |