Changeset 248071 in webkit


Ignore:
Timestamp:
Jul 31, 2019 1:59:00 PM (5 years ago)
Author:
youenn@apple.com
Message:

Use CTFontCreateForCharactersWithLanguageAndOption if available instead of CTFontCreateForCharactersWithLanguage
https://bugs.webkit.org/show_bug.cgi?id=200241

Source/WebCore:

Reviewed by Myles C. Maxfield.

We can use CTFontCreateForCharactersWithLanguageAndOption instead of CTFontCreateForCharactersWithLanguage
as it allows setting more easily the fallback option.
This allows us to never fallback to user installed fonts.
In such a case, we no longer need to wrap the fonts to change the fallback option.
We also prewarm the fonts with the same SPI and use system fallback as the default value.

Covered by existing tests.

  • platform/graphics/cocoa/FontCacheCoreText.cpp:

(WebCore::preparePlatformFont):
(WebCore::lookupFallbackFont):
(WebCore::FontCache::systemFallbackForCharacters):
(WebCore::FontCache::prewarm):
(WebCore::fontFamiliesForPrewarming):

Source/WebCore/PAL:

Reviewed by Myles C. Maxfield.

Add new SPI.

  • pal/spi/cocoa/CoreTextSPI.h:

Source/WTF:

Reviewed by Myles C. Maxfield.

  • wtf/Platform.h: Add macro to enable/disable new SPI.

LayoutTests:

We update the tests to flush font caches as otherwise some debug asserts would be hit.
This is due to changing the user installed font runtime flag while browsing which is not a typical situation.

