Changeset 209875 in webkit


Ignore:
Timestamp:
Dec 15, 2016 2:12:21 PM (7 years ago)
Author:
mmaxfield@apple.com
Message:

[Cocoa] Implement font-synthesis: small-caps
https://bugs.webkit.org/show_bug.cgi?id=165892

Reviewed by David Hyatt.

Source/WebCore:

The CSS Fonts level 4 spec adds a new value to the "font-synthesis"
property which controls whether or not small-caps is allowed to be
synthesized. Luckily, we already have an implementation of this
straightforward, so the implementation is quite simple.

Tests: css3/font-synthesis-small-caps.html

fast/text/font-synthesis-parsing.html

  • css/CSSComputedStyleDeclaration.cpp:

(WebCore::fontSynthesisFromStyle):

  • css/StyleBuilderConverter.h:

(WebCore::StyleBuilderConverter::convertFontSynthesis):

  • css/parser/CSSPropertyParser.cpp:

(WebCore::consumeFontSynthesis):

  • platform/graphics/FontCache.h:

(WebCore::FontDescriptionKey::makeFlagsKey):

  • platform/graphics/FontDescription.cpp:

(WebCore::FontDescription::FontDescription):

  • platform/graphics/FontDescription.h:

(WebCore::FontCascadeDescription::initialFontSynthesis):

  • platform/graphics/mac/ComplexTextController.cpp:

(WebCore::shouldSynthesize):
(WebCore::ComplexTextController::collectComplexTextRuns):

LayoutTests:

  • fast/text/font-synthesis-parsing-expected.txt: Added.
  • fast/text/font-synthesis-parsing.html: Added.
  • css3/font-synthesis-small-caps-expected.html: Added.
  • css3/font-synthesis-small-caps.html: Added.
  • fast/css/getComputedStyle/computed-style-expected.txt:
  • fast/css/getComputedStyle/computed-style-font-family-expected.txt:
  • fast/css/getComputedStyle/computed-style-without-renderer-expected.txt:
  • fast/css3-text/font-synthesis-parse-expected.txt:
  • fast/css3-text/font-synthesis-parse.html:
  • svg/css/getComputedStyle-basic-expected.txt:
