Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1650)

Unified Diff: third_party/WebKit/Source/platform/fonts/skia/FontCacheSkia.cpp

Issue 1685053002: blink fonts: Load Android SkFontMgr on Linux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@windows_change
Patch Set: Rebase. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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)));

Powered by Google App Engine
This is Rietveld 408576698