Refactor user-installed font setting for clarity
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Dec 2017 03:24:15 +0000 (03:24 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Dec 2017 03:24:15 +0000 (03:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=181013

Reviewed by Simon Fraser.

Source/WebCore:

Pave the way for https://bugs.webkit.org/show_bug.cgi?id=180951.

This patch renames the Setting to not have so many grammatical negatives, and moves
some CoreText-specific FontCache function signatures into a new FontCacheCoreText.h
header file. It also uses the AllowUserInstalledFonts enum class in more places instead
of the old boolean we were using, and puts this enum class in the common TextFlags.h
header.

No new tests because there is no behavior change.

* WebCore.xcodeproj/project.pbxproj:
* css/CSSFontFaceSet.cpp:
(WebCore::CSSFontFaceSet::ensureLocalFontFacesForFamilyRegistered):
* css/StyleResolver.cpp:
(WebCore::StyleResolver::initializeFontStyle):
* page/Settings.yaml:
* platform/graphics/FontCache.h:
(WebCore::SynthesisPair::SynthesisPair): Deleted.
(WebCore::SynthesisPair::boldObliquePair const): Deleted.
* platform/graphics/FontDescription.cpp:
(WebCore::m_shouldAllowUserInstalledFonts):
(WebCore::m_mayRepresentUserInstalledFont): Deleted.
* platform/graphics/FontDescription.h:
(WebCore::FontDescription::shouldAllowUserInstalledFonts const):
(WebCore::FontDescription::setShouldAllowUserInstalledFonts):
(WebCore::FontDescription::operator== const):
(WebCore::FontDescription::mayRepresentUserInstalledFont const): Deleted.
(WebCore::FontDescription::setMayRepresentUserInstalledFont): Deleted.
* platform/graphics/cocoa/FontCacheCoreText.cpp:
(WebCore::FontDatabase::singleton):
(WebCore::FontDatabase::singletonAllowingUserInstalledFonts):
(WebCore::FontDatabase::singletonDisallowingUserInstalledFonts):
(WebCore::FontDatabase::FontDatabase):
(WebCore::platformFontLookupWithFamily):
(WebCore::fontWithFamily):
* platform/graphics/cocoa/FontCacheCoreText.h: Added.
(WebCore::SynthesisPair::SynthesisPair):
(WebCore::SynthesisPair::boldObliquePair const):
* platform/text/TextFlags.h:
* style/StyleResolveForDocument.cpp:
(WebCore::Style::resolveForDocument):

Source/WebKit:

There are no clients of this SPI yet, so we can rename it to remove the
grammatical negative.

* Shared/WebPreferences.yaml:
* UIProcess/API/C/WKPreferences.cpp:
(WKPreferencesSetShouldAllowUserInstalledFonts):
(WKPreferencesGetShouldAllowUserInstalledFonts):
(WKPreferencesSetShouldDisallowUserInstalledFonts): Deleted.
(WKPreferencesGetShouldDisallowUserInstalledFonts): Deleted.
* UIProcess/API/C/WKPreferencesRefPrivate.h:
* UIProcess/API/Cocoa/WKPreferences.mm:
(-[WKPreferences _shouldAllowUserInstalledFonts]):
(-[WKPreferences _setShouldAllowUserInstalledFonts:]):
(-[WKPreferences _shouldDisallowUserInstalledFonts]): Deleted.
(-[WKPreferences _setShouldDisallowUserInstalledFonts:]): Deleted.
* UIProcess/API/Cocoa/WKPreferencesPrivate.h:

LayoutTests:

* fast/text/user-installed-fonts/disable.html:
* fast/text/user-installed-fonts/shadow-disable.html:
* fast/text/user-installed-fonts/shadow-family-disable.html:
* fast/text/user-installed-fonts/shadow-postscript-disable.html:
* fast/text/user-installed-fonts/shadow-postscript-family-disable.html:

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

24 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/text/user-installed-fonts/disable.html
LayoutTests/fast/text/user-installed-fonts/shadow-disable.html
LayoutTests/fast/text/user-installed-fonts/shadow-family-disable.html
LayoutTests/fast/text/user-installed-fonts/shadow-postscript-disable.html
LayoutTests/fast/text/user-installed-fonts/shadow-postscript-family-disable.html
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/css/CSSFontFaceSet.cpp
Source/WebCore/css/StyleResolver.cpp
Source/WebCore/page/Settings.yaml
Source/WebCore/platform/graphics/FontCache.h
Source/WebCore/platform/graphics/FontDescription.cpp
Source/WebCore/platform/graphics/FontDescription.h
Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp
Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.h [new file with mode: 0644]
Source/WebCore/platform/text/TextFlags.h
Source/WebCore/style/StyleResolveForDocument.cpp
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebPreferences.yaml
Source/WebKit/UIProcess/API/C/WKPreferences.cpp
Source/WebKit/UIProcess/API/C/WKPreferencesRefPrivate.h
Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm
Source/WebKit/UIProcess/API/Cocoa/WKPreferencesPrivate.h

index 77582a5..bec6574 100644 (file)
@@ -1,3 +1,16 @@
+2017-12-19  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Refactor user-installed font setting for clarity
+        https://bugs.webkit.org/show_bug.cgi?id=181013
+
+        Reviewed by Simon Fraser.
+
+        * fast/text/user-installed-fonts/disable.html:
+        * fast/text/user-installed-fonts/shadow-disable.html:
+        * fast/text/user-installed-fonts/shadow-family-disable.html:
+        * fast/text/user-installed-fonts/shadow-postscript-disable.html:
+        * fast/text/user-installed-fonts/shadow-postscript-family-disable.html:
+
 2017-12-19  Brian Burg  <bburg@apple.com>
 
         Web Inspector: InspectorTest.evaluateInPage should return a rejection if an error was thrown
index 314ea61..213c800 100644 (file)
@@ -3,7 +3,7 @@
 <head>
 <script>
 if (window.internals)
-    internals.settings.setShouldDisallowUserInstalledFonts(true);
+    internals.settings.setShouldAllowUserInstalledFonts(false);
 </script>
 </head>
 <body>
index cc45779..bbe2c99 100644 (file)
@@ -5,7 +5,7 @@
 if (window.testRunner)
     testRunner.installFakeHelvetica("Helvetica-400");
 if (window.internals)
-    internals.settings.setShouldDisallowUserInstalledFonts(true);
+    internals.settings.setShouldAllowUserInstalledFonts(false);
 </script>
 </head>
 <body>
index beddaf5..4a0cdfa 100644 (file)
@@ -5,7 +5,7 @@
 if (window.testRunner)
     testRunner.installFakeHelvetica("Helvetica-500");
 if (window.internals)
-    internals.settings.setShouldDisallowUserInstalledFonts(true);
+    internals.settings.setShouldAllowUserInstalledFonts(false);
 </script>
 </head>
 <body>
index 1e44d5c..dc53240 100644 (file)
@@ -5,7 +5,7 @@
 if (window.testRunner)
     testRunner.installFakeHelvetica("Helvetica2-400");
 if (window.internals)
-    internals.settings.setShouldDisallowUserInstalledFonts(true);
+    internals.settings.setShouldAllowUserInstalledFonts(false);
 </script>
 </head>
 <body>
index f0a3ff4..df5fc09 100644 (file)
@@ -5,7 +5,7 @@
 if (window.testRunner)
     testRunner.installFakeHelvetica("Helvetica2-500");
 if (window.internals)
-    internals.settings.setShouldDisallowUserInstalledFonts(true);
+    internals.settings.setShouldAllowUserInstalledFonts(false);
 </script>
 </head>
 <body>
index cc84856..ac28ffa 100644 (file)
@@ -1,3 +1,52 @@
+2017-12-19  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Refactor user-installed font setting for clarity
+        https://bugs.webkit.org/show_bug.cgi?id=181013
+
+        Reviewed by Simon Fraser.
+
+        Pave the way for https://bugs.webkit.org/show_bug.cgi?id=180951.
+
+        This patch renames the Setting to not have so many grammatical negatives, and moves
+        some CoreText-specific FontCache function signatures into a new FontCacheCoreText.h
+        header file. It also uses the AllowUserInstalledFonts enum class in more places instead
+        of the old boolean we were using, and puts this enum class in the common TextFlags.h
+        header.
+
+        No new tests because there is no behavior change.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * css/CSSFontFaceSet.cpp:
+        (WebCore::CSSFontFaceSet::ensureLocalFontFacesForFamilyRegistered):
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::initializeFontStyle):
+        * page/Settings.yaml:
+        * platform/graphics/FontCache.h:
+        (WebCore::SynthesisPair::SynthesisPair): Deleted.
+        (WebCore::SynthesisPair::boldObliquePair const): Deleted.
+        * platform/graphics/FontDescription.cpp:
+        (WebCore::m_shouldAllowUserInstalledFonts):
+        (WebCore::m_mayRepresentUserInstalledFont): Deleted.
+        * platform/graphics/FontDescription.h:
+        (WebCore::FontDescription::shouldAllowUserInstalledFonts const):
+        (WebCore::FontDescription::setShouldAllowUserInstalledFonts):
+        (WebCore::FontDescription::operator== const):
+        (WebCore::FontDescription::mayRepresentUserInstalledFont const): Deleted.
+        (WebCore::FontDescription::setMayRepresentUserInstalledFont): Deleted.
+        * platform/graphics/cocoa/FontCacheCoreText.cpp:
+        (WebCore::FontDatabase::singleton):
+        (WebCore::FontDatabase::singletonAllowingUserInstalledFonts):
+        (WebCore::FontDatabase::singletonDisallowingUserInstalledFonts):
+        (WebCore::FontDatabase::FontDatabase):
+        (WebCore::platformFontLookupWithFamily):
+        (WebCore::fontWithFamily):
+        * platform/graphics/cocoa/FontCacheCoreText.h: Added.
+        (WebCore::SynthesisPair::SynthesisPair):
+        (WebCore::SynthesisPair::boldObliquePair const):
+        * platform/text/TextFlags.h:
+        * style/StyleResolveForDocument.cpp:
+        (WebCore::Style::resolveForDocument):
+
 2017-12-19  Youenn Fablet  <youenn@apple.com>
 
         UserMediaRequest should stop a request when Document is being stopped
index 8e09d10..1ee3f6e 100644 (file)
                C105DA640F3AA6B8001DD44F /* TextEncodingDetector.h in Headers */ = {isa = PBXBuildFile; fileRef = C105DA630F3AA6B8001DD44F /* TextEncodingDetector.h */; };
                C2015C0A1BE6FEB200822389 /* FontVariantBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = C2015C091BE6FE2C00822389 /* FontVariantBuilder.h */; };
                C21DF2EA1D9E4E9900F5B24C /* CSSFontVariationValue.h in Headers */ = {isa = PBXBuildFile; fileRef = C21DF2E81D9E4E9900F5B24C /* CSSFontVariationValue.h */; };
