Changeset 241288 in webkit


Ignore:
Timestamp:
Feb 11, 2019 6:19:19 PM (5 years ago)
Author:
mmaxfield@apple.com
Message:

[Cocoa] Ask platform for generic font family mappings
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:
Location:
trunk
Files:
2 added
2 deleted
25 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r241286 r241288  
     12019-02-11  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        [Cocoa] Ask platform for generic font family mappings
     4        https://bugs.webkit.org/show_bug.cgi?id=187723
     5        <rdar://problem/41892438>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        Update the tests to work with this new model.
     10
     11        * fast/text/international/font-fallback-to-common-script-expected.html: Removed.
     12        * fast/text/international/font-fallback-to-common-script.html: Removed.
     13        * fast/text/international/lang-sensitive-fonts-expected.html:
     14        * fast/text/international/lang-sensitive-fonts-xml-expected.html:
     15        * fast/text/international/lang-sensitive-fonts-xml.xhtml:
     16        * fast/text/international/lang-sensitive-fonts.html:
     17        * fast/text/international/locale-sensitive-fonts-expected.html:
     18        * fast/text/international/locale-sensitive-fonts.html:
     19        * fast/text/ja-sans-serif-expected-mismatch.html: Added.
     20        * fast/text/ja-sans-serif.html: Added.
     21        * platform/ios/fast/block/float/016-expected.txt:
     22
    1232019-02-11  Shawn Roberts  <sroberts@apple.com>
    224
  • trunk/LayoutTests/fast/text/international/lang-sensitive-fonts-expected.html

    r241268 r241288  
    22<body>
    33<div style="font-size: 20px">
    4 <div style="font-family: 'Ahem'">this is ahem font</div>
    54<div style="font-family: 'Ahem'">this is ahem font</div>
    65<div style="font-family: 'Ahem'">this is ahem font</div>
  • trunk/LayoutTests/fast/text/international/lang-sensitive-fonts-xml-expected.html

    r241268 r241288  
    66<div>this is ahem font</div>
    77<div>this is ahem font</div>
    8 <div>this is ahem font</div>
    98</div>
    109</body>
  • trunk/LayoutTests/fast/text/international/lang-sensitive-fonts-xml.xhtml

    r241268 r241288  
    2222<div lang="zh-CN">this is ahem font</div>
    2323<div id="target1" lang="ar">this is ahem font</div>
    24 <div id="target2" lang="ar" style="font-family: sans-serif">this is ahem font</div>
    2524<div xml:lang="zh-CN">this is ahem font</div>
    2625</div>
    2726<script>
    2827document.getElementById("target1").lang = "zh-CN";
    29 
    30 document.getElementById("target2").lang = "zh-CN";
    31 document.getElementById("target2").style.fontFamily = "fantasy";
    3228</script>
    3329</body>
  • trunk/LayoutTests/fast/text/international/lang-sensitive-fonts.html

    r241268 r241288  
    2121<div lang="zh-CN">this is ahem font</div>
    2222<div id="target1" lang="ar">this is ahem font</div>
    23 <div id="target2" lang="ar" style="font-family: sans-serif">this is ahem font</div>
    2423<div xml:lang="zh-CN">this is not ahem font</div>
    2524</div>
    2625<script>
    2726document.getElementById("target1").lang = "zh-CN";
    28 
    29 document.getElementById("target2").lang = "zh-CN";
    30 document.getElementById("target2").style.fontFamily = "fantasy";
    3127</script>
    3228</body>
  • trunk/LayoutTests/fast/text/international/locale-sensitive-fonts-expected.html

    r241268 r241288  
    77<div style="font-family: 'Ahem'">this is ahem font</div>
    88<div style="font-family: 'Ahem'">this is ahem font</div>
    9 <div style="font-family: 'Ahem'">this is ahem font</div>
    109</div>
    1110</body>
  • trunk/LayoutTests/fast/text/international/locale-sensitive-fonts.html

    r241268 r241288  
    1717<div style="font-family: 'Ahem'">this is ahem font</div>
    1818<div style="-webkit-locale: 'zh_CN'">this is ahem font</div>
    19 <div style="-webkit-locale: 'zh_CN'; font-family: fantasy">this is ahem font</div>
    2019</div>
    2120</body>
  • trunk/LayoutTests/platform/ios/fast/block/float/016-expected.txt

    r241268 r241288  
    11layer at (0,0) size 800x600
    22  RenderView at (0,0) size 800x600
    3 layer at (0,0) size 800x511
    4   RenderBlock {HTML} at (0,0) size 800x512
    5     RenderBody {BODY} at (8,8) size 784x488
     3layer at (0,0) size 800x512
     4  RenderBlock {HTML} at (0,0) size 800x513
     5    RenderBody {BODY} at (8,8) size 784x489
    66      RenderBlock {UL} at (185,0) size 414x192
    77        RenderListItem {LI} at (0,48) size 284x72
     
    6363              RenderText {#text} at (59,0) size 26x20
    6464                text run at (59,0) width 26: "exit"
    65       RenderBlock {P} at (0,403) size 784x85
    66         RenderText {#text} at (327,32) size 130x19
    67           text run at (327,32) width 130: "Ceci n'est pas Flash."
     65      RenderBlock {P} at (0,403) size 784x86
     66        RenderText {#text} at (331,32) size 122x21
     67          text run at (331,32) width 122: "Ceci n'est pas Flash."
  • trunk/Source/WTF/ChangeLog

    r241268 r241288  
     12019-02-11  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        [Cocoa] Ask platform for generic font family mappings
     4        https://bugs.webkit.org/show_bug.cgi?id=187723
     5        <rdar://problem/41892438>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        Add an ENABLE in Platform.
     10
     11        * wtf/Platform.h:
     12
    1132019-02-11  Truitt Savell  <tsavell@apple.com>
    214
  • trunk/Source/WTF/wtf/Platform.h

    r241268 r241288  
    14991499#define HAVE_CSCHECKFIXDISABLE 1
    15001500#endif
     1501
     1502#if PLATFORM(MAC)
     1503#define ENABLE_MONOSPACE_FONT_EXCEPTION (__MAC_OS_X_VERSION_MIN_REQUIRED < 101500)
     1504#elif PLATFORM(IOS_FAMILY)
     1505#define ENABLE_MONOSPACE_FONT_EXCEPTION (__IPHONE_OS_VERSION_MIN_REQUIRED < 130000)
     1506#endif
  • trunk/Source/WebCore/ChangeLog

    r241283 r241288  
     12019-02-11  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        [Cocoa] Ask platform for generic font family mappings
     4        https://bugs.webkit.org/show_bug.cgi?id=187723
     5        <rdar://problem/41892438>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        WebKit API allows setting the generic font families for the USCRIPT_COMMON script.
     10        When trying to style a character with a generic font family, we first look to see if
     11        we have a mapping for the particular script the character is rendered with, and if we
     12        don't find a match, we then check USCRIPT_COMMON.
     13
     14        In the Cocoa ports, the only way families get set for non-USCRIPT_COMMON scripts (aka
     15        the only scripts which won't use the API families) is in
     16        SettingsBase::initializeDefaultFontFamilies(). That function only sets the families
     17        for the CJK scripts.
     18
     19        The mappings inside SettingsBase are incorrect and conflict with our policy regarding
     20        user-installed fonts. Instead, we should be consulting with the platform for some of
     21        these mappings, by calling CTFontDescriptorCreateForCSSFamily(). However, the WebKit
     22        API still has to work to set the mappings for untagged content. Therefore, we use the
     23        system mappings for language-tagged content, and the API mappings for non-language-tagged
     24        content. This is a good balance that makes sure we always have a good mapping for every
     25        language, but API clients can still set the mappings, too.
     26
     27        Test: fast/text/ja-sans-serif.html
     28
     29        * css/CSSComputedStyleDeclaration.cpp:
     30        * css/CSSFontSelector.cpp:
     31        (WebCore::resolveGenericFamily):
     32        * css/parser/CSSPropertyParser.cpp:
     33        (WebCore::consumeFontFamily):
     34        * page/cocoa/SettingsBaseCocoa.mm:
     35        (WebCore::SettingsBase::initializeDefaultFontFamilies):
     36        (WebCore::osakaMonoIsInstalled): Deleted.
     37        * platform/graphics/FontDescription.cpp:
     38        (WebCore::FontDescription::platformResolveGenericFamily):
     39        * platform/graphics/FontDescription.h:
     40        * platform/graphics/cocoa/FontDescriptionCocoa.cpp:
     41        (WebCore::computeSpecializedChineseLocale):
     42        (WebCore::cachedSpecializedChineseLocale):
     43        (WebCore::languageChanged):
     44        (WebCore::FontDescription::platformResolveGenericFamily):
     45        * platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp:
     46        (WebCore::SystemFontDatabaseCoreText::clear):
     47        (WebCore::genericFamily):
     48        (WebCore::SystemFontDatabaseCoreText::serifFamily):
     49        (WebCore::SystemFontDatabaseCoreText::sansSerifFamily):
     50        (WebCore::SystemFontDatabaseCoreText::cursiveFamily):
     51        (WebCore::SystemFontDatabaseCoreText::fantasyFamily):
     52        (WebCore::SystemFontDatabaseCoreText::monospaceFamily):
     53        * platform/graphics/cocoa/SystemFontDatabaseCoreText.h:
     54
    1552019-02-11  Adrian Perez de Castro  <aperez@igalia.com>
    256
  • trunk/Source/WebCore/PAL/ChangeLog

    r241281 r241288  
     12019-02-11  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        [Cocoa] Ask platform for generic font family mappings
     4        https://bugs.webkit.org/show_bug.cgi?id=187723
     5        <rdar://problem/41892438>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        * pal/spi/cocoa/CoreTextSPI.h:
     10
    1112019-02-11  Jer Noble  <jer.noble@apple.com>
    212
  • trunk/Source/WebCore/PAL/pal/spi/cocoa/CoreTextSPI.h

    r241268 r241288  
    8080extern const CFStringRef kCTFontFallbackOptionAttribute;
    8181
     82extern const CFStringRef kCTFontCSSFamilySerif;
     83extern const CFStringRef kCTFontCSSFamilySansSerif;
     84extern const CFStringRef kCTFontCSSFamilyCursive;
     85extern const CFStringRef kCTFontCSSFamilyFantasy;
     86extern const CFStringRef kCTFontCSSFamilyMonospace;
     87extern const CFStringRef kCTFontCSSFamilySystemUI;
     88
    8289bool CTFontTransformGlyphs(CTFontRef, CGGlyph glyphs[], CGSize advances[], CFIndex count, CTFontTransformOptions);
    8390
     
    8895bool CTFontGetVerticalGlyphsForCharacters(CTFontRef, const UniChar characters[], CGGlyph glyphs[], CFIndex count);
    8996void CTFontGetUnsummedAdvancesForGlyphsAndStyle(CTFontRef, CTFontOrientation, CGFontRenderingStyle, const CGGlyph[], CGSize advances[], CFIndex count);
     97CTFontDescriptorRef CTFontDescriptorCreateForCSSFamily(CFStringRef cssFamily, CFStringRef language);
    9098
    9199CTFontDescriptorRef CTFontDescriptorCreateForUIType(CTFontUIFontType, CGFloat size, CFStringRef language);
  • trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp

    r241268 r241288  
    17211721}
    17221722
    1723 
    17241723static CSSValueID identifierForFamily(const AtomicString& family)
    17251724{
  • trunk/Source/WebCore/css/CSSFontSelector.cpp

    r241268 r241288  
    275275}
    276276
    277 static const AtomicString& resolveGenericFamily(Document* document, const FontDescription& fontDescription, const AtomicString& familyName)
    278 {
     277static AtomicString resolveGenericFamily(Document* document, const FontDescription& fontDescription, const AtomicString& familyName)
     278{
     279    auto platformResult = FontDescription::platformResolveGenericFamily(fontDescription.script(), fontDescription.locale(), familyName);
     280    if (!platformResult.isNull())
     281        return platformResult;
     282
    279283    if (!document)
    280284        return familyName;
  • trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp

    r241268 r241288  
    10681068    RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
    10691069    do {
    1070         RefPtr<CSSValue> parsedValue = consumeGenericFamily(range);
    1071         if (parsedValue) {
     1070        if (auto parsedValue = consumeGenericFamily(range))
    10721071            list->append(parsedValue.releaseNonNull());
    1073         } else {
    1074             parsedValue = consumeFamilyName(range);
    1075             if (parsedValue) {
     1072        else {
     1073            if (auto parsedValue = consumeFamilyName(range))
    10761074                list->append(parsedValue.releaseNonNull());
    1077             } else {
     1075            else
    10781076                return nullptr;
    1079             }
    10801077        }
    10811078    } while (consumeCommaIncludingWhitespace(range));
  • trunk/Source/WebCore/page/cocoa/SettingsBaseCocoa.mm

    r241268 r241288  
    4949#if PLATFORM(MAC)
    5050
    51 static bool osakaMonoIsInstalled()
    52 {
    53     int one = 1;
    54     RetainPtr<CFNumberRef> yes = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &one));
    55     CFTypeRef keys[] = { kCTFontEnabledAttribute, kCTFontNameAttribute };
    56     CFTypeRef values[] = { yes.get(), CFSTR("Osaka-Mono") };
    57     RetainPtr<CFDictionaryRef> attributes = adoptCF(CFDictionaryCreate(kCFAllocatorDefault, keys, values, WTF_ARRAY_LENGTH(values), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
    58     RetainPtr<CTFontDescriptorRef> descriptor = adoptCF(CTFontDescriptorCreateWithAttributes(attributes.get()));
    59     RetainPtr<CFSetRef> mandatoryAttributes = adoptCF(CFSetCreate(kCFAllocatorDefault, keys, WTF_ARRAY_LENGTH(keys), &kCFTypeSetCallBacks));
    60     return adoptCF(CTFontDescriptorCreateMatchingFontDescriptor(descriptor.get(), mandatoryAttributes.get()));
    61 }
    62 
    6351void SettingsBase::initializeDefaultFontFamilies()
    6452{
    6553    setStandardFontFamily("Songti TC", USCRIPT_TRADITIONAL_HAN);
    66     setSerifFontFamily("Songti TC", USCRIPT_TRADITIONAL_HAN);
    67     setFixedFontFamily(sansSerifTraditionalHanFontFamily(), USCRIPT_TRADITIONAL_HAN);
    68     setSansSerifFontFamily(sansSerifTraditionalHanFontFamily(), USCRIPT_TRADITIONAL_HAN);
    69     setCursiveFontFamily("Kaiti TC", USCRIPT_TRADITIONAL_HAN);
    70 
    7154    setStandardFontFamily("Songti SC", USCRIPT_SIMPLIFIED_HAN);
    72     setSerifFontFamily("Songti SC", USCRIPT_SIMPLIFIED_HAN);
    73     setFixedFontFamily(sansSerifSimplifiedHanFontFamily(), USCRIPT_SIMPLIFIED_HAN);
    74     setSansSerifFontFamily(sansSerifSimplifiedHanFontFamily(), USCRIPT_SIMPLIFIED_HAN);
    75     setCursiveFontFamily("Kaiti SC", USCRIPT_SIMPLIFIED_HAN);
    76 
    7755    setStandardFontFamily("Hiragino Mincho ProN", USCRIPT_KATAKANA_OR_HIRAGANA);
    78     setFixedFontFamily(osakaMonoIsInstalled() ? "Osaka-Mono" : "Hiragino Sans", USCRIPT_KATAKANA_OR_HIRAGANA);
    79     setSerifFontFamily("Hiragino Mincho ProN", USCRIPT_KATAKANA_OR_HIRAGANA);
    80     setSansSerifFontFamily("Hiragino Kaku Gothic ProN", USCRIPT_KATAKANA_OR_HIRAGANA);
    81 
    8256    setStandardFontFamily("AppleMyungjo", USCRIPT_HANGUL);
    83     setSerifFontFamily("AppleMyungjo", USCRIPT_HANGUL);
    84     setFixedFontFamily("Apple SD Gothic Neo", USCRIPT_HANGUL);
    85     setSansSerifFontFamily("Apple SD Gothic Neo", USCRIPT_HANGUL);
    8657
    8758    setStandardFontFamily("Times", USCRIPT_COMMON);
     
    10071void SettingsBase::initializeDefaultFontFamilies()
    10172{
    102     // There is no serif Chinese font in default iOS installation.
    10373    setStandardFontFamily(sansSerifTraditionalHanFontFamily(), USCRIPT_TRADITIONAL_HAN);
    104     setSerifFontFamily(sansSerifTraditionalHanFontFamily(), USCRIPT_TRADITIONAL_HAN);
    105     setFixedFontFamily(sansSerifTraditionalHanFontFamily(), USCRIPT_TRADITIONAL_HAN);
    106     setSansSerifFontFamily(sansSerifTraditionalHanFontFamily(), USCRIPT_TRADITIONAL_HAN);
    107 
    108     // There is no serif Chinese font in default iOS installation.
    10974    setStandardFontFamily(sansSerifSimplifiedHanFontFamily(), USCRIPT_SIMPLIFIED_HAN);
    110     setSerifFontFamily(sansSerifSimplifiedHanFontFamily(), USCRIPT_SIMPLIFIED_HAN);
    111     setFixedFontFamily(sansSerifSimplifiedHanFontFamily(), USCRIPT_SIMPLIFIED_HAN);
    112     setSansSerifFontFamily(sansSerifSimplifiedHanFontFamily(), USCRIPT_SIMPLIFIED_HAN);
    113 
    11475    setStandardFontFamily("Hiragino Mincho ProN", USCRIPT_KATAKANA_OR_HIRAGANA);
    115     setFixedFontFamily("Hiragino Kaku Gothic ProN", USCRIPT_KATAKANA_OR_HIRAGANA);
    116     setSerifFontFamily("Hiragino Mincho ProN", USCRIPT_KATAKANA_OR_HIRAGANA);
    117     setSansSerifFontFamily("Hiragino Kaku Gothic ProN", USCRIPT_KATAKANA_OR_HIRAGANA);
    118 
    119     // There is no serif Korean font in default iOS installation.
    12076    setStandardFontFamily("Apple SD Gothic Neo", USCRIPT_HANGUL);
    121     setSerifFontFamily("Apple SD Gothic Neo", USCRIPT_HANGUL);
    122     setFixedFontFamily("Apple SD Gothic Neo", USCRIPT_HANGUL);
    123     setSansSerifFontFamily("Apple SD Gothic Neo", USCRIPT_HANGUL);
    12477
    12578    setStandardFontFamily("Times", USCRIPT_COMMON);
  • trunk/Source/WebCore/platform/graphics/FontDescription.cpp

    r241268 r241288  
    7272}
    7373
     74#if !PLATFORM(COCOA)
     75AtomicString FontDescription::platformResolveGenericFamily(UScriptCode, const AtomicString&, const AtomicString&)
     76{
     77    return nullAtom();
     78}
     79#endif
     80
    7481} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/FontDescription.h

    r241268 r241288  
    134134    void setShouldAllowUserInstalledFonts(AllowUserInstalledFonts shouldAllowUserInstalledFonts) { m_shouldAllowUserInstalledFonts = static_cast<unsigned>(shouldAllowUserInstalledFonts); }
    135135
     136    static AtomicString platformResolveGenericFamily(UScriptCode, const AtomicString& locale, const AtomicString& familyName);
     137
    136138private:
    137139    // FIXME: Investigate moving these into their own object on the heap (to save memory).
  • trunk/Source/WebCore/platform/graphics/cocoa/FontDescriptionCocoa.cpp

    r241268 r241288  
    2828
    2929#include "SystemFontDatabaseCoreText.h"
     30#include <mutex>
     31#include <wtf/Language.h>
     32
     33namespace WebCore {
    3034
    3135#if USE_PLATFORM_SYSTEM_FALLBACK_LIST
    32 
    33 namespace WebCore {
    3436
    3537static inline bool isSystemFontString(const AtomicString& string)
     
    139141}
    140142
     143#endif // USE_PLATFORM_SYSTEM_FALLBACK_LIST
     144
     145static String computeSpecializedChineseLocale()
     146{
     147    const Vector<String>& preferredLanguages = userPreferredLanguages();
     148    for (auto& language : preferredLanguages) {
     149        if (equalIgnoringASCIICase(language, "zh") || startsWithLettersIgnoringASCIICase(language, "zh-"))
     150            return language;
     151    }
     152    return "zh-hans"_str; // We have no signal. Pick one option arbitrarily.
    141153}
    142154
    143 #endif
     155static String& cachedSpecializedChineseLocale()
     156{
     157    static NeverDestroyed<String> specializedChineseLocale;
     158    return specializedChineseLocale.get();
     159}
    144160
     161static void languageChanged(void*)
     162{
     163    cachedSpecializedChineseLocale() = computeSpecializedChineseLocale();
     164}
     165
     166AtomicString FontDescription::platformResolveGenericFamily(UScriptCode script, const AtomicString& locale, const AtomicString& familyName)
     167{
     168    if (script == USCRIPT_COMMON)
     169        return nullAtom();
     170
     171    static std::once_flag onceFlag;
     172    std::call_once(onceFlag, [&] {
     173        static char dummy;
     174        addLanguageChangeObserver(&dummy, &languageChanged); // We will never remove the observer, so all we need is a non-null pointer.
     175        languageChanged(nullptr);
     176    });
     177
     178    // FIXME: Delete this once <rdar://problem/47682577> is fixed.
     179    auto& usedLocale = script == USCRIPT_HAN ? cachedSpecializedChineseLocale() : locale.string();
     180
     181    // FIXME: Use the system font database to handle standardFamily
     182    if (familyName == serifFamily)
     183        return SystemFontDatabaseCoreText::singleton().serifFamily(usedLocale);
     184    if (familyName == sansSerifFamily)
     185        return SystemFontDatabaseCoreText::singleton().sansSerifFamily(usedLocale);
     186    if (familyName == cursiveFamily)
     187        return SystemFontDatabaseCoreText::singleton().cursiveFamily(usedLocale);
     188    if (familyName == fantasyFamily)
     189        return SystemFontDatabaseCoreText::singleton().fantasyFamily(usedLocale);
     190    if (familyName == monospaceFamily)
     191        return SystemFontDatabaseCoreText::singleton().monospaceFamily(usedLocale);
     192
     193    return nullAtom();
     194}
     195
     196}
     197
  • trunk/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp

    r241268 r241288  
    2727#include "SystemFontDatabaseCoreText.h"
    2828
    29 #if USE_PLATFORM_SYSTEM_FALLBACK_LIST
    30 
    3129#include "FontCache.h"
    3230#include "FontCascadeDescription.h"
     
    4745{
    4846}
     47
     48#if USE_PLATFORM_SYSTEM_FALLBACK_LIST
    4949
    5050Vector<RetainPtr<CTFontDescriptorRef>> SystemFontDatabaseCoreText::cascadeList(const CascadeListParameters& parameters, ClientUse clientUse)
     
    8181{
    8282    m_systemFontCache.clear();
     83    m_serifFamilies.clear();
     84    m_sansSeriferifFamilies.clear();
     85    m_cursiveFamilies.clear();
     86    m_fantasyFamilies.clear();
     87    m_monospaceFamilies.clear();
    8388}
    8489
     
    173178}
    174179
    175 }
    176 
     180#endif // USE_PLATFORM_SYSTEM_FALLBACK_LIST
     181
     182static String genericFamily(const String& locale, HashMap<String, String>& map, CFStringRef ctKey)
     183{
     184    return map.ensure(locale, [&] {
     185        auto descriptor = adoptCF(CTFontDescriptorCreateForCSSFamily(ctKey, locale.createCFString().get()));
     186        return adoptCF(static_cast<CFStringRef>(CTFontDescriptorCopyAttribute(descriptor.get(), kCTFontFamilyNameAttribute))).get();
     187    }).iterator->value;
     188}
     189
     190String SystemFontDatabaseCoreText::serifFamily(const String& locale)
     191{
     192    return genericFamily(locale, m_serifFamilies, kCTFontCSSFamilySerif);
     193}
     194
     195String SystemFontDatabaseCoreText::sansSerifFamily(const String& locale)
     196{
     197    return genericFamily(locale, m_sansSeriferifFamilies, kCTFontCSSFamilySansSerif);
     198}
     199
     200String SystemFontDatabaseCoreText::cursiveFamily(const String& locale)
     201{
     202    return genericFamily(locale, m_cursiveFamilies, kCTFontCSSFamilyCursive);
     203}
     204
     205String SystemFontDatabaseCoreText::fantasyFamily(const String& locale)
     206{
     207    return genericFamily(locale, m_fantasyFamilies, kCTFontCSSFamilyFantasy);
     208}
     209
     210String SystemFontDatabaseCoreText::monospaceFamily(const String& locale)
     211{
     212    auto result = genericFamily(locale, m_monospaceFamilies, kCTFontCSSFamilyMonospace);
     213#if PLATFORM(MAC) && ENABLE(MONOSPACE_FONT_EXCEPTION)
     214    // In general, CoreText uses Monaco for monospaced (see: Terminal.app and Xcode.app).
     215    // For now, we want to use Courier for web compatibility, until we have more time to do compatibility testing.
     216    if (equalLettersIgnoringASCIICase(result, "monaco"))
     217        return "Courier"_str;
     218#elif PLATFORM(IOS_FAMILY) && ENABLE(MONOSPACE_FONT_EXCEPTION)
     219    if (equalLettersIgnoringASCIICase(result, "courier new"))
     220        return "Courier"_str;
    177221#endif
     222    return result;
     223}
     224
     225}
  • trunk/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.h

    r241268 r241288  
    3232#include <wtf/text/AtomicString.h>
    3333#include <wtf/text/AtomicStringHash.h>
    34 
    35 #if USE_PLATFORM_SYSTEM_FALLBACK_LIST
    3634
    3735namespace WebCore {
     
    102100
    103101    Vector<RetainPtr<CTFontDescriptorRef>> cascadeList(const FontCascadeDescription&, const AtomicString& cssFamily, ClientUse, AllowUserInstalledFonts);
     102
     103    String serifFamily(const String& locale);
     104    String sansSerifFamily(const String& locale);
     105    String cursiveFamily(const String& locale);
     106    String fantasyFamily(const String& locale);
     107    String monospaceFamily(const String& locale);
     108
    104109    void clear();
    105110
     
    115120
    116121    HashMap<CascadeListParameters, Vector<RetainPtr<CTFontDescriptorRef>>, CascadeListParameters::CascadeListParametersHash, SimpleClassHashTraits<CascadeListParameters>> m_systemFontCache;
     122
     123    HashMap<String, String> m_serifFamilies;
     124    HashMap<String, String> m_sansSeriferifFamilies;
     125    HashMap<String, String> m_cursiveFamilies;
     126    HashMap<String, String> m_fantasyFamilies;
     127    HashMap<String, String> m_monospaceFamilies;
    117128};
    118129
    119130}
    120 
    121 #endif
  • trunk/Tools/ChangeLog

    r241283 r241288  
     12019-02-11  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        [Cocoa] Ask platform for generic font family mappings
     4        https://bugs.webkit.org/show_bug.cgi?id=187723
     5        <rdar://problem/41892438>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        Allow testing infrastructure to use fonts that are returned from CTFontDescriptorCreateForCSSFamily().
     10
     11        * DumpRenderTree/mac/DumpRenderTree.mm:
     12        (allowedFontFamilySet):
     13        * WebKitTestRunner/mac/TestControllerMac.mm:
     14        (WTR::allowedFontFamilySet):
     15
    1162019-02-11  Adrian Perez de Castro  <aperez@igalia.com>
    217
  • trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm

    r241268 r241288  
    378378        @"Hiragino Mincho Pro",
    379379        @"Hiragino Mincho ProN",
     380        @"Hiragino Sans",
    380381        @"Hiragino Sans GB",
    381382        @"Hoefler Text",
     
    387388        @"Krungthep",
    388389        @"KufiStandardGK",
     390        @"Lao Sangam MN",
    389391        @"LastResort",
    390392        @"LiHei Pro",
     
    404406        @"PCMyungjo",
    405407        @"PilGi",
     408        @"PingFang HK",
     409        @"PingFang SC",
     410        @"PingFang TC",
    406411        @"Plantagenet Cherokee",
    407412        @"Raanana",
     
    409414        @"Silom",
    410415        @"Skia",
     416        @"Snell Roundhand",
    411417        @"Songti SC",
    412418        @"Songti TC",
  • trunk/Tools/WebKitTestRunner/mac/TestControllerMac.mm

    r241283 r241288  
    227227        @"Hiragino Mincho Pro",
    228228        @"Hiragino Mincho ProN",
     229        @"Hiragino Sans",
    229230        @"Hiragino Sans GB",
    230231        @"Hoefler Text",
     
    236237        @"Krungthep",
    237238        @"KufiStandardGK",
     239        @"Lao Sangam MN",
    238240        @"LastResort",
    239241        @"LiHei Pro",
     
    253255        @"PCMyungjo",
    254256        @"PilGi",
     257        @"PingFang HK",
     258        @"PingFang SC",
     259        @"PingFang TC",
    255260        @"Plantagenet Cherokee",
    256261        @"Raanana",
     
    258263        @"Silom",
    259264        @"Skia",
     265        @"Snell Roundhand",
    260266        @"Songti SC",
    261267        @"Songti TC",
Note: See TracChangeset for help on using the changeset viewer.