Chromium Code Reviews| 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 d9af8814f20745f374402948176848edc5db9597..d3f614c1b58f08303e545a74a7ff1740d9ab1b09 100644 |
| --- a/third_party/WebKit/Source/platform/fonts/skia/FontCacheSkia.cpp |
| +++ b/third_party/WebKit/Source/platform/fonts/skia/FontCacheSkia.cpp |
| @@ -31,6 +31,7 @@ |
| #include "SkFontMgr.h" |
| #include "SkStream.h" |
| #include "SkTypeface.h" |
| +#include "platform/Language.h" |
| #include "platform/fonts/AlternateFontFamily.h" |
| #include "platform/fonts/FontCache.h" |
| #include "platform/fonts/FontDescription.h" |
| @@ -87,6 +88,46 @@ static PassRefPtr<SkTypeface> typefaceForFontconfigInterfaceIdAndTtcIndex(int fo |
| namespace blink { |
| +// 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(); |
| + } |
| +} |
| + |
| +#if OS(ANDROID) || OS(LINUX) |
|
eae
2016/02/17 23:52:10
Do we need this on Android? The only caller I can
Khushal
2016/02/18 00:46:37
Android calls it from FontCacheAndroid. The implem
|
| +AtomicString FontCache::getFamilyNameForCharacter(SkFontMgr* fm, UChar32 c, const FontDescription& fontDescription) |
| +{ |
| + ASSERT(fm); |
| + const char* bcp47Locales[2]; |
| + int localeCount = 0; |
| + CString defaultLocale = toSkFontMgrLocale(defaultLanguage()); |
| + bcp47Locales[localeCount++] = defaultLocale.data(); |
| + CString fontLocale; |
| + if (!fontDescription.locale().isEmpty()) { |
| + fontLocale = toSkFontMgrLocale(fontDescription.locale()); |
| + bcp47Locales[localeCount++] = fontLocale.data(); |
| + } |
| + RefPtr<SkTypeface> typeface = adoptRef(fm->matchFamilyStyleCharacter(0, SkFontStyle(), bcp47Locales, localeCount, c)); |
| + if (!typeface) |
| + return emptyAtom; |
| + |
| + SkString skiaFamilyName; |
| + typeface->getFamilyName(&skiaFamilyName); |
| + return skiaFamilyName.c_str(); |
| +} |
| +#endif |
| + |
| void FontCache::platformInit() |
| { |
| } |
| @@ -113,6 +154,16 @@ PassRefPtr<SimpleFontData> FontCache::fallbackOnStandardFontStyle( |
| #if !OS(WIN) && !OS(ANDROID) |
| PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescription& fontDescription, UChar32 c, const SimpleFontData*) |
| { |
| +#if OS(LINUX) |
| + // Try the SkFontMgr first if we have one. |
| + if (m_fontManager) { |
|
eae
2016/02/17 23:52:10
When would we not have a font manager? On windows
Khushal
2016/02/18 00:46:37
On linux the default font manager is backed by an
|
| + AtomicString familyName = getFamilyNameForCharacter(m_fontManager.get(), c, fontDescription); |
| + if (familyName.isEmpty()) |
| + return getLastResortFallbackFont(fontDescription, DoNotRetain); |
| + return fontDataFromFontPlatformData(getFontPlatformData(fontDescription, FontFaceCreationParams(familyName)), DoNotRetain); |
| + } |
| +#endif |
| + |
| // First try the specified font with standard style & weight. |
| if (fontDescription.style() == FontStyleItalic |
| || fontDescription.weight() >= FontWeight600) { |
| @@ -277,6 +328,11 @@ PassRefPtr<SkTypeface> FontCache::createTypeface(const FontDescription& fontDesc |
| } |
| #endif |
| +#if OS(LINUX) |
| + if (m_fontManager) |
| + return adoptRef(m_fontManager->legacyCreateTypeface(name.data(), style)); |
| +#endif |
| + |
| // FIXME: Use m_fontManager, SkFontStyle and matchFamilyStyle instead of |
| // CreateFromName on all platforms. |
| return adoptRef(SkTypeface::CreateFromName(name.data(), static_cast<SkTypeface::Style>(style))); |