+               C2458E631FE897B000594759 /* FontCacheCoreText.h in Headers */ = {isa = PBXBuildFile; fileRef = C2458E611FE8979E00594759 /* FontCacheCoreText.h */; settings = {ATTRIBUTES = (Private, ); }; };
                C26017A41C72DC9900F74A16 /* CSSFontFaceSet.h in Headers */ = {isa = PBXBuildFile; fileRef = C26017A21C72DC9900F74A16 /* CSSFontFaceSet.h */; };
                C280833F1C6DC26F001451B6 /* JSFontFace.h in Headers */ = {isa = PBXBuildFile; fileRef = C280833E1C6DC22C001451B6 /* JSFontFace.h */; };
                C2AB0AF71E6B3C6C001348C5 /* FontSelectionAlgorithm.h in Headers */ = {isa = PBXBuildFile; fileRef = C2AB0AF51E6B3C6C001348C5 /* FontSelectionAlgorithm.h */; settings = {ATTRIBUTES = (Private, ); }; };
                C2015C091BE6FE2C00822389 /* FontVariantBuilder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontVariantBuilder.h; sourceTree = "<group>"; };
                C21DF2E71D9E4E9900F5B24C /* CSSFontVariationValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSFontVariationValue.cpp; sourceTree = "<group>"; };
                C21DF2E81D9E4E9900F5B24C /* CSSFontVariationValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSFontVariationValue.h; sourceTree = "<group>"; };
+               C2458E611FE8979E00594759 /* FontCacheCoreText.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontCacheCoreText.h; sourceTree = "<group>"; };
                C26017A11C72DC9900F74A16 /* CSSFontFaceSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSFontFaceSet.cpp; sourceTree = "<group>"; };
                C26017A21C72DC9900F74A16 /* CSSFontFaceSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSFontFaceSet.h; sourceTree = "<group>"; };
                C280833C1C6DB194001451B6 /* FontFace.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = FontFace.idl; sourceTree = "<group>"; };
                        isa = PBXGroup;
                        children = (
                                1C3969CF1B74211E002BCFA7 /* FontCacheCoreText.cpp */,
