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

Unified Diff: Source/platform/fonts/win/FontFallbackWin.cpp

Issue 1311043010: Improve getFallbackFamily() for Unified Han Ideographs on Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add test Created 5 years, 3 months 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 | « Source/platform/fonts/win/FontFallbackWin.h ('k') | Source/platform/fonts/win/FontFallbackWinTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/fonts/win/FontFallbackWin.cpp
diff --git a/Source/platform/fonts/win/FontFallbackWin.cpp b/Source/platform/fonts/win/FontFallbackWin.cpp
index a7f5be4cdc1052d3035da781586990baa85dbd20..7d2f8f43ab570ab92c67ebb4512ba21c6b859db3 100644
--- a/Source/platform/fonts/win/FontFallbackWin.cpp
+++ b/Source/platform/fonts/win/FontFallbackWin.cpp
@@ -35,14 +35,36 @@
#include "SkFontMgr.h"
#include "SkTypeface.h"
#include "wtf/HashMap.h"
+#include "wtf/StringExtras.h"
#include "wtf/text/StringHash.h"
#include "wtf/text/WTFString.h"
#include <limits>
-#include <unicode/locid.h>
#include <unicode/uchar.h>
namespace blink {
+UScriptCode scriptCodeForUnifiedHanFromLocale(const icu::Locale& locale)
+{
+ // ICU default locale may have country as an empty string or differently.
+ // Avoid fullName comparisons for Japanese and Korean where language()
+ // can safely disambiguate.
+ if (strcasecmp(locale.getLanguage(), icu::Locale::getJapanese().getLanguage()) == 0)
+ return USCRIPT_HIRAGANA;
+ if (strcasecmp(locale.getLanguage(), icu::Locale::getKorean().getLanguage()) == 0)
+ return USCRIPT_HANGUL;
+
+ const icu::Locale& traditionalChinese = icu::Locale::getTraditionalChinese();
+ if (strcasecmp(locale.getLanguage(), traditionalChinese.getLanguage()) == 0
+ && (strcasecmp(locale.getCountry(), traditionalChinese.getCountry()) == 0
+ || strcasecmp(locale.getCountry(), "HK") == 0
+ || strcasecmp(locale.getScript(), "Hant") == 0)) {
+ return USCRIPT_TRADITIONAL_HAN;
+ }
+
+ // For other locales, use the simplified Chinese font for Han.
+ return USCRIPT_SIMPLIFIED_HAN;
+}
+
namespace {
static inline bool isFontPresent(const UChar* fontName, SkFontMgr* fontManager)
@@ -218,18 +240,8 @@ void initializeScriptFontMap(ScriptToFontMap& scriptFontMap, SkFontMgr* fontMana
// Initialize the locale-dependent mapping.
// Since Chrome synchronizes the ICU default locale with its UI locale,
// this ICU locale tells the current UI locale of Chrome.
- icu::Locale locale = icu::Locale::getDefault();
- const UChar* localeFamily = 0;
- if (locale == icu::Locale::getJapanese()) {
- localeFamily = scriptFontMap[USCRIPT_HIRAGANA];
- } else if (locale == icu::Locale::getKorean()) {
- localeFamily = scriptFontMap[USCRIPT_HANGUL];
- } else if (locale == icu::Locale::getTraditionalChinese()) {
- localeFamily = scriptFontMap[USCRIPT_TRADITIONAL_HAN];
- } else {
- // For other locales, use the simplified Chinese font for Han.
- localeFamily = scriptFontMap[USCRIPT_SIMPLIFIED_HAN];
- }
+ const UChar* localeFamily = scriptFontMap[scriptCodeForUnifiedHanFromLocale(
+ icu::Locale::getDefault())];
if (localeFamily)
scriptFontMap[USCRIPT_HAN] = localeFamily;
}
« no previous file with comments | « Source/platform/fonts/win/FontFallbackWin.h ('k') | Source/platform/fonts/win/FontFallbackWinTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698