<rdar://problem/10674686> Implement the font-kerning CSS property
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Jan 2012 08:38:29 +0000 (08:38 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Jan 2012 08:38:29 +0000 (08:38 +0000)
https://bugs.webkit.org/show_bug.cgi?id=76033

Reviewed by Darin Adler.

Source/WebCore:

Tests: fast/text/font-kerning-expected.html
       fast/text/font-kerning.html

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue): Added code to handle
font-kerning.
* css/CSSParser.cpp:
(WebCore::CSSParser::parseValue): Ditto.
* css/CSSPrimitiveValueMappings.h:
(WebCore::CSSPrimitiveValue::CSSPrimitiveValue): Added mapping from FontDescription::Kerning.
(WebCore::CSSPrimitiveValue::operator FontDescription::Kerning): Added mapping to
FontDescription::Kerning.
* css/CSSProperty.cpp:
(WebCore::CSSProperty::isInheritedProperty): Added font-kerning to the set of inherited
properties.
* css/CSSPropertyNames.in: Added -webkit-font-kerning.
* css/CSSStyleApplyProperty.cpp:
(WebCore::CSSStyleApplyProperty::CSSStyleApplyProperty): Added a handler for font-kerning.
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::applyDeclaration): Updated for the number of properties that
affect the font.
* platform/graphics/Font.h:
(WebCore::Font::typesettingFeatures): Changed to enable kerning if font-kerning is set to
normal, disable it if font-kerning is set to none, and leave it to the default (determined
by the text-rendering property) if font-kerning is set to auto.
* platform/graphics/FontDescription.h:
(WebCore::FontDescription::FontDescription): Added a Kerning enum.
(WebCore::FontDescription::kerning): Added this getter.
(WebCore::FontDescription::setKerning): Added this setter.
(WebCore::FontDescription::operator==): Updated to compare the m_kerning member.

LayoutTests:

* fast/css/getComputedStyle/computed-style-expected.txt:
* fast/text/font-kerning-expected.html: Added.
* fast/text/font-kerning.html: Added.
* platform/chromium-win/fast/css/getComputedStyle/computed-style-without-renderer-expected.txt:
* platform/chromium-win/svg/css/getComputedStyle-basic-expected.txt:
* platform/gtk/fast/css/getComputedStyle/computed-style-without-renderer-expected.txt:
* platform/mac/fast/css/getComputedStyle/computed-style-without-renderer-expected.txt:
* platform/qt/fast/css/getComputedStyle/computed-style-without-renderer-expected.txt:
* svg/css/getComputedStyle-basic-expected.txt:

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

19 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/css/getComputedStyle/computed-style-expected.txt
LayoutTests/fast/text/font-kerning-expected.html [new file with mode: 0644]
LayoutTests/fast/text/font-kerning.html [new file with mode: 0644]
LayoutTests/platform/chromium-win/fast/css/getComputedStyle/computed-style-without-renderer-expected.txt
LayoutTests/platform/chromium-win/svg/css/getComputedStyle-basic-expected.txt
LayoutTests/platform/gtk/fast/css/getComputedStyle/computed-style-without-renderer-expected.txt
LayoutTests/platform/mac/fast/css/getComputedStyle/computed-style-without-renderer-expected.txt
LayoutTests/platform/qt/fast/css/getComputedStyle/computed-style-without-renderer-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/css/CSSComputedStyleDeclaration.cpp
Source/WebCore/css/CSSParser.cpp
Source/WebCore/css/CSSPrimitiveValueMappings.h
Source/WebCore/css/CSSProperty.cpp
Source/WebCore/css/CSSPropertyNames.in
Source/WebCore/css/CSSStyleApplyProperty.cpp
Source/WebCore/css/CSSStyleSelector.cpp
Source/WebCore/platform/graphics/Font.h
Source/WebCore/platform/graphics/FontDescription.h

