| Index: third_party/WebKit/Source/platform/fonts/skia/FontCacheSkia.cpp
|
| diff --git a/third_party/WebKit/Source/platform/fonts/skia/FontCacheSkia.cpp b/third_party/WebKit/Source/platform/fonts/skia/FontCacheSkia.cpp
|
| index 5ad1346766c4fe1af86bfd1490e90f6a37ac2342..dd414101083c219e1f8b9c1e9b53ab62966701de 100644
|
| --- a/third_party/WebKit/Source/platform/fonts/skia/FontCacheSkia.cpp
|
| +++ b/third_party/WebKit/Source/platform/fonts/skia/FontCacheSkia.cpp
|
| @@ -67,6 +67,23 @@
|
| // http://www.unicode.org/reports/tr51/proposed.html#Emoji_Script
|
| static const char* kAndroidColorEmojiLocale = "und-Zsye";
|
|
|
| +// SkFontMgr requires script-based locale names, like "zh-Hant" and "zh-Hans",
|
| +// instead of "zh-CN" and "zh-TW".
|
| +static CString toSkFontMgrLocale(const String& locale)
|
| +{
|
| + if (!locale.startsWith("zh", TextCaseInsensitive))
|
| + return locale.ascii();
|
| +
|
| + switch (localeToScriptCodeForFontSelection(locale)) {
|
| + case USCRIPT_SIMPLIFIED_HAN:
|
| + return "zh-Hans";
|
| + case USCRIPT_TRADITIONAL_HAN:
|
| + return "zh-Hant";
|
| + default:
|
| + return locale.ascii();
|
| + }
|
| +}
|
| +
|
| // This function is called on android or when we are emulating android fonts on linux and the
|
| // embedder has overriden the default fontManager with WebFontRendering::setSkiaFontMgr.
|
| // static
|
| @@ -154,6 +171,25 @@
|
| return fontDataFromFontPlatformData(fontPlatformData, shouldRetain);
|
| }
|
|
|
| +#if OS(WIN) || OS(LINUX)
|
| +static inline SkFontStyle fontStyle(const FontDescription& fontDescription)
|
| +{
|
| + int width = static_cast<int>(fontDescription.stretch());
|
| + int weight = (fontDescription.weight() - FontWeight100 + 1) * 100;
|
| + SkFontStyle::Slant slant = fontDescription.style() == FontStyleItalic
|
| + ? SkFontStyle::kItalic_Slant
|
| + : SkFontStyle::kUpright_Slant;
|
| + return SkFontStyle(weight, width, slant);
|
| +}
|
| +
|
| +static_assert(static_cast<int>(FontStretchUltraCondensed) == static_cast<int>(SkFontStyle::kUltraCondensed_Width),
|
| + "FontStretchUltraCondensed should map to kUltraCondensed_Width");
|
| +static_assert(static_cast<int>(FontStretchNormal) == static_cast<int>(SkFontStyle::kNormal_Width),
|
| + "FontStretchNormal should map to kNormal_Width");
|
| +static_assert(static_cast<int>(FontStretchUltraExpanded) == static_cast<int>(SkFontStyle::kUltaExpanded_Width),
|
| + "FontStretchUltraExpanded should map to kUltaExpanded_Width");
|
| +#endif
|
| +
|
| PassRefPtr<SkTypeface> FontCache::createTypeface(const FontDescription& fontDescription, const FontFaceCreationParams& creationParams, CString& name)
|
| {
|
| #if !OS(WIN) && !OS(ANDROID)
|
| @@ -184,8 +220,9 @@
|
|
|
| if (m_fontManager) {
|
| return adoptRef(useDirectWrite()
|
| - ? m_fontManager->matchFamilyStyle(name.data(), fontDescription.skiaFontStyle())
|
| - : m_fontManager->legacyCreateTypeface(name.data(), fontDescription.skiaFontStyle()));
|
| + ? m_fontManager->matchFamilyStyle(name.data(), fontStyle(fontDescription))
|
| + : m_fontManager->legacyCreateTypeface(name.data(), fontStyle(fontDescription))
|
| + );
|
| }
|
| #endif
|
|
|
| @@ -194,7 +231,7 @@
|
| // provided font Manager rather than calling SkTypeface::CreateFromName which may redirect the
|
| // call to the default font Manager.
|
| if (m_fontManager)
|
| - return adoptRef(m_fontManager->matchFamilyStyle(name.data(), fontDescription.skiaFontStyle()));
|
| + return adoptRef(m_fontManager->matchFamilyStyle(name.data(), fontStyle(fontDescription)));
|
| #endif
|
|
|
| // FIXME: Use m_fontManager, SkFontStyle and matchFamilyStyle instead of
|
|
|