+                               C2458E611FE8979E00594759 /* FontCacheCoreText.h */,
                                B2AFFC780D00A5C10030074D /* FontCascadeCocoa.mm */,
                                7C4EDD731A7B607800198C4D /* FontCocoa.mm */,
                                1C12AC2C1EE779950079E0A0 /* FontDescriptionCocoa.cpp */,
                                1AC2D89D1B1E291F00D52E87 /* FontAntialiasingStateSaver.h in Headers */,
                                BCB92D4F1293550B00C8387F /* FontBaseline.h in Headers */,
                                B2C3DA630D006CD600EF6F26 /* FontCache.h in Headers */,
+                               C2458E631FE897B000594759 /* FontCacheCoreText.h in Headers */,
                                B2C3DA610D006CD600EF6F26 /* FontCascade.h in Headers */,
                                B2C3DA680D006CD600EF6F26 /* FontCascadeFonts.h in Headers */,
                                B2AFFC7E0D00A5C10030074D /* FontCustomPlatformData.h in Headers */,
index 5c40313..b810403 100644 (file)
@@ -104,9 +104,9 @@ void CSSFontFaceSet::ensureLocalFontFacesForFamilyRegistered(const String& famil
     if (m_locallyInstalledFacesLookupTable.contains(familyName))
         return;
 
-    FontCache::AllowUserInstalledFonts allowUserInstalledFonts = FontCache::AllowUserInstalledFonts::Yes;
-    if (m_owningFontSelector->document() && m_owningFontSelector->document()->settings().shouldDisallowUserInstalledFonts())
-        allowUserInstalledFonts = FontCache::AllowUserInstalledFonts::No;
+    AllowUserInstalledFonts allowUserInstalledFonts = AllowUserInstalledFonts::Yes;
+    if (m_owningFontSelector->document())
+        allowUserInstalledFonts = m_owningFontSelector->document()->settings().shouldAllowUserInstalledFonts() ? AllowUserInstalledFonts::Yes : AllowUserInstalledFonts::No;
     Vector<FontSelectionCapabilities> capabilities = FontCache::singleton().getFontSelectionCapabilitiesInFamily(familyName, allowUserInstalledFonts);
     if (capabilities.isEmpty())
         return;
index 7fd25b8..8947c00 100644 (file)
@@ -1788,7 +1788,7 @@ void StyleResolver::initializeFontStyle()
     fontDescription.setOneFamily(standardFamily);
     fontDescription.setKeywordSizeFromIdentifier(CSSValueMedium);
     setFontSize(fontDescription, Style::fontSizeForKeyword(CSSValueMedium, false, document()));
-    fontDescription.setMayRepresentUserInstalledFont(!settings().shouldDisallowUserInstalledFonts());
+    fontDescription.setShouldAllowUserInstalledFonts(settings().shouldAllowUserInstalledFonts() ? AllowUserInstalledFonts::Yes : AllowUserInstalledFonts::No);
     setFontDescription(fontDescription);
 }
 
