Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(821)

Unified Diff: src/ports/SkFontConfigParser_android.cpp

Issue 912053003: Fix append_fallback_font_families_for_locale. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Full test and address comments. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ports/SkFontConfigParser_android.h ('k') | tests/FontConfigParser.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 {
« no previous file with comments | « src/ports/SkFontConfigParser_android.h ('k') | tests/FontConfigParser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698