Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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/locid.h> |
| 42 #include <unicode/uchar.h> | 43 #include <unicode/uchar.h> |
| 43 | 44 |
| 44 namespace blink { | 45 namespace blink { |
| 45 | 46 |
| 46 namespace { | 47 namespace { |
| 47 | 48 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 | 86 |
| 86 static const FontMap fontMap[] = { | 87 static const FontMap fontMap[] = { |
| 87 { USCRIPT_HEBREW, L"courier new" }, | 88 { USCRIPT_HEBREW, L"courier new" }, |
| 88 { USCRIPT_ARABIC, L"courier new" }, | 89 { USCRIPT_ARABIC, L"courier new" }, |
| 89 }; | 90 }; |
| 90 | 91 |
| 91 for (size_t i = 0; i < WTF_ARRAY_LENGTH(fontMap); ++i) | 92 for (size_t i = 0; i < WTF_ARRAY_LENGTH(fontMap); ++i) |
| 92 scriptFontMap[fontMap[i].script] = fontMap[i].family; | 93 scriptFontMap[fontMap[i].script] = fontMap[i].family; |
| 93 } | 94 } |
| 94 | 95 |
| 96 static UScriptCode scriptCodeForUnifiedHanFromDefaultLocale() | |
|
drott
2015/09/04 08:26:15
I think it would be helpful if you would give this
| |
| 97 { | |
| 98 // Since Chrome synchronizes the ICU default locale with its UI locale, | |
| 99 // this ICU locale tells the current UI locale of Chrome. | |
| 100 const icu::Locale& locale = icu::Locale::getDefault(); | |
| 101 | |
| 102 // ICU default locale may have country as an empty string or differently. | |
| 103 // Avoid fullName comparisons for Japanese and Korean where language() | |
| 104 // can safely disambiguate. | |
| 105 if (strcasecmp(locale.getLanguage(), icu::Locale::getJapanese().getLanguage( )) == 0) | |
| 106 return USCRIPT_HIRAGANA; | |
| 107 if (strcasecmp(locale.getLanguage(), icu::Locale::getKorean().getLanguage()) == 0) | |
| 108 return USCRIPT_HANGUL; | |
| 109 | |
| 110 const icu::Locale& traditionalChinese = icu::Locale::getTraditionalChinese() ; | |
| 111 if (strcasecmp(locale.getLanguage(), traditionalChinese.getLanguage()) == 0 | |
| 112 && (strcasecmp(locale.getCountry(), traditionalChinese.getCountry()) == 0 | |
| 113 || strcasecmp(locale.getCountry(), "HK") == 0 | |
| 114 || strcasecmp(locale.getScript(), "Hant") == 0)) { | |
| 115 return USCRIPT_TRADITIONAL_HAN; | |
| 116 } | |
| 117 | |
| 118 // For other locales, use the simplified Chinese font for Han. | |
| 119 return USCRIPT_SIMPLIFIED_HAN; | |
| 120 } | |
| 121 | |
| 95 void initializeScriptFontMap(ScriptToFontMap& scriptFontMap, SkFontMgr* fontMana ger) | 122 void initializeScriptFontMap(ScriptToFontMap& scriptFontMap, SkFontMgr* fontMana ger) |
| 96 { | 123 { |
| 97 struct FontMap { | 124 struct FontMap { |
| 98 UScriptCode script; | 125 UScriptCode script; |
| 99 const UChar* family; | 126 const UChar* family; |
| 100 }; | 127 }; |
| 101 | 128 |
| 102 static const FontMap fontMap[] = { | 129 static const FontMap fontMap[] = { |
| 103 {USCRIPT_LATIN, L"times new roman"}, | 130 {USCRIPT_LATIN, L"times new roman"}, |
| 104 {USCRIPT_GREEK, L"times new roman"}, | 131 {USCRIPT_GREEK, L"times new roman"}, |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 while (*familyPtr) { | 236 while (*familyPtr) { |
| 210 if (isFontPresent(*familyPtr, fontManager)) { | 237 if (isFontPresent(*familyPtr, fontManager)) { |
| 211 scriptFontMap[script] = *familyPtr; | 238 scriptFontMap[script] = *familyPtr; |
| 212 break; | 239 break; |
| 213 } | 240 } |
| 214 ++familyPtr; | 241 ++familyPtr; |
| 215 } | 242 } |
| 216 } | 243 } |
| 217 | 244 |
| 218 // Initialize the locale-dependent mapping. | 245 // Initialize the locale-dependent mapping. |
| 219 // Since Chrome synchronizes the ICU default locale with its UI locale, | 246 const UChar* localeFamily = scriptFontMap[scriptCodeForUnifiedHanFromDefault Locale()]; |
| 220 // this ICU locale tells the current UI locale of Chrome. | |
| 221 icu::Locale locale = icu::Locale::getDefault(); | |
| 222 const UChar* localeFamily = 0; | |
| 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) | 247 if (localeFamily) |
| 234 scriptFontMap[USCRIPT_HAN] = localeFamily; | 248 scriptFontMap[USCRIPT_HAN] = localeFamily; |
| 235 } | 249 } |
| 236 | 250 |
| 237 // There are a lot of characters in USCRIPT_COMMON that can be covered | 251 // There are a lot of characters in USCRIPT_COMMON that can be covered |
| 238 // by fonts for scripts closely related to them. See | 252 // by fonts for scripts closely related to them. See |
| 239 // http://unicode.org/cldr/utility/list-unicodeset.jsp?a=[:Script=Common:] | 253 // http://unicode.org/cldr/utility/list-unicodeset.jsp?a=[:Script=Common:] |
| 240 // FIXME: make this more efficient with a wider coverage | 254 // FIXME: make this more efficient with a wider coverage |
| 241 UScriptCode getScriptBasedOnUnicodeBlock(int ucs4) | 255 UScriptCode getScriptBasedOnUnicodeBlock(int ucs4) |
| 242 { | 256 { |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 411 family = L"lucida sans unicode"; | 425 family = L"lucida sans unicode"; |
| 412 } | 426 } |
| 413 } | 427 } |
| 414 | 428 |
| 415 if (scriptChecked) | 429 if (scriptChecked) |
| 416 *scriptChecked = script; | 430 *scriptChecked = script; |
| 417 return family; | 431 return family; |
| 418 } | 432 } |
| 419 | 433 |
| 420 } // namespace blink | 434 } // namespace blink |
| OLD | NEW |