diff options
author | Billy Hewlett <billyh@google.com> | 2012-07-20 13:49:05 -0700 |
---|---|---|
committer | Victoria Lease <violets@google.com> | 2012-08-20 08:46:42 -0700 |
commit | 480e731e47d6e9b2b80cc758c1b5f672c9d3b4d4 (patch) | |
tree | bd6c1127f467916a0515fdbeb36e32ee4e24e82c /Source/WebKit/android/jni | |
parent | d4389e24221d2c1c202990256f138c75effaa41b (diff) | |
download | external_webkit-480e731e47d6e9b2b80cc758c1b5f672c9d3b4d4.zip external_webkit-480e731e47d6e9b2b80cc758c1b5f672c9d3b4d4.tar.gz external_webkit-480e731e47d6e9b2b80cc758c1b5f672c9d3b4d4.tar.bz2 |
DO NOT MERGE Text locale compatibility shim
Cherry-pick I2a69f2834ca50c37302dcd4816edb630b1208a41 from master.
This change allows WebView to continue to function as before,
displaying text using the system default fallback font chain.
Change-Id: Ibcb8924d270cc602295158684bd700cfcbb1ec46
Diffstat (limited to 'Source/WebKit/android/jni')
-rw-r--r-- | Source/WebKit/android/jni/WebViewCore.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Source/WebKit/android/jni/WebViewCore.cpp b/Source/WebKit/android/jni/WebViewCore.cpp index fd5e9c4..920119b 100644 --- a/Source/WebKit/android/jni/WebViewCore.cpp +++ b/Source/WebKit/android/jni/WebViewCore.cpp @@ -134,6 +134,7 @@ #include "autofill/WebAutofill.h" #include "htmlediting.h" #include "markup.h" +#include "unicode/uloc.h" #include "visible_units.h" #include <JNIHelp.h> @@ -4407,6 +4408,44 @@ void WebViewCore::getLocale(String& language, String& region) region = String(propRegn, 2); } +// generate bcp47 identifier for the supplied language/region +static void toLanguageTag(char* output, size_t outSize, const String& language, + const String& region) { + if (output == NULL || outSize <= 0) + return; + String locale = language; + locale.append('_'); + locale.append(region); + char canonicalChars[ULOC_FULLNAME_CAPACITY]; + UErrorCode uErr = U_ZERO_ERROR; + uloc_canonicalize(locale.ascii().data(), canonicalChars, + ULOC_FULLNAME_CAPACITY, &uErr); + if (U_SUCCESS(uErr)) { + char likelyChars[ULOC_FULLNAME_CAPACITY]; + uErr = U_ZERO_ERROR; + uloc_addLikelySubtags(canonicalChars, likelyChars, + ULOC_FULLNAME_CAPACITY, &uErr); + if (U_SUCCESS(uErr)) { + uErr = U_ZERO_ERROR; + uloc_toLanguageTag(likelyChars, output, outSize, FALSE, &uErr); + if (U_SUCCESS(uErr)) { + return; + } else { + ALOGD("uloc_toLanguageTag(\"%s\") failed: %s", likelyChars, + u_errorName(uErr)); + } + } else { + ALOGD("uloc_addLikelySubtags(\"%s\") failed: %s", canonicalChars, + u_errorName(uErr)); + } + } else { + ALOGD("uloc_canonicalize(\"%s\") failed: %s", locale.ascii().data(), + u_errorName(uErr)); + } + // unable to build a proper language identifier + output[0] = '\0'; +} + void WebViewCore::updateLocale() { static String prevLang; @@ -4421,6 +4460,9 @@ void WebViewCore::updateLocale() prevRegn = region; GlyphPageTreeNode::resetRoots(); fontCache()->invalidate(); + char langTag[ULOC_FULLNAME_CAPACITY]; + toLanguageTag(langTag, ULOC_FULLNAME_CAPACITY, language, region); + FontPlatformData::setDefaultLanguage(langTag); } } |