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

Unified Diff: third_party/WebKit/Source/platform/fonts/win/FontCacheSkiaWin.cpp

Issue 1740593002: Use Skia's matchFamilyStyleCharacter API for font fallback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/win/FontCacheSkiaWin.cpp
diff --git a/third_party/WebKit/Source/platform/fonts/win/FontCacheSkiaWin.cpp b/third_party/WebKit/Source/platform/fonts/win/FontCacheSkiaWin.cpp
index 5a61fc126196325097777b82e2cfa2d24a56a1ce..923e19fddbe07cd547b92a60befe520e159b398b 100644
--- a/third_party/WebKit/Source/platform/fonts/win/FontCacheSkiaWin.cpp
+++ b/third_party/WebKit/Source/platform/fonts/win/FontCacheSkiaWin.cpp
@@ -33,6 +33,7 @@
#include "SkFontMgr.h"
#include "SkTypeface_win.h"
+#include "platform/Language.h"
#include "platform/RuntimeEnabledFeatures.h"
#include "platform/fonts/FontDescription.h"
#include "platform/fonts/FontFaceCreationParams.h"
@@ -139,6 +140,35 @@ PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(
data = getFontPlatformData(fontDescription, createByFamily);
}
+ if (!data || !data->fontContainsCharacter(character)) {
+ const char* bcp47Locale = nullptr;
+ int localeCount = 0;
+ CString fontLocale;
+ // If the font description has a locale, use that. Otherwise, Skia will fall back
eae 2016/02/29 23:11:26 Wrap at 80 col, you'll probably do a better job of
Ilya Kulshin 2016/03/01 03:31:14 Done.
+ // on the user's default locale.
+ // TODO(kulshin): extract locale fallback logic from FontCacheAndroid.cpp and share that code
+ if (!fontDescription.locale().isEmpty()) {
+ fontLocale = toSkFontMgrLocale(fontDescription.locale());
+ bcp47Locale = fontLocale.data();
+ localeCount = 1;
eae 2016/02/29 23:11:26 This is set but never used. Please remove.
Ilya Kulshin 2016/03/01 03:31:14 This is used in the call to matchFamilyStyleCharac
+ }
+
+ // LChar is unsigned, while matchFamilyStyleCharacter requires a plain char*.
+ const LChar* fontDescriptionFamilyName = fontDescription.family().family().characters8();
+ const char* skiaFamilyName = reinterpret_cast<const char*>(fontDescriptionFamilyName);
eae 2016/02/29 23:11:26 Elsewhere we convert the family name to utf8 befor
Ilya Kulshin 2016/03/01 03:31:14 Oh, not sure how I missed that API. That works muc
+ static_assert(sizeof(*fontDescriptionFamilyName) == sizeof(*skiaFamilyName),
+ "skiaFamilyName and fontDescriptionFamilyName must be same size");
+
+ SkTypeface* typeface = m_fontManager->matchFamilyStyleCharacter(
+ skiaFamilyName, fontDescription.skiaFontStyle(), &bcp47Locale, localeCount, character);
+ if (typeface) {
+ SkString skiaFamily;
+ typeface->getFamilyName(&skiaFamily);
+ FontFaceCreationParams createByFamily(AtomicString(skiaFamily.c_str()));
+ data = getFontPlatformData(fontDescription, createByFamily);
+ }
+ }
+
// Last resort font list : PanUnicode. CJK fonts have a pretty
// large repertoire. Eventually, we need to scan all the fonts
// on the system to have a Firefox-like coverage.

Powered by Google App Engine
This is Rietveld 408576698