Changeset 247566 in webkit


Ignore:
Timestamp:
Jul 18, 2019 11:34:29 AM (5 years ago)
Author:
youenn@apple.com
Message:

Make sure to set kCTFontFallbackOptionAttribute to kCTFontFallbackOptionSystem for system fonts
https://bugs.webkit.org/show_bug.cgi?id=199769
<rdar://problem/49390297>

Reviewed by Myles C. Maxfield.

Source/WebCore:

When getting a system font, set the appropriate attribute so that it
does not fallback to a user initiated font.
Add an ASSERT that checks that the font in use is not a user font if
policy is to not use user installed fonts.

Tests: fast/text/user-installed-fonts/extended-character-with-user-font.html

fast/text/user-installed-fonts/extended-character.html

  • platform/graphics/Font.h:
  • platform/graphics/FontCascadeFonts.cpp:

(WebCore::FontCascadeFonts::glyphDataForSystemFallback):

  • platform/graphics/cocoa/FontCacheCoreText.cpp:

(WebCore::preparePlatformFont):
(WebCore::FontDatabase::singletonAllowingUserInstalledFonts):
(WebCore::FontDatabase::singletonDisallowingUserInstalledFonts):
(WebCore::addAttributesForInstalledFonts):
(WebCore::addAttributesForWebFonts):
(WebCore::installedFontMandatoryAttributes):

  • platform/graphics/mac/SimpleFontDataCoreText.cpp:

(WebCore::Font::isUserInstalledFont const):

Source/WTF:

  • wtf/Platform.h:

Tools:

Add a font containing one extended character not found in system fonts.

  • WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj:
  • WebKitTestRunner/fonts/FakeHelvetica-SingleExtendedCharacter.ttf: Added.

LayoutTests:

Tests require WTR and recent MacOS, hence why they are disabled elsewhere.

  • TestExpectations:
  • platform/mac-wk2/TestExpectations:
  • fast/text/user-installed-fonts/extended-character-expected.html: Added.
  • fast/text/user-installed-fonts/extended-character-with-user-font-expected-mismatch.html: Added.
  • fast/text/user-installed-fonts/extended-character-with-user-font.html: Added.
  • fast/text/user-installed-fonts/extended-character.html: Added.
