Test fix after r227995
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 3 Feb 2018 04:22:04 +0000 (04:22 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 3 Feb 2018 04:22:04 +0000 (04:22 +0000)
https://bugs.webkit.org/show_bug.cgi?id=180951

Unreviewed.

Webfonts shouldn't be run through CTFontDescriptorCreateMatchingFontDescriptor().
Also, unify macOS's and iOS's implementation of FontCache::lastResortFallbackFont().

Covered by existing tests.

* platform/graphics/cocoa/FontCacheCoreText.cpp:
(WebCore::FontDatabase::collectionForFamily):
(WebCore::FontDatabase::fontForPostScriptName):
(WebCore::addAttributesForInstalledFonts):
(WebCore::addAttributesForWebFonts):
(WebCore::installedFontMandatoryAttributes):
(WebCore::FontCache::lastResortFallbackFont):
(WebCore::addAttributesForUserInstalledFonts): Deleted.
(WebCore::mandatoryAttributesForUserInstalledFonts): Deleted.
* platform/graphics/cocoa/FontCacheCoreText.h:
* platform/graphics/ios/FontCacheIOS.mm:
(WebCore::FontCache::lastResortFallbackFont): Deleted.
* platform/graphics/mac/FontCacheMac.mm:
(WebCore::FontCache::lastResortFallbackFont): Deleted.
* platform/graphics/mac/FontCustomPlatformData.cpp:
(WebCore::FontCustomPlatformData::fontPlatformData):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@228044 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp
Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.h
Source/WebCore/platform/graphics/ios/FontCacheIOS.mm
Source/WebCore/platform/graphics/mac/FontCacheMac.mm
Source/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp

index b7e6ddb..b2232d9 100644 (file)
@@ -1,3 +1,32 @@
+2018-02-02  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Test fix after r227995
+        https://bugs.webkit.org/show_bug.cgi?id=180951
+
+        Unreviewed.
+
+        Webfonts shouldn't be run through CTFontDescriptorCreateMatchingFontDescriptor().
+        Also, unify macOS's and iOS's implementation of FontCache::lastResortFallbackFont().
+
+        Covered by existing tests.
+
+        * platform/graphics/cocoa/FontCacheCoreText.cpp:
+        (WebCore::FontDatabase::collectionForFamily):
+        (WebCore::FontDatabase::fontForPostScriptName):
+        (WebCore::addAttributesForInstalledFonts):
+        (WebCore::addAttributesForWebFonts):
+        (WebCore::installedFontMandatoryAttributes):
+        (WebCore::FontCache::lastResortFallbackFont):
+        (WebCore::addAttributesForUserInstalledFonts): Deleted.
+        (WebCore::mandatoryAttributesForUserInstalledFonts): Deleted.
+        * platform/graphics/cocoa/FontCacheCoreText.h:
+        * platform/graphics/ios/FontCacheIOS.mm:
+        (WebCore::FontCache::lastResortFallbackFont): Deleted.
+        * platform/graphics/mac/FontCacheMac.mm:
+        (WebCore::FontCache::lastResortFallbackFont): Deleted.
+        * platform/graphics/mac/FontCustomPlatformData.cpp:
+        (WebCore::FontCustomPlatformData::fontPlatformData):
+
 2018-02-02  Basuke Suzuki  <Basuke.Suzuki@sony.com>
 
         Fix build error after r 227457 with VIDEO and WEB_AUDIO disabled
index 225b097..cdf595d 100644 (file)
@@ -891,9 +891,9 @@ public:
             auto familyNameString = folded.createCFString();
             auto attributes = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
             CFDictionaryAddValue(attributes.get(), kCTFontFamilyNameAttribute, familyNameString.get());
-            addAttributesForUserInstalledFonts(attributes.get(), m_allowUserInstalledFonts);
+            addAttributesForInstalledFonts(attributes.get(), m_allowUserInstalledFonts);
             auto fontDescriptorToMatch = adoptCF(CTFontDescriptorCreateWithAttributes(attributes.get()));
-            RetainPtr<CFSetRef> mandatoryAttributes = mandatoryAttributesForUserInstalledFonts(m_allowUserInstalledFonts);
+            RetainPtr<CFSetRef> mandatoryAttributes = installedFontMandatoryAttributes(m_allowUserInstalledFonts);
             if (auto matches = adoptCF(CTFontDescriptorCreateMatchingFontDescriptors(fontDescriptorToMatch.get(), mandatoryAttributes.get()))) {
                 auto count = CFArrayGetCount(matches.get());
                 Vector<InstalledFont> result;
@@ -921,9 +921,9 @@ public:
             auto attributes = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
             CFDictionaryAddValue(attributes.get(), kCTFontEnabledAttribute, kCFBooleanTrue);
             CFDictionaryAddValue(attributes.get(), nameAttribute, postScriptNameString.get());
-            addAttributesForUserInstalledFonts(attributes.get(), m_allowUserInstalledFonts);
+            addAttributesForInstalledFonts(attributes.get(), m_allowUserInstalledFonts);
             auto fontDescriptorToMatch = adoptCF(CTFontDescriptorCreateWithAttributes(attributes.get()));
-            RetainPtr<CFSetRef> mandatoryAttributes = mandatoryAttributesForUserInstalledFonts(m_allowUserInstalledFonts);
+            RetainPtr<CFSetRef> mandatoryAttributes = installedFontMandatoryAttributes(m_allowUserInstalledFonts);
             auto match = adoptCF(CTFontDescriptorCreateMatchingFontDescriptor(fontDescriptorToMatch.get(), mandatoryAttributes.get()));
             return InstalledFont(match.get());
         }).iterator->value;