Location:
trunk
Files:
4 added
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r209867 r209875  
     12016-12-15  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        [Cocoa] Implement font-synthesis: small-caps
     4        https://bugs.webkit.org/show_bug.cgi?id=165892
     5
     6        Reviewed by David Hyatt.
     7
     8        * fast/text/font-synthesis-parsing-expected.txt: Added.
     9        * fast/text/font-synthesis-parsing.html: Added.
     10        * css3/font-synthesis-small-caps-expected.html: Added.
     11        * css3/font-synthesis-small-caps.html: Added.
     12        * fast/css/getComputedStyle/computed-style-expected.txt:
     13        * fast/css/getComputedStyle/computed-style-font-family-expected.txt:
     14        * fast/css/getComputedStyle/computed-style-without-renderer-expected.txt:
     15        * fast/css3-text/font-synthesis-parse-expected.txt:
     16        * fast/css3-text/font-synthesis-parse.html:
     17        * svg/css/getComputedStyle-basic-expected.txt:
     18
    1192016-12-15  Simon Fraser  <simon.fraser@apple.com>
    220
  • trunk/LayoutTests/fast/css/getComputedStyle/computed-style-expected.txt

    r207757 r209875  
    4646font-size: 16px;
    4747font-style: normal;
    48 font-synthesis: style weight;
     48font-synthesis: style weight small-caps;
    4949font-variant: normal;
    5050font-weight: normal;
  • trunk/LayoutTests/fast/css/getComputedStyle/computed-style-font-family-expected.txt

    r190192 r209875  
    44font-size: 16px;
    55font-style: normal;
    6 font-synthesis: style weight;
     6font-synthesis: style weight small-caps;
    77font-variant: normal;
    88font-weight: normal;
  • trunk/LayoutTests/fast/css/getComputedStyle/computed-style-without-renderer-expected.txt

    r207757 r209875  
    4545font-size: 16px
    4646font-style: normal
    47 font-synthesis: style weight
     47font-synthesis: style weight small-caps
    4848font-variant: normal
    4949font-weight: normal
  • trunk/LayoutTests/fast/css3-text/font-synthesis-parse-expected.txt

    r208733 r209875  
    22PASS declaration.length is 0
    33PASS declaration.getPropertyValue('font-synthesis') is ""
    4 PASS computedStyle.getPropertyCSSValue('font-synthesis').cssText is "style weight"
     4PASS computedStyle.getPropertyCSSValue('font-synthesis').cssText is "style weight small-caps"
    55PASS cssRule.type is cssRule.STYLE_RULE
    66PASS declaration.length is 1
    77PASS declaration.getPropertyValue('font-synthesis') is "initial"
    8 PASS computedStyle.getPropertyCSSValue('font-synthesis').cssText is "style weight"
     8PASS computedStyle.getPropertyCSSValue('font-synthesis').cssText is "style weight small-caps"
    99PASS cssRule.type is cssRule.STYLE_RULE
    1010PASS declaration.length is 1
     
    2626PASS declaration.length is 0
    2727PASS declaration.getPropertyValue('font-synthesis') is ""
    28 PASS computedStyle.getPropertyCSSValue('font-synthesis').cssText is "style weight"
     28PASS computedStyle.getPropertyCSSValue('font-synthesis').cssText is "style weight small-caps"
    2929PASS cssRule.type is cssRule.STYLE_RULE
    3030PASS declaration.length is 0
    3131PASS declaration.getPropertyValue('font-synthesis') is ""
    32 PASS computedStyle.getPropertyCSSValue('font-synthesis').cssText is "style weight"
     32PASS computedStyle.getPropertyCSSValue('font-synthesis').cssText is "style weight small-caps"
    3333PASS cssRule.type is cssRule.STYLE_RULE
    3434PASS declaration.length is 0
    3535PASS declaration.getPropertyValue('font-synthesis') is ""
    36 PASS computedStyle.getPropertyCSSValue('font-synthesis').cssText is "style weight"
     36PASS computedStyle.getPropertyCSSValue('font-synthesis').cssText is "style weight small-caps"
    3737PASS cssRule.type is cssRule.STYLE_RULE
    3838PASS declaration.length is 0
    3939PASS declaration.getPropertyValue('font-synthesis') is ""
    40 PASS computedStyle.getPropertyCSSValue('font-synthesis').cssText is "style weight"
     40PASS computedStyle.getPropertyCSSValue('font-synthesis').cssText is "style weight small-caps"
    4141PASS cssRule.type is cssRule.STYLE_RULE
    4242PASS declaration.length is 0
    4343PASS declaration.getPropertyValue('font-synthesis') is ""
    44 PASS computedStyle.getPropertyCSSValue('font-synthesis').cssText is "style weight"
     44PASS computedStyle.getPropertyCSSValue('font-synthesis').cssText is "style weight small-caps"
    4545PASS successfullyParsed is true
    4646
  • trunk/LayoutTests/fast/css3-text/font-synthesis-parse.html

    r208733 r209875  
    1515      shouldBeEqualToString("declaration.getPropertyValue('font-synthesis')", "");
    1616      computedStyle = window.getComputedStyle(target, null);
    17       shouldBeEqualToString("computedStyle.getPropertyCSSValue('font-synthesis').cssText", "style weight");
     17      shouldBeEqualToString("computedStyle.getPropertyCSSValue('font-synthesis').cssText", "style weight small-caps");
    1818      stylesheet.deleteRule(0);
    1919    }
     
    2626      shouldBeEqualToString("declaration.getPropertyValue('font-synthesis')", "initial");
    2727      computedStyle = window.getComputedStyle(target, null);
    28       shouldBeEqualToString("computedStyle.getPropertyCSSValue('font-synthesis').cssText", "style weight");
     28      shouldBeEqualToString("computedStyle.getPropertyCSSValue('font-synthesis').cssText", "style weight small-caps");
    2929      stylesheet.deleteRule(0);
    3030    }
  • trunk/LayoutTests/svg/css/getComputedStyle-basic-expected.txt

    r209777 r209875  
    8989rect: style.getPropertyValue(font-style) : normal
    9090rect: style.getPropertyCSSValue(font-style) : [object CSSPrimitiveValue]
    91 rect: style.getPropertyValue(font-synthesis) : style weight
     91rect: style.getPropertyValue(font-synthesis) : style weight small-caps
    9292rect: style.getPropertyCSSValue(font-synthesis) : [object CSSValueList]
    9393rect: style.getPropertyValue(font-variant) : normal
     
    597597g: style.getPropertyValue(font-style) : normal
    598598g: style.getPropertyCSSValue(font-style) : [object CSSPrimitiveValue]
    599 g: style.getPropertyValue(font-synthesis) : style weight
     599g: style.getPropertyValue(font-synthesis) : style weight small-caps
    600600g: style.getPropertyCSSValue(font-synthesis) : [object CSSValueList]
    601601g: style.getPropertyValue(font-variant) : normal
  • trunk/Source/WebCore/ChangeLog

    r209873 r209875  
     12016-12-15  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        [Cocoa] Implement font-synthesis: small-caps
     4        https://bugs.webkit.org/show_bug.cgi?id=165892
     5
     6        Reviewed by David Hyatt.
     7
     8        The CSS Fonts level 4 spec adds a new value to the "font-synthesis"
     9        property which controls whether or not small-caps is allowed to be
     10        synthesized. Luckily, we already have an implementation of this
     11        straightforward, so the implementation is quite simple.
     12
     13        Tests: css3/font-synthesis-small-caps.html
     14               fast/text/font-synthesis-parsing.html
     15
     16        * css/CSSComputedStyleDeclaration.cpp:
     17        (WebCore::fontSynthesisFromStyle):
     18        * css/StyleBuilderConverter.h:
     19        (WebCore::StyleBuilderConverter::convertFontSynthesis):
     20        * css/parser/CSSPropertyParser.cpp:
     21        (WebCore::consumeFontSynthesis):
     22        * platform/graphics/FontCache.h:
     23        (WebCore::FontDescriptionKey::makeFlagsKey):
     24        * platform/graphics/FontDescription.cpp:
     25        (WebCore::FontDescription::FontDescription):
     26        * platform/graphics/FontDescription.h:
     27        (WebCore::FontCascadeDescription::initialFontSynthesis):
     28        * platform/graphics/mac/ComplexTextController.cpp:
     29        (WebCore::shouldSynthesize):
     30        (WebCore::ComplexTextController::collectComplexTextRuns):
     31
    1322016-12-15  Brady Eidson  <beidson@apple.com>
    233
  • trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp

    r209805 r209875  
    21452145    if (style.fontDescription().fontSynthesis() & FontSynthesisWeight)
    21462146        list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueWeight));
     2147    if (style.fontDescription().fontSynthesis() & FontSynthesisSmallCaps)
     2148        list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueSmallCaps));
    21472149    return Ref<CSSValue>(list.get());
    21482150}
  • trunk/Source/WebCore/css/StyleBuilderConverter.h

    r209788 r209875  
    14421442            result |= FontSynthesisStyle;
    14431443            break;
     1444        case CSSValueSmallCaps:
     1445            result |= FontSynthesisSmallCaps;
     1446            break;
    14441447        default:
    14451448            ASSERT_NOT_REACHED();
  • trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp

    r209826 r209875  
    949949static RefPtr<CSSValue> consumeFontSynthesis(CSSParserTokenRange& range)
    950950{
    951     // none | [ weight || style ]
     951    // none | [ weight || style || small-caps ]
    952952    CSSValueID id = range.peek().id();
    953953    if (id == CSSValueNone)
     
    956956    RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
    957957    while (true) {
    958         auto ident = consumeIdent<CSSValueWeight, CSSValueStyle>(range);
     958        auto ident = consumeIdent<CSSValueWeight, CSSValueStyle, CSSValueSmallCaps>(range);
    959959        if (!ident)
    960960            break;
  • trunk/Source/WebCore/platform/graphics/FontCache.h

    r206839 r209875  
    122122    {
    123123        static_assert(USCRIPT_CODE_LIMIT < 0x1000, "Script code must fit in an unsigned along with the other flags");
    124         unsigned first = static_cast<unsigned>(description.script()) << 10
    125             | static_cast<unsigned>(description.textRenderingMode()) << 8
     124        unsigned first = static_cast<unsigned>(description.script()) << 11
     125            | static_cast<unsigned>(description.textRenderingMode()) << 9
    126126            | static_cast<unsigned>(description.fontSynthesis()) << 6
    127127            | static_cast<unsigned>(description.widthVariant()) << 4
  • trunk/Source/WebCore/platform/graphics/FontDescription.cpp

    r206839 r209875  
    6262    , m_textRendering(AutoTextRendering)
    6363    , m_script(USCRIPT_COMMON)
    64     , m_fontSynthesis(FontSynthesisWeight | FontSynthesisStyle)
     64    , m_fontSynthesis(FontSynthesisWeight | FontSynthesisStyle | FontSynthesisSmallCaps)
    6565    , m_variantCommonLigatures(static_cast<unsigned>(FontVariantLigatures::Normal))
    6666    , m_variantDiscretionaryLigatures(static_cast<unsigned>(FontVariantLigatures::Normal))
  • trunk/Source/WebCore/platform/graphics/FontDescription.h

    r206839 r209875  
    144144    unsigned m_textRendering : 2; // TextRenderingMode
    145145    unsigned m_script : 7; // Used to help choose an appropriate font for generic font families.
    146     unsigned m_fontSynthesis : 2; // FontSynthesis type
     146    unsigned m_fontSynthesis : 3; // FontSynthesis type
    147147    unsigned m_variantCommonLigatures : 2; // FontVariantLigatures
    148148    unsigned m_variantDiscretionaryLigatures : 2; // FontVariantLigatures
     
    266266    static FontSmoothingMode initialFontSmoothing() { return AutoSmoothing; }
    267267    static TextRenderingMode initialTextRenderingMode() { return AutoTextRendering; }
    268     static FontSynthesis initialFontSynthesis() { return FontSynthesisWeight | FontSynthesisStyle; }
     268    static FontSynthesis initialFontSynthesis() { return FontSynthesisWeight | FontSynthesisStyle | FontSynthesisSmallCaps; }
    269269    static FontVariantPosition initialVariantPosition() { return FontVariantPosition::Normal; }
    270270    static FontVariantCaps initialVariantCaps() { return FontVariantCaps::Normal; }
  • trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.cpp

    r209410 r209875  
    289289}
    290290
    291 static bool shouldSynthesize(const Font* nextFont, UChar32 baseCharacter, std::optional<UChar32> capitalizedBase, FontVariantCaps fontVariantCaps, bool engageAllSmallCapsProcessing)
    292 {
     291static bool shouldSynthesize(bool dontSynthesizeSmallCaps, const Font* nextFont, UChar32 baseCharacter, std::optional<UChar32> capitalizedBase, FontVariantCaps fontVariantCaps, bool engageAllSmallCapsProcessing)
     292{
     293    if (dontSynthesizeSmallCaps)
     294        return false;
    293295    if (!nextFont || nextFont == Font::systemFallback())
    294296        return false;
     
    316318
    317319    auto fontVariantCaps = m_font.fontDescription().variantCaps();
     320    bool dontSynthesizeSmallCaps = !static_cast<bool>(m_font.fontDescription().fontSynthesis() & FontSynthesisSmallCaps);
    318321    bool engageAllSmallCapsProcessing = fontVariantCaps == FontVariantCaps::AllSmall || fontVariantCaps == FontVariantCaps::AllPetite;
    319322    bool engageSmallCapsProcessing = engageAllSmallCapsProcessing || fontVariantCaps == FontVariantCaps::Small || fontVariantCaps == FontVariantCaps::Petite;
     
    342345
    343346    auto capitalizedBase = capitalized(baseCharacter);
    344     if (shouldSynthesize(nextFont, baseCharacter, capitalizedBase, fontVariantCaps, engageAllSmallCapsProcessing)) {
     347    if (shouldSynthesize(dontSynthesizeSmallCaps, nextFont, baseCharacter, capitalizedBase, fontVariantCaps, engageAllSmallCapsProcessing)) {
    345348        synthesizedFont = &nextFont->noSynthesizableFeaturesFont();
    346349        smallSynthesizedFont = synthesizedFont->smallCapsFont(m_font.fontDescription());
     
    383386
    384387        capitalizedBase = capitalized(baseCharacter);
    385         if (!synthesizedFont && shouldSynthesize(nextFont, baseCharacter, capitalizedBase, fontVariantCaps, engageAllSmallCapsProcessing)) {
     388        if (!synthesizedFont && shouldSynthesize(dontSynthesizeSmallCaps, nextFont, baseCharacter, capitalizedBase, fontVariantCaps, engageAllSmallCapsProcessing)) {
    386389            // Rather than synthesize each character individually, we should synthesize the entire "run" if any character requires synthesis.
    387390            synthesizedFont = &nextFont->noSynthesizableFeaturesFont();
  • trunk/Source/WebCore/platform/text/TextFlags.h

    r205282 r209875  
    6161    FontSynthesisNone = 0x0,
    6262    FontSynthesisWeight = 0x1,
    63     FontSynthesisStyle = 0x2
     63    FontSynthesisStyle = 0x2,
     64    FontSynthesisSmallCaps = 0x4
    6465};
    6566typedef unsigned FontSynthesis;
    66 const unsigned FontSynthesisWidth = 2;
     67const unsigned FontSynthesisWidth = 3;
    6768
    6869enum class FontVariantLigatures {
Note: See TracChangeset for help on using the changeset viewer.