Use a NDK-compliant way of reading locale.
Remove !SK_BUILD_FOR_ANDROID_NDK from locale-related code git-svn-id: http://skia.googlecode.com/svn/trunk@3899 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
c3e050f322
commit
fc9054d4dc
@ -19,9 +19,7 @@
|
||||
#include "SkString.h"
|
||||
#include "SkTDArray.h"
|
||||
#include <expat.h>
|
||||
#if !defined(SK_BUILD_FOR_ANDROID_NDK)
|
||||
#include <cutils/properties.h>
|
||||
#endif
|
||||
#include <sys/system_properties.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
@ -52,8 +52,11 @@ void getSystemFontFamilies(SkTDArray<FontFamily*> &fontFamilies);
|
||||
*/
|
||||
void getFallbackFontFamilies(SkTDArray<FontFamily*> &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_ */
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user