index 995eb8d..7afb6a2 100644 (file)
@@ -661,8 +661,8 @@ storageBlockingPolicy:
   initial: SecurityOrigin::AllowAllStorage
   onChange: storageBlockingPolicyChanged
 
-shouldDisallowUserInstalledFonts:
-  initial: false
+shouldAllowUserInstalledFonts:
+  initial: true
   onChange: setNeedsRecalcStyleInAllFrames
 
 # Only set by Layout Tests.
index 4af47d4..a2ea213 100644 (file)
@@ -41,7 +41,7 @@
 #include <wtf/text/WTFString.h>
 
 #if PLATFORM(COCOA)
-#include <CoreText/CTFont.h>
+#include "FontCacheCoreText.h"
 #endif
 
 #if OS(WINDOWS)
@@ -200,10 +200,6 @@ public:
     static IMultiLanguage* getMultiLanguageInterface();
 #endif
 
-    enum class AllowUserInstalledFonts {
-        Yes,
-        No
-    };
     // This function exists so CSSFontSelector can have a unified notion of preinstalled fonts and @font-face.
     // It comes into play when you create an @font-face which shares a family name as a preinstalled font.
     Vector<FontSelectionCapabilities> getFontSelectionCapabilitiesInFamily(const AtomicString&, AllowUserInstalledFonts);
@@ -270,32 +266,7 @@ inline std::unique_ptr<FontPlatformData> FontCache::createFontPlatformDataForTes
     return createFontPlatformData(fontDescription, family, nullptr, nullptr, { });
 }
 
