Index: src/ports/SkFontConfigParser_android.cpp |
diff --git a/src/ports/SkFontConfigParser_android.cpp b/src/ports/SkFontConfigParser_android.cpp |
index 2e9054d36d62527eab17a5497f0b1a7c9b48eb0f..e5483c8000a518a85eefed963b80cc4f3e4bf91a 100644 |
--- a/src/ports/SkFontConfigParser_android.cpp |
+++ b/src/ports/SkFontConfigParser_android.cpp |
@@ -57,13 +57,15 @@ struct FamilyData { |
, fCurrentFamily(NULL) |
, fCurrentFontInfo(NULL) |
, fCurrentTag(NO_TAG) |
- { }; |
+ , fVersion(0) |
+ { } |
XML_Parser fParser; // The expat parser doing the work, owned by caller |
SkTDArray<FontFamily*>& fFamilies; // The array to append families, owned by caller |
SkAutoTDelete<FontFamily> fCurrentFamily; // The family being created, owned by this |
FontFileInfo* fCurrentFontInfo; // The fontInfo being created, owned by currentFamily |
int fCurrentTag; // Flag to indicate when we're in nameset/fileset tags |
+ int fVersion; // The version of the file parsed. |
}; |
/** http://www.w3.org/TR/html-markup/datatypes.html#common.data.integer.non-negative-def */ |
@@ -331,6 +333,7 @@ static void startElementHandler(void* data, const char* tag, const char** atts) |
XML_SetElementHandler(familyData->fParser, |
lmpParser::startElementHandler, |
lmpParser::endElementHandler); |
+ familyData->fVersion = version; |
} |
} |
} else if (len == 6 && strncmp(tag, "family", len) == 0) { |
@@ -387,16 +390,16 @@ static void endElementHandler(void* data, const char* tag) { |
/** |
* This function parses the given filename and stores the results in the given |
- * families array. |
+ * families array. Returns the version of the file, negative if the file does not exist. |
*/ |
-static void parseConfigFile(const char* filename, SkTDArray<FontFamily*> &families) { |
+static int parseConfigFile(const char* filename, SkTDArray<FontFamily*> &families) { |
FILE* file = fopen(filename, "r"); |
// Some of the files we attempt to parse (in particular, /vendor/etc/fallback_fonts.xml) |
// are optional - failure here is okay because one of these optional files may not exist. |
if (NULL == file) { |
- return; |
+ return -1; |
} |
XML_Parser parser = XML_ParserCreate(NULL); |
@@ -417,15 +420,17 @@ static void parseConfigFile(const char* filename, SkTDArray<FontFamily*> &famili |
} |
XML_ParserFree(parser); |
fclose(file); |
+ return familyData.fVersion; |
} |
-static void getSystemFontFamilies(SkTDArray<FontFamily*> &fontFamilies) { |
+/** Returns the version of the system font file actually found, negative if none. */ |
+static int appendSystemFontFamilies(SkTDArray<FontFamily*> &fontFamilies) { |
mtklein
2015/02/02 16:55:49
Let's update to static_function_name_style and T&
bungeman-skia
2015/02/02 18:36:37
Done.
|
int initialCount = fontFamilies.count(); |
- parseConfigFile(LMP_SYSTEM_FONTS_FILE, fontFamilies); |
- |
- if (initialCount == fontFamilies.count()) { |
- parseConfigFile(OLD_SYSTEM_FONTS_FILE, fontFamilies); |
+ int version = parseConfigFile(LMP_SYSTEM_FONTS_FILE, fontFamilies); |
+ if (version < 0 || fontFamilies.count() == initialCount) { |
+ version = parseConfigFile(OLD_SYSTEM_FONTS_FILE, fontFamilies); |
} |
+ return version; |
} |
/** |
@@ -435,7 +440,9 @@ static void getSystemFontFamilies(SkTDArray<FontFamily*> &fontFamilies) { |
* directory for those files,add all of their entries to the fallback chain, and |
* include the locale as part of each entry. |
*/ |
-static void getFallbackFontFamiliesForLocale(SkTDArray<FontFamily*> &fallbackFonts, const char* dir) { |
+static void appendFallbackFontFamiliesForLocale(SkTDArray<FontFamily*> &fallbackFonts, |
+ const char* dir) |
+{ |
#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) |
// The framework is beyond Android 4.2 and can therefore skip this function |
return; |
@@ -482,13 +489,15 @@ static void getFallbackFontFamiliesForLocale(SkTDArray<FontFamily*> &fallbackFon |
} |
} |
-static void getFallbackFontFamilies(SkTDArray<FontFamily*> &fallbackFonts) { |
- SkTDArray<FontFamily*> vendorFonts; |
+static void appendSystemFallbackFontFamilies(SkTDArray<FontFamily*> &fallbackFonts) { |
parseConfigFile(FALLBACK_FONTS_FILE, fallbackFonts); |
- parseConfigFile(VENDOR_FONTS_FILE, vendorFonts); |
+ appendFallbackFontFamiliesForLocale(fallbackFonts, LOCALE_FALLBACK_FONTS_SYSTEM_DIR); |
+} |
- getFallbackFontFamiliesForLocale(fallbackFonts, LOCALE_FALLBACK_FONTS_SYSTEM_DIR); |
- getFallbackFontFamiliesForLocale(vendorFonts, LOCALE_FALLBACK_FONTS_VENDOR_DIR); |
+static void mixinVendorFallbackFontFamilies(SkTDArray<FontFamily*> &fallbackFonts) { |
+ SkTDArray<FontFamily*> vendorFonts; |
+ parseConfigFile(VENDOR_FONTS_FILE, vendorFonts); |
+ appendFallbackFontFamiliesForLocale(vendorFonts, LOCALE_FALLBACK_FONTS_VENDOR_DIR); |
// This loop inserts the vendor fallback fonts in the correct order in the |
// overall fallbacks list. |
@@ -519,12 +528,15 @@ static void getFallbackFontFamilies(SkTDArray<FontFamily*> &fallbackFonts) { |
* resulting data is returned in the given fontFamilies array. |
*/ |
void SkFontConfigParser::GetFontFamilies(SkTDArray<FontFamily*> &fontFamilies) { |
- |
- getSystemFontFamilies(fontFamilies); |
+ // Version 21 of the system font configuration does not need any fallback configuration files. |
+ if (appendSystemFontFamilies(fontFamilies) >= 21) { |
+ return; |
+ } |
// Append all the fallback fonts to system fonts |
SkTDArray<FontFamily*> fallbackFonts; |
- getFallbackFontFamilies(fallbackFonts); |
+ appendSystemFallbackFontFamilies(fallbackFonts); |
+ mixinVendorFallbackFontFamilies(fallbackFonts); |
for (int i = 0; i < fallbackFonts.count(); ++i) { |
fallbackFonts[i]->fIsFallbackFont = true; |
*fontFamilies.append() = fallbackFonts[i]; |