Changeset 228044 in webkit


Ignore:
Timestamp:
Feb 2, 2018 8:22:04 PM (6 years ago)
Author:
mmaxfield@apple.com
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):

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r228043 r228044  
     12018-02-02  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        Test fix after r227995
     4        https://bugs.webkit.org/show_bug.cgi?id=180951
     5
     6        Unreviewed.
     7
     8        Webfonts shouldn't be run through CTFontDescriptorCreateMatchingFontDescriptor().
     9        Also, unify macOS's and iOS's implementation of FontCache::lastResortFallbackFont().
     10
     11        Covered by existing tests.
     12
     13        * platform/graphics/cocoa/FontCacheCoreText.cpp:
     14        (WebCore::FontDatabase::collectionForFamily):
     15        (WebCore::FontDatabase::fontForPostScriptName):
     16        (WebCore::addAttributesForInstalledFonts):
     17        (WebCore::addAttributesForWebFonts):
     18        (WebCore::installedFontMandatoryAttributes):
     19        (WebCore::FontCache::lastResortFallbackFont):
     20        (WebCore::addAttributesForUserInstalledFonts): Deleted.
     21        (WebCore::mandatoryAttributesForUserInstalledFonts): Deleted.
     22        * platform/graphics/cocoa/FontCacheCoreText.h:
     23        * platform/graphics/ios/FontCacheIOS.mm:
     24        (WebCore::FontCache::lastResortFallbackFont): Deleted.
     25        * platform/graphics/mac/FontCacheMac.mm:
     26        (WebCore::FontCache::lastResortFallbackFont): Deleted.
     27        * platform/graphics/mac/FontCustomPlatformData.cpp:
     28        (WebCore::FontCustomPlatformData::fontPlatformData):
     29
    1302018-02-02  Basuke Suzuki  <Basuke.Suzuki@sony.com>
    231
  • trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp

    r227995 r228044  
    892892            auto attributes = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
    893893            CFDictionaryAddValue(attributes.get(), kCTFontFamilyNameAttribute, familyNameString.get());
    894             addAttributesForUserInstalledFonts(attributes.get(), m_allowUserInstalledFonts);
     894            addAttributesForInstalledFonts(attributes.get(), m_allowUserInstalledFonts);
    895895            auto fontDescriptorToMatch = adoptCF(CTFontDescriptorCreateWithAttributes(attributes.get()));
    896             RetainPtr<CFSetRef> mandatoryAttributes = mandatoryAttributesForUserInstalledFonts(m_allowUserInstalledFonts);
     896            RetainPtr<CFSetRef> mandatoryAttributes = installedFontMandatoryAttributes(m_allowUserInstalledFonts);
    897897            if (auto matches = adoptCF(CTFontDescriptorCreateMatchingFontDescriptors(fontDescriptorToMatch.get(), mandatoryAttributes.get()))) {
    898898                auto count = CFArrayGetCount(matches.get());
     
    922922            CFDictionaryAddValue(attributes.get(), kCTFontEnabledAttribute, kCFBooleanTrue);
    923923            CFDictionaryAddValue(attributes.get(), nameAttribute, postScriptNameString.get());
    924             addAttributesForUserInstalledFonts(attributes.get(), m_allowUserInstalledFonts);
     924            addAttributesForInstalledFonts(attributes.get(), m_allowUserInstalledFonts);
    925925            auto fontDescriptorToMatch = adoptCF(CTFontDescriptorCreateWithAttributes(attributes.get()));
    926             RetainPtr<CFSetRef> mandatoryAttributes = mandatoryAttributesForUserInstalledFonts(m_allowUserInstalledFonts);
     926            RetainPtr<CFSetRef> mandatoryAttributes = installedFontMandatoryAttributes(m_allowUserInstalledFonts);
    927927            auto match = adoptCF(CTFontDescriptorCreateMatchingFontDescriptor(fontDescriptorToMatch.get(), mandatoryAttributes.get()));
    928928            return InstalledFont(match.get());
     
    14141414}
    14151415
    1416 void addAttributesForUserInstalledFonts(CFMutableDictionaryRef attributes, AllowUserInstalledFonts allowUserInstalledFonts)
     1416void addAttributesForInstalledFonts(CFMutableDictionaryRef attributes, AllowUserInstalledFonts allowUserInstalledFonts)
    14171417{
    14181418#if CAN_DISALLOW_USER_INSTALLED_FONTS
     
    14291429}
    14301430
    1431 RetainPtr<CFSetRef> mandatoryAttributesForUserInstalledFonts(AllowUserInstalledFonts allowUserInstalledFonts)
     1431void addAttributesForWebFonts(CFMutableDictionaryRef attributes, AllowUserInstalledFonts allowUserInstalledFonts)
     1432{
     1433#if CAN_DISALLOW_USER_INSTALLED_FONTS
     1434    if (allowUserInstalledFonts == AllowUserInstalledFonts::No) {
     1435        CTFontFallbackOption fallbackOption = kCTFontFallbackOptionSystem;
     1436        auto fallbackOptionNumber = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &fallbackOption));
     1437        CFDictionaryAddValue(attributes, kCTFontFallbackOptionAttribute, fallbackOptionNumber.get());
     1438    }
     1439#else
     1440    UNUSED_PARAM(attributes);
     1441    UNUSED_PARAM(allowUserInstalledFonts);
     1442#endif
     1443}
     1444
     1445RetainPtr<CFSetRef> installedFontMandatoryAttributes(AllowUserInstalledFonts allowUserInstalledFonts)
    14321446{
    14331447#if CAN_DISALLOW_USER_INSTALLED_FONTS
     
    14421456}
    14431457
    1444 }
     1458Ref<Font> FontCache::lastResortFallbackFont(const FontDescription& fontDescription)
     1459{
     1460    // FIXME: Would be even better to somehow get the user's default font here.  For now we'll pick
     1461    // the default that the user would get without changing any prefs.
     1462    if (RefPtr<Font> font = fontForFamily(fontDescription, AtomicString("Times", AtomicString::ConstructFromLiteral)))
     1463        return *font;
     1464
     1465    // The Times fallback will almost always work, but in the highly unusual case where
     1466    // the user doesn't have it, we fall back on Lucida Grande because that's
     1467    // guaranteed to be there, according to Nathan Taylor. This is good enough
     1468    // to avoid a crash at least.
     1469    return *fontForFamily(fontDescription, AtomicString("Lucida Grande", AtomicString::ConstructFromLiteral), nullptr, nullptr, { }, false);
     1470}
     1471
     1472}
  • trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.h

    r227776 r228044  
    5757bool requiresCustomFallbackFont(UChar32 character);
    5858FontSelectionCapabilities capabilitiesForFontDescriptor(CTFontDescriptorRef);
    59 void addAttributesForUserInstalledFonts(CFMutableDictionaryRef attributes, AllowUserInstalledFonts);
    60 RetainPtr<CFSetRef> mandatoryAttributesForUserInstalledFonts(AllowUserInstalledFonts);
     59void addAttributesForInstalledFonts(CFMutableDictionaryRef attributes, AllowUserInstalledFonts);
     60void addAttributesForWebFonts(CFMutableDictionaryRef attributes, AllowUserInstalledFonts);
     61RetainPtr<CFSetRef> installedFontMandatoryAttributes(AllowUserInstalledFonts);
    6162
    6263}
  • trunk/Source/WebCore/platform/graphics/ios/FontCacheIOS.mm

    r220506 r228044  
    7474        return nullptr;
    7575    return getCachedFontPlatformData(description, *family);
    76 }
    77 
    78 Ref<Font> FontCache::lastResortFallbackFont(const FontDescription& fontDescription)
    79 {
    80     return *fontForFamily(fontDescription, AtomicString(".PhoneFallback", AtomicString::ConstructFromLiteral));
    8176}
    8277
  • trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm

    r225087 r228044  
    127127}
    128128
    129 Ref<Font> FontCache::lastResortFallbackFont(const FontDescription& fontDescription)
    130 {
    131     // FIXME: Would be even better to somehow get the user's default font here.  For now we'll pick
    132     // the default that the user would get without changing any prefs.
    133     if (RefPtr<Font> font = fontForFamily(fontDescription, AtomicString("Times", AtomicString::ConstructFromLiteral)))
    134         return *font;
    135 
    136     // The Times fallback will almost always work, but in the highly unusual case where
    137     // the user doesn't have it, we fall back on Lucida Grande because that's
    138     // guaranteed to be there, according to Nathan Taylor. This is good enough
    139     // to avoid a crash at least.
    140     return *fontForFamily(fontDescription, AtomicString("Lucida Grande", AtomicString::ConstructFromLiteral), nullptr, nullptr, { }, false);
    141 }
    142 
    143129#endif // PLATFORM(MAC)
    144130
  • trunk/Source/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp

    r227776 r228044  
    3939{
    4040    auto attributes = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
    41     addAttributesForUserInstalledFonts(attributes.get(), fontDescription.shouldAllowUserInstalledFonts());
     41    addAttributesForWebFonts(attributes.get(), fontDescription.shouldAllowUserInstalledFonts());
    4242    auto modifiedFontDescriptor = adoptCF(CTFontDescriptorCreateCopyWithAttributes(m_fontDescriptor.get(), attributes.get()));
    43     RetainPtr<CFSetRef> mandatoryAttributes = mandatoryAttributesForUserInstalledFonts(fontDescription.shouldAllowUserInstalledFonts());
    44     auto matchingFontDescriptor = adoptCF(CTFontDescriptorCreateMatchingFontDescriptor(modifiedFontDescriptor.get(), mandatoryAttributes.get()));
    45     ASSERT(matchingFontDescriptor);
     43    ASSERT(modifiedFontDescriptor);
    4644
    4745    int size = fontDescription.computedPixelSize();
    4846    FontOrientation orientation = fontDescription.orientation();
    4947    FontWidthVariant widthVariant = fontDescription.widthVariant();
    50     RetainPtr<CTFontRef> font = adoptCF(CTFontCreateWithFontDescriptor(matchingFontDescriptor.get(), size, nullptr));
     48    RetainPtr<CTFontRef> font = adoptCF(CTFontCreateWithFontDescriptor(modifiedFontDescriptor.get(), size, nullptr));
    5149    font = preparePlatformFont(font.get(), fontDescription, &fontFaceFeatures, &fontFaceVariantSettings, fontFaceCapabilities, fontDescription.computedSize());
    5250    ASSERT(font);
Note: See TracChangeset for help on using the changeset viewer.