| 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 12 matching lines...) Expand all Loading... |
| 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" | |
| 34 #include "platform/fonts/FontCache.h" | 33 #include "platform/fonts/FontCache.h" |
| 35 #include "SkFontMgr.h" | 34 #include "SkFontMgr.h" |
| 36 #include "SkTypeface.h" | 35 #include "SkTypeface.h" |
| 37 #include "wtf/HashMap.h" | 36 #include "wtf/HashMap.h" |
| 38 #include "wtf/StringExtras.h" | 37 #include "wtf/StringExtras.h" |
| 39 #include "wtf/text/StringHash.h" | 38 #include "wtf/text/StringHash.h" |
| 40 #include "wtf/text/WTFString.h" | 39 #include "wtf/text/WTFString.h" |
| 41 #include <limits> | 40 #include <limits> |
| 42 #include <unicode/uchar.h> | 41 #include <unicode/uchar.h> |
| 43 | 42 |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 const UChar** familyPtr = scriptToFontFamilies[i].families; | 298 const UChar** familyPtr = scriptToFontFamilies[i].families; |
| 300 while (*familyPtr) { | 299 while (*familyPtr) { |
| 301 if (isFontPresent(*familyPtr, fontManager)) { | 300 if (isFontPresent(*familyPtr, fontManager)) { |
| 302 scriptFontMap[script] = *familyPtr; | 301 scriptFontMap[script] = *familyPtr; |
| 303 break; | 302 break; |
| 304 } | 303 } |
| 305 ++familyPtr; | 304 ++familyPtr; |
| 306 } | 305 } |
| 307 } | 306 } |
| 308 | 307 |
| 309 // Initialize the locale-dependent mapping. | 308 // Initialize the locale-dependent mapping from system locale. |
| 310 // Since Chrome synchronizes the ICU default locale with its UI locale, | 309 UScriptCode hanScript = LayoutLocale::getSystem().scriptForHan(); |
| 311 // this ICU locale tells the current UI locale of Chrome. | 310 if (const UChar* localeFamily = scriptFontMap[hanScript]) |
| 312 UScriptCode hanScript = scriptCodeForHanFromLocale( | |
| 313 icu::Locale::getDefault().getName(), '_'); | |
| 314 // For other locales, use the simplified Chinese font for Han. | |
| 315 const UChar* localeFamily = scriptFontMap[hanScript == USCRIPT_COMMON | |
| 316 ? USCRIPT_SIMPLIFIED_HAN : hanScript]; | |
| 317 if (localeFamily) | |
| 318 scriptFontMap[USCRIPT_HAN] = localeFamily; | 311 scriptFontMap[USCRIPT_HAN] = localeFamily; |
| 319 } | 312 } |
| 320 | 313 |
| 321 static UScriptCode scriptForHan(const LayoutLocale& contentLocale) | |
| 322 { | |
| 323 UScriptCode script = contentLocale.scriptForHan(); | |
| 324 if (script != USCRIPT_HAN) | |
| 325 return script; | |
| 326 script = AcceptLanguagesResolver::preferredHanScript(); | |
| 327 if (script != USCRIPT_COMMON) | |
| 328 return script; | |
| 329 // Use UI locale. See initializeScriptFontMap(). | |
| 330 return USCRIPT_HAN; | |
| 331 } | |
| 332 | |
| 333 // There are a lot of characters in USCRIPT_COMMON that can be covered | 314 // There are a lot of characters in USCRIPT_COMMON that can be covered |
| 334 // by fonts for scripts closely related to them. See | 315 // by fonts for scripts closely related to them. See |
| 335 // http://unicode.org/cldr/utility/list-unicodeset.jsp?a=[:Script=Common:] | 316 // http://unicode.org/cldr/utility/list-unicodeset.jsp?a=[:Script=Common:] |
| 336 // FIXME: make this more efficient with a wider coverage | 317 // FIXME: make this more efficient with a wider coverage |
| 337 UScriptCode getScriptBasedOnUnicodeBlock(int ucs4) | 318 UScriptCode getScriptBasedOnUnicodeBlock(int ucs4) |
| 338 { | 319 { |
| 339 UBlockCode block = ublock_getCode(ucs4); | 320 UBlockCode block = ublock_getCode(ucs4); |
| 340 switch (block) { | 321 switch (block) { |
| 341 case UBLOCK_CJK_SYMBOLS_AND_PUNCTUATION: | 322 case UBLOCK_CJK_SYMBOLS_AND_PUNCTUATION: |
| 342 return USCRIPT_HAN; | 323 return USCRIPT_HAN; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 // FIXME: | 454 // FIXME: |
| 474 // - Handle 'Inherited', 'Common' and 'Unknown' | 455 // - Handle 'Inherited', 'Common' and 'Unknown' |
| 475 // (see http://www.unicode.org/reports/tr24/#Usage_Model ) | 456 // (see http://www.unicode.org/reports/tr24/#Usage_Model ) |
| 476 // For 'Inherited' and 'Common', perhaps we need to | 457 // For 'Inherited' and 'Common', perhaps we need to |
| 477 // accept another parameter indicating the previous family | 458 // accept another parameter indicating the previous family |
| 478 // and just return it. | 459 // and just return it. |
| 479 // - All the characters (or characters up to the point a single | 460 // - All the characters (or characters up to the point a single |
| 480 // font can cover) need to be taken into account | 461 // font can cover) need to be taken into account |
| 481 const UChar* getFallbackFamily(UChar32 character, | 462 const UChar* getFallbackFamily(UChar32 character, |
| 482 FontDescription::GenericFamilyType generic, | 463 FontDescription::GenericFamilyType generic, |
| 483 const LayoutLocale& contentLocale, | 464 const LayoutLocale* contentLocale, |
| 484 UScriptCode* scriptChecked, | 465 UScriptCode* scriptChecked, |
| 485 FontFallbackPriority fallbackPriority, | 466 FontFallbackPriority fallbackPriority, |
| 486 SkFontMgr* fontManager) | 467 SkFontMgr* fontManager) |
| 487 { | 468 { |
| 488 ASSERT(character); | 469 ASSERT(character); |
| 489 ASSERT(fontManager); | 470 ASSERT(fontManager); |
| 490 UBlockCode block = fallbackPriority == FontFallbackPriority::EmojiEmoji ? | 471 UBlockCode block = fallbackPriority == FontFallbackPriority::EmojiEmoji ? |
| 491 UBLOCK_EMOTICONS : ublock_getCode(character); | 472 UBLOCK_EMOTICONS : ublock_getCode(character); |
| 492 const UChar* family = getFontBasedOnUnicodeBlock(block, fontManager); | 473 const UChar* family = getFontBasedOnUnicodeBlock(block, fontManager); |
| 493 if (family) { | 474 if (family) { |
| 494 if (scriptChecked) | 475 if (scriptChecked) |
| 495 *scriptChecked = USCRIPT_INVALID_CODE; | 476 *scriptChecked = USCRIPT_INVALID_CODE; |
| 496 return family; | 477 return family; |
| 497 } | 478 } |
| 498 | 479 |
| 499 UScriptCode script = getScript(character); | 480 UScriptCode script = getScript(character); |
| 500 | 481 |
| 501 // For the full-width ASCII characters (U+FF00 - U+FF5E), use the font for | 482 // For the full-width ASCII characters (U+FF00 - U+FF5E), use the font for |
| 502 // Han (determined in a locale-dependent way above). Full-width ASCII | 483 // Han (determined in a locale-dependent way above). Full-width ASCII |
| 503 // characters are rather widely used in Japanese and Chinese documents and | 484 // characters are rather widely used in Japanese and Chinese documents and |
| 504 // they're fully covered by Chinese, Japanese and Korean fonts. | 485 // they're fully covered by Chinese, Japanese and Korean fonts. |
| 505 if (0xFF00 < character && character < 0xFF5F) | 486 if (0xFF00 < character && character < 0xFF5F) |
| 506 script = USCRIPT_HAN; | 487 script = USCRIPT_HAN; |
| 507 | 488 |
| 508 if (script == USCRIPT_COMMON) | 489 if (script == USCRIPT_COMMON) |
| 509 script = getScriptBasedOnUnicodeBlock(character); | 490 script = getScriptBasedOnUnicodeBlock(character); |
| 510 | 491 |
| 511 // For unified-Han scripts, try the lang attribute, system, or | 492 // For unified-Han scripts, try the lang attribute, system, or |
| 512 // accept-languages. | 493 // accept-languages. |
| 513 if (script == USCRIPT_HAN) | 494 if (script == USCRIPT_HAN) { |
| 514 script = scriptForHan(contentLocale); | 495 if (const LayoutLocale* localeForHan = LayoutLocale::localeForHan(conten
tLocale)) |
| 496 script = localeForHan->scriptForHan(); |
| 497 // If still unknown, USCRIPT_HAN uses UI locale. |
| 498 // See initializeScriptFontMap(). |
| 499 } |
| 515 | 500 |
| 516 family = getFontFamilyForScript(script, generic, fontManager); | 501 family = getFontFamilyForScript(script, generic, fontManager); |
| 517 // Another lame work-around to cover non-BMP characters. | 502 // Another lame work-around to cover non-BMP characters. |
| 518 // If the font family for script is not found or the character is | 503 // If the font family for script is not found or the character is |
| 519 // not in BMP (> U+FFFF), we resort to the hard-coded list of | 504 // not in BMP (> U+FFFF), we resort to the hard-coded list of |
| 520 // fallback fonts for now. | 505 // fallback fonts for now. |
| 521 if (!family || character > 0xFFFF) { | 506 if (!family || character > 0xFFFF) { |
| 522 int plane = character >> 16; | 507 int plane = character >> 16; |
| 523 switch (plane) { | 508 switch (plane) { |
| 524 case 1: | 509 case 1: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 539 family = L"lucida sans unicode"; | 524 family = L"lucida sans unicode"; |
| 540 } | 525 } |
| 541 } | 526 } |
| 542 | 527 |
| 543 if (scriptChecked) | 528 if (scriptChecked) |
| 544 *scriptChecked = script; | 529 *scriptChecked = script; |
| 545 return family; | 530 return family; |
| 546 } | 531 } |
| 547 | 532 |
| 548 } // namespace blink | 533 } // namespace blink |
| OLD | NEW |