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

Side by Side 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, 1 month 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> 3 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 30 matching lines...) Expand all
41 #include "platform/fonts/FontDescription.h" 41 #include "platform/fonts/FontDescription.h"
42 #include "platform/fonts/FontPlatformData.h" 42 #include "platform/fonts/FontPlatformData.h"
43 #include "platform/fonts/FontSmoothingMode.h" 43 #include "platform/fonts/FontSmoothingMode.h"
44 #include "platform/fonts/SimpleFontData.h" 44 #include "platform/fonts/SimpleFontData.h"
45 #include "platform/fonts/TextRenderingMode.h" 45 #include "platform/fonts/TextRenderingMode.h"
46 #include "platform/fonts/opentype/OpenTypeVerticalData.h" 46 #include "platform/fonts/opentype/OpenTypeVerticalData.h"
47 #include "platform/fonts/shaping/ShapeCache.h" 47 #include "platform/fonts/shaping/ShapeCache.h"
48 #include "platform/tracing/web_memory_allocator_dump.h" 48 #include "platform/tracing/web_memory_allocator_dump.h"
49 #include "platform/tracing/web_process_memory_dump.h" 49 #include "platform/tracing/web_process_memory_dump.h"
50 #include "public/platform/Platform.h" 50 #include "public/platform/Platform.h"
51 #include "ui/gfx/font.h"
51 #include "wtf/HashMap.h" 52 #include "wtf/HashMap.h"
52 #include "wtf/ListHashSet.h" 53 #include "wtf/ListHashSet.h"
53 #include "wtf/PtrUtil.h" 54 #include "wtf/PtrUtil.h"
54 #include "wtf/StdLibExtras.h" 55 #include "wtf/StdLibExtras.h"
55 #include "wtf/Vector.h" 56 #include "wtf/Vector.h"
56 #include "wtf/text/AtomicStringHash.h" 57 #include "wtf/text/AtomicStringHash.h"
57 #include "wtf/text/StringHash.h" 58 #include "wtf/text/StringHash.h"
58 #include <memory> 59 #include <memory>
59 60
60 using namespace WTF; 61 using namespace WTF;
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 } 296 }
296 297
297 bool FontCache::isPlatformFontAvailable(const FontDescription& fontDescription, 298 bool FontCache::isPlatformFontAvailable(const FontDescription& fontDescription,
298 const AtomicString& family) { 299 const AtomicString& family) {
299 bool checkingAlternateName = true; 300 bool checkingAlternateName = true;
300 return getFontPlatformData( 301 return getFontPlatformData(
301 fontDescription, 302 fontDescription,
302 FontFaceCreationParams(adjustFamilyNameToAvoidUnsupportedFonts(family)), 303 FontFaceCreationParams(adjustFamilyNameToAvoidUnsupportedFonts(family)),
303 checkingAlternateName); 304 checkingAlternateName);
304 } 305 }
306 static bool isFontFamilyAvailable(const String& family,
307 SkFontMgr* fontManager) {
308 #if OS(LINUX)
309 sk_sp<SkTypeface> typeface(
310 fontManager->legacyCreateTypeface(family.utf8().data(), SkFontStyle()));
311 return typeface;
312 #else
313 sk_sp<SkFontStyleSet> set(fontManager->matchFamily(family.utf8().data()));
314 return set && set->count();
315 #endif
316 }
317
318 String FontCache::firstAvailableOrFirst(const String& families) {
319 Vector<String> familyList;
320 families.split(',', familyList);
321 if (familyList.isEmpty())
322 return String();
323 sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
324 for (String& family : familyList) {
325 family = family.stripWhiteSpace();
326 if (isFontFamilyAvailable(family, fm.get()))
327 return family;
328 }
329 return familyList.first();
330 }
305 331
306 SimpleFontData* FontCache::getNonRetainedLastResortFallbackFont( 332 SimpleFontData* FontCache::getNonRetainedLastResortFallbackFont(
307 const FontDescription& fontDescription) { 333 const FontDescription& fontDescription) {
308 return getLastResortFallbackFont(fontDescription, DoNotRetain).leakRef(); 334 return getLastResortFallbackFont(fontDescription, DoNotRetain).leakRef();
309 } 335 }
310 336
311 void FontCache::releaseFontData(const SimpleFontData* fontData) { 337 void FontCache::releaseFontData(const SimpleFontData* fontData) {
312 ASSERT(gFontDataCache); 338 ASSERT(gFontDataCache);
313 339
314 gFontDataCache->release(fontData); 340 gFontDataCache->release(fontData);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 for (iter = gFallbackListShaperCache->begin(); 500 for (iter = gFallbackListShaperCache->begin();
475 iter != gFallbackListShaperCache->end(); ++iter) { 501 iter != gFallbackListShaperCache->end(); ++iter) {
476 shapeResultCacheSize += iter->value->byteSize(); 502 shapeResultCacheSize += iter->value->byteSize();
477 } 503 }
478 dump->AddScalar("size", "bytes", shapeResultCacheSize); 504 dump->AddScalar("size", "bytes", shapeResultCacheSize);
479 memoryDump->AddSuballocation(dump->guid(), 505 memoryDump->AddSuballocation(dump->guid(),
480 WTF::Partitions::kAllocatedObjectPoolName); 506 WTF::Partitions::kAllocatedObjectPoolName);
481 } 507 }
482 508
483 } // namespace blink 509 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698