-#if PLATFORM(COCOA)
-
-struct SynthesisPair {
-    SynthesisPair(bool needsSyntheticBold, bool needsSyntheticOblique)
-        : needsSyntheticBold(needsSyntheticBold)
-        , needsSyntheticOblique(needsSyntheticOblique)
-    {
-    }
-
-    std::pair<bool, bool> boldObliquePair() const
-    {
-        return std::make_pair(needsSyntheticBold, needsSyntheticOblique);
-    }
-
-    bool needsSyntheticBold;
-    bool needsSyntheticOblique;
-};
-
-RetainPtr<CTFontRef> preparePlatformFont(CTFontRef, const FontDescription&, const FontFeatureSettings* fontFaceFeatures, const FontVariantSettings* fontFaceVariantSettings, FontSelectionSpecifiedCapabilities fontFaceCapabilities, float size, bool applyWeightWidthSlopeVariations = true);
-SynthesisPair computeNecessarySynthesis(CTFontRef, const FontDescription&, bool isPlatformFont = false);
-RetainPtr<CTFontRef> platformFontWithFamilySpecialCase(const AtomicString& family, FontSelectionRequest, float size);
-RetainPtr<CTFontRef> platformFontWithFamily(const AtomicString& family, FontSelectionRequest, TextRenderingMode, float size);
-bool requiresCustomFallbackFont(UChar32 character);
-FontSelectionCapabilities capabilitiesForFontDescriptor(CTFontDescriptorRef);
-
-#else
+#if !PLATFORM(COCOA)
 
 inline void FontCache::platformPurgeInactiveFontData()
 {
index df4a9cc..3d5dd35 100644 (file)
@@ -80,7 +80,7 @@ FontDescription::FontDescription()
     , m_variantEastAsianRuby(static_cast<unsigned>(FontVariantEastAsianRuby::Normal))
     , m_opticalSizing(static_cast<unsigned>(FontOpticalSizing::Enabled))
     , m_fontStyleAxis(FontCascadeDescription::initialFontStyleAxis() == FontStyleAxis::ital)
-    , m_mayRepresentUserInstalledFont(true)
+    , m_shouldAllowUserInstalledFonts(static_cast<unsigned>(AllowUserInstalledFonts::Yes))
 {
 }
 
index 8b8fa22..96e286e 100644 (file)
@@ -114,7 +114,7 @@ public:
     }
     FontOpticalSizing opticalSizing() const { return static_cast<FontOpticalSizing>(m_opticalSizing); }
     FontStyleAxis fontStyleAxis() const { return m_fontStyleAxis ? FontStyleAxis::ital : FontStyleAxis::slnt; }
-    bool mayRepresentUserInstalledFont() const { return m_mayRepresentUserInstalledFont; }
+    AllowUserInstalledFonts shouldAllowUserInstalledFonts() const { return static_cast<AllowUserInstalledFonts>(m_shouldAllowUserInstalledFonts); }
 
     void setComputedSize(float s) { m_computedSize = clampToFloat(s); }
     void setItalic(FontSelectionValue italic) { m_fontSelectionRequest.slope = italic; }
@@ -149,7 +149,7 @@ public:
     void setVariantEastAsianRuby(FontVariantEastAsianRuby variant) { m_variantEastAsianRuby = static_cast<unsigned>(variant); }
     void setOpticalSizing(FontOpticalSizing sizing) { m_opticalSizing = static_cast<unsigned>(sizing); }
     void setFontStyleAxis(FontStyleAxis axis) { m_fontStyleAxis = axis == FontStyleAxis::ital; }
-    void setMayRepresentUserInstalledFont(bool mayRepresentUserInstalledFont) { m_mayRepresentUserInstalledFont = mayRepresentUserInstalledFont; }
+    void setShouldAllowUserInstalledFonts(AllowUserInstalledFonts shouldAllowUserInstalledFonts) { m_shouldAllowUserInstalledFonts = static_cast<unsigned>(shouldAllowUserInstalledFonts); }
 
     static void invalidateCaches();
 
@@ -185,7 +185,7 @@ private:
     unsigned m_variantEastAsianRuby : 1; // FontVariantEastAsianRuby
     unsigned m_opticalSizing : 1; // FontOpticalSizing
     unsigned m_fontStyleAxis : 1; // Whether "font-style: italic" or "font-style: oblique 20deg" was specified
-    unsigned m_mayRepresentUserInstalledFont : 1; // If this description is allowed to match a user-installed font
+    unsigned m_shouldAllowUserInstalledFonts : 1; // AllowUserInstalledFonts: If this description is allowed to match a user-installed font
 };
 
 inline bool FontDescription::operator==(const FontDescription& other) const
@@ -220,7 +220,7 @@ inline bool FontDescription::operator==(const FontDescription& other) const
         && m_variantEastAsianRuby == other.m_variantEastAsianRuby
         && m_opticalSizing == other.m_opticalSizing
         && m_fontStyleAxis == other.m_fontStyleAxis
-        && m_mayRepresentUserInstalledFont == other.m_mayRepresentUserInstalledFont;
+        && m_shouldAllowUserInstalledFonts == other.m_shouldAllowUserInstalledFonts;
 }
 
 // FIXME: Move to a file of its own.
