Index: src/ports/SkFontConfigParser_android.cpp |
diff --git a/src/ports/SkFontConfigParser_android.cpp b/src/ports/SkFontConfigParser_android.cpp |
index 20fee40a78592ffa212a23fe86ad7339776825ba..ce4ebbeb41bee3dcb7d00cc3e365ad3e0161581d 100644 |
--- a/src/ports/SkFontConfigParser_android.cpp |
+++ b/src/ports/SkFontConfigParser_android.cpp |
@@ -502,44 +502,42 @@ static void append_fallback_font_families_for_locale(SkTDArray<FontFamily*>& fal |
return; |
#endif |
- DIR* fontDirectory = opendir(dir); |
- if (fontDirectory != NULL){ |
- struct dirent* dirEntry = readdir(fontDirectory); |
- while (dirEntry) { |
- |
- // The size of both the prefix, suffix, and a minimum valid language code |
- static const size_t minSize = strlen(LOCALE_FALLBACK_FONTS_PREFIX) + |
- strlen(LOCALE_FALLBACK_FONTS_SUFFIX) + 2; |
- |
- SkString fileName(dirEntry->d_name); |
- if (fileName.size() >= minSize && |
- fileName.startsWith(LOCALE_FALLBACK_FONTS_PREFIX) && |
- fileName.endsWith(LOCALE_FALLBACK_FONTS_SUFFIX)) { |
+ SkAutoTCallIProc<DIR, closedir> fontDirectory(opendir(dir)); |
+ if (NULL == fontDirectory) { |
+ return; |
+ } |
- static const size_t fixedLen = strlen(LOCALE_FALLBACK_FONTS_PREFIX) - |
- strlen(LOCALE_FALLBACK_FONTS_SUFFIX); |
+ for (struct dirent* dirEntry; (dirEntry = readdir(fontDirectory));) { |
+ // The size of both the prefix, suffix, and a minimum valid language code |
+ static const size_t minSize = sizeof(LOCALE_FALLBACK_FONTS_PREFIX) - 1 |
+ + sizeof(LOCALE_FALLBACK_FONTS_SUFFIX) - 1 |
+ + 2; |
+ |
+ SkString fileName(dirEntry->d_name); |
+ if (fileName.size() < minSize || |
+ !fileName.startsWith(LOCALE_FALLBACK_FONTS_PREFIX) || |
+ !fileName.endsWith(LOCALE_FALLBACK_FONTS_SUFFIX)) |
+ { |
+ continue; |
+ } |
- SkString locale(fileName.c_str() - strlen(LOCALE_FALLBACK_FONTS_PREFIX), |
- fileName.size() - fixedLen); |
+ static const size_t fixedLen = sizeof(LOCALE_FALLBACK_FONTS_PREFIX) - 1 |
+ + sizeof(LOCALE_FALLBACK_FONTS_SUFFIX) - 1; |
- SkString absoluteFilename; |
- absoluteFilename.printf("%s/%s", dir, fileName.c_str()); |
+ SkString locale(fileName.c_str() + sizeof(LOCALE_FALLBACK_FONTS_PREFIX) - 1, |
+ fileName.size() - fixedLen); |
- SkTDArray<FontFamily*> langSpecificFonts; |
- parse_config_file(absoluteFilename.c_str(), langSpecificFonts, basePath, true); |
+ SkString absoluteFilename; |
+ absoluteFilename.printf("%s/%s", dir, fileName.c_str()); |
- for (int i = 0; i < langSpecificFonts.count(); ++i) { |
- FontFamily* family = langSpecificFonts[i]; |
- family->fLanguage = SkLanguage(locale); |
- *fallbackFonts.append() = family; |
- } |
- } |
+ SkTDArray<FontFamily*> langSpecificFonts; |
+ parse_config_file(absoluteFilename.c_str(), langSpecificFonts, basePath, true); |
- // proceed to the next entry in the directory |
- dirEntry = readdir(fontDirectory); |
+ for (int i = 0; i < langSpecificFonts.count(); ++i) { |
+ FontFamily* family = langSpecificFonts[i]; |
+ family->fLanguage = SkLanguage(locale); |
+ *fallbackFonts.append() = family; |
} |
- // cleanup the directory reference |
- closedir(fontDirectory); |
} |
} |
@@ -604,7 +602,8 @@ void SkFontConfigParser::GetSystemFontFamilies(SkTDArray<FontFamily*>& fontFamil |
void SkFontConfigParser::GetCustomFontFamilies(SkTDArray<FontFamily*>& fontFamilies, |
const SkString& basePath, |
const char* fontsXml, |
- const char* fallbackFontsXml) |
+ const char* fallbackFontsXml, |
+ const char* langFallbackFontsDir) |
{ |
if (fontsXml) { |
parse_config_file(fontsXml, fontFamilies, basePath, false); |
@@ -612,6 +611,11 @@ void SkFontConfigParser::GetCustomFontFamilies(SkTDArray<FontFamily*>& fontFamil |
if (fallbackFontsXml) { |
parse_config_file(fallbackFontsXml, fontFamilies, basePath, true); |
} |
+ if (langFallbackFontsDir) { |
+ append_fallback_font_families_for_locale(fontFamilies, |
+ langFallbackFontsDir, |
+ basePath); |
+ } |
} |
SkLanguage SkLanguage::getParent() const { |