Location:
trunk
Files:
5 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r247564 r247566  
     12019-07-18  Youenn Fablet  <youenn@apple.com>
     2
     3        Make sure to set kCTFontFallbackOptionAttribute to kCTFontFallbackOptionSystem for system fonts
     4        https://bugs.webkit.org/show_bug.cgi?id=199769
     5        <rdar://problem/49390297>
     6
     7        Reviewed by Myles C. Maxfield.
     8
     9        Tests require WTR and recent MacOS, hence why they are disabled elsewhere.
     10
     11        * TestExpectations:
     12        * platform/mac-wk2/TestExpectations:
     13        * fast/text/user-installed-fonts/extended-character-expected.html: Added.
     14        * fast/text/user-installed-fonts/extended-character-with-user-font-expected-mismatch.html: Added.
     15        * fast/text/user-installed-fonts/extended-character-with-user-font.html: Added.
     16        * fast/text/user-installed-fonts/extended-character.html: Added.
     17
    1182019-07-18  Truitt Savell  <tsavell@apple.com>
    219
  • trunk/LayoutTests/TestExpectations

    r247528 r247566  
    16691669webkit.org/b/190626 imported/w3c/web-platform-tests/html/semantics/forms/the-datalist-element/datalistoptions.html [ Failure ]
    16701670webkit.org/b/190613 imported/blink/fast/forms/datalist/slider-appearance-with-ticks-crash.html [ Skip ]
     1671
     1672# Tests require WTR and disabling of user installed fonts. Reenabling them in supported platforms
     1673fast/text/user-installed-fonts/extended-character.html [ Skip ]
     1674fast/text/user-installed-fonts/extended-character-with-user-font.html [ Skip ]
    16711675
    16721676# Does timeout
  • trunk/LayoutTests/platform/mac-wk2/TestExpectations

    r247528 r247566  
    774774webkit.org/b/185994 fast/text/user-installed-fonts/shadow-postscript-family.html [ Pass ImageOnlyFailure ]
    775775
     776# Reenabled tests for supported platforms
     777[ Mojave+ ] fast/text/user-installed-fonts/extended-character.html [ Pass ]
     778[ Mojave+ ] fast/text/user-installed-fonts/extended-character-with-user-font.html [ Pass ]
     779
    776780# <rdar://problem/25010307>
    777781[ HighSierra+ ] http/tests/ssl/applepay/ApplePayError.html [ Pass ]
  • trunk/Source/WTF/ChangeLog

    r247542 r247566  
     12019-07-18  Youenn Fablet  <youenn@apple.com>
     2
     3        Make sure to set kCTFontFallbackOptionAttribute to kCTFontFallbackOptionSystem for system fonts
     4        https://bugs.webkit.org/show_bug.cgi?id=199769
     5        <rdar://problem/49390297>
     6
     7        Reviewed by Myles C. Maxfield.
     8
     9        * wtf/Platform.h:
     10
    1112019-07-17  Christopher Reid  <chris.reid@sony.com>
    212
  • trunk/Source/WTF/wtf/Platform.h

    r247482 r247566  
    15371537#endif
    15381538
     1539#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || PLATFORM(IOS_FAMILY)
     1540#define HAVE_DISALLOWABLE_USER_INSTALLED_FONTS 1
     1541#endif
     1542
    15391543#if PLATFORM(IOS_FAMILY) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 130000
    15401544#define HAVE_ARKIT_QUICK_LOOK_PREVIEW_ITEM 1
  • trunk/Source/WebCore/ChangeLog

    r247562 r247566  
     12019-07-18  Youenn Fablet  <youenn@apple.com>
     2
     3        Make sure to set kCTFontFallbackOptionAttribute to kCTFontFallbackOptionSystem for system fonts
     4        https://bugs.webkit.org/show_bug.cgi?id=199769
     5        <rdar://problem/49390297>
     6
     7        Reviewed by Myles C. Maxfield.
     8
     9        When getting a system font, set the appropriate attribute so that it
     10        does not fallback to a user initiated font.
     11        Add an ASSERT that checks that the font in use is not a user font if
     12        policy is to not use user installed fonts.
     13
     14        Tests: fast/text/user-installed-fonts/extended-character-with-user-font.html
     15               fast/text/user-installed-fonts/extended-character.html
     16
     17        * platform/graphics/Font.h:
     18        * platform/graphics/FontCascadeFonts.cpp:
     19        (WebCore::FontCascadeFonts::glyphDataForSystemFallback):
     20        * platform/graphics/cocoa/FontCacheCoreText.cpp:
     21        (WebCore::preparePlatformFont):
     22        (WebCore::FontDatabase::singletonAllowingUserInstalledFonts):
     23        (WebCore::FontDatabase::singletonDisallowingUserInstalledFonts):
     24        (WebCore::addAttributesForInstalledFonts):
     25        (WebCore::addAttributesForWebFonts):
     26        (WebCore::installedFontMandatoryAttributes):
     27        * platform/graphics/mac/SimpleFontDataCoreText.cpp:
     28        (WebCore::Font::isUserInstalledFont const):
     29
    1302019-07-18  Zalan Bujtas  <zalan@apple.com>
    231
  • trunk/Source/WebCore/platform/graphics/Font.h

    r245393 r247566  
    205205#endif
    206206
     207#if HAVE(DISALLOWABLE_USER_INSTALLED_FONTS)
     208    bool isUserInstalledFont() const;
     209#endif
     210
    207211    bool canRenderCombiningCharacterSequence(const UChar*, size_t) const;
    208212    bool applyTransforms(GlyphBufferGlyph*, GlyphBufferAdvance*, size_t glyphCount, bool enableKerning, bool requiresShaping) const;
  • trunk/Source/WebCore/platform/graphics/FontCascadeFonts.cpp

    r246490 r247566  
    350350        return GlyphData();
    351351
     352#if HAVE(DISALLOWABLE_USER_INSTALLED_FONTS)
     353    ASSERT(!systemFallbackFont->isUserInstalledFont() || description.shouldAllowUserInstalledFonts() == AllowUserInstalledFonts::Yes);
     354#endif
     355
    352356    if (systemFallbackShouldBeInvisible)
    353357        systemFallbackFont = const_cast<Font*>(&systemFallbackFont->invisibleFont());
  • trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp

    r247498 r247566  
    4141
    4242#define HAS_CORE_TEXT_WIDTH_ATTRIBUTE ((PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || (PLATFORM(IOS_FAMILY) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000))
    43 #define CAN_DISALLOW_USER_INSTALLED_FONTS ((PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || (PLATFORM(IOS_FAMILY) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000))
    4443
    4544namespace WebCore {
     
    573572    bool fontFaceDoesntSpecifyVariations = !fontFaceVariantSettings || fontFaceVariantSettings->isAllNormal();
    574573    if (noFontFeatureSettings && noFontVariationSettings && textRenderingModeIsAuto && variantSettingsIsNormal && dontNeedToApplyOpticalSizing && fontFaceDoesntSpecifyFeatures && fontFaceDoesntSpecifyVariations)
    575         return originalFont;
     574        return createFontForInstalledFonts(originalFont, fontDescription.shouldAllowUserInstalledFonts());
    576575
    577576    // This algorithm is described at http://www.w3.org/TR/css3-fonts/#feature-precedence
     
    688687    }
    689688
     689    addAttributesForInstalledFonts(attributes.get(), fontDescription.shouldAllowUserInstalledFonts());
     690
    690691    auto descriptor = adoptCF(CTFontDescriptorCreateWithAttributes(attributes.get()));
    691     auto result = adoptCF(CTFontCreateCopyWithAttributes(originalFont, CTFontGetSize(originalFont), nullptr, descriptor.get()));
    692     return result;
     692    return adoptCF(CTFontCreateCopyWithAttributes(originalFont, CTFontGetSize(originalFont), nullptr, descriptor.get()));
    693693}
    694694
     
    841841class FontDatabase {
    842842public:
    843 #if !CAN_DISALLOW_USER_INSTALLED_FONTS
     843#if !HAVE(DISALLOWABLE_USER_INSTALLED_FONTS)
    844844    static FontDatabase& singleton()
    845845    {
     
    851851    static FontDatabase& singletonAllowingUserInstalledFonts()
    852852    {
    853 #if CAN_DISALLOW_USER_INSTALLED_FONTS
     853#if HAVE(DISALLOWABLE_USER_INSTALLED_FONTS)
    854854        static NeverDestroyed<FontDatabase> database(AllowUserInstalledFonts::Yes);
    855855        return database;
     
    861861    static FontDatabase& singletonDisallowingUserInstalledFonts()
    862862    {
    863 #if CAN_DISALLOW_USER_INSTALLED_FONTS
     863#if HAVE(DISALLOWABLE_USER_INSTALLED_FONTS)
    864864        static NeverDestroyed<FontDatabase> database(AllowUserInstalledFonts::No);
    865865        return database;
     
    875875        InstalledFont() = default;
    876876
    877         InstalledFont(CTFontDescriptorRef fontDescriptor)
     877        InstalledFont(CTFontDescriptorRef fontDescriptor, AllowUserInstalledFonts allowUserInstalledFonts)
    878878            : fontDescriptor(fontDescriptor)
    879879            , capabilities(capabilitiesForFontDescriptor(fontDescriptor))
    880880        {
     881            if (allowUserInstalledFonts != AllowUserInstalledFonts::No)
     882                return;
     883            auto attributes = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
     884            addAttributesForInstalledFonts(attributes.get(), allowUserInstalledFonts);
     885            this->fontDescriptor = CTFontDescriptorCreateCopyWithAttributes(fontDescriptor, attributes.get());
    881886        }
    882887
     
    936941                result.reserveInitialCapacity(count);
    937942                for (CFIndex i = 0; i < count; ++i) {
    938                     InstalledFont installedFont(static_cast<CTFontDescriptorRef>(CFArrayGetValueAtIndex(matches.get(), i)));
     943                    InstalledFont installedFont(static_cast<CTFontDescriptorRef>(CFArrayGetValueAtIndex(matches.get(), i)), m_allowUserInstalledFonts);
    939944                    result.uncheckedAppend(WTFMove(installedFont));
    940945                }
     
    965970            auto mandatoryAttributes = installedFontMandatoryAttributes(m_allowUserInstalledFonts);
    966971            auto match = adoptCF(CTFontDescriptorCreateMatchingFontDescriptor(fontDescriptorToMatch.get(), mandatoryAttributes.get()));
    967             return InstalledFont(match.get());
     972            return InstalledFont(match.get(), m_allowUserInstalledFonts);
    968973        }).iterator->value;
    969974    }
     
    15091514void addAttributesForInstalledFonts(CFMutableDictionaryRef attributes, AllowUserInstalledFonts allowUserInstalledFonts)
    15101515{
    1511 #if CAN_DISALLOW_USER_INSTALLED_FONTS
     1516#if HAVE(DISALLOWABLE_USER_INSTALLED_FONTS)
    15121517    if (allowUserInstalledFonts == AllowUserInstalledFonts::No) {
    15131518        CFDictionaryAddValue(attributes, kCTFontUserInstalledAttribute, kCFBooleanFalse);
     
    15331538}
    15341539
     1540static inline bool isFontMatchingUserInstalledFontFallback(CTFontRef font, AllowUserInstalledFonts allowUserInstalledFonts)
     1541{
     1542#if HAVE(DISALLOWABLE_USER_INSTALLED_FONTS)
     1543    bool willFallbackToSystemOnly = false;
     1544    if (auto fontFallbackOptionAttributeRef = adoptCF(static_cast<CFNumberRef>(CTFontCopyAttribute(font, kCTFontFallbackOptionAttribute)))) {
     1545        int64_t fontFallbackOptionAttribute;
     1546        CFNumberGetValue(fontFallbackOptionAttributeRef.get(), kCFNumberSInt64Type, &fontFallbackOptionAttribute);
     1547        willFallbackToSystemOnly = fontFallbackOptionAttribute == kCTFontFallbackOptionSystem;
     1548    }
     1549
     1550    bool shouldFallbackToSystemOnly = allowUserInstalledFonts == AllowUserInstalledFonts::No;
     1551    return willFallbackToSystemOnly == shouldFallbackToSystemOnly;
     1552#else
     1553    UNUSED_PARAM(font);
     1554    UNUSED_PARAM(allowUserInstalledFonts);
     1555    return true;
     1556#endif
     1557}
     1558
    15351559RetainPtr<CTFontRef> createFontForInstalledFonts(CTFontRef font, AllowUserInstalledFonts allowUserInstalledFonts)
    15361560{
     1561    if (isFontMatchingUserInstalledFontFallback(font, allowUserInstalledFonts))
     1562        return font;
     1563
    15371564    auto attributes = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
    15381565    addAttributesForInstalledFonts(attributes.get(), allowUserInstalledFonts);
     
    15461573void addAttributesForWebFonts(CFMutableDictionaryRef attributes, AllowUserInstalledFonts allowUserInstalledFonts)
    15471574{
    1548 #if CAN_DISALLOW_USER_INSTALLED_FONTS
     1575#if HAVE(DISALLOWABLE_USER_INSTALLED_FONTS)
    15491576    if (allowUserInstalledFonts == AllowUserInstalledFonts::No) {
    15501577        CTFontFallbackOption fallbackOption = kCTFontFallbackOptionSystem;
     
    15601587RetainPtr<CFSetRef> installedFontMandatoryAttributes(AllowUserInstalledFonts allowUserInstalledFonts)
    15611588{
    1562 #if CAN_DISALLOW_USER_INSTALLED_FONTS
     1589#if HAVE(DISALLOWABLE_USER_INSTALLED_FONTS)
    15631590    if (allowUserInstalledFonts == AllowUserInstalledFonts::No) {
    15641591        CFTypeRef mandatoryAttributesValues[] = { kCTFontFamilyNameAttribute, kCTFontPostScriptNameAttribute, kCTFontEnabledAttribute, kCTFontUserInstalledAttribute, kCTFontFallbackOptionAttribute };
  • trunk/Source/WebCore/platform/graphics/mac/SimpleFontDataCoreText.cpp

    r233851 r247566  
    2929
    3030#include <CoreText/CoreText.h>
     31#include <pal/spi/cocoa/CoreTextSPI.h>
    3132
    3233namespace WebCore {
     
    5455}
    5556
     57#if HAVE(DISALLOWABLE_USER_INSTALLED_FONTS)
     58bool Font::isUserInstalledFont() const
     59{
     60    auto isUserInstalledFont = adoptCF(static_cast<CFBooleanRef>(CTFontCopyAttribute(getCTFont(), kCTFontUserInstalledAttribute)));
     61    return isUserInstalledFont && CFBooleanGetValue(isUserInstalledFont.get());
     62}
     63#endif
     64
    5665} // namespace WebCore
  • trunk/Tools/ChangeLog

    r247561 r247566  
     12019-07-18  Youenn Fablet  <youenn@apple.com>
     2
     3        Make sure to set kCTFontFallbackOptionAttribute to kCTFontFallbackOptionSystem for system fonts
     4        https://bugs.webkit.org/show_bug.cgi?id=199769
     5        <rdar://problem/49390297>
     6
     7        Reviewed by Myles C. Maxfield.
     8
     9        Add a font containing one extended character not found in system fonts.
     10
     11        * WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj:
     12        * WebKitTestRunner/fonts/FakeHelvetica-SingleExtendedCharacter.ttf: Added.
     13
    1142019-07-18  Konstantin Tokarev  <annulen@yandex.ru>
    215
  • trunk/Tools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj

    r241841 r247566  
    9797                31DA8A3D1E7205CC00E1DF2F /* IOSLayoutTestCommunication.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3148A0531E6F85B600D3B316 /* IOSLayoutTestCommunication.cpp */; };
    9898                41C5378E21F13414008B1FAD /* TestWebsiteDataStoreDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 41C5378D21F1333C008B1FAD /* TestWebsiteDataStoreDelegate.mm */; };
     99                41D5B62622DD9D36000F4C4A /* FakeHelvetica-SingleExtendedCharacter.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 41D5B62522DD9D36000F4C4A /* FakeHelvetica-SingleExtendedCharacter.ttf */; };
    99100                4430AE191F82C4FD0099915A /* GeneratedTouchesDebugWindow.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4430AE171F82C4EE0099915A /* GeneratedTouchesDebugWindow.mm */; };
    100101                51058AD51D678820009A538C /* libWebCoreTestSupport.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 41230E16138C78BF00BCCFCA /* libWebCoreTestSupport.dylib */; };
     
    301302                41C5378C21F1333C008B1FAD /* TestWebsiteDataStoreDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TestWebsiteDataStoreDelegate.h; path = cocoa/TestWebsiteDataStoreDelegate.h; sourceTree = "<group>"; };
    302303                41C5378D21F1333C008B1FAD /* TestWebsiteDataStoreDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = TestWebsiteDataStoreDelegate.mm; path = cocoa/TestWebsiteDataStoreDelegate.mm; sourceTree = "<group>"; };
     304                41D5B62522DD9D36000F4C4A /* FakeHelvetica-SingleExtendedCharacter.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = "FakeHelvetica-SingleExtendedCharacter.ttf"; path = "fonts/FakeHelvetica-SingleExtendedCharacter.ttf"; sourceTree = "<group>"; };
    303305                4429FC5E1627089600F66D8B /* WorkQueueManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WorkQueueManager.cpp; sourceTree = "<group>"; };
    304306                4429FC611627089600F66D8B /* WorkQueueManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkQueueManager.h; sourceTree = "<group>"; };
     
    750752                                1CBA02921FD86EA100179C7D /* FakeHelvetica-Helvetica2-400.ttf */,
    751753                                1CBA02951FD86EA100179C7D /* FakeHelvetica-Helvetica2-500.ttf */,
     754                                41D5B62522DD9D36000F4C4A /* FakeHelvetica-SingleExtendedCharacter.ttf */,
    752755                                1CA211C71BCA107300B2101F /* FontWithFeatures.otf */,
    753756                                1CA211C81BCA107300B2101F /* FontWithFeatures.ttf */,
     
    10291032                                1CBA02971FD87DEE00179C7D /* FakeHelvetica-Helvetica2-400.ttf in Resources */,
    10301033                                1CBA02961FD87DEC00179C7D /* FakeHelvetica-Helvetica2-500.ttf in Resources */,
     1034                                41D5B62622DD9D36000F4C4A /* FakeHelvetica-SingleExtendedCharacter.ttf in Resources */,
    10311035                                1CA211C91BCA107300B2101F /* FontWithFeatures.otf in Resources */,
    10321036                                1CA211CA1BCA107300B2101F /* FontWithFeatures.ttf in Resources */,
Note: See TracChangeset for help on using the changeset viewer.