| 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 23 matching lines...) Expand all Loading... |
| 34 #include "platform/fonts/AcceptLanguagesResolver.h" | 34 #include "platform/fonts/AcceptLanguagesResolver.h" |
| 35 #include "platform/fonts/SimpleFontData.h" | 35 #include "platform/fonts/SimpleFontData.h" |
| 36 #include "platform/fonts/FontDescription.h" | 36 #include "platform/fonts/FontDescription.h" |
| 37 #include "platform/fonts/FontFaceCreationParams.h" | 37 #include "platform/fonts/FontFaceCreationParams.h" |
| 38 #include "platform/text/LocaleToScriptMapping.h" | 38 #include "platform/text/LocaleToScriptMapping.h" |
| 39 #include "third_party/skia/include/core/SkTypeface.h" | 39 #include "third_party/skia/include/core/SkTypeface.h" |
| 40 #include "third_party/skia/include/ports/SkFontMgr.h" | 40 #include "third_party/skia/include/ports/SkFontMgr.h" |
| 41 | 41 |
| 42 namespace blink { | 42 namespace blink { |
| 43 | 43 |
| 44 // SkFontMgr requires script-based locale names, like "zh-Hant" and "zh-Hans", | |
| 45 // instead of "zh-CN" and "zh-TW". | |
| 46 static CString toSkFontMgrLocale(const String& locale) | |
| 47 { | |
| 48 if (!locale.startsWith("zh", TextCaseInsensitive)) | |
| 49 return locale.ascii(); | |
| 50 | |
| 51 switch (localeToScriptCodeForFontSelection(locale)) { | |
| 52 case USCRIPT_SIMPLIFIED_HAN: | |
| 53 return "zh-Hans"; | |
| 54 case USCRIPT_TRADITIONAL_HAN: | |
| 55 return "zh-Hant"; | |
| 56 default: | |
| 57 return locale.ascii(); | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 static AtomicString getFamilyNameForCharacter(UChar32 c, const FontDescription&
fontDescription) | 44 static AtomicString getFamilyNameForCharacter(UChar32 c, const FontDescription&
fontDescription) |
| 62 { | 45 { |
| 63 RefPtr<SkFontMgr> fm = adoptRef(SkFontMgr::RefDefault()); | 46 RefPtr<SkFontMgr> fm = adoptRef(SkFontMgr::RefDefault()); |
| 64 const char* bcp47Locales[3]; | 47 const char* bcp47Locales[3]; |
| 65 int localeCount = 0; | 48 int localeCount = 0; |
| 66 if (const char* hanLocale = AcceptLanguagesResolver::preferredHanSkFontMgrLo
cale()) | 49 if (const char* hanLocale = AcceptLanguagesResolver::preferredHanSkFontMgrLo
cale()) |
| 67 bcp47Locales[localeCount++] = hanLocale; | 50 bcp47Locales[localeCount++] = hanLocale; |
| 68 CString defaultLocale = toSkFontMgrLocale(defaultLanguage()); | 51 CString defaultLocale = toSkFontMgrLocale(defaultLanguage()); |
| 69 bcp47Locales[localeCount++] = defaultLocale.data(); | 52 bcp47Locales[localeCount++] = defaultLocale.data(); |
| 70 CString fontLocale; | 53 CString fontLocale; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 break; | 89 break; |
| 107 default: | 90 default: |
| 108 // For other scripts, use the default generic family mapping logic. | 91 // For other scripts, use the default generic family mapping logic. |
| 109 return familyName; | 92 return familyName; |
| 110 } | 93 } |
| 111 | 94 |
| 112 return getFamilyNameForCharacter(examplerChar, fontDescription); | 95 return getFamilyNameForCharacter(examplerChar, fontDescription); |
| 113 } | 96 } |
| 114 | 97 |
| 115 } // namespace blink | 98 } // namespace blink |
| OLD | NEW |