index 1e618b4..e1f4175 100644 (file)
@@ -1,3 +1,20 @@
+2012-01-11  Dan Bernstein  <mitz@apple.com>
+
+        <rdar://problem/10674686> Implement the font-kerning CSS property
+        https://bugs.webkit.org/show_bug.cgi?id=76033
+
+        Reviewed by Darin Adler.
+
+        * fast/css/getComputedStyle/computed-style-expected.txt:
+        * fast/text/font-kerning-expected.html: Added.
+        * fast/text/font-kerning.html: Added.
+        * platform/chromium-win/fast/css/getComputedStyle/computed-style-without-renderer-expected.txt:
+        * platform/chromium-win/svg/css/getComputedStyle-basic-expected.txt:
+        * platform/gtk/fast/css/getComputedStyle/computed-style-without-renderer-expected.txt:
+        * platform/mac/fast/css/getComputedStyle/computed-style-without-renderer-expected.txt:
+        * platform/qt/fast/css/getComputedStyle/computed-style-without-renderer-expected.txt:
+        * svg/css/getComputedStyle-basic-expected.txt:
+
 2012-01-10  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r104263 and r104381.
index 7602b17..5d585b8 100644 (file)
@@ -148,6 +148,7 @@ zoom: 1;
 -webkit-flex-direction: row;
 -webkit-flex-flow: row nowrap;
 -webkit-flex-wrap: nowrap;
+-webkit-font-kerning: auto;
 -webkit-font-smoothing: auto;
 -webkit-highlight: none;
 -webkit-hyphenate-character: auto;
diff --git a/LayoutTests/fast/text/font-kerning-expected.html b/LayoutTests/fast/text/font-kerning-expected.html
new file mode 100644 (file)
index 0000000..6a0d1d9
--- /dev/null
@@ -0,0 +1,11 @@
+<style>
+    .kerned { text-rendering: optimizelegibility; }
+</style>
+<body style="font-size: 36px;">
+    <div>AVAVAVAV</div>
+    <div>AVAVAVAV</div>
+    <div class="kerned">AVAVAVAV</div>
+    <div>AVAVAVAV</div>
+    <div class="kerned">AVAVAVAV</div>
+    <div class="kerned">AVAVAVAV</div>
+</body>
diff --git a/LayoutTests/fast/text/font-kerning.html b/LayoutTests/fast/text/font-kerning.html
new file mode 100644 (file)
index 0000000..a0dfc2d
--- /dev/null
@@ -0,0 +1,17 @@
+<style>
+    .kerning-none { -webkit-font-kerning: none; }
+    .kerning-auto { -webkit-font-kerning: auto; }
+    .kerning-normal { -webkit-font-kerning: normal; }
+</style>
+<body style="font-size: 36px;">
+    <div>
+        <div class="kerning-none">AVAVAVAV</div>
+        <div class="kerning-auto">AVAVAVAV</div>
+        <div class="kerning-normal">AVAVAVAV</div>
+    </div>
+    <div style="text-rendering: optimizelegibility">
+        <div class="kerning-none">AVAVAVAV</div>
+        <div class="kerning-auto">AVAVAVAV</div>
+        <div class="kerning-normal">AVAVAVAV</div>
+    </div>
+</body>
index 67a57d9..4d53571 100644 (file)
@@ -147,6 +147,7 @@ Computed style of an element whose parent's 'display' value is 'none':
     -webkit-flex-direction: row
     -webkit-flex-flow: row nowrap
     -webkit-flex-wrap: nowrap
+    -webkit-font-kerning: auto
     -webkit-font-smoothing: auto
     -webkit-highlight: none
     -webkit-hyphenate-character: auto
