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

Side by Side Diff: third_party/WebKit/Source/platform/fonts/win/FontFallbackWin.cpp

Issue 1693563003: Take Accept-Language into account in CJK font fallback for Android/Win (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@aceept-lang
Patch Set: Fix non-Windows builds Created 4 years, 10 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
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/win/FontCacheSkiaWin.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
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 "platform/fonts/win/FontFallbackWin.h" 31 #include "platform/fonts/win/FontFallbackWin.h"
32 32
33 #include "platform/fonts/AcceptLanguagesResolver.h"
33 #include "platform/fonts/FontCache.h" 34 #include "platform/fonts/FontCache.h"
34 #include "SkFontMgr.h" 35 #include "SkFontMgr.h"
35 #include "SkTypeface.h" 36 #include "SkTypeface.h"
36 #include "wtf/HashMap.h" 37 #include "wtf/HashMap.h"
37 #include "wtf/StringExtras.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/uchar.h> 42 #include <unicode/uchar.h>
42 43
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 // this ICU locale tells the current UI locale of Chrome. 224 // this ICU locale tells the current UI locale of Chrome.
224 UScriptCode hanScript = scriptCodeForHanFromLocale( 225 UScriptCode hanScript = scriptCodeForHanFromLocale(
225 icu::Locale::getDefault().getName(), '_'); 226 icu::Locale::getDefault().getName(), '_');
226 // For other locales, use the simplified Chinese font for Han. 227 // For other locales, use the simplified Chinese font for Han.
227 const UChar* localeFamily = scriptFontMap[hanScript == USCRIPT_COMMON 228 const UChar* localeFamily = scriptFontMap[hanScript == USCRIPT_COMMON
228 ? USCRIPT_SIMPLIFIED_HAN : hanScript]; 229 ? USCRIPT_SIMPLIFIED_HAN : hanScript];
229 if (localeFamily) 230 if (localeFamily)
230 scriptFontMap[USCRIPT_HAN] = localeFamily; 231 scriptFontMap[USCRIPT_HAN] = localeFamily;
231 } 232 }
232 233
234 static UScriptCode scriptForHan(UScriptCode contentScript,
235 const AtomicString& contentLocale)
236 {
237 UScriptCode script = scriptCodeForHanFromLocale(contentScript, contentLocale );
238 if (script != USCRIPT_COMMON)
239 return script;
240 script = AcceptLanguagesResolver::preferredHanScript();
241 if (script != USCRIPT_COMMON)
242 return script;
243 // Use UI locale. See initializeScriptFontMap().
244 return USCRIPT_HAN;
245 }
246
233 // There are a lot of characters in USCRIPT_COMMON that can be covered 247 // There are a lot of characters in USCRIPT_COMMON that can be covered
234 // by fonts for scripts closely related to them. See 248 // by fonts for scripts closely related to them. See
235 // http://unicode.org/cldr/utility/list-unicodeset.jsp?a=[:Script=Common:] 249 // http://unicode.org/cldr/utility/list-unicodeset.jsp?a=[:Script=Common:]
236 // FIXME: make this more efficient with a wider coverage 250 // FIXME: make this more efficient with a wider coverage
237 UScriptCode getScriptBasedOnUnicodeBlock(int ucs4) 251 UScriptCode getScriptBasedOnUnicodeBlock(int ucs4)
238 { 252 {
239 UBlockCode block = ublock_getCode(ucs4); 253 UBlockCode block = ublock_getCode(ucs4);
240 switch (block) { 254 switch (block) {
241 case UBLOCK_CJK_SYMBOLS_AND_PUNCTUATION: 255 case UBLOCK_CJK_SYMBOLS_AND_PUNCTUATION:
242 return USCRIPT_HAN; 256 return USCRIPT_HAN;
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 // For the full-width ASCII characters (U+FF00 - U+FF5E), use the font for 415 // For the full-width ASCII characters (U+FF00 - U+FF5E), use the font for
402 // Han (determined in a locale-dependent way above). Full-width ASCII 416 // Han (determined in a locale-dependent way above). Full-width ASCII
403 // characters are rather widely used in Japanese and Chinese documents and 417 // characters are rather widely used in Japanese and Chinese documents and
404 // they're fully covered by Chinese, Japanese and Korean fonts. 418 // they're fully covered by Chinese, Japanese and Korean fonts.
405 if (0xFF00 < character && character < 0xFF5F) 419 if (0xFF00 < character && character < 0xFF5F)
406 script = USCRIPT_HAN; 420 script = USCRIPT_HAN;
407 421
408 if (script == USCRIPT_COMMON) 422 if (script == USCRIPT_COMMON)
409 script = getScriptBasedOnUnicodeBlock(character); 423 script = getScriptBasedOnUnicodeBlock(character);
410 424
411 // For unified-Han scripts, try the lang attribute. 425 // For unified-Han scripts, try the lang attribute, system, or
412 if (script == USCRIPT_HAN) { 426 // accept-languages.
413 script = scriptCodeForHanFromLocale(contentScript, contentLocale); 427 if (script == USCRIPT_HAN)
414 // Use the UI locale if it is still ambiguous. 428 script = scriptForHan(contentScript, contentLocale);
415 if (script == USCRIPT_COMMON)
416 script = USCRIPT_SIMPLIFIED_HAN;
417 }
418 429
419 family = getFontFamilyForScript(script, generic, fontManager); 430 family = getFontFamilyForScript(script, generic, fontManager);
420 // Another lame work-around to cover non-BMP characters. 431 // Another lame work-around to cover non-BMP characters.
421 // If the font family for script is not found or the character is 432 // If the font family for script is not found or the character is
422 // not in BMP (> U+FFFF), we resort to the hard-coded list of 433 // not in BMP (> U+FFFF), we resort to the hard-coded list of
423 // fallback fonts for now. 434 // fallback fonts for now.
424 if (!family || character > 0xFFFF) { 435 if (!family || character > 0xFFFF) {
425 int plane = character >> 16; 436 int plane = character >> 16;
426 switch (plane) { 437 switch (plane) {
427 case 1: 438 case 1:
(...skipping 14 matching lines...) Expand all
442 family = L"lucida sans unicode"; 453 family = L"lucida sans unicode";
443 } 454 }
444 } 455 }
445 456
446 if (scriptChecked) 457 if (scriptChecked)
447 *scriptChecked = script; 458 *scriptChecked = script;
448 return family; 459 return family;
449 } 460 }
450 461
451 } // namespace blink 462 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/win/FontCacheSkiaWin.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698