@@ -1413,7 +1413,7 @@ const AtomicString& FontCache::platformAlternateFamilyName(const AtomicString& f
     return nullAtom();
 }
 
-void addAttributesForUserInstalledFonts(CFMutableDictionaryRef attributes, AllowUserInstalledFonts allowUserInstalledFonts)
+void addAttributesForInstalledFonts(CFMutableDictionaryRef attributes, AllowUserInstalledFonts allowUserInstalledFonts)
 {
 #if CAN_DISALLOW_USER_INSTALLED_FONTS
     if (allowUserInstalledFonts == AllowUserInstalledFonts::No) {
@@ -1428,7 +1428,21 @@ void addAttributesForUserInstalledFonts(CFMutableDictionaryRef attributes, Allow
 #endif
 }
 
-RetainPtr<CFSetRef> mandatoryAttributesForUserInstalledFonts(AllowUserInstalledFonts allowUserInstalledFonts)
+void addAttributesForWebFonts(CFMutableDictionaryRef attributes, AllowUserInstalledFonts allowUserInstalledFonts)
+{
+#if CAN_DISALLOW_USER_INSTALLED_FONTS
+    if (allowUserInstalledFonts == AllowUserInstalledFonts::No) {
+        CTFontFallbackOption fallbackOption = kCTFontFallbackOptionSystem;
+        auto fallbackOptionNumber = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &fallbackOption));
+        CFDictionaryAddValue(attributes, kCTFontFallbackOptionAttribute, fallbackOptionNumber.get());
+    }
+#else
+    UNUSED_PARAM(attributes);
+    UNUSED_PARAM(allowUserInstalledFonts);
+#endif
+}
+
+RetainPtr<CFSetRef> installedFontMandatoryAttributes(AllowUserInstalledFonts allowUserInstalledFonts)
 {
 #if CAN_DISALLOW_USER_INSTALLED_FONTS
     if (allowUserInstalledFonts == AllowUserInstalledFonts::No) {
@@ -1441,4 +1455,18 @@ RetainPtr<CFSetRef> mandatoryAttributesForUserInstalledFonts(AllowUserInstalledF
     return nullptr;
 }
 
+Ref<Font> FontCache::lastResortFallbackFont(const FontDescription& fontDescription)
+{
+    // FIXME: Would be even better to somehow get the user's default font here.  For now we'll pick
+    // the default that the user would get without changing any prefs.
+    if (RefPtr<Font> font = fontForFamily(fontDescription, AtomicString("Times", AtomicString::ConstructFromLiteral)))
+        return *font;
+
+    // The Times fallback will almost always work, but in the highly unusual case where
+    // the user doesn't have it, we fall back on Lucida Grande because that's
+    // guaranteed to be there, according to Nathan Taylor. This is good enough
+    // to avoid a crash at least.
+    return *fontForFamily(fontDescription, AtomicString("Lucida Grande", AtomicString::ConstructFromLiteral), nullptr, nullptr, { }, false);
+}
+
 }
index 13da715..2b4b241 100644 (file)
@@ -56,7 +56,8 @@ RetainPtr<CTFontRef> platformFontWithFamilySpecialCase(const AtomicString& famil
 RetainPtr<CTFontRef> platformFontWithFamily(const AtomicString& family, FontSelectionRequest, TextRenderingMode, float size);
 bool requiresCustomFallbackFont(UChar32 character);
 FontSelectionCapabilities capabilitiesForFontDescriptor(CTFontDescriptorRef);
-void addAttributesForUserInstalledFonts(CFMutableDictionaryRef attributes, AllowUserInstalledFonts);
-RetainPtr<CFSetRef> mandatoryAttributesForUserInstalledFonts(AllowUserInstalledFonts);
+void addAttributesForInstalledFonts(CFMutableDictionaryRef attributes, AllowUserInstalledFonts);
+void addAttributesForWebFonts(CFMutableDictionaryRef attributes, AllowUserInstalledFonts);
+RetainPtr<CFSetRef> installedFontMandatoryAttributes(AllowUserInstalledFonts);
 
 }
index e93a02c..1a064f5 100644 (file)
@@ -75,11 +75,6 @@ FontPlatformData* FontCache::getCustomFallbackFont(const UInt32 c, const FontDes
     return getCachedFontPlatformData(description, *family);
 }
 
-Ref<Font> FontCache::lastResortFallbackFont(const FontDescription& fontDescription)
-{
-    return *fontForFamily(fontDescription, AtomicString(".PhoneFallback", AtomicString::ConstructFromLiteral));
-}
-
 static RetainPtr<CTFontDescriptorRef> baseSystemFontDescriptor(FontSelectionValue weight, bool bold, float size)
 {
     CTFontUIFontType fontType = kCTFontUIFontSystem;
index 9118d8e..230a973 100644 (file)
@@ -126,20 +126,6 @@ RetainPtr<CTFontRef> platformFontWithFamilySpecialCase(const AtomicString& famil
     return nullptr;
 }
 
-Ref<Font> FontCache::lastResortFallbackFont(const FontDescription& fontDescription)
-{
-    // FIXME: Would be even better to somehow get the user's default font here.  For now we'll pick
-    // the default that the user would get without changing any prefs.
-    if (RefPtr<Font> font = fontForFamily(fontDescription, AtomicString("Times", AtomicString::ConstructFromLiteral)))
-        return *font;
-
-    // The Times fallback will almost always work, but in the highly unusual case where
-    // the user doesn't have it, we fall back on Lucida Grande because that's
-    // guaranteed to be there, according to Nathan Taylor. This is good enough
-    // to avoid a crash at least.
-    return *fontForFamily(fontDescription, AtomicString("Lucida Grande", AtomicString::ConstructFromLiteral), nullptr, nullptr, { }, false);
-}
-
 #endif // PLATFORM(MAC)
 
 } // namespace WebCore
index 494b2b4..dc0afa3 100644 (file)
@@ -38,16 +38,14 @@ FontCustomPlatformData::~FontCustomPlatformData() = default;
 FontPlatformData FontCustomPlatformData::fontPlatformData(const FontDescription& fontDescription, bool bold, bool italic, const FontFeatureSettings& fontFaceFeatures, const FontVariantSettings& fontFaceVariantSettings, FontSelectionSpecifiedCapabilities fontFaceCapabilities)
 {
     auto attributes = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
-    addAttributesForUserInstalledFonts(attributes.get(), fontDescription.shouldAllowUserInstalledFonts());
+    addAttributesForWebFonts(attributes.get(), fontDescription.shouldAllowUserInstalledFonts());
     auto modifiedFontDescriptor = adoptCF(CTFontDescriptorCreateCopyWithAttributes(m_fontDescriptor.get(), attributes.get()));
-    RetainPtr<CFSetRef> mandatoryAttributes = mandatoryAttributesForUserInstalledFonts(fontDescription.shouldAllowUserInstalledFonts());
-    auto matchingFontDescriptor = adoptCF(CTFontDescriptorCreateMatchingFontDescriptor(modifiedFontDescriptor.get(), mandatoryAttributes.get()));
-    ASSERT(matchingFontDescriptor);
+    ASSERT(modifiedFontDescriptor);
 
     int size = fontDescription.computedPixelSize();
     FontOrientation orientation = fontDescription.orientation();
     FontWidthVariant widthVariant = fontDescription.widthVariant();
-    RetainPtr<CTFontRef> font = adoptCF(CTFontCreateWithFontDescriptor(matchingFontDescriptor.get(), size, nullptr));
+    RetainPtr<CTFontRef> font = adoptCF(CTFontCreateWithFontDescriptor(modifiedFontDescriptor.get(), size, nullptr));
     font = preparePlatformFont(font.get(), fontDescription, &fontFaceFeatures, &fontFaceVariantSettings, fontFaceCapabilities, fontDescription.computedSize());
     ASSERT(font);
     return FontPlatformData(font.get(), size, bold, italic, orientation, widthVariant, fontDescription.textRenderingMode());