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

Unified Diff: third_party/WebKit/Source/platform/fonts/FontCache.cpp

Issue 2441343003: Allow the default generic font family settings to find the first available font (Closed)
Patch Set: Un-shared FirstAvailableOrFirst as per msw review Created 4 years, 2 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/FontCache.cpp
diff --git a/third_party/WebKit/Source/platform/fonts/FontCache.cpp b/third_party/WebKit/Source/platform/fonts/FontCache.cpp
index 2844a92e37aa811a9dd023d1d65441be65a5e5da..a4b1de73bb7d398008ad5d7a195cf7684834c4ec 100644
--- a/third_party/WebKit/Source/platform/fonts/FontCache.cpp
+++ b/third_party/WebKit/Source/platform/fonts/FontCache.cpp
@@ -48,6 +48,7 @@
#include "platform/tracing/web_memory_allocator_dump.h"
#include "platform/tracing/web_process_memory_dump.h"
#include "public/platform/Platform.h"
+#include "ui/gfx/font.h"
#include "wtf/HashMap.h"
#include "wtf/ListHashSet.h"
#include "wtf/PtrUtil.h"
@@ -302,6 +303,31 @@ bool FontCache::isPlatformFontAvailable(const FontDescription& fontDescription,
FontFaceCreationParams(adjustFamilyNameToAvoidUnsupportedFonts(family)),
checkingAlternateName);
}
+static bool isFontFamilyAvailable(const String& family,
+ SkFontMgr* fontManager) {
+#if OS(LINUX)
+ sk_sp<SkTypeface> typeface(
+ fontManager->legacyCreateTypeface(family.utf8().data(), SkFontStyle()));
+ return typeface;
+#else
+ sk_sp<SkFontStyleSet> set(fontManager->matchFamily(family.utf8().data()));
+ return set && set->count();
+#endif
+}
+
+String FontCache::firstAvailableOrFirst(const String& families) {
+ Vector<String> familyList;
+ families.split(',', familyList);
+ if (familyList.isEmpty())
+ return String();
+ sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
+ for (String& family : familyList) {
+ family = family.stripWhiteSpace();
+ if (isFontFamilyAvailable(family, fm.get()))
+ return family;
+ }
+ return familyList.first();
+}
SimpleFontData* FontCache::getNonRetainedLastResortFallbackFont(
const FontDescription& fontDescription) {

Powered by Google App Engine
This is Rietveld 408576698