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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2006, 2007, 2008, 2009, 2010, 2012 Google Inc. All rights reser ved. 2 * Copyright (c) 2006, 2007, 2008, 2009, 2010, 2012 Google Inc. All rights reser ved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 17 matching lines...) Expand all
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "platform/fonts/win/FontFallbackWin.h" 32 #include "platform/fonts/win/FontFallbackWin.h"
33 33
34 #include "platform/fonts/FontCache.h" 34 #include "platform/fonts/FontCache.h"
35 #include "SkFontMgr.h" 35 #include "SkFontMgr.h"
36 #include "SkTypeface.h" 36 #include "SkTypeface.h"
37 #include "wtf/HashMap.h" 37 #include "wtf/HashMap.h"
38 #include "wtf/StringExtras.h"
38 #include "wtf/text/StringHash.h" 39 #include "wtf/text/StringHash.h"
39 #include "wtf/text/WTFString.h" 40 #include "wtf/text/WTFString.h"
40 #include <limits> 41 #include <limits>
41 #include <unicode/locid.h>
42 #include <unicode/uchar.h> 42 #include <unicode/uchar.h>
43 43
44 namespace blink { 44 namespace blink {
45 45
46 UScriptCode scriptCodeForUnifiedHanFromLocale(const icu::Locale& locale)
47 {
48 // ICU default locale may have country as an empty string or differently.
49 // Avoid fullName comparisons for Japanese and Korean where language()
50 // can safely disambiguate.
51 if (strcasecmp(locale.getLanguage(), icu::Locale::getJapanese().getLanguage( )) == 0)
52 return USCRIPT_HIRAGANA;
53 if (strcasecmp(locale.getLanguage(), icu::Locale::getKorean().getLanguage()) == 0)
54 return USCRIPT_HANGUL;
55
56 const icu::Locale& traditionalChinese = icu::Locale::getTraditionalChinese() ;
57 if (strcasecmp(locale.getLanguage(), traditionalChinese.getLanguage()) == 0
58 && (strcasecmp(locale.getCountry(), traditionalChinese.getCountry()) == 0
59 || strcasecmp(locale.getCountry(), "HK") == 0
60 || strcasecmp(locale.getScript(), "Hant") == 0)) {
61 return USCRIPT_TRADITIONAL_HAN;
62 }
63
64 // For other locales, use the simplified Chinese font for Han.
65 return USCRIPT_SIMPLIFIED_HAN;
66 }
67
46 namespace { 68 namespace {
47 69
48 static inline bool isFontPresent(const UChar* fontName, SkFontMgr* fontManager) 70 static inline bool isFontPresent(const UChar* fontName, SkFontMgr* fontManager)
49 { 71 {
50 String family = fontName; 72 String family = fontName;
51 SkTypeface* typeface; 73 SkTypeface* typeface;
52 if (FontCache::useDirectWrite()) 74 if (FontCache::useDirectWrite())
53 typeface = fontManager->matchFamilyStyle(family.utf8().data(), SkFontSty le()); 75 typeface = fontManager->matchFamilyStyle(family.utf8().data(), SkFontSty le());
54 else 76 else
55 typeface = fontManager->legacyCreateTypeface(family.utf8().data(), SkTyp eface::kNormal); 77 typeface = fontManager->legacyCreateTypeface(family.utf8().data(), SkTyp eface::kNormal);
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 scriptFontMap[script] = *familyPtr; 233 scriptFontMap[script] = *familyPtr;
212 break; 234 break;
213 } 235 }
214 ++familyPtr; 236 ++familyPtr;
215 } 237 }
216 } 238 }
217 239
218 // Initialize the locale-dependent mapping. 240 // Initialize the locale-dependent mapping.
219 // Since Chrome synchronizes the ICU default locale with its UI locale, 241 // Since Chrome synchronizes the ICU default locale with its UI locale,
220 // this ICU locale tells the current UI locale of Chrome. 242 // this ICU locale tells the current UI locale of Chrome.
221 icu::Locale locale = icu::Locale::getDefault(); 243 const UChar* localeFamily = scriptFontMap[scriptCodeForUnifiedHanFromLocale(
222 const UChar* localeFamily = 0; 244 icu::Locale::getDefault())];
223 if (locale == icu::Locale::getJapanese()) {
224 localeFamily = scriptFontMap[USCRIPT_HIRAGANA];
225 } else if (locale == icu::Locale::getKorean()) {
226 localeFamily = scriptFontMap[USCRIPT_HANGUL];
227 } else if (locale == icu::Locale::getTraditionalChinese()) {
228 localeFamily = scriptFontMap[USCRIPT_TRADITIONAL_HAN];
229 } else {
230 // For other locales, use the simplified Chinese font for Han.
231 localeFamily = scriptFontMap[USCRIPT_SIMPLIFIED_HAN];
232 }
233 if (localeFamily) 245 if (localeFamily)
234 scriptFontMap[USCRIPT_HAN] = localeFamily; 246 scriptFontMap[USCRIPT_HAN] = localeFamily;
235 } 247 }
236 248
237 // There are a lot of characters in USCRIPT_COMMON that can be covered 249 // There are a lot of characters in USCRIPT_COMMON that can be covered
238 // by fonts for scripts closely related to them. See 250 // by fonts for scripts closely related to them. See
239 // http://unicode.org/cldr/utility/list-unicodeset.jsp?a=[:Script=Common:] 251 // http://unicode.org/cldr/utility/list-unicodeset.jsp?a=[:Script=Common:]
240 // FIXME: make this more efficient with a wider coverage 252 // FIXME: make this more efficient with a wider coverage
241 UScriptCode getScriptBasedOnUnicodeBlock(int ucs4) 253 UScriptCode getScriptBasedOnUnicodeBlock(int ucs4)
242 { 254 {
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 family = L"lucida sans unicode"; 423 family = L"lucida sans unicode";
412 } 424 }
413 } 425 }
414 426
415 if (scriptChecked) 427 if (scriptChecked)
416 *scriptChecked = script; 428 *scriptChecked = script;
417 return family; 429 return family;
418 } 430 }
419 431
420 } // namespace blink 432 } // namespace blink
OLDNEW
« 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