| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 Google Inc. All rights reserved. | 2 * Copyright (c) 2011 Google Inc. All rights reserved. |
| 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 13 matching lines...) Expand all Loading... |
| 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/FontCache.h" | 31 #include "platform/fonts/FontCache.h" |
| 32 | 32 |
| 33 #include "platform/Language.h" | 33 #include "platform/Language.h" |
| 34 #include "platform/fonts/AcceptLanguagesResolver.h" |
| 34 #include "platform/fonts/SimpleFontData.h" | 35 #include "platform/fonts/SimpleFontData.h" |
| 35 #include "platform/fonts/FontDescription.h" | 36 #include "platform/fonts/FontDescription.h" |
| 36 #include "platform/fonts/FontFaceCreationParams.h" | 37 #include "platform/fonts/FontFaceCreationParams.h" |
| 37 #include "platform/text/LocaleToScriptMapping.h" | 38 #include "platform/text/LocaleToScriptMapping.h" |
| 38 #include "third_party/skia/include/core/SkTypeface.h" | 39 #include "third_party/skia/include/core/SkTypeface.h" |
| 39 #include "third_party/skia/include/ports/SkFontMgr.h" | 40 #include "third_party/skia/include/ports/SkFontMgr.h" |
| 40 | 41 |
| 41 namespace blink { | 42 namespace blink { |
| 42 | 43 |
| 43 // SkFontMgr requires script-based locale names, like "zh-Hant" and "zh-Hans", | 44 // SkFontMgr requires script-based locale names, like "zh-Hant" and "zh-Hans", |
| 44 // instead of "zh-CN" and "zh-TW". | 45 // instead of "zh-CN" and "zh-TW". |
| 45 static CString toSkFontMgrLocale(const String& locale) | 46 static CString toSkFontMgrLocale(const String& locale) |
| 46 { | 47 { |
| 47 if (!locale.startsWith("zh", TextCaseInsensitive)) | 48 if (!locale.startsWith("zh", TextCaseInsensitive)) |
| 48 return locale.ascii(); | 49 return locale.ascii(); |
| 49 | 50 |
| 50 switch (localeToScriptCodeForFontSelection(locale)) { | 51 switch (localeToScriptCodeForFontSelection(locale)) { |
| 51 case USCRIPT_SIMPLIFIED_HAN: | 52 case USCRIPT_SIMPLIFIED_HAN: |
| 52 return "zh-Hans"; | 53 return "zh-Hans"; |
| 53 case USCRIPT_TRADITIONAL_HAN: | 54 case USCRIPT_TRADITIONAL_HAN: |
| 54 return "zh-Hant"; | 55 return "zh-Hant"; |
| 55 default: | 56 default: |
| 56 return locale.ascii(); | 57 return locale.ascii(); |
| 57 } | 58 } |
| 58 } | 59 } |
| 59 | 60 |
| 60 void FontCache::acceptLanguagesChanged(const String&) | |
| 61 { | |
| 62 // TODO(kojii): Take acceptLanguages into account for ambiguos scripts. | |
| 63 } | |
| 64 | |
| 65 static AtomicString getFamilyNameForCharacter(UChar32 c, const FontDescription&
fontDescription) | 61 static AtomicString getFamilyNameForCharacter(UChar32 c, const FontDescription&
fontDescription) |
| 66 { | 62 { |
| 67 RefPtr<SkFontMgr> fm = adoptRef(SkFontMgr::RefDefault()); | 63 RefPtr<SkFontMgr> fm = adoptRef(SkFontMgr::RefDefault()); |
| 68 const char* bcp47Locales[2]; | 64 const char* bcp47Locales[3]; |
| 69 int localeCount = 0; | 65 int localeCount = 0; |
| 66 if (const char* hanLocale = AcceptLanguagesResolver::preferredHanSkFontMgrLo
cale()) |
| 67 bcp47Locales[localeCount++] = hanLocale; |
| 70 CString defaultLocale = toSkFontMgrLocale(defaultLanguage()); | 68 CString defaultLocale = toSkFontMgrLocale(defaultLanguage()); |
| 71 bcp47Locales[localeCount++] = defaultLocale.data(); | 69 bcp47Locales[localeCount++] = defaultLocale.data(); |
| 72 CString fontLocale; | 70 CString fontLocale; |
| 73 if (!fontDescription.locale().isEmpty()) { | 71 if (!fontDescription.locale().isEmpty()) { |
| 74 fontLocale = toSkFontMgrLocale(fontDescription.locale()); | 72 fontLocale = toSkFontMgrLocale(fontDescription.locale()); |
| 75 bcp47Locales[localeCount++] = fontLocale.data(); | 73 bcp47Locales[localeCount++] = fontLocale.data(); |
| 76 } | 74 } |
| 77 RefPtr<SkTypeface> typeface = adoptRef(fm->matchFamilyStyleCharacter(0, SkFo
ntStyle(), bcp47Locales, localeCount, c)); | 75 RefPtr<SkTypeface> typeface = adoptRef(fm->matchFamilyStyleCharacter(0, SkFo
ntStyle(), bcp47Locales, localeCount, c)); |
| 78 if (!typeface) | 76 if (!typeface) |
| 79 return emptyAtom; | 77 return emptyAtom; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 108 break; | 106 break; |
| 109 default: | 107 default: |
| 110 // For other scripts, use the default generic family mapping logic. | 108 // For other scripts, use the default generic family mapping logic. |
| 111 return familyName; | 109 return familyName; |
| 112 } | 110 } |
| 113 | 111 |
| 114 return getFamilyNameForCharacter(examplerChar, fontDescription); | 112 return getFamilyNameForCharacter(examplerChar, fontDescription); |
| 115 } | 113 } |
| 116 | 114 |
| 117 } // namespace blink | 115 } // namespace blink |
| OLD | NEW |