Changeset 226352 in webkit


Ignore:
Timestamp:
Jan 2, 2018 8:16:06 PM (6 years ago)
Author:
Joseph Pecoraro
Message:

Web Inspector: Slow open time enumerating system fonts (FontCache::systemFontFamilies)
https://bugs.webkit.org/show_bug.cgi?id=180979
<rdar://problem/36146670>

Reviewed by Matt Baker.

Source/WebCore:

  • platform/graphics/cocoa/FontCacheCoreText.cpp:

(WebCore::FontCache::systemFontFamilies):
Switch to the original Mac algorithm before r180979 that uses
CTFontManagerCopyAvailableFontFamilyNames. Previously this wasn't
available on iOS but now it is. This is a performance improvement on
both platforms, but significantly so on macOS. It also finds more,
valid, family names.

LayoutTests:

  • inspector/css/get-system-fonts.html:

Cleanup the test a bit.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r226346 r226352  
     12018-01-02  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        Web Inspector: Slow open time enumerating system fonts (FontCache::systemFontFamilies)
     4        https://bugs.webkit.org/show_bug.cgi?id=180979
     5        <rdar://problem/36146670>
     6
     7        Reviewed by Matt Baker.
     8
     9        * inspector/css/get-system-fonts.html:
     10        Cleanup the test a bit.
     11
    1122018-01-02  Michael Catanzaro  <mcatanzaro@igalia.com>
    213
  • trunk/LayoutTests/inspector/css/get-system-fonts.html

    r210062 r226352  
    2929</head>
    3030<body onload="runTest()">
    31   <p>This test ensures that the inspector can enumerate system font families, and checks for the
    32      existence of common fonts.</p>
     31<p>This test ensures that the inspector can enumerate system font families, and checks for the existence of common fonts.</p>
    3332</body>
    3433</html>
  • trunk/Source/WebCore/ChangeLog

    r226350 r226352  
     12018-01-02  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        Web Inspector: Slow open time enumerating system fonts (FontCache::systemFontFamilies)
     4        https://bugs.webkit.org/show_bug.cgi?id=180979
     5        <rdar://problem/36146670>
     6
     7        Reviewed by Matt Baker.
     8
     9        * platform/graphics/cocoa/FontCacheCoreText.cpp:
     10        (WebCore::FontCache::systemFontFamilies):
     11        Switch to the original Mac algorithm before r180979 that uses
     12        CTFontManagerCopyAvailableFontFamilyNames. Previously this wasn't
     13        available on iOS but now it is. This is a performance improvement on
     14        both platforms, but significantly so on macOS. It also finds more,
     15        valid, family names.
     16
    1172018-01-02  Yusuke Suzuki  <utatane.tea@gmail.com>
    218
  • trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp

    r226191 r226352  
    414414}
    415415
     416static inline bool fontNameIsSystemFont(CFStringRef fontName)
     417{
     418    return CFStringGetLength(fontName) > 0 && CFStringGetCharacterAtIndex(fontName, 0) == '.';
     419}
     420
    416421static inline bool fontIsSystemFont(CTFontRef font)
    417422{
    418423    if (CTFontDescriptorIsSystemUIFont(adoptCF(CTFontCopyFontDescriptor(font)).get()))
    419424        return true;
     425
    420426    auto name = adoptCF(CTFontCopyPostScriptName(font));
    421     return CFStringGetLength(name.get()) > 0 && CFStringGetCharacterAtIndex(name.get(), 0) == '.';
     427    return fontNameIsSystemFont(name.get());
    422428}
    423429
     
    732738Vector<String> FontCache::systemFontFamilies()
    733739{
    734     // FIXME: <rdar://problem/21890188>
    735     auto attributes = adoptCF(CFDictionaryCreate(kCFAllocatorDefault, nullptr, nullptr, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
    736     auto emptyFontDescriptor = adoptCF(CTFontDescriptorCreateWithAttributes(attributes.get()));
    737     auto matchedDescriptors = adoptCF(CTFontDescriptorCreateMatchingFontDescriptors(emptyFontDescriptor.get(), nullptr));
    738     if (!matchedDescriptors)
    739         return { };
    740 
    741     CFIndex numMatches = CFArrayGetCount(matchedDescriptors.get());
    742     if (!numMatches)
    743         return { };
    744 
    745     HashSet<String> visited;
    746     for (CFIndex i = 0; i < numMatches; ++i) {
    747         auto fontDescriptor = static_cast<CTFontDescriptorRef>(CFArrayGetValueAtIndex(matchedDescriptors.get(), i));
    748         if (auto familyName = adoptCF(static_cast<CFStringRef>(CTFontDescriptorCopyAttribute(fontDescriptor, kCTFontFamilyNameAttribute))))
    749             visited.add(familyName.get());
    750     }
    751 
    752     return copyToVector(visited);
     740    Vector<String> fontFamilies;
     741
     742    auto availableFontFamilies = adoptCF(CTFontManagerCopyAvailableFontFamilyNames());
     743    CFIndex count = CFArrayGetCount(availableFontFamilies.get());
     744    for (CFIndex i = 0; i < count; ++i) {
     745        CFStringRef fontName = static_cast<CFStringRef>(CFArrayGetValueAtIndex(availableFontFamilies.get(), i));
     746        if (CFGetTypeID(fontName) != CFStringGetTypeID()) {
     747            ASSERT_NOT_REACHED();
     748            continue;
     749        }
     750
     751        if (fontNameIsSystemFont(fontName))
     752            continue;
     753
     754        fontFamilies.append(fontName);
     755    }
     756
     757    return fontFamilies;
    753758}
    754759
Note: See TracChangeset for help on using the changeset viewer.