Chromium Code Reviews| Index: src/ports/SkFontConfigParser_android.cpp |
| diff --git a/src/ports/SkFontConfigParser_android.cpp b/src/ports/SkFontConfigParser_android.cpp |
| index b1c815993a82510f52e49013236bef7ba70f29ec..e8692e912fa5c82b863c23923fc1f99cb2ec65b6 100644 |
| --- a/src/ports/SkFontConfigParser_android.cpp |
| +++ b/src/ports/SkFontConfigParser_android.cpp |
| @@ -163,16 +163,52 @@ static void endElementHandler(void *data, const char *tag) { |
| * families array. |
| */ |
| static void parseConfigFile(const char *filename, SkTDArray<FontFamily*> &families) { |
| - XML_Parser parser = XML_ParserCreate(NULL); |
| - FamilyData *familyData = new FamilyData(&parser, families); |
| - XML_SetUserData(parser, familyData); |
| - XML_SetElementHandler(parser, startElementHandler, endElementHandler); |
| - FILE *file = fopen(filename, "r"); |
| + |
| + FILE* file = NULL; |
| + |
| +#if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) |
|
scroggo
2013/08/27 19:14:01
So this is only for Android, but not in the framew
djsollen
2013/08/27 19:22:49
This code will not be possible to run as part of t
|
| + // if we are using a version of Android prior to Android 4.2 (JellyBean MR1 |
| + // at API Level 17) then we need to look for files with a different suffix. |
| + char sdkVersion[PROP_VALUE_MAX]; |
| + __system_property_get("ro.build.version.sdk", sdkVersion); |
| + const int sdkVersionInt = atoi(sdkVersion); |
| + |
| + if (0 != *sdkVersion && sdkVersionInt < 17) { |
| + SkString basename; |
| + SkString updatedFilename; |
| + SkString locale = SkFontConfigParser::GetLocale(); |
|
scroggo
2013/08/27 19:14:01
could be const.
|
| + |
| + basename.set(filename); |
| + // Remove the .xml suffix. We'll add it back in a moment. |
| + if (basename.endsWith(".xml")) { |
| + basename.resize(basename.size()-4); |
| + } |
| + // Try first with language and region |
| + updatedFilename.printf("%s-%s.xml", basename.c_str(), locale.c_str()); |
| + file = fopen(updatedFilename.c_str(), "r"); |
| + if (!file) { |
| + // If not found, try next with just language |
| + updatedFilename.printf("%s-%.2s.xml", basename.c_str(), locale.c_str()); |
| + file = fopen(updatedFilename.c_str(), "r"); |
| + } |
| + } |
| +#endif |
| + |
| + if (NULL == 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 (file == NULL) { |
| + if (NULL == file) { |
| return; |
| } |
| + |
| + XML_Parser parser = XML_ParserCreate(NULL); |
| + FamilyData *familyData = new FamilyData(&parser, families); |
| + XML_SetUserData(parser, familyData); |
| + XML_SetElementHandler(parser, startElementHandler, endElementHandler); |
| + |
| char buffer[512]; |
| bool done = false; |
| while (!done) { |