index ce70374..0ab17f5 100644 (file)
@@ -833,7 +833,7 @@ public:
 #if !CAN_DISALLOW_USER_INSTALLED_FONTS
     static FontDatabase& singleton()
     {
-        static NeverDestroyed<FontDatabase> database(FontCache::AllowUserInstalledFonts::Yes);
+        static NeverDestroyed<FontDatabase> database(AllowUserInstalledFonts::Yes);
         return database;
     }
 #endif
@@ -841,7 +841,7 @@ public:
     static FontDatabase& singletonAllowingUserInstalledFonts()
     {
 #if CAN_DISALLOW_USER_INSTALLED_FONTS
-        static NeverDestroyed<FontDatabase> database(FontCache::AllowUserInstalledFonts::Yes);
+        static NeverDestroyed<FontDatabase> database(AllowUserInstalledFonts::Yes);
         return database;
 #else
         return singleton();
@@ -851,7 +851,7 @@ public:
     static FontDatabase& singletonDisallowingUserInstalledFonts()
     {
 #if CAN_DISALLOW_USER_INSTALLED_FONTS
-        static NeverDestroyed<FontDatabase> database(FontCache::AllowUserInstalledFonts::No);
+        static NeverDestroyed<FontDatabase> database(AllowUserInstalledFonts::No);
         return database;
 #else
         return singleton();
@@ -974,14 +974,14 @@ public:
 private:
     friend class NeverDestroyed<FontDatabase>;
 
-    FontDatabase(FontCache::AllowUserInstalledFonts allowUserInstalledFonts)
+    FontDatabase(AllowUserInstalledFonts allowUserInstalledFonts)
         : m_allowUserInstalledFonts(allowUserInstalledFonts)
     {
     }
 
     HashMap<String, InstalledFontFamily> m_familyNameToFontDescriptors;
     HashMap<String, InstalledFont> m_postScriptNameToFontDescriptors;
-    FontCache::AllowUserInstalledFonts m_allowUserInstalledFonts;
+    AllowUserInstalledFonts m_allowUserInstalledFonts;
 };
 
 // Because this struct holds intermediate values which may be in the compressed -1 - 1 GX range, we don't want to use the relatively large
@@ -1190,18 +1190,18 @@ struct FontLookup {
     bool createdFromPostScriptName { false };
 };
 
-static FontLookup platformFontLookupWithFamily(const AtomicString& family, FontSelectionRequest request, float size, bool mayRepresentUserInstalledFont)
+static FontLookup platformFontLookupWithFamily(const AtomicString& family, FontSelectionRequest request, float size, AllowUserInstalledFonts allowUserInstalledFonts)
 {
     const auto& whitelist = fontWhitelist();
     if (!isSystemFont(family) && whitelist.size() && !whitelist.contains(family))
         return { nullptr };
 
 #if SHOULD_USE_CORE_TEXT_FONT_LOOKUP
-    UNUSED_PARAM(mayRepresentUserInstalledFont);
+    UNUSED_PARAM(allowUserInstalledFonts);
     CTFontSymbolicTraits traits = (isFontWeightBold(request.weight) ? kCTFontTraitBold : 0) | (isItalic(request.slope) ? kCTFontTraitItalic : 0);
     return { adoptCF(CTFontCreateForCSS(family.string().createCFString().get(), static_cast<float>(request.weight), traits, size)) };
 #else
-    auto& fontDatabase = mayRepresentUserInstalledFont ? FontDatabase::singletonAllowingUserInstalledFonts() : FontDatabase::singletonDisallowingUserInstalledFonts();
+    auto& fontDatabase = allowUserInstalledFonts == AllowUserInstalledFonts::Yes ? FontDatabase::singletonAllowingUserInstalledFonts() : FontDatabase::singletonDisallowingUserInstalledFonts();
     const auto& familyFonts = fontDatabase.collectionForFamily(family.string());
     if (familyFonts.isEmpty()) {
         // The CSS spec states that font-family only accepts a name of an actual font family. However, in WebKit, we claim to also
@@ -1265,7 +1265,7 @@ static RetainPtr<CTFontRef> fontWithFamily(const AtomicString& family, const Fon
     FontLookup fontLookup;
     fontLookup.result = platformFontWithFamilySpecialCase(family, request, size);
     if (!fontLookup.result)
-        fontLookup = platformFontLookupWithFamily(family, request, size, fontDescription.mayRepresentUserInstalledFont());
+        fontLookup = platformFontLookupWithFamily(family, request, size, fontDescription.shouldAllowUserInstalledFonts());
     return preparePlatformFont(fontLookup.result.get(), fontDescription, fontFaceFeatures, fontFaceVariantSettings, fontFaceCapabilities, size, !fontLookup.createdFromPostScriptName);
 }
 
diff --git a/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.h b/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.h
new file mode 100644 (file)
index 0000000..1b16f7b
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2017 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "FontDescription.h"
+
+#include <CoreText/CTFont.h>
+
+namespace WebCore {
+
+struct SynthesisPair {
+    SynthesisPair(bool needsSyntheticBold, bool needsSyntheticOblique)
+        : needsSyntheticBold(needsSyntheticBold)
+        , needsSyntheticOblique(needsSyntheticOblique)
+    {
+    }
+
+    std::pair<bool, bool> boldObliquePair() const
+    {
+        return std::make_pair(needsSyntheticBold, needsSyntheticOblique);
+    }
+
+    bool needsSyntheticBold;
+    bool needsSyntheticOblique;
+};
+
+RetainPtr<CTFontRef> preparePlatformFont(CTFontRef, const FontDescription&, const FontFeatureSettings* fontFaceFeatures, const FontVariantSettings* fontFaceVariantSettings, FontSelectionSpecifiedCapabilities fontFaceCapabilities, float size, bool applyWeightWidthSlopeVariations = true);
+SynthesisPair computeNecessarySynthesis(CTFontRef, const FontDescription&, bool isPlatformFont = false);
+RetainPtr<CTFontRef> platformFontWithFamilySpecialCase(const AtomicString& family, FontSelectionRequest, float size);
+RetainPtr<CTFontRef> platformFontWithFamily(const AtomicString& family, FontSelectionRequest, TextRenderingMode, float size);
+bool requiresCustomFallbackFont(UChar32 character);
+FontSelectionCapabilities capabilitiesForFontDescriptor(CTFontDescriptorRef);
+
+}
index dfde5bf..e295661 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2003, 2006 Apple Inc.  All rights reserved.
+ * Copyright (C) 2003, 2006, 2017 Apple Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -362,4 +362,9 @@ enum class FontStyleAxis {
     ital
 };
 
+enum class AllowUserInstalledFonts {
+    No,
+    Yes
+};
+
 }
index cbf6723..b6e7204 100644 (file)
@@ -109,7 +109,7 @@ RenderStyle resolveForDocument(const Document& document)
     fontDescription.setLocale(document.contentLanguage());
     fontDescription.setRenderingMode(settings.fontRenderingMode());
     fontDescription.setOneFamily(standardFamily);
-    fontDescription.setMayRepresentUserInstalledFont(!settings.shouldDisallowUserInstalledFonts());
+    fontDescription.setShouldAllowUserInstalledFonts(settings.shouldAllowUserInstalledFonts() ? AllowUserInstalledFonts::Yes : AllowUserInstalledFonts::No);
 
     fontDescription.setKeywordSizeFromIdentifier(CSSValueMedium);
     int size = fontSizeForKeyword(CSSValueMedium, false, document);
index 898fc33..97f3ef4 100644 (file)
@@ -1,3 +1,27 @@
+2017-12-19  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Refactor user-installed font setting for clarity
+        https://bugs.webkit.org/show_bug.cgi?id=181013
+
+        Reviewed by Simon Fraser.
+
+        There are no clients of this SPI yet, so we can rename it to remove the
+        grammatical negative.
+
+        * Shared/WebPreferences.yaml:
+        * UIProcess/API/C/WKPreferences.cpp:
+        (WKPreferencesSetShouldAllowUserInstalledFonts):
+        (WKPreferencesGetShouldAllowUserInstalledFonts):
+        (WKPreferencesSetShouldDisallowUserInstalledFonts): Deleted.
+        (WKPreferencesGetShouldDisallowUserInstalledFonts): Deleted.
+        * UIProcess/API/C/WKPreferencesRefPrivate.h:
+        * UIProcess/API/Cocoa/WKPreferences.mm:
+        (-[WKPreferences _shouldAllowUserInstalledFonts]):
+        (-[WKPreferences _setShouldAllowUserInstalledFonts:]):
+        (-[WKPreferences _shouldDisallowUserInstalledFonts]): Deleted.
+        (-[WKPreferences _setShouldDisallowUserInstalledFonts:]): Deleted.
+        * UIProcess/API/Cocoa/WKPreferencesPrivate.h:
+
 2017-12-19  Eric Carlson  <eric.carlson@apple.com>
 
         [MediaStream] Clean up RealtimeMediaSource interfaces
index 1f4b9d9..5452435 100644 (file)
@@ -1034,9 +1034,9 @@ VisibleDebugOverlayRegions:
   defaultValue: 0
   category: debug
 
-ShouldDisallowUserInstalledFonts:
+ShouldAllowUserInstalledFonts:
   type: bool
-  defaultValue: false
+  defaultValue: true
 
 
 # For experimental features:
index d303e49..37e6cb1 100644 (file)
@@ -1920,12 +1920,12 @@ bool WKPreferencesGetAccessibilityObjectModelEnabled(WKPreferencesRef preference
     return toImpl(preferencesRef)->accessibilityObjectModelEnabled();
 }
 
-void WKPreferencesSetShouldDisallowUserInstalledFonts(WKPreferencesRef preferencesRef, bool flag)
+void WKPreferencesSetShouldAllowUserInstalledFonts(WKPreferencesRef preferencesRef, bool flag)
 {
-    toImpl(preferencesRef)->setShouldDisallowUserInstalledFonts(flag);
+    toImpl(preferencesRef)->setShouldAllowUserInstalledFonts(flag);
 }
 
-bool WKPreferencesGetShouldDisallowUserInstalledFonts(WKPreferencesRef preferencesRef)
+bool WKPreferencesGetShouldAllowUserInstalledFonts(WKPreferencesRef preferencesRef)
 {
-    return toImpl(preferencesRef)->shouldDisallowUserInstalledFonts();
+    return toImpl(preferencesRef)->shouldAllowUserInstalledFonts();
 }
index 6efcfe0..e793923 100644 (file)
@@ -546,8 +546,8 @@ WK_EXPORT void WKPreferencesSetAccessibilityObjectModelEnabled(WKPreferencesRef,
 WK_EXPORT bool WKPreferencesGetAccessibilityObjectModelEnabled(WKPreferencesRef);
 
 // Defaults to false.
-WK_EXPORT void WKPreferencesSetShouldDisallowUserInstalledFonts(WKPreferencesRef, bool flag);
-WK_EXPORT bool WKPreferencesGetShouldDisallowUserInstalledFonts(WKPreferencesRef);
+WK_EXPORT void WKPreferencesSetShouldAllowUserInstalledFonts(WKPreferencesRef, bool flag);
+WK_EXPORT bool WKPreferencesGetShouldAllowUserInstalledFonts(WKPreferencesRef);
     
 #ifdef __cplusplus
 }
index 76f4044..cf692cc 100644 (file)
@@ -657,14 +657,14 @@ static _WKStorageBlockingPolicy toAPI(WebCore::SecurityOrigin::StorageBlockingPo
     _preferences->setJavaScriptCanAccessClipboard(javaScriptCanAccessClipboard);
 }
 
-- (BOOL)_shouldDisallowUserInstalledFonts
+- (BOOL)_shouldAllowUserInstalledFonts
 {
-    return _preferences->shouldDisallowUserInstalledFonts();
+    return _preferences->shouldAllowUserInstalledFonts();
 }
 
-- (void)_setShouldDisallowUserInstalledFonts:(BOOL)_shouldDisallowUserInstalledFonts
+- (void)_setShouldAllowUserInstalledFonts:(BOOL)_shouldAllowUserInstalledFonts
 {
-    _preferences->setShouldDisallowUserInstalledFonts(_shouldDisallowUserInstalledFonts);
+    _preferences->setShouldAllowUserInstalledFonts(_shouldAllowUserInstalledFonts);
 }
 
 #if PLATFORM(MAC)
index cb914fb..6a18806 100644 (file)
@@ -115,7 +115,7 @@ typedef NS_OPTIONS(NSUInteger, _WKJavaScriptRuntimeFlags) {
 @property (nonatomic, setter=_setJavaScriptCanAccessClipboard:) BOOL _javaScriptCanAccessClipboard WK_API_AVAILABLE(macosx(10.13), ios(11.0));
 @property (nonatomic, setter=_setDOMPasteAllowed:) BOOL _domPasteAllowed WK_API_AVAILABLE(macosx(10.13), ios(11.0));
 
-@property (nonatomic, setter=_setShouldDisallowUserInstalledFonts:) BOOL _shouldDisallowUserInstalledFonts WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+@property (nonatomic, setter=_setShouldAllowUserInstalledFonts:) BOOL _shouldAllowUserInstalledFonts WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 + (NSArray<_WKExperimentalFeature *> *)_experimentalFeatures WK_API_AVAILABLE(macosx(10.12), ios(10.0));
 - (BOOL)_isEnabledForFeature:(_WKExperimentalFeature *)feature WK_API_AVAILABLE(macosx(10.12), ios(10.0));