Diff
Modified: trunk/Source/WebCore/ChangeLog (236937 => 236938)
--- trunk/Source/WebCore/ChangeLog 2018-10-08 20:24:56 UTC (rev 236937)
+++ trunk/Source/WebCore/ChangeLog 2018-10-08 20:37:26 UTC (rev 236938)
@@ -1,3 +1,59 @@
+2018-10-08 Antti Koivisto <[email protected]>
+
+ Move SystemFontDatabase to a file of its own
+ https://bugs.webkit.org/show_bug.cgi?id=190347
+
+ Reviewed by Chris Dumez.
+
+ Also rename it to SystemFontDatabaseCoreText as it is CoreText specific.
+
+ * SourcesCocoa.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ * page/MemoryRelease.cpp:
+ (WebCore::releaseNoncriticalMemory):
+ * page/cocoa/MemoryReleaseCocoa.mm:
+
+ Release SystemFontDatabaseCoreText directly from platform specific cleanup code.
+
+ (WebCore::platformReleaseMemory):
+ * platform/graphics/cocoa/FontDescriptionCocoa.cpp:
+ (WebCore::FontDescription::invalidateCaches):
+ (WebCore::systemFontCascadeList):
+ (WebCore::FontCascadeDescription::effectiveFamilyCount const):
+ (WebCore::FontCascadeDescription::effectiveFamilyAt const):
+ (WebCore::SystemFontDatabase::CoreTextCascadeListParameters::CoreTextCascadeListParameters): Deleted.
+ (WebCore::SystemFontDatabase::CoreTextCascadeListParameters::isHashTableDeletedValue const): Deleted.
+ (WebCore::SystemFontDatabase::CoreTextCascadeListParameters::operator== const): Deleted.
+ (WebCore::SystemFontDatabase::CoreTextCascadeListParameters::hash const): Deleted.
+ (WebCore::SystemFontDatabase::CoreTextCascadeListParameters::CoreTextCascadeListParametersHash::hash): Deleted.
+ (WebCore::SystemFontDatabase::CoreTextCascadeListParameters::CoreTextCascadeListParametersHash::equal): Deleted.
+ (): Deleted.
+ (WebCore::SystemFontDatabase::singleton): Deleted.
+ (WebCore::SystemFontDatabase::systemFontCascadeList): Deleted.
+ (WebCore::SystemFontDatabase::clear): Deleted.
+ (WebCore::SystemFontDatabase::SystemFontDatabase): Deleted.
+ (WebCore::SystemFontDatabase::applyWeightItalicsAndFallbackBehavior): Deleted.
+ (WebCore::SystemFontDatabase::removeCascadeList): Deleted.
+ (WebCore::SystemFontDatabase::computeCascadeList): Deleted.
+ (WebCore::systemFontParameters): Deleted.
+ * platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp: Added.
+ (WebCore::SystemFontDatabaseCoreText::singleton):
+ (WebCore::SystemFontDatabaseCoreText::SystemFontDatabaseCoreText):
+ (WebCore::SystemFontDatabaseCoreText::systemFontCascadeList):
+ (WebCore::SystemFontDatabaseCoreText::clear):
+ (WebCore::SystemFontDatabaseCoreText::applyWeightItalicsAndFallbackBehavior):
+ (WebCore::SystemFontDatabaseCoreText::removeCascadeList):
+ (WebCore::SystemFontDatabaseCoreText::computeCascadeList):
+ (WebCore::SystemFontDatabaseCoreText::systemFontParameters):
+ * platform/graphics/cocoa/SystemFontDatabaseCoreText.h: Added.
+ (WebCore::SystemFontDatabaseCoreText::CascadeListParameters::CascadeListParameters):
+ (WebCore::SystemFontDatabaseCoreText::CascadeListParameters::isHashTableDeletedValue const):
+ (WebCore::SystemFontDatabaseCoreText::CascadeListParameters::operator== const):
+ (WebCore::SystemFontDatabaseCoreText::CascadeListParameters::hash const):
+ (WebCore::SystemFontDatabaseCoreText::CascadeListParameters::CascadeListParametersHash::hash):
+ (WebCore::SystemFontDatabaseCoreText::CascadeListParameters::CascadeListParametersHash::equal):
+ * platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp:
+
2018-10-08 Jeremy Jones <[email protected]>
Remove dead code: VideoFullscreenModel::isVisible()
Modified: trunk/Source/WebCore/SourcesCocoa.txt (236937 => 236938)
--- trunk/Source/WebCore/SourcesCocoa.txt 2018-10-08 20:24:56 UTC (rev 236937)
+++ trunk/Source/WebCore/SourcesCocoa.txt 2018-10-08 20:37:26 UTC (rev 236938)
@@ -306,6 +306,7 @@
platform/graphics/cocoa/IOSurface.mm
platform/graphics/cocoa/IOSurfacePoolCocoa.mm
platform/graphics/cocoa/MediaEngineConfigurationFactoryCocoa.cpp
+platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp
platform/graphics/cocoa/WebActionDisablingCALayerDelegate.mm
platform/graphics/cocoa/WebCoreCALayerExtras.mm
platform/graphics/cocoa/WebCoreDecompressionSession.mm
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (236937 => 236938)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2018-10-08 20:24:56 UTC (rev 236937)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2018-10-08 20:37:26 UTC (rev 236938)
@@ -4811,6 +4811,7 @@
E4DEAA1817A93DC3000E0430 /* StyleTreeResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = E4DEAA1617A93DC3000E0430 /* StyleTreeResolver.h */; settings = {ATTRIBUTES = (Private, ); }; };
E4E243831DAB953E00C26E4B /* meterElementShadow.css in Resources */ = {isa = PBXBuildFile; fileRef = E4E243821DAB953E00C26E4B /* meterElementShadow.css */; };
E4E39AFB1330EFA8003AB274 /* LegacyTileLayerPool.h in Headers */ = {isa = PBXBuildFile; fileRef = E4E39AFA1330EFA8003AB274 /* LegacyTileLayerPool.h */; };
+ E4E8B4EC216B79E500B8834D /* SystemFontDatabaseCoreText.h in Headers */ = {isa = PBXBuildFile; fileRef = E4E8B4EA216B79E500B8834D /* SystemFontDatabaseCoreText.h */; };
E4E8B4F5216B956500B8834D /* FontCascadeDescription.h in Headers */ = {isa = PBXBuildFile; fileRef = E4E8B4F2216B8B6000B8834D /* FontCascadeDescription.h */; settings = {ATTRIBUTES = (Private, ); }; };
E4E9B1191810916F003ACCDF /* SimpleLineLayoutResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = E4E9B1181810916F003ACCDF /* SimpleLineLayoutResolver.h */; };
E4E9B11D1814569C003ACCDF /* SimpleLineLayoutFunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = E4E9B11C1814569C003ACCDF /* SimpleLineLayoutFunctions.h */; };
@@ -14548,6 +14549,8 @@
E4E243821DAB953E00C26E4B /* meterElementShadow.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = meterElementShadow.css; sourceTree = "<group>"; };
E4E39AFA1330EFA8003AB274 /* LegacyTileLayerPool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LegacyTileLayerPool.h; sourceTree = "<group>"; };
E4E39AFC1330EFC5003AB274 /* LegacyTileLayerPool.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LegacyTileLayerPool.mm; sourceTree = "<group>"; };
+ E4E8B4EA216B79E500B8834D /* SystemFontDatabaseCoreText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SystemFontDatabaseCoreText.h; sourceTree = "<group>"; };
+ E4E8B4ED216B79F400B8834D /* SystemFontDatabaseCoreText.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SystemFontDatabaseCoreText.cpp; sourceTree = "<group>"; };
E4E8B4F0216B8B5F00B8834D /* FontCascadeDescription.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontCascadeDescription.cpp; sourceTree = "<group>"; };
E4E8B4F2216B8B6000B8834D /* FontCascadeDescription.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FontCascadeDescription.h; sourceTree = "<group>"; };
E4E9B1181810916F003ACCDF /* SimpleLineLayoutResolver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleLineLayoutResolver.h; sourceTree = "<group>"; };
@@ -24025,6 +24028,8 @@
AD9FF6E01908391D003B61E0 /* IOSurfacePoolCocoa.mm */,
CDC48AC82149CF2A0024FD59 /* MediaEngineConfigurationFactoryCocoa.cpp */,
CDC48AC72149CF2A0024FD59 /* MediaEngineConfigurationFactoryCocoa.h */,
+ E4E8B4ED216B79F400B8834D /* SystemFontDatabaseCoreText.cpp */,
+ E4E8B4EA216B79E500B8834D /* SystemFontDatabaseCoreText.h */,
526724F21CB2FDF60075974D /* TextTrackRepresentationCocoa.h */,
526724F11CB2FDF60075974D /* TextTrackRepresentationCocoa.mm */,
2D3EF4441917915C00034184 /* WebActionDisablingCALayerDelegate.h */,
@@ -27493,6 +27498,7 @@
57303BBB2006C6EE00355965 /* CBORBinary.h in Headers */,
57303BC12006E00C00355965 /* CBORReader.h in Headers */,
57303BB92006C6EE00355965 /* CBORValue.h in Headers */,
+ E4E8B4EC216B79E500B8834D /* SystemFontDatabaseCoreText.h in Headers */,
57303BBA2006C6EE00355965 /* CBORWriter.h in Headers */,
6550B69E099DF0270090D781 /* CDATASection.h in Headers */,
CDF4B7161E00B7E500E235A2 /* CDM.h in Headers */,
Modified: trunk/Source/WebCore/page/MemoryRelease.cpp (236937 => 236938)
--- trunk/Source/WebCore/page/MemoryRelease.cpp 2018-10-08 20:24:56 UTC (rev 236937)
+++ trunk/Source/WebCore/page/MemoryRelease.cpp 2018-10-08 20:37:26 UTC (rev 236938)
@@ -63,7 +63,6 @@
RenderTheme::singleton().purgeCaches();
FontCache::singleton().purgeInactiveFontData();
- FontDescription::invalidateCaches();
clearWidthCaches();
TextPainter::clearGlyphDisplayLists();
Modified: trunk/Source/WebCore/page/cocoa/MemoryReleaseCocoa.mm (236937 => 236938)
--- trunk/Source/WebCore/page/cocoa/MemoryReleaseCocoa.mm 2018-10-08 20:24:56 UTC (rev 236937)
+++ trunk/Source/WebCore/page/cocoa/MemoryReleaseCocoa.mm 2018-10-08 20:37:26 UTC (rev 236938)
@@ -29,6 +29,7 @@
#import "GCController.h"
#import "IOSurfacePool.h"
#import "LayerPool.h"
+#import "SystemFontDatabaseCoreText.h"
#import <notify.h>
#import <pal/spi/ios/GraphicsServicesSPI.h>
@@ -42,6 +43,10 @@
void platformReleaseMemory(Critical)
{
+#if USE_PLATFORM_SYSTEM_FALLBACK_LIST
+ SystemFontDatabaseCoreText::singleton().clear();
+#endif
+
#if PLATFORM(IOS) && !PLATFORM(IOS_SIMULATOR) && !PLATFORM(IOSMAC)
// FIXME: Remove this call to GSFontInitialize() once <rdar://problem/32886715> is fixed.
GSFontInitialize();
Modified: trunk/Source/WebCore/platform/graphics/FontDescription.cpp (236937 => 236938)
--- trunk/Source/WebCore/platform/graphics/FontDescription.cpp 2018-10-08 20:24:56 UTC (rev 236937)
+++ trunk/Source/WebCore/platform/graphics/FontDescription.cpp 2018-10-08 20:37:26 UTC (rev 236938)
@@ -71,10 +71,4 @@
m_script = localeToScriptCodeForFontSelection(m_locale);
}
-#if !USE_PLATFORM_SYSTEM_FALLBACK_LIST
-void FontDescription::invalidateCaches()
-{
-}
-#endif
-
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/FontDescription.h (236937 => 236938)
--- trunk/Source/WebCore/platform/graphics/FontDescription.h 2018-10-08 20:24:56 UTC (rev 236937)
+++ trunk/Source/WebCore/platform/graphics/FontDescription.h 2018-10-08 20:37:26 UTC (rev 236938)
@@ -133,8 +133,6 @@
void setFontStyleAxis(FontStyleAxis axis) { m_fontStyleAxis = axis == FontStyleAxis::ital; }
void setShouldAllowUserInstalledFonts(AllowUserInstalledFonts shouldAllowUserInstalledFonts) { m_shouldAllowUserInstalledFonts = static_cast<unsigned>(shouldAllowUserInstalledFonts); }
- static void invalidateCaches();
-
private:
// FIXME: Investigate moving these into their own object on the heap (to save memory).
FontFeatureSettings m_featureSettings;
Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp (236937 => 236938)
--- trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp 2018-10-08 20:24:56 UTC (rev 236937)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp 2018-10-08 20:37:26 UTC (rev 236938)
@@ -27,6 +27,7 @@
#include "FontCache.h"
#include "Font.h"
+#include "SystemFontDatabaseCoreText.h"
#include <pal/spi/cocoa/CoreTextSPI.h>
#include <CoreText/SFNTLayoutTypes.h>
@@ -1186,7 +1187,9 @@
return;
}
- FontDescription::invalidateCaches();
+#if USE_PLATFORM_SYSTEM_FALLBACK_LIST
+ SystemFontDatabaseCoreText::singleton().clear();
+#endif
FontDatabase::singletonAllowingUserInstalledFonts().clear();
FontDatabase::singletonDisallowingUserInstalledFonts().clear();
Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontDescriptionCocoa.cpp (236937 => 236938)
--- trunk/Source/WebCore/platform/graphics/cocoa/FontDescriptionCocoa.cpp 2018-10-08 20:24:56 UTC (rev 236937)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontDescriptionCocoa.cpp 2018-10-08 20:37:26 UTC (rev 236938)
@@ -26,175 +26,12 @@
#include "config.h"
#include "FontDescription.h"
-#include "FontCache.h"
-#include "FontFamilySpecificationCoreText.h"
-#include <pal/spi/cocoa/CoreTextSPI.h>
-#include <wtf/HashMap.h>
-#include <wtf/HashTraits.h>
-#include <wtf/text/AtomicString.h>
-#include <wtf/text/AtomicStringHash.h>
+#include "SystemFontDatabaseCoreText.h"
-#if PLATFORM(IOS)
-#include "RenderThemeIOS.h"
-#endif
-
#if USE_PLATFORM_SYSTEM_FALLBACK_LIST
namespace WebCore {
-class SystemFontDatabase {
-public:
- struct CoreTextCascadeListParameters {
- CoreTextCascadeListParameters()
- {
- }
-
- CoreTextCascadeListParameters(WTF::HashTableDeletedValueType)
- : fontName(WTF::HashTableDeletedValue)
- {
- }
-
- bool isHashTableDeletedValue() const
- {
- return fontName.isHashTableDeletedValue();
- }
-
- bool operator==(const CoreTextCascadeListParameters& other) const
- {
- return fontName == other.fontName
- && locale == other.locale
- && weight == other.weight
- && size == other.size
- && allowUserInstalledFonts == other.allowUserInstalledFonts
- && italic == other.italic;
- }
-
- unsigned hash() const
- {
- IntegerHasher hasher;
- ASSERT(!fontName.isNull());
- hasher.add(locale.existingHash());
- hasher.add(locale.isNull() ? 0 : locale.existingHash());
- hasher.add(weight);
- hasher.add(size);
- hasher.add(static_cast<unsigned>(allowUserInstalledFonts));
- hasher.add(italic);
- return hasher.hash();
- }
-
- struct CoreTextCascadeListParametersHash : WTF::PairHash<AtomicString, float> {
- static unsigned hash(const CoreTextCascadeListParameters& parameters)
- {
- return parameters.hash();
- }
- static bool equal(const CoreTextCascadeListParameters& a, const CoreTextCascadeListParameters& b)
- {
- return a == b;
- }
- static const bool safeToCompareToEmptyOrDeleted = true;
- };
-
- AtomicString fontName;
- AtomicString locale;
- CGFloat weight { 0 };
- float size { 0 };
- AllowUserInstalledFonts allowUserInstalledFonts { AllowUserInstalledFonts::No };
- bool italic { false };
- };
-
- static SystemFontDatabase& singleton()
- {
- static NeverDestroyed<SystemFontDatabase> database = SystemFontDatabase();
- return database.get();
- }
-
- enum class ClientUse { ForSystemUI, ForTextStyle };
-
- Vector<RetainPtr<CTFontDescriptorRef>> systemFontCascadeList(const CoreTextCascadeListParameters& parameters, ClientUse clientUse)
- {
- ASSERT(!parameters.fontName.isNull());
- return m_systemFontCache.ensure(parameters, [&] {
- auto localeString = parameters.locale.string().createCFString();
- RetainPtr<CTFontRef> systemFont;
- if (clientUse == ClientUse::ForSystemUI) {
- systemFont = adoptCF(CTFontCreateUIFontForLanguage(kCTFontUIFontSystem, parameters.size, localeString.get()));
- ASSERT(systemFont);
- // FIXME: Use applyWeightItalicsAndFallbackBehavior() in both cases once <rdar://problem/33046041> is fixed.
- systemFont = applyWeightItalicsAndFallbackBehavior(systemFont.get(), parameters.weight, parameters.italic, parameters.size, parameters.allowUserInstalledFonts);
- } else {
-#if PLATFORM(IOS)
- ASSERT(clientUse == ClientUse::ForTextStyle);
- auto fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(parameters.fontName.string().createCFString().get(), RenderThemeIOS::contentSizeCategory(), nullptr));
- CTFontSymbolicTraits traits = (parameters.weight >= kCTFontWeightSemibold ? kCTFontTraitBold : 0) | (parameters.italic ? kCTFontTraitItalic : 0);
- if (traits)
- fontDescriptor = adoptCF(CTFontDescriptorCreateCopyWithSymbolicTraits(fontDescriptor.get(), traits, traits));
- systemFont = createFontForInstalledFonts(fontDescriptor.get(), parameters.size, parameters.allowUserInstalledFonts);
-#else
- ASSERT_NOT_REACHED();
-#endif
- }
- ASSERT(systemFont);
- auto result = computeCascadeList(systemFont.get(), localeString.get());
- ASSERT(!result.isEmpty());
- return result;
- }).iterator->value;
- }
-
- void clear()
- {
- m_systemFontCache.clear();
- }
-
-private:
- SystemFontDatabase()
- {
- }
-
- static RetainPtr<CTFontRef> applyWeightItalicsAndFallbackBehavior(CTFontRef font, CGFloat weight, bool italic, float size, AllowUserInstalledFonts allowUserInstalledFonts)
- {
- auto weightNumber = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberCGFloatType, &weight));
- const float systemFontItalicSlope = 0.07;
- float italicsRawNumber = italic ? systemFontItalicSlope : 0;
- auto italicsNumber = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberFloatType, &italicsRawNumber));
- CFTypeRef traitsKeys[] = { kCTFontWeightTrait, kCTFontSlantTrait, kCTFontUIFontDesignTrait };
- CFTypeRef traitsValues[] = { weightNumber.get(), italicsNumber.get(), kCFBooleanTrue };
- auto traitsDictionary = adoptCF(CFDictionaryCreate(kCFAllocatorDefault, traitsKeys, traitsValues, WTF_ARRAY_LENGTH(traitsKeys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
- auto attributes = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
- CFDictionaryAddValue(attributes.get(), kCTFontTraitsAttribute, traitsDictionary.get());
- addAttributesForInstalledFonts(attributes.get(), allowUserInstalledFonts);
- auto modification = adoptCF(CTFontDescriptorCreateWithAttributes(attributes.get()));
- return adoptCF(CTFontCreateCopyWithAttributes(font, size, nullptr, modification.get()));
- }
-
- static RetainPtr<CTFontDescriptorRef> removeCascadeList(CTFontDescriptorRef fontDescriptor)
- {
- auto emptyArray = adoptCF(CFArrayCreate(kCFAllocatorDefault, nullptr, 0, &kCFTypeArrayCallBacks));
- CFTypeRef fallbackDictionaryKeys[] = { kCTFontCascadeListAttribute };
- CFTypeRef fallbackDictionaryValues[] = { emptyArray.get() };
- auto fallbackDictionary = adoptCF(CFDictionaryCreate(kCFAllocatorDefault, fallbackDictionaryKeys, fallbackDictionaryValues, WTF_ARRAY_LENGTH(fallbackDictionaryKeys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
- auto modifiedFontDescriptor = adoptCF(CTFontDescriptorCreateCopyWithAttributes(fontDescriptor, fallbackDictionary.get()));
- return modifiedFontDescriptor;
- }
-
- static Vector<RetainPtr<CTFontDescriptorRef>> computeCascadeList(CTFontRef font, CFStringRef locale)
- {
- CFTypeRef arrayValues[] = { locale };
- auto localeArray = adoptCF(CFArrayCreate(kCFAllocatorDefault, arrayValues, WTF_ARRAY_LENGTH(arrayValues), &kCFTypeArrayCallBacks));
- auto cascadeList = adoptCF(CTFontCopyDefaultCascadeListForLanguages(font, localeArray.get()));
- Vector<RetainPtr<CTFontDescriptorRef>> result;
- // WebKit handles the cascade list, and WebKit 2's IPC code doesn't know how to serialize Core Text's cascade list.
- result.append(removeCascadeList(adoptCF(CTFontCopyFontDescriptor(font)).get()));
- if (cascadeList) {
- CFIndex arrayLength = CFArrayGetCount(cascadeList.get());
- for (CFIndex i = 0; i < arrayLength; ++i)
- result.append(static_cast<CTFontDescriptorRef>(CFArrayGetValueAtIndex(cascadeList.get(), i)));
- }
- return result;
- }
-
- HashMap<CoreTextCascadeListParameters, Vector<RetainPtr<CTFontDescriptorRef>>, CoreTextCascadeListParameters::CoreTextCascadeListParametersHash, SimpleClassHashTraits<CoreTextCascadeListParameters>> m_systemFontCache;
-};
-
static inline bool isSystemFontString(const AtomicString& string)
{
return equalLettersIgnoringASCIICase(string, "-webkit-system-font")
@@ -244,59 +81,11 @@
}
#endif
-static inline SystemFontDatabase::CoreTextCascadeListParameters systemFontParameters(const FontCascadeDescription& description, const AtomicString& familyName, SystemFontDatabase::ClientUse clientUse, AllowUserInstalledFonts allowUserInstalledFonts)
+static inline Vector<RetainPtr<CTFontDescriptorRef>> systemFontCascadeList(const FontCascadeDescription& description, const AtomicString& cssFamily, SystemFontDatabaseCoreText::ClientUse clientUse, AllowUserInstalledFonts allowUserInstalledFonts)
{
- SystemFontDatabase::CoreTextCascadeListParameters result;
- result.locale = description.locale();
- result.size = description.computedSize();
- result.italic = isItalic(description.italic());
-
- auto weight = description.weight();
- if (FontCache::singleton().shouldMockBoldSystemFontForAccessibility())
- weight = weight + FontSelectionValue(200);
-
- if (weight < FontSelectionValue(150))
- result.weight = kCTFontWeightUltraLight;
- else if (weight < FontSelectionValue(250))
- result.weight = kCTFontWeightThin;
- else if (weight < FontSelectionValue(350))
- result.weight = kCTFontWeightLight;
- else if (weight < FontSelectionValue(450))
- result.weight = kCTFontWeightRegular;
- else if (weight < FontSelectionValue(550))
- result.weight = kCTFontWeightMedium;
- else if (weight < FontSelectionValue(650))
- result.weight = kCTFontWeightSemibold;
- else if (weight < FontSelectionValue(750))
- result.weight = kCTFontWeightBold;
- else if (weight < FontSelectionValue(850))
- result.weight = kCTFontWeightHeavy;
- else
- result.weight = kCTFontWeightBlack;
-
- if (clientUse == SystemFontDatabase::ClientUse::ForSystemUI) {
- static NeverDestroyed<AtomicString> systemUI = AtomicString("system-ui", AtomicString::ConstructFromLiteral);
- result.fontName = systemUI.get();
- } else {
- ASSERT(clientUse == SystemFontDatabase::ClientUse::ForTextStyle);
- result.fontName = familyName;
- }
-
- result.allowUserInstalledFonts = allowUserInstalledFonts;
-
- return result;
+ return SystemFontDatabaseCoreText::singleton().cascadeList(description, cssFamily, clientUse, allowUserInstalledFonts);
}
-void FontDescription::invalidateCaches()
-{
- SystemFontDatabase::singleton().clear();
-}
-
-static inline Vector<RetainPtr<CTFontDescriptorRef>> systemFontCascadeList(const FontCascadeDescription& description, const AtomicString& cssFamily, SystemFontDatabase::ClientUse clientUse, AllowUserInstalledFonts allowUserInstalledFonts)
-{
- return SystemFontDatabase::singleton().systemFontCascadeList(systemFontParameters(description, cssFamily, clientUse, allowUserInstalledFonts), clientUse);
-}
-
unsigned FontCascadeDescription::effectiveFamilyCount() const
{
// FIXME: Move all the other system font keywords from platformFontWithFamilySpecialCase() to here.
@@ -304,10 +93,10 @@
for (unsigned i = 0; i < familyCount(); ++i) {
const auto& cssFamily = familyAt(i);
if (isSystemFontString(cssFamily))
- result += systemFontCascadeList(*this, cssFamily, SystemFontDatabase::ClientUse::ForSystemUI, shouldAllowUserInstalledFonts()).size();
+ result += systemFontCascadeList(*this, cssFamily, SystemFontDatabaseCoreText::ClientUse::ForSystemUI, shouldAllowUserInstalledFonts()).size();
#if PLATFORM(IOS)
else if (isUIFontTextStyle(cssFamily))
- result += systemFontCascadeList(*this, cssFamily, SystemFontDatabase::ClientUse::ForTextStyle, shouldAllowUserInstalledFonts()).size();
+ result += systemFontCascadeList(*this, cssFamily, SystemFontDatabaseCoreText::ClientUse::ForTextStyle, shouldAllowUserInstalledFonts()).size();
#endif
else
++result;
@@ -327,7 +116,7 @@
for (unsigned i = 0; i < familyCount(); ++i) {
const auto& cssFamily = familyAt(i);
if (isSystemFontString(cssFamily)) {
- auto cascadeList = systemFontCascadeList(*this, cssFamily, SystemFontDatabase::ClientUse::ForSystemUI, shouldAllowUserInstalledFonts());
+ auto cascadeList = systemFontCascadeList(*this, cssFamily, SystemFontDatabaseCoreText::ClientUse::ForSystemUI, shouldAllowUserInstalledFonts());
if (index < cascadeList.size())
return FontFamilySpecification(cascadeList[index].get());
index -= cascadeList.size();
@@ -334,7 +123,7 @@
}
#if PLATFORM(IOS)
else if (isUIFontTextStyle(cssFamily)) {
- auto cascadeList = systemFontCascadeList(*this, cssFamily, SystemFontDatabase::ClientUse::ForTextStyle, shouldAllowUserInstalledFonts());
+ auto cascadeList = systemFontCascadeList(*this, cssFamily, SystemFontDatabaseCoreText::ClientUse::ForTextStyle, shouldAllowUserInstalledFonts());
if (index < cascadeList.size())
return FontFamilySpecification(cascadeList[index].get());
index -= cascadeList.size();
Added: trunk/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp (0 => 236938)
--- trunk/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp (rev 0)
+++ trunk/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp 2018-10-08 20:37:26 UTC (rev 236938)
@@ -0,0 +1,177 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "SystemFontDatabaseCoreText.h"
+
+#if USE_PLATFORM_SYSTEM_FALLBACK_LIST
+
+#include "FontCache.h"
+#include "FontCascadeDescription.h"
+
+#if PLATFORM(IOS)
+#include "RenderThemeIOS.h"
+#endif
+
+namespace WebCore {
+
+SystemFontDatabaseCoreText& SystemFontDatabaseCoreText::singleton()
+{
+ static NeverDestroyed<SystemFontDatabaseCoreText> database = SystemFontDatabaseCoreText();
+ return database.get();
+}
+
+SystemFontDatabaseCoreText::SystemFontDatabaseCoreText()
+{
+}
+
+Vector<RetainPtr<CTFontDescriptorRef>> SystemFontDatabaseCoreText::cascadeList(const CascadeListParameters& parameters, ClientUse clientUse)
+{
+ ASSERT(!parameters.fontName.isNull());
+ return m_systemFontCache.ensure(parameters, [&] {
+ auto localeString = parameters.locale.string().createCFString();
+ RetainPtr<CTFontRef> systemFont;
+ if (clientUse == ClientUse::ForSystemUI) {
+ systemFont = adoptCF(CTFontCreateUIFontForLanguage(kCTFontUIFontSystem, parameters.size, localeString.get()));
+ ASSERT(systemFont);
+ // FIXME: Use applyWeightItalicsAndFallbackBehavior() in both cases once <rdar://problem/33046041> is fixed.
+ systemFont = applyWeightItalicsAndFallbackBehavior(systemFont.get(), parameters.weight, parameters.italic, parameters.size, parameters.allowUserInstalledFonts);
+ } else {
+#if PLATFORM(IOS)
+ ASSERT(clientUse == ClientUse::ForTextStyle);
+ auto fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(parameters.fontName.string().createCFString().get(), RenderThemeIOS::contentSizeCategory(), nullptr));
+ CTFontSymbolicTraits traits = (parameters.weight >= kCTFontWeightSemibold ? kCTFontTraitBold : 0) | (parameters.italic ? kCTFontTraitItalic : 0);
+ if (traits)
+ fontDescriptor = adoptCF(CTFontDescriptorCreateCopyWithSymbolicTraits(fontDescriptor.get(), traits, traits));
+ systemFont = createFontForInstalledFonts(fontDescriptor.get(), parameters.size, parameters.allowUserInstalledFonts);
+#else
+ ASSERT_NOT_REACHED();
+#endif
+ }
+ ASSERT(systemFont);
+ auto result = computeCascadeList(systemFont.get(), localeString.get());
+ ASSERT(!result.isEmpty());
+ return result;
+ }).iterator->value;
+}
+
+void SystemFontDatabaseCoreText::clear()
+{
+ m_systemFontCache.clear();
+}
+
+RetainPtr<CTFontRef> SystemFontDatabaseCoreText::applyWeightItalicsAndFallbackBehavior(CTFontRef font, CGFloat weight, bool italic, float size, AllowUserInstalledFonts allowUserInstalledFonts)
+{
+ auto weightNumber = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberCGFloatType, &weight));
+ const float systemFontItalicSlope = 0.07;
+ float italicsRawNumber = italic ? systemFontItalicSlope : 0;
+ auto italicsNumber = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberFloatType, &italicsRawNumber));
+ CFTypeRef traitsKeys[] = { kCTFontWeightTrait, kCTFontSlantTrait, kCTFontUIFontDesignTrait };
+ CFTypeRef traitsValues[] = { weightNumber.get(), italicsNumber.get(), kCFBooleanTrue };
+ auto traitsDictionary = adoptCF(CFDictionaryCreate(kCFAllocatorDefault, traitsKeys, traitsValues, WTF_ARRAY_LENGTH(traitsKeys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
+ auto attributes = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
+ CFDictionaryAddValue(attributes.get(), kCTFontTraitsAttribute, traitsDictionary.get());
+ addAttributesForInstalledFonts(attributes.get(), allowUserInstalledFonts);
+ auto modification = adoptCF(CTFontDescriptorCreateWithAttributes(attributes.get()));
+ return adoptCF(CTFontCreateCopyWithAttributes(font, size, nullptr, modification.get()));
+}
+
+RetainPtr<CTFontDescriptorRef> SystemFontDatabaseCoreText::removeCascadeList(CTFontDescriptorRef fontDescriptor)
+{
+ auto emptyArray = adoptCF(CFArrayCreate(kCFAllocatorDefault, nullptr, 0, &kCFTypeArrayCallBacks));
+ CFTypeRef fallbackDictionaryKeys[] = { kCTFontCascadeListAttribute };
+ CFTypeRef fallbackDictionaryValues[] = { emptyArray.get() };
+ auto fallbackDictionary = adoptCF(CFDictionaryCreate(kCFAllocatorDefault, fallbackDictionaryKeys, fallbackDictionaryValues, WTF_ARRAY_LENGTH(fallbackDictionaryKeys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
+ auto modifiedFontDescriptor = adoptCF(CTFontDescriptorCreateCopyWithAttributes(fontDescriptor, fallbackDictionary.get()));
+ return modifiedFontDescriptor;
+}
+
+Vector<RetainPtr<CTFontDescriptorRef>> SystemFontDatabaseCoreText::computeCascadeList(CTFontRef font, CFStringRef locale)
+{
+ CFTypeRef arrayValues[] = { locale };
+ auto localeArray = adoptCF(CFArrayCreate(kCFAllocatorDefault, arrayValues, WTF_ARRAY_LENGTH(arrayValues), &kCFTypeArrayCallBacks));
+ auto cascadeList = adoptCF(CTFontCopyDefaultCascadeListForLanguages(font, localeArray.get()));
+ Vector<RetainPtr<CTFontDescriptorRef>> result;
+ // WebKit handles the cascade list, and WebKit 2's IPC code doesn't know how to serialize Core Text's cascade list.
+ result.append(removeCascadeList(adoptCF(CTFontCopyFontDescriptor(font)).get()));
+ if (cascadeList) {
+ CFIndex arrayLength = CFArrayGetCount(cascadeList.get());
+ for (CFIndex i = 0; i < arrayLength; ++i)
+ result.append(static_cast<CTFontDescriptorRef>(CFArrayGetValueAtIndex(cascadeList.get(), i)));
+ }
+ return result;
+}
+
+SystemFontDatabaseCoreText::CascadeListParameters SystemFontDatabaseCoreText::systemFontParameters(const FontCascadeDescription& description, const AtomicString& familyName, ClientUse clientUse, AllowUserInstalledFonts allowUserInstalledFonts)
+{
+ CascadeListParameters result;
+ result.locale = description.locale();
+ result.size = description.computedSize();
+ result.italic = isItalic(description.italic());
+
+ auto weight = description.weight();
+ if (FontCache::singleton().shouldMockBoldSystemFontForAccessibility())
+ weight = weight + FontSelectionValue(200);
+
+ if (weight < FontSelectionValue(150))
+ result.weight = kCTFontWeightUltraLight;
+ else if (weight < FontSelectionValue(250))
+ result.weight = kCTFontWeightThin;
+ else if (weight < FontSelectionValue(350))
+ result.weight = kCTFontWeightLight;
+ else if (weight < FontSelectionValue(450))
+ result.weight = kCTFontWeightRegular;
+ else if (weight < FontSelectionValue(550))
+ result.weight = kCTFontWeightMedium;
+ else if (weight < FontSelectionValue(650))
+ result.weight = kCTFontWeightSemibold;
+ else if (weight < FontSelectionValue(750))
+ result.weight = kCTFontWeightBold;
+ else if (weight < FontSelectionValue(850))
+ result.weight = kCTFontWeightHeavy;
+ else
+ result.weight = kCTFontWeightBlack;
+
+ if (clientUse == ClientUse::ForSystemUI) {
+ static NeverDestroyed<AtomicString> systemUI = AtomicString("system-ui", AtomicString::ConstructFromLiteral);
+ result.fontName = systemUI.get();
+ } else {
+ ASSERT(clientUse == ClientUse::ForTextStyle);
+ result.fontName = familyName;
+ }
+
+ result.allowUserInstalledFonts = allowUserInstalledFonts;
+
+ return result;
+}
+
+Vector<RetainPtr<CTFontDescriptorRef>> SystemFontDatabaseCoreText::cascadeList(const FontCascadeDescription& description, const AtomicString& cssFamily, ClientUse clientUse, AllowUserInstalledFonts allowUserInstalledFonts)
+{
+ return cascadeList(systemFontParameters(description, cssFamily, clientUse, allowUserInstalledFonts), clientUse);
+}
+
+}
+
+#endif
Added: trunk/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.h (0 => 236938)
--- trunk/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.h (rev 0)
+++ trunk/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.h 2018-10-08 20:37:26 UTC (rev 236938)
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "FontCascadeDescription.h"
+#include <pal/spi/cocoa/CoreTextSPI.h>
+#include <wtf/HashMap.h>
+#include <wtf/HashTraits.h>
+#include <wtf/text/AtomicString.h>
+#include <wtf/text/AtomicStringHash.h>
+
+#if USE_PLATFORM_SYSTEM_FALLBACK_LIST
+
+namespace WebCore {
+
+class SystemFontDatabaseCoreText {
+public:
+ struct CascadeListParameters {
+ CascadeListParameters()
+ {
+ }
+
+ CascadeListParameters(WTF::HashTableDeletedValueType)
+ : fontName(WTF::HashTableDeletedValue)
+ {
+ }
+
+ bool isHashTableDeletedValue() const
+ {
+ return fontName.isHashTableDeletedValue();
+ }
+
+ bool operator==(const CascadeListParameters& other) const
+ {
+ return fontName == other.fontName
+ && locale == other.locale
+ && weight == other.weight
+ && size == other.size
+ && allowUserInstalledFonts == other.allowUserInstalledFonts
+ && italic == other.italic;
+ }
+
+ unsigned hash() const
+ {
+ IntegerHasher hasher;
+ ASSERT(!fontName.isNull());
+ hasher.add(locale.existingHash());
+ hasher.add(locale.isNull() ? 0 : locale.existingHash());
+ hasher.add(weight);
+ hasher.add(size);
+ hasher.add(static_cast<unsigned>(allowUserInstalledFonts));
+ hasher.add(italic);
+ return hasher.hash();
+ }
+
+ struct CascadeListParametersHash : WTF::PairHash<AtomicString, float> {
+ static unsigned hash(const CascadeListParameters& parameters)
+ {
+ return parameters.hash();
+ }
+ static bool equal(const CascadeListParameters& a, const CascadeListParameters& b)
+ {
+ return a == b;
+ }
+ static const bool safeToCompareToEmptyOrDeleted = true;
+ };
+
+ AtomicString fontName;
+ AtomicString locale;
+ CGFloat weight { 0 };
+ float size { 0 };
+ AllowUserInstalledFonts allowUserInstalledFonts { AllowUserInstalledFonts::No };
+ bool italic { false };
+ };
+
+ static SystemFontDatabaseCoreText& singleton();
+
+ enum class ClientUse { ForSystemUI, ForTextStyle };
+
+ Vector<RetainPtr<CTFontDescriptorRef>> cascadeList(const FontCascadeDescription&, const AtomicString& cssFamily, ClientUse, AllowUserInstalledFonts);
+ void clear();
+
+private:
+ SystemFontDatabaseCoreText();
+
+ Vector<RetainPtr<CTFontDescriptorRef>> cascadeList(const CascadeListParameters&, ClientUse);
+
+ static RetainPtr<CTFontRef> applyWeightItalicsAndFallbackBehavior(CTFontRef, CGFloat weight, bool italic, float size, AllowUserInstalledFonts);
+ static RetainPtr<CTFontDescriptorRef> removeCascadeList(CTFontDescriptorRef);
+ static Vector<RetainPtr<CTFontDescriptorRef>> computeCascadeList(CTFontRef, CFStringRef locale);
+ static CascadeListParameters systemFontParameters(const FontCascadeDescription&, const AtomicString& familyName, ClientUse, AllowUserInstalledFonts);
+
+ HashMap<CascadeListParameters, Vector<RetainPtr<CTFontDescriptorRef>>, CascadeListParameters::CascadeListParametersHash, SimpleClassHashTraits<CascadeListParameters>> m_systemFontCache;
+};
+
+}
+
+#endif