Changeset 241229 in webkit


Ignore:
Timestamp:
Feb 8, 2019 7:42:23 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::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:

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. This test is no longer testing

anything relevant.

  • 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.
Location:
trunk
Files:
2 added
2 deleted
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r241219 r241229  
     12019-02-08  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. This test is no longer testing
     13        anything relevant.
     14        * fast/text/international/lang-sensitive-fonts-expected.html:
     15        * fast/text/international/lang-sensitive-fonts-xml-expected.html:
     16        * fast/text/international/lang-sensitive-fonts-xml.xhtml:
     17        * fast/text/international/lang-sensitive-fonts.html:
     18        * fast/text/international/locale-sensitive-fonts-expected.html:
     19        * fast/text/international/locale-sensitive-fonts.html:
     20        * fast/text/ja-sans-serif-expected-mismatch.html: Added.
     21        * fast/text/ja-sans-serif.html: Added.
     22
    1232019-02-08  Joseph Pecoraro  <pecoraro@apple.com>
    224
  • trunk/LayoutTests/fast/text/international/lang-sensitive-fonts-expected.html

    r110936 r241229  
    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

    r110936 r241229  
    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

    r189038 r241229  
    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

    r189038 r241229  
    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

    r110808 r241229  
    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

    r189038 r241229  
    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

    r199034 r241229  
    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/wtf/Platform.h

    r241169 r241229  
    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

    r241222 r241229  
     12019-02-08  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::SystemFontDatabaseCoreText::serifFamily):
     48        (WebCore::SystemFontDatabaseCoreText::sansSerifFamily):
     49        (WebCore::SystemFontDatabaseCoreText::cursiveFamily):
     50        (WebCore::SystemFontDatabaseCoreText::fantasyFamily):
     51        (WebCore::SystemFontDatabaseCoreText::monospaceFamily):
     52        * platform/graphics/cocoa/SystemFontDatabaseCoreText.h:
     53
    1542019-02-08  Yusuke Suzuki  <ysuzuki@apple.com>
    255
  • trunk/Source/WebCore/PAL/ChangeLog

    r241183 r241229  
     12019-02-08  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-07  Chris Dumez  <cdumez@apple.com>
    212
  • trunk/Source/WebCore/PAL/pal/spi/cocoa/CoreTextSPI.h

    r237266 r241229  
    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

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

    r235897 r241229  
    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

    r240641 r241229  
    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

    r240592 r241229  
    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

    r236938 r241229  
    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

    r239427 r241229  
    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

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

    r237266 r241229  
    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 
    177 #endif
     180String SystemFontDatabaseCoreText::serifFamily(const String& locale)
     181{
     182    return m_serifFamilies.ensure(locale, [&] {
     183        auto descriptor = adoptCF(CTFontDescriptorCreateForCSSFamily(kCTFontCSSFamilySerif, locale.createCFString().get()));
     184        return adoptCF(static_cast<CFStringRef>(CTFontDescriptorCopyAttribute(descriptor.get(), kCTFontFamilyNameAttribute))).get();
     185    }).iterator->value;
     186}
     187
     188String SystemFontDatabaseCoreText::sansSerifFamily(const String& locale)
     189{
     190    return m_sansSeriferifFamilies.ensure(locale, [&] {
     191        auto descriptor = adoptCF(CTFontDescriptorCreateForCSSFamily(kCTFontCSSFamilySansSerif, locale.createCFString().get()));
     192        return adoptCF(static_cast<CFStringRef>(CTFontDescriptorCopyAttribute(descriptor.get(), kCTFontFamilyNameAttribute))).get();
     193    }).iterator->value;
     194}
     195
     196String SystemFontDatabaseCoreText::cursiveFamily(const String& locale)
     197{
     198    return m_cursiveFamilies.ensure(locale, [&] {
     199        auto descriptor = adoptCF(CTFontDescriptorCreateForCSSFamily(kCTFontCSSFamilyCursive, locale.createCFString().get()));
     200        return adoptCF(static_cast<CFStringRef>(CTFontDescriptorCopyAttribute(descriptor.get(), kCTFontFamilyNameAttribute))).get();
     201    }).iterator->value;
     202}
     203
     204String SystemFontDatabaseCoreText::fantasyFamily(const String& locale)
     205{
     206    return m_fantasyFamilies.ensure(locale, [&] {
     207        auto descriptor = adoptCF(CTFontDescriptorCreateForCSSFamily(kCTFontCSSFamilyFantasy, locale.createCFString().get()));
     208        return adoptCF(static_cast<CFStringRef>(CTFontDescriptorCopyAttribute(descriptor.get(), kCTFontFamilyNameAttribute))).get();
     209    }).iterator->value;
     210}
     211
     212String SystemFontDatabaseCoreText::monospaceFamily(const String& locale)
     213{
     214    return m_monospaceFamilies.ensure(locale, [&] {
     215        auto descriptor = adoptCF(CTFontDescriptorCreateForCSSFamily(kCTFontCSSFamilyMonospace, locale.createCFString().get()));
     216        String result = adoptCF(static_cast<CFStringRef>(CTFontDescriptorCopyAttribute(descriptor.get(), kCTFontFamilyNameAttribute))).get();
     217#if PLATFORM(MAC) && ENABLE(MONOSPACE_FONT_EXCEPTION)
     218        // In general, CoreText uses Monaco for monospaced (see: Terminal.app and Xcode.app).
     219        // For now, we want to use Courier for web compatibility, until we have more time to do compatibility testing.
     220        if (equalLettersIgnoringASCIICase(result, "monaco"))
     221            return "Courier"_str;
     222#elif PLATFORM(IOS_FAMILY) && ENABLE(MONOSPACE_FONT_EXCEPTION)
     223        if (equalLettersIgnoringASCIICase(result, "courier new"))
     224            return "Courier"_str;
     225#endif
     226        return result;
     227    }).iterator->value;
     228}
     229
     230}
     231
     232#endif
  • trunk/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.h

    r236938 r241229  
    102102
    103103    Vector<RetainPtr<CTFontDescriptorRef>> cascadeList(const FontCascadeDescription&, const AtomicString& cssFamily, ClientUse, AllowUserInstalledFonts);
     104
     105    String serifFamily(const String& locale);
     106    String sansSerifFamily(const String& locale);
     107    String cursiveFamily(const String& locale);
     108    String fantasyFamily(const String& locale);
     109    String monospaceFamily(const String& locale);
     110
    104111    void clear();
    105112
     
    115122
    116123    HashMap<CascadeListParameters, Vector<RetainPtr<CTFontDescriptorRef>>, CascadeListParameters::CascadeListParametersHash, SimpleClassHashTraits<CascadeListParameters>> m_systemFontCache;
     124
     125    HashMap<String, String> m_serifFamilies;
     126    HashMap<String, String> m_sansSeriferifFamilies;
     127    HashMap<String, String> m_cursiveFamilies;
     128    HashMap<String, String> m_fantasyFamilies;
     129    HashMap<String, String> m_monospaceFamilies;
    117130};
    118131
  • trunk/Tools/ChangeLog

    r241224 r241229  
     12019-02-08  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-08  Alexander Mikhaylenko  <exalm7659@gmail.com>
    217
  • trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm

    r240700 r241229  
    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

    r239871 r241229  
    223223        @"Hiragino Mincho Pro",
    224224        @"Hiragino Mincho ProN",
     225        @"Hiragino Sans",
    225226        @"Hiragino Sans GB",
    226227        @"Hoefler Text",
     
    232233        @"Krungthep",
    233234        @"KufiStandardGK",
     235        @"Lao Sangam MN",
    234236        @"LastResort",
    235237        @"LiHei Pro",
     
    249251        @"PCMyungjo",
    250252        @"PilGi",
     253        @"PingFang HK",
     254        @"PingFang SC",
     255        @"PingFang TC",
    251256        @"Plantagenet Cherokee",
    252257        @"Raanana",
     
    254259        @"Silom",
    255260        @"Skia",
     261        @"Snell Roundhand",
    256262        @"Songti SC",
    257263        @"Songti TC",
Note: See TracChangeset for help on using the changeset viewer.