Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1356)

Unified Diff: Source/platform/fonts/android/FontCacheAndroid.cpp

Issue 729573003: Pass script-based locale names to Skia (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add a manual test Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ManualTests/zh-font-fallback-android.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/fonts/android/FontCacheAndroid.cpp
diff --git a/Source/platform/fonts/android/FontCacheAndroid.cpp b/Source/platform/fonts/android/FontCacheAndroid.cpp
index 25c4c75952334abb3ac35a654647c846e25eb5b0..369f6b70ed709404a794b77dc9d04f588cd81a79 100644
--- a/Source/platform/fonts/android/FontCacheAndroid.cpp
+++ b/Source/platform/fonts/android/FontCacheAndroid.cpp
@@ -35,21 +35,39 @@
#include "platform/fonts/SimpleFontData.h"
#include "platform/fonts/FontDescription.h"
#include "platform/fonts/FontFaceCreationParams.h"
+#include "platform/text/LocaleToScriptMapping.h"
#include "third_party/skia/include/core/SkTypeface.h"
#include "third_party/skia/include/ports/SkFontMgr.h"
namespace blink {
+// SkFontMgr requires script-based locale names, like "zh-Hant" and "zh-Hans",
+// instead of "zh-CN" and "zh-TW".
+static CString toSkFontMgrLocale(const String& locale)
+{
+ if (!locale.startsWith("zh", false))
+ return locale.ascii();
+
+ switch (localeToScriptCodeForFontSelection(locale)) {
+ case USCRIPT_SIMPLIFIED_HAN:
+ return "zh-Hans";
+ case USCRIPT_TRADITIONAL_HAN:
+ return "zh-Hant";
+ default:
+ return locale.ascii();
+ }
+}
+
static AtomicString getFamilyNameForCharacter(UChar32 c, const FontDescription& fontDescription)
{
RefPtr<SkFontMgr> fm = adoptRef(SkFontMgr::RefDefault());
const char* bcp47Locales[2];
int localeCount = 0;
- CString defaultLocale = defaultLanguage().ascii();
+ CString defaultLocale = toSkFontMgrLocale(defaultLanguage());
bcp47Locales[localeCount++] = defaultLocale.data();
CString fontLocale;
if (!fontDescription.locale().isEmpty()) {
- fontLocale = fontDescription.locale().ascii();
+ fontLocale = toSkFontMgrLocale(fontDescription.locale());
bcp47Locales[localeCount++] = fontLocale.data();
}
RefPtr<SkTypeface> typeface = adoptRef(fm->matchFamilyStyleCharacter(0, SkFontStyle(), bcp47Locales, localeCount, c));
« no previous file with comments | « ManualTests/zh-font-fallback-android.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698