Title: [228044] trunk/Source/WebCore
Revision
228044
Author
mmaxfi...@apple.com
Date
2018-02-02 20:22:04 -0800 (Fri, 02 Feb 2018)

Log Message

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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (228043 => 228044)


--- trunk/Source/WebCore/ChangeLog	2018-02-03 02:14:32 UTC (rev 228043)
+++ trunk/Source/WebCore/ChangeLog	2018-02-03 04:22:04 UTC (rev 228044)
@@ -1,3 +1,32 @@
+2018-02-02  Myles C. Maxfield  <mmaxfi...@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.suz...@sony.com>
 
         Fix build error after r 227457 with VIDEO and WEB_AUDIO disabled

Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp (228043 => 228044)


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp	2018-02-03 02:14:32 UTC (rev 228043)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp	2018-02-03 04:22:04 UTC (rev 228044)
@@ -891,9 +891,9 @@
             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 @@
             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 @@
     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,10 +1428,24 @@
 #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) {
         CFTypeRef mandatoryAttributesValues[] = { kCTFontFamilyNameAttribute, kCTFontPostScriptNameAttribute, kCTFontEnabledAttribute, kCTFontUserInstalledAttribute, kCTFontFallbackOptionAttribute };
         return adoptCF(CFSetCreate(kCFAllocatorDefault, mandatoryAttributesValues, WTF_ARRAY_LENGTH(mandatoryAttributesValues), &kCFTypeSetCallBacks));
     }
@@ -1441,4 +1455,18 @@
     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);
 }
+
+}

Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.h (228043 => 228044)


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.h	2018-02-03 02:14:32 UTC (rev 228043)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.h	2018-02-03 04:22:04 UTC (rev 228044)
@@ -56,7 +56,8 @@
 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);
 
 }

Modified: trunk/Source/WebCore/platform/graphics/ios/FontCacheIOS.mm (228043 => 228044)


--- trunk/Source/WebCore/platform/graphics/ios/FontCacheIOS.mm	2018-02-03 02:14:32 UTC (rev 228043)
+++ trunk/Source/WebCore/platform/graphics/ios/FontCacheIOS.mm	2018-02-03 04:22:04 UTC (rev 228044)
@@ -75,11 +75,6 @@
     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;

Modified: trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm (228043 => 228044)


--- trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm	2018-02-03 02:14:32 UTC (rev 228043)
+++ trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm	2018-02-03 04:22:04 UTC (rev 228044)
@@ -126,20 +126,6 @@
     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

Modified: trunk/Source/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp (228043 => 228044)


--- trunk/Source/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp	2018-02-03 02:14:32 UTC (rev 228043)
+++ trunk/Source/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp	2018-02-03 04:22:04 UTC (rev 228044)
@@ -38,16 +38,14 @@
 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());
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to