index 5e19cbd..a7c9e90 100644 (file)
@@ -294,6 +294,8 @@ rect: style.getPropertyValue(-webkit-flex-flow) : row nowrap
 rect: style.getPropertyCSSValue(-webkit-flex-flow) : [object CSSValueList]
 rect: style.getPropertyValue(-webkit-flex-wrap) : nowrap
 rect: style.getPropertyCSSValue(-webkit-flex-wrap) : [object CSSPrimitiveValue]
+rect: style.getPropertyValue(-webkit-font-kerning) : auto
+rect: style.getPropertyCSSValue(-webkit-font-kerning) : [object CSSPrimitiveValue]
 rect: style.getPropertyValue(-webkit-font-smoothing) : auto
 rect: style.getPropertyCSSValue(-webkit-font-smoothing) : [object CSSPrimitiveValue]
 rect: style.getPropertyValue(-webkit-highlight) : none
@@ -802,6 +804,8 @@ g: style.getPropertyValue(-webkit-flex-flow) : row nowrap
 g: style.getPropertyCSSValue(-webkit-flex-flow) : [object CSSValueList]
 g: style.getPropertyValue(-webkit-flex-wrap) : nowrap
 g: style.getPropertyCSSValue(-webkit-flex-wrap) : [object CSSPrimitiveValue]
+g: style.getPropertyValue(-webkit-font-kerning) : auto
+g: style.getPropertyCSSValue(-webkit-font-kerning) : [object CSSPrimitiveValue]
 g: style.getPropertyValue(-webkit-font-smoothing) : auto
 g: style.getPropertyCSSValue(-webkit-font-smoothing) : [object CSSPrimitiveValue]
 g: style.getPropertyValue(-webkit-highlight) : none
index dff02bb..5e12aef 100644 (file)
@@ -147,6 +147,7 @@ Computed style of an element whose parent's 'display' value is 'none':
     -webkit-flex-direction: row
     -webkit-flex-flow: row nowrap
     -webkit-flex-wrap: nowrap
+    -webkit-font-kerning: auto
     -webkit-font-smoothing: auto
     -webkit-highlight: none
     -webkit-hyphenate-character: auto
index 5b586d2..4c70aad 100644 (file)
@@ -147,6 +147,7 @@ Computed style of an element whose parent's 'display' value is 'none':
     -webkit-flex-direction: row
     -webkit-flex-flow: row nowrap
     -webkit-flex-wrap: nowrap
+    -webkit-font-kerning: auto
     -webkit-font-smoothing: auto
     -webkit-highlight: none
     -webkit-hyphenate-character: auto
index b9781ef..ed62ef6 100644 (file)
@@ -147,6 +147,7 @@ Computed style of an element whose parent's 'display' value is 'none':
     -webkit-flex-direction: row
     -webkit-flex-flow: row nowrap
     -webkit-flex-wrap: nowrap
+    -webkit-font-kerning: auto
     -webkit-font-smoothing: auto
     -webkit-highlight: none
     -webkit-hyphenate-character: auto
