Web Inspector: [iOS] Allow inspector to retrieve a list of system fonts
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 10 Aug 2015 20:51:32 +0000 (20:51 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 10 Aug 2015 20:51:32 +0000 (20:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=147033

Reviewed by Joseph Pecoraro.

Implement systemFontFamilies for iOS.

* platform/graphics/ios/FontCacheIOS.mm:
(WebCore::FontCache::systemFontFamilies):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/ios/FontCacheIOS.mm

index c03c430..d7a03f9 100644 (file)
@@ -1,5 +1,17 @@
 2015-08-10  Devin Rousso  <drousso@apple.com>
 
 2015-08-10  Devin Rousso  <drousso@apple.com>
 
+        Web Inspector: [iOS] Allow inspector to retrieve a list of system fonts
+        https://bugs.webkit.org/show_bug.cgi?id=147033
+
+        Reviewed by Joseph Pecoraro.
+
+        Implement systemFontFamilies for iOS.
+
+        * platform/graphics/ios/FontCacheIOS.mm:
+        (WebCore::FontCache::systemFontFamilies):
+
+2015-08-10  Devin Rousso  <drousso@apple.com>
+
         Web Inspector: Invalid selectors can be applied to the stylesheet
         https://bugs.webkit.org/show_bug.cgi?id=147230
 
         Web Inspector: Invalid selectors can be applied to the stylesheet
         https://bugs.webkit.org/show_bug.cgi?id=147230
 
index adbe2ed..0a8394a 100644 (file)
@@ -33,6 +33,7 @@
 #import "CoreTextSPI.h"
 #import "FontCascade.h"
 #import "RenderThemeIOS.h"
 #import "CoreTextSPI.h"
 #import "FontCascade.h"
 #import "RenderThemeIOS.h"
+#import <wtf/HashSet.h>
 #import <wtf/NeverDestroyed.h>
 #import <wtf/RetainPtr.h>
 #import <wtf/text/CString.h>
 #import <wtf/NeverDestroyed.h>
 #import <wtf/RetainPtr.h>
 #import <wtf/text/CString.h>
@@ -472,8 +473,25 @@ RefPtr<Font> FontCache::systemFallbackForCharacters(const FontDescription& descr
 
 Vector<String> FontCache::systemFontFamilies()
 {
 
 Vector<String> FontCache::systemFontFamilies()
 {
-    // FIXME: <https://webkit.org/b/147033> Web Inspector: [iOS] Allow inspector to retrieve a list of system fonts
+    // FIXME: <rdar://problem/21890188>
     Vector<String> fontFamilies;
     Vector<String> fontFamilies;
+    auto emptyFontDescriptor = adoptCF(CTFontDescriptorCreateWithAttributes((CFDictionaryRef) @{ }));
+    auto matchedDescriptors = adoptCF(CTFontDescriptorCreateMatchingFontDescriptors(emptyFontDescriptor.get(), nullptr));
+    if (!matchedDescriptors)
+        return fontFamilies;
+
+    CFIndex numMatches = CFArrayGetCount(matchedDescriptors.get());
+    if (!numMatches)
+        return fontFamilies;
+
+    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());
+    }
+
+    copyToVector(visited, fontFamilies);
     return fontFamilies;
 }
 
     return fontFamilies;
 }