Reviewed by Myles C. Maxfield.

  • fast/text/user-installed-fonts/extended-character-with-user-font.html:
  • fast/text/user-installed-fonts/extended-character.html:
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r248046 r248071  
     12019-07-31  Youenn Fablet  <youenn@apple.com>
     2
     3        Use CTFontCreateForCharactersWithLanguageAndOption if available instead of CTFontCreateForCharactersWithLanguage
     4        https://bugs.webkit.org/show_bug.cgi?id=200241
     5
     6        We update the tests to flush font caches as otherwise some debug asserts would be hit.
     7        This is due to changing the user installed font runtime flag while browsing which is not a typical situation.
     8
     9        Reviewed by Myles C. Maxfield.
     10
     11        * fast/text/user-installed-fonts/extended-character-with-user-font.html:
     12        * fast/text/user-installed-fonts/extended-character.html:
     13
    1142019-07-31  Youenn Fablet  <youenn@apple.com>
    215
  • trunk/LayoutTests/fast/text/user-installed-fonts/extended-character-with-user-font.html

    r247566 r248071  
    66    <body>
    77        <script>
     8if (window.internals)
     9    internals.invalidateFontCache();
    810if (window.testRunner)
    911    testRunner.installFakeHelvetica("SingleExtendedCharacter");
  • trunk/LayoutTests/fast/text/user-installed-fonts/extended-character.html

    r247566 r248071  
    66    <body>
    77        <script>
    8 if (window.internals)
     8if (window.internals) {
     9    internals.invalidateFontCache();
    910    internals.settings.setShouldAllowUserInstalledFonts(false);
     11}
    1012if (window.testRunner)
    1113    testRunner.installFakeHelvetica("SingleExtendedCharacter");
  • trunk/Source/WTF/ChangeLog

    r248044 r248071  
     12019-07-31  Youenn Fablet  <youenn@apple.com>
     2
     3        Use CTFontCreateForCharactersWithLanguageAndOption if available instead of CTFontCreateForCharactersWithLanguage
     4        https://bugs.webkit.org/show_bug.cgi?id=200241
     5
     6        Reviewed by Myles C. Maxfield.
     7
     8        * wtf/Platform.h: Add macro to enable/disable new SPI.
     9
    1102019-07-31  Keith Rollin  <krollin@apple.com>
    211
  • trunk/Source/WTF/wtf/Platform.h

    r248018 r248071  
    15451545#endif
    15461546
     1547#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) || (PLATFORM(IOS_FAMILY) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 130000)
     1548#define HAVE_CTFONTCREATEFORCHARACTERSWITHLANGUAGEANDOPTION 1
     1549#endif
     1550
    15471551#if PLATFORM(IOS_FAMILY) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 130000
    15481552#define HAVE_ARKIT_QUICK_LOOK_PREVIEW_ITEM 1
  • trunk/Source/WebCore/ChangeLog

    r248053 r248071  
     12019-07-31  Youenn Fablet  <youenn@apple.com>
     2
     3        Use CTFontCreateForCharactersWithLanguageAndOption if available instead of CTFontCreateForCharactersWithLanguage
     4        https://bugs.webkit.org/show_bug.cgi?id=200241
     5
     6        Reviewed by Myles C. Maxfield.
     7
     8        We can use CTFontCreateForCharactersWithLanguageAndOption instead of CTFontCreateForCharactersWithLanguage
     9        as it allows setting more easily the fallback option.
     10        This allows us to never fallback to user installed fonts.
     11        In such a case, we no longer need to wrap the fonts to change the fallback option.
     12        We also prewarm the fonts with the same SPI and use system fallback as the default value.
     13
     14        Covered by existing tests.
     15
     16        * platform/graphics/cocoa/FontCacheCoreText.cpp:
     17        (WebCore::preparePlatformFont):
     18        (WebCore::lookupFallbackFont):
     19        (WebCore::FontCache::systemFallbackForCharacters):
     20        (WebCore::FontCache::prewarm):
     21        (WebCore::fontFamiliesForPrewarming):
     22
    1232019-07-31  Devin Rousso  <drousso@apple.com>
    224
  • trunk/Source/WebCore/PAL/ChangeLog

    r247841 r248071  
     12019-07-31  Youenn Fablet  <youenn@apple.com>
     2
     3        Use CTFontCreateForCharactersWithLanguageAndOption if available instead of CTFontCreateForCharactersWithLanguage
     4        https://bugs.webkit.org/show_bug.cgi?id=200241
     5
     6        Reviewed by Myles C. Maxfield.
     7
     8        Add new SPI.
     9
     10        * pal/spi/cocoa/CoreTextSPI.h:
     11
    1122019-07-25  Brent Fulgham  <bfulgham@apple.com>
    213
  • trunk/Source/WebCore/PAL/pal/spi/cocoa/CoreTextSPI.h

    r247674 r248071  
    133133CTFontRef CTFontCreateForCSS(CFStringRef name, uint16_t weight, CTFontSymbolicTraits, CGFloat size);
    134134CTFontRef CTFontCreateForCharactersWithLanguage(CTFontRef currentFont, const UTF16Char *characters, CFIndex length, CFStringRef language, CFIndex *coveredLength);
     135CTFontRef CTFontCreateForCharactersWithLanguageAndOption(CTFontRef currentFont, const UTF16Char *characters, CFIndex length, CFStringRef language, CTFontFallbackOption option, CFIndex *coveredLength);
    135136CTFontRef CTFontCopyPhysicalFont(CTFontRef);
    136137
  • trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp

    r247720 r248071  
    571571    bool fontFaceDoesntSpecifyFeatures = !fontFaceFeatures || fontFaceFeatures->isEmpty();
    572572    bool fontFaceDoesntSpecifyVariations = !fontFaceVariantSettings || fontFaceVariantSettings->isAllNormal();
    573     if (noFontFeatureSettings && noFontVariationSettings && textRenderingModeIsAuto && variantSettingsIsNormal && dontNeedToApplyOpticalSizing && fontFaceDoesntSpecifyFeatures && fontFaceDoesntSpecifyVariations)
     573    if (noFontFeatureSettings && noFontVariationSettings && textRenderingModeIsAuto && variantSettingsIsNormal && dontNeedToApplyOpticalSizing && fontFaceDoesntSpecifyFeatures && fontFaceDoesntSpecifyVariations) {
     574#if HAVE(CTFONTCREATEFORCHARACTERSWITHLANGUAGEANDOPTION)
     575        return originalFont;
     576#else
    574577        return createFontForInstalledFonts(originalFont, fontDescription.shouldAllowUserInstalledFonts());
     578#endif
     579    }
    575580
    576581    // This algorithm is described at http://www.w3.org/TR/css3-fonts/#feature-precedence
     
    884889            , capabilities(capabilitiesForFontDescriptor(fontDescriptor))
    885890        {
     891#if HAVE(CTFONTCREATEFORCHARACTERSWITHLANGUAGEANDOPTION)
     892            UNUSED_PARAM(allowUserInstalledFonts);
     893#else
    886894            if (allowUserInstalledFonts != AllowUserInstalledFonts::No)
    887895                return;
     
    889897            addAttributesForInstalledFonts(attributes.get(), allowUserInstalledFonts);
    890898            this->fontDescriptor = CTFontDescriptorCreateCopyWithAttributes(fontDescriptor, attributes.get());
     899#endif
    891900        }
    892901
     
    13911400#endif
    13921401
    1393 static RetainPtr<CTFontRef> lookupFallbackFont(CTFontRef font, FontSelectionValue fontWeight, const AtomString& locale, const UChar* characters, unsigned length)
     1402#if !ASSERT_DISABLED
     1403static inline bool isUserInstalledFont(CTFontRef font)
     1404{
     1405#if HAVE(DISALLOWABLE_USER_INSTALLED_FONTS)
     1406    auto isUserInstalledFont = adoptCF(static_cast<CFBooleanRef>(CTFontCopyAttribute(font, kCTFontUserInstalledAttribute)));
     1407    return isUserInstalledFont && CFBooleanGetValue(isUserInstalledFont.get());
     1408#else
     1409    UNUSED_PARAM(font);
     1410    return false;
     1411#endif
     1412}
     1413#endif
     1414
     1415#if !USE(PLATFORM_SYSTEM_FALLBACK_LIST) && (PLATFORM(MAC) || (PLATFORM(IOS_FAMILY) && TARGET_OS_IOS))
     1416static RetainPtr<CTFontRef> createFontForCharacters(CTFontRef font, CFStringRef localeString, AllowUserInstalledFonts, const UChar* characters, unsigned length)
     1417{
     1418    CFIndex coveredLength = 0;
     1419    return adoptCF(CTFontCreatePhysicalFontForCharactersWithLanguage(font, characters, length, localeString, &coveredLength));
     1420}
     1421#elif HAVE(CTFONTCREATEFORCHARACTERSWITHLANGUAGEANDOPTION)
     1422static RetainPtr<CTFontRef> createFontForCharacters(CTFontRef font, CFStringRef localeString, AllowUserInstalledFonts allowUserInstalledFonts, const UChar* characters, unsigned length)
     1423{
     1424    CFIndex coveredLength = 0;
     1425    auto fallbackOption = allowUserInstalledFonts == AllowUserInstalledFonts::No ? kCTFontFallbackOptionSystem : kCTFontFallbackOptionDefault;
     1426    return adoptCF(CTFontCreateForCharactersWithLanguageAndOption(font, characters, length, localeString, fallbackOption, &coveredLength));
     1427}
     1428#else
     1429static RetainPtr<CTFontRef> createFontForCharacters(CTFontRef font, CFStringRef localeString, AllowUserInstalledFonts, const UChar* characters, unsigned length)
     1430{
     1431    CFIndex coveredLength = 0;
     1432    return adoptCF(CTFontCreateForCharactersWithLanguage(font, characters, length, localeString, &coveredLength));
     1433}
     1434#endif
     1435
     1436static RetainPtr<CTFontRef> lookupFallbackFont(CTFontRef font, FontSelectionValue fontWeight, const AtomString& locale, AllowUserInstalledFonts allowUserInstalledFonts, const UChar* characters, unsigned length)
    13941437{
    13951438    ASSERT(length > 0);
     
    14031446#endif
    14041447
    1405     CFIndex coveredLength = 0;
    1406     RetainPtr<CTFontRef> result;
    1407 #if !USE(PLATFORM_SYSTEM_FALLBACK_LIST) && (PLATFORM(MAC) || (PLATFORM(IOS_FAMILY) && TARGET_OS_IOS))
    1408     result = adoptCF(CTFontCreatePhysicalFontForCharactersWithLanguage(font, characters, length, localeString.get(), &coveredLength));
    1409 #else
    1410     result = adoptCF(CTFontCreateForCharactersWithLanguage(font, characters, length, localeString.get(), &coveredLength));
    1411 #endif
     1448    auto result = createFontForCharacters(font, localeString.get(), allowUserInstalledFonts, characters, length);
     1449    ASSERT(!isUserInstalledFont(result.get()) || allowUserInstalledFonts == AllowUserInstalledFonts::Yes);
    14121450
    14131451#if PLATFORM(IOS_FAMILY)
     
    14501488        m_fontNamesRequiringSystemFallbackForPrewarming.add(fullName);
    14511489
    1452     auto result = lookupFallbackFont(platformData.font(), description.weight(), description.locale(), characters, length);
     1490    auto result = lookupFallbackFont(platformData.font(), description.weight(), description.locale(), description.shouldAllowUserInstalledFonts(), characters, length);
    14531491    result = preparePlatformFont(result.get(), description, nullptr, nullptr, { });
    14541492
     
    16491687                CFIndex coveredLength = 0;
    16501688                UChar character = ' ';
     1689
     1690#if HAVE(CTFONTCREATEFORCHARACTERSWITHLANGUAGEANDOPTION)
     1691                auto fallbackWarmingFont = adoptCF(CTFontCreateForCharactersWithLanguageAndOption(warmingFont.get(), &character, 1, nullptr, kCTFontFallbackOptionSystem, &coveredLength));
     1692#else
    16511693                auto fallbackWarmingFont = adoptCF(CTFontCreateForCharactersWithLanguage(warmingFont.get(), &character, 1, nullptr, &coveredLength));
     1694#endif
    16521695            }
    16531696        }
Note: See TracChangeset for help on using the changeset viewer.