index 20caa75..d8d28c2 100644 (file)
@@ -1,3 +1,41 @@
+2012-01-11  Dan Bernstein  <mitz@apple.com>
+
+        <rdar://problem/10674686> Implement the font-kerning CSS property
+        https://bugs.webkit.org/show_bug.cgi?id=76033
+
+        Reviewed by Darin Adler.
+
+        Tests: fast/text/font-kerning-expected.html
+               fast/text/font-kerning.html
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue): Added code to handle
+        font-kerning.
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::parseValue): Ditto.
+        * css/CSSPrimitiveValueMappings.h:
+        (WebCore::CSSPrimitiveValue::CSSPrimitiveValue): Added mapping from FontDescription::Kerning.
+        (WebCore::CSSPrimitiveValue::operator FontDescription::Kerning): Added mapping to
+        FontDescription::Kerning.
+        * css/CSSProperty.cpp:
+        (WebCore::CSSProperty::isInheritedProperty): Added font-kerning to the set of inherited
+        properties.
+        * css/CSSPropertyNames.in: Added -webkit-font-kerning.
+        * css/CSSStyleApplyProperty.cpp:
+        (WebCore::CSSStyleApplyProperty::CSSStyleApplyProperty): Added a handler for font-kerning.
+        * css/CSSStyleSelector.cpp:
+        (WebCore::CSSStyleSelector::applyDeclaration): Updated for the number of properties that
+        affect the font.
+        * platform/graphics/Font.h:
+        (WebCore::Font::typesettingFeatures): Changed to enable kerning if font-kerning is set to
+        normal, disable it if font-kerning is set to none, and leave it to the default (determined
+        by the text-rendering property) if font-kerning is set to auto.
+        * platform/graphics/FontDescription.h:
+        (WebCore::FontDescription::FontDescription): Added a Kerning enum.
+        (WebCore::FontDescription::kerning): Added this getter.
+        (WebCore::FontDescription::setKerning): Added this setter.
+        (WebCore::FontDescription::operator==): Updated to compare the m_kerning member.
+
 2012-01-10  Ryosuke Niwa  <rniwa@webkit.org>
 
         Build fix. Forgot to revert Node.h.
index c9a1f00..112abbe 100644 (file)
@@ -221,6 +221,7 @@ static const int computedProperties[] = {
     CSSPropertyWebkitFlexDirection,
     CSSPropertyWebkitFlexFlow,
     CSSPropertyWebkitFlexWrap,
+    CSSPropertyWebkitFontKerning,
     CSSPropertyWebkitFontSmoothing,
 #if ENABLE(CSS_GRID_LAYOUT)
     CSSPropertyWebkitGridColumns,
@@ -1866,6 +1867,8 @@ PassRefPtr<CSSValue> CSSComputedStyleDeclaration::getPropertyCSSValue(int proper
             return cssValuePool->createValue(style->matchNearestMailBlockquoteColor());
         case CSSPropertyResize:
             return cssValuePool->createValue(style->resize());
+        case CSSPropertyWebkitFontKerning:
+            return cssValuePool->createValue(style->fontDescription().kerning());
         case CSSPropertyWebkitFontSmoothing:
             return cssValuePool->createValue(style->fontDescription().fontSmoothing());
         case CSSPropertyZIndex:
index cc50fa2..2f5cab6 100644 (file)
@@ -2228,6 +2228,11 @@ bool CSSParser::parseValue(int propId, bool important)
             return parseFontFeatureSettings(important);
         break;
 
+    case CSSPropertyWebkitFontKerning:
+        if (id == CSSValueAuto || id == CSSValueNormal || id == CSSValueNone)
+            validPrimitive = true;
+        break;
+
     case CSSPropertyWebkitWrapShapeInside:
     case CSSPropertyWebkitWrapShapeOutside:
         if (id == CSSValueAuto)
index f7c725f..6d85bee 100644 (file)
@@ -2826,6 +2826,41 @@ template<> inline CSSPrimitiveValue::operator EPointerEvents() const
     }
 }
 
