[Cocoa] Ask platform for generic font family mappings
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Feb 2019 02:19:19 +0000 (02:19 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Feb 2019 02:19:19 +0000 (02:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187723
<rdar://problem/41892438>

Reviewed by Brent Fulgham.

Source/WebCore:

WebKit API allows setting the generic font families for the USCRIPT_COMMON script.
When trying to style a character with a generic font family, we first look to see if
we have a mapping for the particular script the character is rendered with, and if we
don't find a match, we then check USCRIPT_COMMON.

In the Cocoa ports, the only way families get set for non-USCRIPT_COMMON scripts (aka
the only scripts which won't use the API families) is in
SettingsBase::initializeDefaultFontFamilies(). That function only sets the families
for the CJK scripts.

The mappings inside SettingsBase are incorrect and conflict with our policy regarding
user-installed fonts. Instead, we should be consulting with the platform for some of
these mappings, by calling CTFontDescriptorCreateForCSSFamily(). However, the WebKit
API still has to work to set the mappings for untagged content. Therefore, we use the
system mappings for language-tagged content, and the API mappings for non-language-tagged
content. This is a good balance that makes sure we always have a good mapping for every
language, but API clients can still set the mappings, too.

Test: fast/text/ja-sans-serif.html

* css/CSSComputedStyleDeclaration.cpp:
* css/CSSFontSelector.cpp:
(WebCore::resolveGenericFamily):
* css/parser/CSSPropertyParser.cpp:
(WebCore::consumeFontFamily):
* page/cocoa/SettingsBaseCocoa.mm:
(WebCore::SettingsBase::initializeDefaultFontFamilies):
(WebCore::osakaMonoIsInstalled): Deleted.
* platform/graphics/FontDescription.cpp:
(WebCore::FontDescription::platformResolveGenericFamily):
* platform/graphics/FontDescription.h:
* platform/graphics/cocoa/FontDescriptionCocoa.cpp:
(WebCore::computeSpecializedChineseLocale):
(WebCore::cachedSpecializedChineseLocale):
(WebCore::languageChanged):
(WebCore::FontDescription::platformResolveGenericFamily):
* platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp:
(WebCore::SystemFontDatabaseCoreText::clear):
(WebCore::genericFamily):
(WebCore::SystemFontDatabaseCoreText::serifFamily):
(WebCore::SystemFontDatabaseCoreText::sansSerifFamily):
(WebCore::SystemFontDatabaseCoreText::cursiveFamily):
(WebCore::SystemFontDatabaseCoreText::fantasyFamily):
(WebCore::SystemFontDatabaseCoreText::monospaceFamily):
* platform/graphics/cocoa/SystemFontDatabaseCoreText.h:

Source/WebCore/PAL:

* pal/spi/cocoa/CoreTextSPI.h:

Source/WTF:

Add an ENABLE in Platform.

* wtf/Platform.h:

Tools:

Allow testing infrastructure to use fonts that are returned from CTFontDescriptorCreateForCSSFamily().

* DumpRenderTree/mac/DumpRenderTree.mm:
(allowedFontFamilySet):
* WebKitTestRunner/mac/TestControllerMac.mm:
(WTR::allowedFontFamilySet):

LayoutTests:

Update the tests to work with this new model.

* fast/text/international/font-fallback-to-common-script-expected.html: Removed.
* fast/text/international/font-fallback-to-common-script.html: Removed.
* fast/text/international/lang-sensitive-fonts-expected.html:
* fast/text/international/lang-sensitive-fonts-xml-expected.html:
* fast/text/international/lang-sensitive-fonts-xml.xhtml:
* fast/text/international/lang-sensitive-fonts.html:
* fast/text/international/locale-sensitive-fonts-expected.html:
* fast/text/international/locale-sensitive-fonts.html:
* fast/text/ja-sans-serif-expected-mismatch.html: Added.
* fast/text/ja-sans-serif.html: Added.
* platform/ios/fast/block/float/016-expected.txt:

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

29 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/text/international/font-fallback-to-common-script-expected.html [deleted file]
LayoutTests/fast/text/international/font-fallback-to-common-script.html [deleted file]
LayoutTests/fast/text/international/lang-sensitive-fonts-expected.html
LayoutTests/fast/text/international/lang-sensitive-fonts-xml-expected.html
LayoutTests/fast/text/international/lang-sensitive-fonts-xml.xhtml
LayoutTests/fast/text/international/lang-sensitive-fonts.html
LayoutTests/fast/text/international/locale-sensitive-fonts-expected.html
LayoutTests/fast/text/international/locale-sensitive-fonts.html
LayoutTests/fast/text/ja-sans-serif-expected-mismatch.html [new file with mode: 0644]
LayoutTests/fast/text/ja-sans-serif.html [new file with mode: 0644]
LayoutTests/platform/ios/fast/block/float/016-expected.txt
Source/WTF/ChangeLog
Source/WTF/wtf/Platform.h
Source/WebCore/ChangeLog
Source/WebCore/PAL/ChangeLog
Source/WebCore/PAL/pal/spi/cocoa/CoreTextSPI.h
Source/WebCore/css/CSSComputedStyleDeclaration.cpp
Source/WebCore/css/CSSFontSelector.cpp
Source/WebCore/css/parser/CSSPropertyParser.cpp
Source/WebCore/page/cocoa/SettingsBaseCocoa.mm
Source/WebCore/platform/graphics/FontDescription.cpp
Source/WebCore/platform/graphics/FontDescription.h
Source/WebCore/platform/graphics/cocoa/FontDescriptionCocoa.cpp
Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp
Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.h
Tools/ChangeLog
Tools/DumpRenderTree/mac/DumpRenderTree.mm
Tools/WebKitTestRunner/mac/TestControllerMac.mm

index 790c552..7d3bee2 100644 (file)
@@ -1,3 +1,25 @@
+2019-02-11  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        [Cocoa] Ask platform for generic font family mappings
+        https://bugs.webkit.org/show_bug.cgi?id=187723
+        <rdar://problem/41892438>
+
+        Reviewed by Brent Fulgham.
+
+        Update the tests to work with this new model.
+
+        * fast/text/international/font-fallback-to-common-script-expected.html: Removed.
+        * fast/text/international/font-fallback-to-common-script.html: Removed.
+        * fast/text/international/lang-sensitive-fonts-expected.html:
+        * fast/text/international/lang-sensitive-fonts-xml-expected.html:
+        * fast/text/international/lang-sensitive-fonts-xml.xhtml:
+        * fast/text/international/lang-sensitive-fonts.html:
+        * fast/text/international/locale-sensitive-fonts-expected.html:
+        * fast/text/international/locale-sensitive-fonts.html:
+        * fast/text/ja-sans-serif-expected-mismatch.html: Added.
+        * fast/text/ja-sans-serif.html: Added.
+        * platform/ios/fast/block/float/016-expected.txt:
+
 2019-02-11  Shawn Roberts  <sroberts@apple.com>
 
         Updating for all of Mac WK2 for flaky test
diff --git a/LayoutTests/fast/text/international/font-fallback-to-common-script-expected.html b/LayoutTests/fast/text/international/font-fallback-to-common-script-expected.html
deleted file mode 100644 (file)
index 02e21c4..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<html>
-<body>
-<div style="font-size: 20px">
-<div style="font-family: 'Ahem'">this is ahem font</div>
-<div style="font-family: 'Ahem'">this is ahem font</div>
-</div>
-</body>
-</html>
diff --git a/LayoutTests/fast/text/international/font-fallback-to-common-script.html b/LayoutTests/fast/text/international/font-fallback-to-common-script.html
deleted file mode 100644 (file)
index e78a435..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<script>
-if (window.internals) {
-    window.internals.settings.setStandardFontFamily("Times", "Hans");
-    window.internals.settings.setStandardFontFamily("", "Hans");
-    window.internals.settings.setStandardFontFamily("Ahem", "Zyyy");
-
-    window.internals.settings.setSansSerifFontFamily("Ahem", "Zyyy");
-
-    window.internals.setUserPreferredLanguages("en", "zh-cn");
-}
-</script>
-</head>
-<body>
-<!-- Test for font fallback to the common script when the per-script font setting is missing or the empty string.
-Bug 81329 <https://bugs.webkit.org/show_bug.cgi?id=81329> -->
-<div style="font-size: 20px">
-<div lang="zh-CN">this is ahem font</div>
-
-<!-- Test fallback to common script when no setting is set. This assumes there is no setting for "Zxxx" (script code for unwritten languages). -->
-<div lang="und-Zxxx" style="font-family: sans-serif;">this is ahem font</div>
-</div>
-</body>
-</html>
index 0060d23..7742f2f 100644 (file)
@@ -4,7 +4,6 @@
 <div style="font-family: 'Ahem'">this is ahem font</div>
 <div style="font-family: 'Ahem'">this is ahem font</div>
 <div style="font-family: 'Ahem'">this is ahem font</div>
-<div style="font-family: 'Ahem'">this is ahem font</div>
 <div>this is not ahem font</div>
 </div>
 </body>
index 66159b4..38ae279 100644 (file)
@@ -5,7 +5,6 @@
 <div>this is ahem font</div>
 <div>this is ahem font</div>
 <div>this is ahem font</div>
-<div>this is ahem font</div>
 </div>
 </body>
 </html>
index 17c0708..e7a874e 100644 (file)
@@ -21,14 +21,10 @@ font.
 <div style="font-family: 'Ahem'">this is ahem font</div>
 <div lang="zh-CN">this is ahem font</div>
 <div id="target1" lang="ar">this is ahem font</div>
-<div id="target2" lang="ar" style="font-family: sans-serif">this is ahem font</div>
 <div xml:lang="zh-CN">this is ahem font</div>
 </div>
 <script>
 document.getElementById("target1").lang = "zh-CN";
-
-document.getElementById("target2").lang = "zh-CN";
-document.getElementById("target2").style.fontFamily = "fantasy";
 </script>
 </body>
 </html>
index c7edd1c..92e832e 100644 (file)
@@ -20,14 +20,10 @@ font, except for the final div as xml:lang should be ignored in HTML.
 <div style="font-family: 'Ahem'">this is ahem font</div>
 <div lang="zh-CN">this is ahem font</div>
 <div id="target1" lang="ar">this is ahem font</div>
-<div id="target2" lang="ar" style="font-family: sans-serif">this is ahem font</div>
 <div xml:lang="zh-CN">this is not ahem font</div>
 </div>
 <script>
 document.getElementById("target1").lang = "zh-CN";
-
-document.getElementById("target2").lang = "zh-CN";
-document.getElementById("target2").style.fontFamily = "fantasy";
 </script>
 </body>
 </html>
index 64f9189..0810b6b 100644 (file)
@@ -6,7 +6,6 @@
 <div style="font-size: 20px">
 <div style="font-family: 'Ahem'">this is ahem font</div>
 <div style="font-family: 'Ahem'">this is ahem font</div>
-<div style="font-family: 'Ahem'">this is ahem font</div>
 </div>
 </body>
 </html>
index 4b40de4..66016a8 100644 (file)
@@ -16,7 +16,6 @@ fonts for Simplified Han are to Ahem font.  So all divs should match. -->
 <div style="font-size: 20px">
 <div style="font-family: 'Ahem'">this is ahem font</div>
 <div style="-webkit-locale: 'zh_CN'">this is ahem font</div>
-<div style="-webkit-locale: 'zh_CN'; font-family: fantasy">this is ahem font</div>
 </div>
 </body>
 </html>
diff --git a/LayoutTests/fast/text/ja-sans-serif-expected-mismatch.html b/LayoutTests/fast/text/ja-sans-serif-expected-mismatch.html
new file mode 100644 (file)
index 0000000..0b52aa7
--- /dev/null
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+</head>
+<body>
+<div lang="ja" style="font: 48px serif;">かくれキリシ</div>
+</body>
+</html>
diff --git a/LayoutTests/fast/text/ja-sans-serif.html b/LayoutTests/fast/text/ja-sans-serif.html
new file mode 100644 (file)
index 0000000..b675fd9
--- /dev/null
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+</head>
+<body>
+<div lang="ja" style="font: 48px sans-serif;">かくれキリシ</div>
+</body>
+</html>
index 6b9eeac..14704bf 100644 (file)
@@ -1,8 +1,8 @@
 layer at (0,0) size 800x600
   RenderView at (0,0) size 800x600
-layer at (0,0) size 800x511
-  RenderBlock {HTML} at (0,0) size 800x512
-    RenderBody {BODY} at (8,8) size 784x488
+layer at (0,0) size 800x512
+  RenderBlock {HTML} at (0,0) size 800x513
+    RenderBody {BODY} at (8,8) size 784x489
       RenderBlock {UL} at (185,0) size 414x192
         RenderListItem {LI} at (0,48) size 284x72
           RenderBlock {A} at (123,0) size 161x139 [color=#CCCCCC]
@@ -62,6 +62,6 @@ layer at (0,0) size 800x511
             RenderBlock {SPAN} at (8,61) size 144x21 [color=#000000]
               RenderText {#text} at (59,0) size 26x20
                 text run at (59,0) width 26: "exit"
-      RenderBlock {P} at (0,403) size 784x85
-        RenderText {#text} at (327,32) size 130x19
-          text run at (327,32) width 130: "Ceci n'est pas Flash."
+      RenderBlock {P} at (0,403) size 784x86
+        RenderText {#text} at (331,32) size 122x21
+          text run at (331,32) width 122: "Ceci n'est pas Flash."
index 823ab06..da5eece 100644 (file)
@@ -1,3 +1,15 @@
+2019-02-11  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        [Cocoa] Ask platform for generic font family mappings
+        https://bugs.webkit.org/show_bug.cgi?id=187723
+        <rdar://problem/41892438>
+
+        Reviewed by Brent Fulgham.
+
+        Add an ENABLE in Platform.
+
+        * wtf/Platform.h:
+
 2019-02-11  Truitt Savell  <tsavell@apple.com>
 
         Unreviewed, rolling out r241229.
index 87f8cd3..8ccbcab 100644 (file)
 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500
 #define HAVE_CSCHECKFIXDISABLE 1
 #endif
+
+#if PLATFORM(MAC)
+#define ENABLE_MONOSPACE_FONT_EXCEPTION (__MAC_OS_X_VERSION_MIN_REQUIRED < 101500)
+#elif PLATFORM(IOS_FAMILY)
+#define ENABLE_MONOSPACE_FONT_EXCEPTION (__IPHONE_OS_VERSION_MIN_REQUIRED < 130000)
+#endif
index 6b5b3e0..18ee725 100644 (file)
@@ -1,3 +1,57 @@
+2019-02-11  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        [Cocoa] Ask platform for generic font family mappings
+        https://bugs.webkit.org/show_bug.cgi?id=187723
+        <rdar://problem/41892438>
+
+        Reviewed by Brent Fulgham.
+
+        WebKit API allows setting the generic font families for the USCRIPT_COMMON script.
+        When trying to style a character with a generic font family, we first look to see if
+        we have a mapping for the particular script the character is rendered with, and if we
+        don't find a match, we then check USCRIPT_COMMON.
+
+        In the Cocoa ports, the only way families get set for non-USCRIPT_COMMON scripts (aka
+        the only scripts which won't use the API families) is in
+        SettingsBase::initializeDefaultFontFamilies(). That function only sets the families
+        for the CJK scripts.
+
+        The mappings inside SettingsBase are incorrect and conflict with our policy regarding
+        user-installed fonts. Instead, we should be consulting with the platform for some of
+        these mappings, by calling CTFontDescriptorCreateForCSSFamily(). However, the WebKit
+        API still has to work to set the mappings for untagged content. Therefore, we use the
+        system mappings for language-tagged content, and the API mappings for non-language-tagged
+        content. This is a good balance that makes sure we always have a good mapping for every
+        language, but API clients can still set the mappings, too.
+
+        Test: fast/text/ja-sans-serif.html
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        * css/CSSFontSelector.cpp:
+        (WebCore::resolveGenericFamily):
+        * css/parser/CSSPropertyParser.cpp:
+        (WebCore::consumeFontFamily):
+        * page/cocoa/SettingsBaseCocoa.mm:
+        (WebCore::SettingsBase::initializeDefaultFontFamilies):
+        (WebCore::osakaMonoIsInstalled): Deleted.
+        * platform/graphics/FontDescription.cpp:
+        (WebCore::FontDescription::platformResolveGenericFamily):
+        * platform/graphics/FontDescription.h:
+        * platform/graphics/cocoa/FontDescriptionCocoa.cpp:
+        (WebCore::computeSpecializedChineseLocale):
+        (WebCore::cachedSpecializedChineseLocale):
+        (WebCore::languageChanged):
+        (WebCore::FontDescription::platformResolveGenericFamily):
+        * platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp:
+        (WebCore::SystemFontDatabaseCoreText::clear):
+        (WebCore::genericFamily):
+        (WebCore::SystemFontDatabaseCoreText::serifFamily):
+        (WebCore::SystemFontDatabaseCoreText::sansSerifFamily):
+        (WebCore::SystemFontDatabaseCoreText::cursiveFamily):
+        (WebCore::SystemFontDatabaseCoreText::fantasyFamily):
+        (WebCore::SystemFontDatabaseCoreText::monospaceFamily):
+        * platform/graphics/cocoa/SystemFontDatabaseCoreText.h:
+
 2019-02-11  Adrian Perez de Castro  <aperez@igalia.com>
 
         [GTK][WPE] Add content extensions support in WKTR and unskip layout tests
index 1ad95ca..9d9abaa 100644 (file)
@@ -1,3 +1,13 @@
+2019-02-11  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        [Cocoa] Ask platform for generic font family mappings
+        https://bugs.webkit.org/show_bug.cgi?id=187723
+        <rdar://problem/41892438>
+
+        Reviewed by Brent Fulgham.
+
+        * pal/spi/cocoa/CoreTextSPI.h:
+
 2019-02-11  Jer Noble  <jer.noble@apple.com>
 
         [Cocoa] Notify AVSystemController of our presenting PID before registering as a Now Playing app.
index 09af37d..d62bb25 100644 (file)
@@ -79,6 +79,13 @@ extern const CFStringRef kCTFontPostScriptNameAttribute;
 extern const CFStringRef kCTFontUserInstalledAttribute;
 extern const CFStringRef kCTFontFallbackOptionAttribute;
 
+extern const CFStringRef kCTFontCSSFamilySerif;
+extern const CFStringRef kCTFontCSSFamilySansSerif;
+extern const CFStringRef kCTFontCSSFamilyCursive;
+extern const CFStringRef kCTFontCSSFamilyFantasy;
+extern const CFStringRef kCTFontCSSFamilyMonospace;
+extern const CFStringRef kCTFontCSSFamilySystemUI;
+
 bool CTFontTransformGlyphs(CTFontRef, CGGlyph glyphs[], CGSize advances[], CFIndex count, CTFontTransformOptions);
 
 CGSize CTRunGetInitialAdvance(CTRunRef);
@@ -87,6 +94,7 @@ void CTRunGetBaseAdvancesAndOrigins(CTRunRef, CFRange, CGSize baseAdvances[], CG
 CTTypesetterRef CTTypesetterCreateWithUniCharProviderAndOptions(CTUniCharProviderCallback, CTUniCharDisposeCallback, void* refCon, CFDictionaryRef options);
 bool CTFontGetVerticalGlyphsForCharacters(CTFontRef, const UniChar characters[], CGGlyph glyphs[], CFIndex count);
 void CTFontGetUnsummedAdvancesForGlyphsAndStyle(CTFontRef, CTFontOrientation, CGFontRenderingStyle, const CGGlyph[], CGSize advances[], CFIndex count);
+CTFontDescriptorRef CTFontDescriptorCreateForCSSFamily(CFStringRef cssFamily, CFStringRef language);
 
 CTFontDescriptorRef CTFontDescriptorCreateForUIType(CTFontUIFontType, CGFloat size, CFStringRef language);
 CTFontDescriptorRef CTFontDescriptorCreateWithTextStyle(CFStringRef style, CFStringRef size, CFStringRef language);
index 5aaae72..977eca3 100644 (file)
@@ -1720,7 +1720,6 @@ bool ComputedStyleExtractor::useFixedFontDefaultSize()
     return style->fontDescription().useFixedDefaultSize();
 }
 
-
 static CSSValueID identifierForFamily(const AtomicString& family)
 {
     if (family == cursiveFamily)
index d55127b..4afb42e 100644 (file)
@@ -274,8 +274,12 @@ void CSSFontSelector::fontCacheInvalidated()
     dispatchInvalidationCallbacks();
 }
 
-static const AtomicString& resolveGenericFamily(Document* document, const FontDescription& fontDescription, const AtomicString& familyName)
+static AtomicString resolveGenericFamily(Document* document, const FontDescription& fontDescription, const AtomicString& familyName)
 {
+    auto platformResult = FontDescription::platformResolveGenericFamily(fontDescription.script(), fontDescription.locale(), familyName);
+    if (!platformResult.isNull())
+        return platformResult;
+
     if (!document)
         return familyName;
 
index 2f536e9..b6f117c 100644 (file)
@@ -1067,16 +1067,13 @@ static RefPtr<CSSValueList> consumeFontFamily(CSSParserTokenRange& range)
 {
     RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
     do {
-        RefPtr<CSSValue> parsedValue = consumeGenericFamily(range);
-        if (parsedValue) {
+        if (auto parsedValue = consumeGenericFamily(range))
             list->append(parsedValue.releaseNonNull());
-        } else {
-            parsedValue = consumeFamilyName(range);
-            if (parsedValue) {
+        else {
+            if (auto parsedValue = consumeFamilyName(range))
                 list->append(parsedValue.releaseNonNull());
-            } else {
+            else
                 return nullptr;
-            }
         }
     } while (consumeCommaIncludingWhitespace(range));
     return list;
index 57f825d..89ca139 100644 (file)
@@ -48,41 +48,12 @@ static inline const char* sansSerifSimplifiedHanFontFamily()
 
 #if PLATFORM(MAC)
 
-static bool osakaMonoIsInstalled()
-{
-    int one = 1;
-    RetainPtr<CFNumberRef> yes = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &one));
-    CFTypeRef keys[] = { kCTFontEnabledAttribute, kCTFontNameAttribute };
-    CFTypeRef values[] = { yes.get(), CFSTR("Osaka-Mono") };
-    RetainPtr<CFDictionaryRef> attributes = adoptCF(CFDictionaryCreate(kCFAllocatorDefault, keys, values, WTF_ARRAY_LENGTH(values), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
-    RetainPtr<CTFontDescriptorRef> descriptor = adoptCF(CTFontDescriptorCreateWithAttributes(attributes.get()));
-    RetainPtr<CFSetRef> mandatoryAttributes = adoptCF(CFSetCreate(kCFAllocatorDefault, keys, WTF_ARRAY_LENGTH(keys), &kCFTypeSetCallBacks));
-    return adoptCF(CTFontDescriptorCreateMatchingFontDescriptor(descriptor.get(), mandatoryAttributes.get()));
-}
-
 void SettingsBase::initializeDefaultFontFamilies()
 {
     setStandardFontFamily("Songti TC", USCRIPT_TRADITIONAL_HAN);
-    setSerifFontFamily("Songti TC", USCRIPT_TRADITIONAL_HAN);
-    setFixedFontFamily(sansSerifTraditionalHanFontFamily(), USCRIPT_TRADITIONAL_HAN);
-    setSansSerifFontFamily(sansSerifTraditionalHanFontFamily(), USCRIPT_TRADITIONAL_HAN);
-    setCursiveFontFamily("Kaiti TC", USCRIPT_TRADITIONAL_HAN);
-
     setStandardFontFamily("Songti SC", USCRIPT_SIMPLIFIED_HAN);
-    setSerifFontFamily("Songti SC", USCRIPT_SIMPLIFIED_HAN);
-    setFixedFontFamily(sansSerifSimplifiedHanFontFamily(), USCRIPT_SIMPLIFIED_HAN);
-    setSansSerifFontFamily(sansSerifSimplifiedHanFontFamily(), USCRIPT_SIMPLIFIED_HAN);
-    setCursiveFontFamily("Kaiti SC", USCRIPT_SIMPLIFIED_HAN);
-
     setStandardFontFamily("Hiragino Mincho ProN", USCRIPT_KATAKANA_OR_HIRAGANA);
-    setFixedFontFamily(osakaMonoIsInstalled() ? "Osaka-Mono" : "Hiragino Sans", USCRIPT_KATAKANA_OR_HIRAGANA);
-    setSerifFontFamily("Hiragino Mincho ProN", USCRIPT_KATAKANA_OR_HIRAGANA);
-    setSansSerifFontFamily("Hiragino Kaku Gothic ProN", USCRIPT_KATAKANA_OR_HIRAGANA);
-
     setStandardFontFamily("AppleMyungjo", USCRIPT_HANGUL);
-    setSerifFontFamily("AppleMyungjo", USCRIPT_HANGUL);
-    setFixedFontFamily("Apple SD Gothic Neo", USCRIPT_HANGUL);
-    setSansSerifFontFamily("Apple SD Gothic Neo", USCRIPT_HANGUL);
 
     setStandardFontFamily("Times", USCRIPT_COMMON);
     setFixedFontFamily("Courier", USCRIPT_COMMON);
@@ -99,28 +70,10 @@ bool SettingsBase::platformDefaultMediaSourceEnabled()
 
 void SettingsBase::initializeDefaultFontFamilies()
 {
-    // There is no serif Chinese font in default iOS installation.
     setStandardFontFamily(sansSerifTraditionalHanFontFamily(), USCRIPT_TRADITIONAL_HAN);
-    setSerifFontFamily(sansSerifTraditionalHanFontFamily(), USCRIPT_TRADITIONAL_HAN);
-    setFixedFontFamily(sansSerifTraditionalHanFontFamily(), USCRIPT_TRADITIONAL_HAN);
-    setSansSerifFontFamily(sansSerifTraditionalHanFontFamily(), USCRIPT_TRADITIONAL_HAN);
-
-    // There is no serif Chinese font in default iOS installation.
     setStandardFontFamily(sansSerifSimplifiedHanFontFamily(), USCRIPT_SIMPLIFIED_HAN);
-    setSerifFontFamily(sansSerifSimplifiedHanFontFamily(), USCRIPT_SIMPLIFIED_HAN);
-    setFixedFontFamily(sansSerifSimplifiedHanFontFamily(), USCRIPT_SIMPLIFIED_HAN);
-    setSansSerifFontFamily(sansSerifSimplifiedHanFontFamily(), USCRIPT_SIMPLIFIED_HAN);
-
     setStandardFontFamily("Hiragino Mincho ProN", USCRIPT_KATAKANA_OR_HIRAGANA);
-    setFixedFontFamily("Hiragino Kaku Gothic ProN", USCRIPT_KATAKANA_OR_HIRAGANA);
-    setSerifFontFamily("Hiragino Mincho ProN", USCRIPT_KATAKANA_OR_HIRAGANA);
-    setSansSerifFontFamily("Hiragino Kaku Gothic ProN", USCRIPT_KATAKANA_OR_HIRAGANA);
-
-    // There is no serif Korean font in default iOS installation.
     setStandardFontFamily("Apple SD Gothic Neo", USCRIPT_HANGUL);
-    setSerifFontFamily("Apple SD Gothic Neo", USCRIPT_HANGUL);
-    setFixedFontFamily("Apple SD Gothic Neo", USCRIPT_HANGUL);
-    setSansSerifFontFamily("Apple SD Gothic Neo", USCRIPT_HANGUL);
 
     setStandardFontFamily("Times", USCRIPT_COMMON);
     setFixedFontFamily("Courier", USCRIPT_COMMON);
index df590bb..b8b46e7 100644 (file)
@@ -71,4 +71,11 @@ void FontDescription::setLocale(const AtomicString& locale)
     m_script = localeToScriptCodeForFontSelection(m_locale);
 }
 
+#if !PLATFORM(COCOA)
+AtomicString FontDescription::platformResolveGenericFamily(UScriptCode, const AtomicString&, const AtomicString&)
+{
+    return nullAtom();
+}
+#endif
+
 } // namespace WebCore
index 99bd407..cb05cf5 100644 (file)
@@ -133,6 +133,8 @@ public:
     void setFontStyleAxis(FontStyleAxis axis) { m_fontStyleAxis = axis == FontStyleAxis::ital; }
     void setShouldAllowUserInstalledFonts(AllowUserInstalledFonts shouldAllowUserInstalledFonts) { m_shouldAllowUserInstalledFonts = static_cast<unsigned>(shouldAllowUserInstalledFonts); }
 
+    static AtomicString platformResolveGenericFamily(UScriptCode, const AtomicString& locale, const AtomicString& familyName);
+
 private:
     // FIXME: Investigate moving these into their own object on the heap (to save memory).
     FontFeatureSettings m_featureSettings;
index 8a3309d..9fe2cca 100644 (file)
 #include "FontDescription.h"
 
 #include "SystemFontDatabaseCoreText.h"
-
-#if USE_PLATFORM_SYSTEM_FALLBACK_LIST
+#include <mutex>
+#include <wtf/Language.h>
 
 namespace WebCore {
 
+#if USE_PLATFORM_SYSTEM_FALLBACK_LIST
+
 static inline bool isSystemFontString(const AtomicString& string)
 {
     return equalLettersIgnoringASCIICase(string, "-webkit-system-font")
@@ -138,7 +140,58 @@ FontFamilySpecification FontCascadeDescription::effectiveFamilyAt(unsigned index
     return nullAtom();
 }
 
+#endif // USE_PLATFORM_SYSTEM_FALLBACK_LIST
+
+static String computeSpecializedChineseLocale()
+{
+    const Vector<String>& preferredLanguages = userPreferredLanguages();
+    for (auto& language : preferredLanguages) {
+        if (equalIgnoringASCIICase(language, "zh") || startsWithLettersIgnoringASCIICase(language, "zh-"))
+            return language;
+    }
+    return "zh-hans"_str; // We have no signal. Pick one option arbitrarily.
+}
+
+static String& cachedSpecializedChineseLocale()
+{
+    static NeverDestroyed<String> specializedChineseLocale;
+    return specializedChineseLocale.get();
 }
 
-#endif
+static void languageChanged(void*)
+{
+    cachedSpecializedChineseLocale() = computeSpecializedChineseLocale();
+}
+
+AtomicString FontDescription::platformResolveGenericFamily(UScriptCode script, const AtomicString& locale, const AtomicString& familyName)
+{
+    if (script == USCRIPT_COMMON)
+        return nullAtom();
+
+    static std::once_flag onceFlag;
+    std::call_once(onceFlag, [&] {
+        static char dummy;
+        addLanguageChangeObserver(&dummy, &languageChanged); // We will never remove the observer, so all we need is a non-null pointer.
+        languageChanged(nullptr);
+    });
+
+    // FIXME: Delete this once <rdar://problem/47682577> is fixed.
+    auto& usedLocale = script == USCRIPT_HAN ? cachedSpecializedChineseLocale() : locale.string();
+
+    // FIXME: Use the system font database to handle standardFamily
+    if (familyName == serifFamily)
+        return SystemFontDatabaseCoreText::singleton().serifFamily(usedLocale);
+    if (familyName == sansSerifFamily)
+        return SystemFontDatabaseCoreText::singleton().sansSerifFamily(usedLocale);
+    if (familyName == cursiveFamily)
+        return SystemFontDatabaseCoreText::singleton().cursiveFamily(usedLocale);
+    if (familyName == fantasyFamily)
+        return SystemFontDatabaseCoreText::singleton().fantasyFamily(usedLocale);
+    if (familyName == monospaceFamily)
+        return SystemFontDatabaseCoreText::singleton().monospaceFamily(usedLocale);
+
+    return nullAtom();
+}
+
+}
 
index b4a396d..b134681 100644 (file)
@@ -26,8 +26,6 @@
 #include "config.h"
 #include "SystemFontDatabaseCoreText.h"
 
-#if USE_PLATFORM_SYSTEM_FALLBACK_LIST
-
 #include "FontCache.h"
 #include "FontCascadeDescription.h"
 
@@ -47,6 +45,8 @@ SystemFontDatabaseCoreText::SystemFontDatabaseCoreText()
 {
 }
 
+#if USE_PLATFORM_SYSTEM_FALLBACK_LIST
+
 Vector<RetainPtr<CTFontDescriptorRef>> SystemFontDatabaseCoreText::cascadeList(const CascadeListParameters& parameters, ClientUse clientUse)
 {
     ASSERT(!parameters.fontName.isNull());
@@ -80,6 +80,11 @@ Vector<RetainPtr<CTFontDescriptorRef>> SystemFontDatabaseCoreText::cascadeList(c
 void SystemFontDatabaseCoreText::clear()
 {
     m_systemFontCache.clear();
+    m_serifFamilies.clear();
+    m_sansSeriferifFamilies.clear();
+    m_cursiveFamilies.clear();
+    m_fantasyFamilies.clear();
+    m_monospaceFamilies.clear();
 }
 
 RetainPtr<CTFontRef> SystemFontDatabaseCoreText::applyWeightItalicsAndFallbackBehavior(CTFontRef font, CGFloat weight, bool italic, float size, AllowUserInstalledFonts allowUserInstalledFonts)
@@ -172,6 +177,49 @@ Vector<RetainPtr<CTFontDescriptorRef>> SystemFontDatabaseCoreText::cascadeList(c
     return cascadeList(systemFontParameters(description, cssFamily, clientUse, allowUserInstalledFonts), clientUse);
 }
 
+#endif // USE_PLATFORM_SYSTEM_FALLBACK_LIST
+
+static String genericFamily(const String& locale, HashMap<String, String>& map, CFStringRef ctKey)
+{
+    return map.ensure(locale, [&] {
+        auto descriptor = adoptCF(CTFontDescriptorCreateForCSSFamily(ctKey, locale.createCFString().get()));
+        return adoptCF(static_cast<CFStringRef>(CTFontDescriptorCopyAttribute(descriptor.get(), kCTFontFamilyNameAttribute))).get();
+    }).iterator->value;
+}
+
+String SystemFontDatabaseCoreText::serifFamily(const String& locale)
+{
+    return genericFamily(locale, m_serifFamilies, kCTFontCSSFamilySerif);
+}
+
+String SystemFontDatabaseCoreText::sansSerifFamily(const String& locale)
+{
+    return genericFamily(locale, m_sansSeriferifFamilies, kCTFontCSSFamilySansSerif);
+}
+
+String SystemFontDatabaseCoreText::cursiveFamily(const String& locale)
+{
+    return genericFamily(locale, m_cursiveFamilies, kCTFontCSSFamilyCursive);
+}
+
+String SystemFontDatabaseCoreText::fantasyFamily(const String& locale)
+{
+    return genericFamily(locale, m_fantasyFamilies, kCTFontCSSFamilyFantasy);
 }
 
+String SystemFontDatabaseCoreText::monospaceFamily(const String& locale)
+{
+    auto result = genericFamily(locale, m_monospaceFamilies, kCTFontCSSFamilyMonospace);
+#if PLATFORM(MAC) && ENABLE(MONOSPACE_FONT_EXCEPTION)
+    // In general, CoreText uses Monaco for monospaced (see: Terminal.app and Xcode.app).
+    // For now, we want to use Courier for web compatibility, until we have more time to do compatibility testing.
+    if (equalLettersIgnoringASCIICase(result, "monaco"))
+        return "Courier"_str;
+#elif PLATFORM(IOS_FAMILY) && ENABLE(MONOSPACE_FONT_EXCEPTION)
+    if (equalLettersIgnoringASCIICase(result, "courier new"))
+        return "Courier"_str;
 #endif
+    return result;
+}
+
+}
index 8359a41..35e3546 100644 (file)
@@ -32,8 +32,6 @@
 #include <wtf/text/AtomicString.h>
 #include <wtf/text/AtomicStringHash.h>
 
-#if USE_PLATFORM_SYSTEM_FALLBACK_LIST
-
 namespace WebCore {
 
 class SystemFontDatabaseCoreText {
@@ -101,6 +99,13 @@ public:
     enum class ClientUse { ForSystemUI, ForTextStyle };
 
     Vector<RetainPtr<CTFontDescriptorRef>> cascadeList(const FontCascadeDescription&, const AtomicString& cssFamily, ClientUse, AllowUserInstalledFonts);
+
+    String serifFamily(const String& locale);
+    String sansSerifFamily(const String& locale);
+    String cursiveFamily(const String& locale);
+    String fantasyFamily(const String& locale);
+    String monospaceFamily(const String& locale);
+
     void clear();
 
 private:
@@ -114,8 +119,12 @@ private:
     static CascadeListParameters systemFontParameters(const FontCascadeDescription&, const AtomicString& familyName, ClientUse, AllowUserInstalledFonts);
 
     HashMap<CascadeListParameters, Vector<RetainPtr<CTFontDescriptorRef>>, CascadeListParameters::CascadeListParametersHash, SimpleClassHashTraits<CascadeListParameters>> m_systemFontCache;
+
+    HashMap<String, String> m_serifFamilies;
+    HashMap<String, String> m_sansSeriferifFamilies;
+    HashMap<String, String> m_cursiveFamilies;
+    HashMap<String, String> m_fantasyFamilies;
+    HashMap<String, String> m_monospaceFamilies;
 };
 
 }
-
-#endif
index f2930ce..41ae710 100644 (file)
@@ -1,3 +1,18 @@
+2019-02-11  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        [Cocoa] Ask platform for generic font family mappings
+        https://bugs.webkit.org/show_bug.cgi?id=187723
+        <rdar://problem/41892438>
+
+        Reviewed by Brent Fulgham.
+
+        Allow testing infrastructure to use fonts that are returned from CTFontDescriptorCreateForCSSFamily().
+
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (allowedFontFamilySet):
+        * WebKitTestRunner/mac/TestControllerMac.mm:
+        (WTR::allowedFontFamilySet):
+
 2019-02-11  Adrian Perez de Castro  <aperez@igalia.com>
 
         [GTK][WPE] Add content extensions support in WKTR and unskip layout tests
index 255be2d..b052412 100644 (file)
@@ -377,6 +377,7 @@ static NSSet *allowedFontFamilySet()
         @"Hiragino Maru Gothic ProN",
         @"Hiragino Mincho Pro",
         @"Hiragino Mincho ProN",
+        @"Hiragino Sans",
         @"Hiragino Sans GB",
         @"Hoefler Text",
         @"Impact",
@@ -386,6 +387,7 @@ static NSSet *allowedFontFamilySet()
         @"Kokonor",
         @"Krungthep",
         @"KufiStandardGK",
+        @"Lao Sangam MN",
         @"LastResort",
         @"LiHei Pro",
         @"LiSong Pro",
@@ -403,11 +405,15 @@ static NSSet *allowedFontFamilySet()
         @"Papyrus",
         @"PCMyungjo",
         @"PilGi",
+        @"PingFang HK",
+        @"PingFang SC",
+        @"PingFang TC",
         @"Plantagenet Cherokee",
         @"Raanana",
         @"Sathu",
         @"Silom",
         @"Skia",
+        @"Snell Roundhand",
         @"Songti SC",
         @"Songti TC",
         @"STFangsong",
index 31eda93..3e773bc 100644 (file)
@@ -226,6 +226,7 @@ static NSSet *allowedFontFamilySet()
         @"Hiragino Maru Gothic ProN",
         @"Hiragino Mincho Pro",
         @"Hiragino Mincho ProN",
+        @"Hiragino Sans",
         @"Hiragino Sans GB",
         @"Hoefler Text",
         @"Impact",
@@ -235,6 +236,7 @@ static NSSet *allowedFontFamilySet()
         @"Kokonor",
         @"Krungthep",
         @"KufiStandardGK",
+        @"Lao Sangam MN",
         @"LastResort",
         @"LiHei Pro",
         @"LiSong Pro",
@@ -252,11 +254,15 @@ static NSSet *allowedFontFamilySet()
         @"Papyrus",
         @"PCMyungjo",
         @"PilGi",
+        @"PingFang HK",
+        @"PingFang SC",
+        @"PingFang TC",
         @"Plantagenet Cherokee",
         @"Raanana",
         @"Sathu",
         @"Silom",
         @"Skia",
+        @"Snell Roundhand",
         @"Songti SC",
         @"Songti TC",
         @"STFangsong",