Unreviewed, rolling out r226352.
authorryanhaddad@apple.com <ryanhaddad@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Jan 2018 17:05:12 +0000 (17:05 +0000)
committerryanhaddad@apple.com <ryanhaddad@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Jan 2018 17:05:12 +0000 (17:05 +0000)
Breaks Sierra and El Capitan builds.

Reverted changeset:

"Web Inspector: Slow open time enumerating system fonts
(FontCache::systemFontFamilies)"
https://bugs.webkit.org/show_bug.cgi?id=180979
https://trac.webkit.org/changeset/226352

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

LayoutTests/ChangeLog
LayoutTests/inspector/css/get-system-fonts.html
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp

index b44d5b0..191397c 100644 (file)
@@ -1,3 +1,16 @@
+2018-01-03  Ryan Haddad  <ryanhaddad@apple.com>
+
+        Unreviewed, rolling out r226352.
+
+        Breaks Sierra and El Capitan builds.
+
+        Reverted changeset:
+
+        "Web Inspector: Slow open time enumerating system fonts
+        (FontCache::systemFontFamilies)"
+        https://bugs.webkit.org/show_bug.cgi?id=180979
+        https://trac.webkit.org/changeset/226352
+
 2018-01-03  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] Crash destroying WebCore::FileMonitor
index 3f51b21..75e9c15 100644 (file)
@@ -28,6 +28,7 @@ function test() {
 </script>
 </head>
 <body onload="runTest()">
-<p>This test ensures that the inspector can enumerate system font families, and checks for the existence of common fonts.</p>
+  <p>This test ensures that the inspector can enumerate system font families, and checks for the
+     existence of common fonts.</p>
 </body>
 </html>
index 48f0ba2..fd6aa6a 100644 (file)
@@ -1,3 +1,16 @@
+2018-01-03  Ryan Haddad  <ryanhaddad@apple.com>
+
+        Unreviewed, rolling out r226352.
+
+        Breaks Sierra and El Capitan builds.
+
+        Reverted changeset:
+
+        "Web Inspector: Slow open time enumerating system fonts
+        (FontCache::systemFontFamilies)"
+        https://bugs.webkit.org/show_bug.cgi?id=180979
+        https://trac.webkit.org/changeset/226352
+
 2018-01-03  Philippe Normand  <pnormand@igalia.com>
 
         [GStreamer] The bus synchronous handler should be in the base player class
index 860dac6..38e5083 100644 (file)
@@ -413,18 +413,12 @@ static VariationDefaultsMap defaultVariationValues(CTFontRef font)
     return result;
 }
 
-static inline bool fontNameIsSystemFont(CFStringRef fontName)
-{
-    return CFStringGetLength(fontName) > 0 && CFStringGetCharacterAtIndex(fontName, 0) == '.';
-}
-
 static inline bool fontIsSystemFont(CTFontRef font)
 {
     if (CTFontDescriptorIsSystemUIFont(adoptCF(CTFontCopyFontDescriptor(font)).get()))
         return true;
-
     auto name = adoptCF(CTFontCopyPostScriptName(font));
-    return fontNameIsSystemFont(name.get());
+    return CFStringGetLength(name.get()) > 0 && CFStringGetCharacterAtIndex(name.get(), 0) == '.';
 }
 
 // These values were calculated by performing a linear regression on the CSS weights/widths/slopes and Core Text weights/widths/slopes of San Francisco.
@@ -737,24 +731,25 @@ void FontCache::platformInit()
 
 Vector<String> FontCache::systemFontFamilies()
 {
-    Vector<String> fontFamilies;
-
-    auto availableFontFamilies = adoptCF(CTFontManagerCopyAvailableFontFamilyNames());
-    CFIndex count = CFArrayGetCount(availableFontFamilies.get());
-    for (CFIndex i = 0; i < count; ++i) {
-        CFStringRef fontName = static_cast<CFStringRef>(CFArrayGetValueAtIndex(availableFontFamilies.get(), i));
-        if (CFGetTypeID(fontName) != CFStringGetTypeID()) {
-            ASSERT_NOT_REACHED();
-            continue;
-        }
+    // FIXME: <rdar://problem/21890188>
+    auto attributes = adoptCF(CFDictionaryCreate(kCFAllocatorDefault, nullptr, nullptr, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
+    auto emptyFontDescriptor = adoptCF(CTFontDescriptorCreateWithAttributes(attributes.get()));
+    auto matchedDescriptors = adoptCF(CTFontDescriptorCreateMatchingFontDescriptors(emptyFontDescriptor.get(), nullptr));
+    if (!matchedDescriptors)
+        return { };
 
-        if (fontNameIsSystemFont(fontName))
-            continue;
+    CFIndex numMatches = CFArrayGetCount(matchedDescriptors.get());
+    if (!numMatches)
+        return { };
 
-        fontFamilies.append(fontName);
+    HashSet<String> visited;
+    for (CFIndex i = 0; i < numMatches; ++i) {
+        auto fontDescriptor = static_cast<CTFontDescriptorRef>(CFArrayGetValueAtIndex(matchedDescriptors.get(), i));
+        if (auto familyName = adoptCF(static_cast<CFStringRef>(CTFontDescriptorCopyAttribute(fontDescriptor, kCTFontFamilyNameAttribute))))
+            visited.add(familyName.get());
     }
 
-    return fontFamilies;
+    return copyToVector(visited);
 }
 
 static CTFontSymbolicTraits computeTraits(const FontDescription& fontDescription)