+template<> inline CSSPrimitiveValue::CSSPrimitiveValue(FontDescription::Kerning kerning)
+    : CSSValue(PrimitiveClass)
+{
+    m_primitiveUnitType = CSS_IDENT;
+    switch (kerning) {
+    case FontDescription::AutoKerning:
+        m_value.ident = CSSValueAuto;
+        return;
+    case FontDescription::NormalKerning:
+        m_value.ident = CSSValueNormal;
+        return;
+    case FontDescription::NoneKerning:
+        m_value.ident = CSSValueNone;
+        return;
+    }
+
+    ASSERT_NOT_REACHED();
+    m_value.ident = CSSValueAuto;
+}
+
+template<> inline CSSPrimitiveValue::operator FontDescription::Kerning() const
+{
+    switch (m_value.ident) {
+    case CSSValueAuto:
+        return FontDescription::AutoKerning;
+    case CSSValueNormal:
+        return FontDescription::NormalKerning;
+    case CSSValueNone:
+        return FontDescription::NoneKerning;
+    }
+
+    ASSERT_NOT_REACHED();
+    return FontDescription::AutoKerning;
+}
+
 template<> inline CSSPrimitiveValue::CSSPrimitiveValue(FontSmoothingMode smoothing)
     : CSSValue(PrimitiveClass)
 {
index 6d13562..b3d056c 100644 (file)
@@ -318,6 +318,7 @@ bool CSSProperty::isInheritedProperty(unsigned propertyID)
     case CSSPropertyWebkitBoxDirection:
     case CSSPropertyWebkitColorCorrection:
     case CSSPropertyWebkitFontFeatureSettings:
+    case CSSPropertyWebkitFontKerning:
     case CSSPropertyWebkitFontSmoothing:
     case CSSPropertyWebkitLocale:
     case CSSPropertyWebkitHighlight:
index 1ab3e89..e69875b 100644 (file)
@@ -21,6 +21,7 @@ font-variant
 font-weight
 text-rendering
 -webkit-font-feature-settings
+-webkit-font-kerning
 -webkit-font-smoothing
 -webkit-locale
 -webkit-text-orientation
index 931dda4..0b4a633 100644 (file)
@@ -1681,6 +1681,7 @@ CSSStyleApplyProperty::CSSStyleApplyProperty()
     setPropertyHandler(CSSPropertyFontStyle, ApplyPropertyFont<FontItalic, &FontDescription::italic, &FontDescription::setItalic, FontItalicOff>::createHandler());
     setPropertyHandler(CSSPropertyFontVariant, ApplyPropertyFont<FontSmallCaps, &FontDescription::smallCaps, &FontDescription::setSmallCaps, FontSmallCapsOff>::createHandler());
     setPropertyHandler(CSSPropertyTextRendering, ApplyPropertyFont<TextRenderingMode, &FontDescription::textRenderingMode, &FontDescription::setTextRenderingMode, AutoTextRendering>::createHandler());
+    setPropertyHandler(CSSPropertyWebkitFontKerning, ApplyPropertyFont<FontDescription::Kerning, &FontDescription::kerning, &FontDescription::setKerning, FontDescription::AutoKerning>::createHandler());
     setPropertyHandler(CSSPropertyWebkitFontSmoothing, ApplyPropertyFont<FontSmoothingMode, &FontDescription::fontSmoothing, &FontDescription::setFontSmoothing, AutoSmoothing>::createHandler());
     setPropertyHandler(CSSPropertyWebkitTextOrientation, ApplyPropertyFont<TextOrientation, &FontDescription::textOrientation, &FontDescription::setTextOrientation, TextOrientationVerticalRight>::createHandler());
     setPropertyHandler(CSSPropertyFontWeight, ApplyPropertyFontWeight::createHandler());
index c50aa27..97f19cf 100644 (file)
@@ -2227,7 +2227,7 @@ void CSSStyleSelector::applyDeclaration(CSSMutableStyleDeclaration* styleDeclara
         int property = current.id();
         if (applyFirst) {
             COMPILE_ASSERT(firstCSSProperty == CSSPropertyColor, CSS_color_is_first_property);
-            COMPILE_ASSERT(CSSPropertyZoom == CSSPropertyColor + 16, CSS_zoom_is_end_of_first_prop_range);
+            COMPILE_ASSERT(CSSPropertyZoom == CSSPropertyColor + 17, CSS_zoom_is_end_of_first_prop_range);
             COMPILE_ASSERT(CSSPropertyLineHeight == CSSPropertyZoom + 1, CSS_line_height_is_after_zoom);
             // give special priority to font-xxx, color properties, etc
             if (property > CSSPropertyLineHeight)
index 11484db..9a7a862 100644 (file)
@@ -116,7 +116,20 @@ public:
     TypesettingFeatures typesettingFeatures() const
     {
         TextRenderingMode textRenderingMode = m_fontDescription.textRenderingMode();
-        return textRenderingMode == OptimizeLegibility || textRenderingMode == GeometricPrecision ? Kerning | Ligatures : 0;
+        TypesettingFeatures features = textRenderingMode == OptimizeLegibility || textRenderingMode == GeometricPrecision ? Kerning | Ligatures : 0;
+
+        switch (m_fontDescription.kerning()) {
+        case FontDescription::NoneKerning:
+            features &= ~Kerning;
+            break;
+        case FontDescription::NormalKerning:
+            features |= Kerning;
+            break;
+        case FontDescription::AutoKerning:
+            break;
+        }
+
+        return features;
     }
 
     FontFamily& firstFamily() { return m_fontDescription.firstFamily(); }
index 71ca218..51a257b 100644 (file)
@@ -72,6 +72,8 @@ public:
     enum GenericFamilyType { NoFamily, StandardFamily, SerifFamily, SansSerifFamily, 
                              MonospaceFamily, CursiveFamily, FantasyFamily, PictographFamily };
 
+    enum Kerning { AutoKerning, NormalKerning, NoneKerning };
+
     FontDescription()
         : m_specifiedSize(0)
         , m_computedSize(0)
@@ -85,6 +87,7 @@ public:
         , m_genericFamily(NoFamily)
         , m_usePrinterFont(false)
         , m_renderingMode(NormalRenderingMode)
+        , m_kerning(AutoKerning)
         , m_keywordSize(0)
         , m_fontSmoothing(AutoSmoothing)
         , m_textRendering(AutoTextRendering)
@@ -112,6 +115,7 @@ public:
     // only use fixed default size when there is only one font family, and that family is "monospace"
     bool useFixedDefaultSize() const { return genericFamily() == MonospaceFamily && !family().next() && family().family() == monospaceFamily; }
     FontRenderingMode renderingMode() const { return static_cast<FontRenderingMode>(m_renderingMode); }
+    Kerning kerning() const { return static_cast<Kerning>(m_kerning); }
     unsigned keywordSize() const { return m_keywordSize; }
     FontSmoothingMode fontSmoothing() const { return static_cast<FontSmoothingMode>(m_fontSmoothing); }
     TextRenderingMode textRenderingMode() const { return static_cast<TextRenderingMode>(m_textRendering); }
@@ -141,6 +145,7 @@ public:
     void setUsePrinterFont(bool p) { m_usePrinterFont = p; }
 #endif
     void setRenderingMode(FontRenderingMode mode) { m_renderingMode = mode; }
+    void setKerning(Kerning kerning) { m_kerning = kerning; }
     void setKeywordSize(unsigned s) { m_keywordSize = s; }
     void setFontSmoothing(FontSmoothingMode smoothing) { m_fontSmoothing = smoothing; }
     void setTextRenderingMode(TextRenderingMode rendering) { m_textRendering = rendering; }
@@ -173,6 +178,7 @@ private:
     bool m_usePrinterFont : 1;
 
     unsigned m_renderingMode : 1;  // Used to switch between CG and GDI text on Windows.
+    unsigned m_kerning : 2; // Kerning
 
     unsigned m_keywordSize : 4; // We cache whether or not a font is currently represented by a CSS keyword (e.g., medium).  If so,
                            // then we can accurately translate across different generic families to adjust for different preference settings
@@ -196,6 +202,7 @@ inline bool FontDescription::operator==(const FontDescription& other) const
         && m_genericFamily == other.m_genericFamily
         && m_usePrinterFont == other.m_usePrinterFont
         && m_renderingMode == other.m_renderingMode
+        && m_kerning == other.m_kerning
         && m_keywordSize == other.m_keywordSize
         && m_fontSmoothing == other.m_fontSmoothing
         && m_textRendering == other.m_textRendering