diff --git a/src/ports/FontHostConfiguration_android.cpp b/src/ports/FontHostConfiguration_android.cpp index d1164c800d..c12bb40114 100644 --- a/src/ports/FontHostConfiguration_android.cpp +++ b/src/ports/FontHostConfiguration_android.cpp @@ -19,9 +19,7 @@ #include "SkString.h" #include "SkTDArray.h" #include -#if !defined(SK_BUILD_FOR_ANDROID_NDK) - #include -#endif +#include #define SYSTEM_FONTS_FILE "/system/etc/system_fonts.xml" #define FALLBACK_FONTS_FILE "/system/etc/fallback_fonts.xml" @@ -131,25 +129,29 @@ void endElementHandler(void *data, const char *tag) { } } -#if !defined(SK_BUILD_FOR_ANDROID_NDK) /** * Read the persistent locale. */ -void getLocale(char* language, char* region) +void getLocale(AndroidLocale &locale) { - char propLang[PROPERTY_VALUE_MAX], propRegn[PROPERTY_VALUE_MAX]; + char propLang[PROP_VALUE_MAX], propRegn[PROP_VALUE_MAX]; + __system_property_get("persist.sys.language", propLang); + __system_property_get("persist.sys.country", propRegn); - property_get("persist.sys.language", propLang, ""); - property_get("persist.sys.country", propRegn, ""); if (*propLang == 0 && *propRegn == 0) { /* Set to ro properties, default is en_US */ - property_get("ro.product.locale.language", propLang, "en"); - property_get("ro.product.locale.region", propRegn, "US"); + __system_property_get("ro.product.locale.language", propLang); + __system_property_get("ro.product.locale.region", propRegn); + if (*propLang == 0 && *propRegn == 0) { + strcpy(propLang, "en"); + strcpy(propRegn, "US"); + } } - strncat(language, propLang, 2); - strncat(region, propRegn, 2); + strncpy(locale.language, propLang, 2); + locale.language[2] = '\0'; + strncpy(locale.region, propRegn, 2); + locale.region[2] = '\0'; } -#endif /** * Use the current system locale (language and region) to open the best matching @@ -160,32 +162,28 @@ void getLocale(char* language, char* region) */ FILE* openLocalizedFile(const char* origname) { FILE* file = 0; - -#if !defined(SK_BUILD_FOR_ANDROID_NDK) SkString basename; SkString filename; - char language[3] = ""; - char region[3] = ""; + AndroidLocale locale; basename.set(origname); // Remove the .xml suffix. We'll add it back in a moment. if (basename.endsWith(".xml")) { basename.resize(basename.size()-4); } - getLocale(language, region); + getLocale(locale); // Try first with language and region - filename.printf("%s-%s-%s.xml", basename.c_str(), language, region); + filename.printf("%s-%s-%s.xml", basename.c_str(), locale.language, locale.region); file = fopen(filename.c_str(), "r"); if (!file) { // If not found, try next with just language - filename.printf("%s-%s.xml", basename.c_str(), language); + filename.printf("%s-%s.xml", basename.c_str(), locale.language); file = fopen(filename.c_str(), "r"); - } -#endif - if (!file) { - // If still not found, try just the original name - file = fopen(origname, "r"); + if (!file) { + // If still not found, try just the original name + file = fopen(origname, "r"); + } } return file; } diff --git a/src/ports/FontHostConfiguration_android.h b/src/ports/FontHostConfiguration_android.h index 2441f0e436..fb634881ed 100644 --- a/src/ports/FontHostConfiguration_android.h +++ b/src/ports/FontHostConfiguration_android.h @@ -52,8 +52,11 @@ void getSystemFontFamilies(SkTDArray &fontFamilies); */ void getFallbackFontFamilies(SkTDArray &fallbackFonts); -#if !defined(SK_BUILD_FOR_ANDROID_NDK) - void getLocale(char* language, char* region); -#endif +struct AndroidLocale { + char language[3]; + char region[3]; +}; + +void getLocale(AndroidLocale &locale); #endif /* FONTHOSTCONFIGURATION_ANDROID_H_ */ diff --git a/src/ports/SkFontHost_android.cpp b/src/ports/SkFontHost_android.cpp index df240ab44b..0d8ebd31be 100644 --- a/src/ports/SkFontHost_android.cpp +++ b/src/ports/SkFontHost_android.cpp @@ -705,32 +705,21 @@ static void reload_fallback_fonts() { } static void load_system_fonts() { -#if !defined(SK_BUILD_FOR_ANDROID_NDK) - static char prevLanguage[3]; - static char prevRegion[3]; - char language[3] = ""; - char region[3] = ""; + static AndroidLocale prevLocale; + AndroidLocale locale; - getLocale(language, region); + getLocale(locale); if (!gDefaultNormal) { - strncpy(prevLanguage, language, 2); - strncpy(prevRegion, region, 2); + prevLocale = locale; init_system_fonts(); - } else if (strncmp(language, prevLanguage, 2) || strncmp(region, prevRegion, 2)) { - strncpy(prevLanguage, language, 2); - strncpy(prevRegion, region, 2); + } else if (strncmp(locale.language, prevLocale.language, 2) || + strncmp(locale.region, prevLocale.region, 2)) { + prevLocale = locale; reload_fallback_fonts(); } -#else - if (!gDefaultNormal) { - init_system_fonts(); - reload_fallback_fonts(); - } -#endif } - /////////////////////////////////////////////////////////////////////////////// void SkFontHost::Serialize(const SkTypeface* face, SkWStream* stream) {