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 a97fbbf87aa2ebec7e7fe74f866f0355c8f7f237..d454c7bf64999190b07ebd31510e7520cd3f82ea 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,51 @@ 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) |
+// 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 |
+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() |
{ |
} |
@@ -227,6 +273,14 @@ PassRefPtr<SkTypeface> FontCache::createTypeface(const FontDescription& fontDesc |
} |
#endif |
+#if OS(LINUX) |
+ // On linux if the fontManager has been overridden then we should be calling the embedder |
+ // 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->legacyCreateTypeface(name.data(), style)); |
bungeman-chromium
2016/02/29 22:48:50
This is a little bit sneaky, but I think this shou
Khushal
2016/03/01 18:52:43
You're right, I was trying to be consistent with t
|
+#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))); |