Title: [130437] trunk
Revision
130437
Author
[email protected]
Date
2012-10-04 17:35:56 -0700 (Thu, 04 Oct 2012)

Log Message

1ex should equal .5em when the font has no x-height metric
https://bugs.webkit.org/show_bug.cgi?id=80360

Patch by Tab Atkins <[email protected]> on 2012-10-04
Reviewed by Eric Seidel.

Source/WebCore:

Updated FontMetrics and CSSPrimitiveValue to have/use an explicit "hasXHeight" flag to determine how to size an 'ex' unit.

Updated a few of the platform font files to set the flag properly.

Patch cleanup by David Barr <[email protected]>.

Test: fast/css/ex-unit-with-no-x-height.html

* css/CSSPrimitiveValue.cpp:
(WebCore::CSSPrimitiveValue::computeLengthDouble):
* platform/graphics/FontMetrics.h:
(WebCore::FontMetrics::FontMetrics):
(WebCore::FontMetrics::setXHeight):
(FontMetrics):
(WebCore::FontMetrics::hasXHeight):
(WebCore::FontMetrics::setHasXHeight):
(WebCore::FontMetrics::reset):
* platform/graphics/skia/SimpleFontDataSkia.cpp:
(WebCore::SimpleFontData::platformInit):

LayoutTests:

If a font has no x-height metric, 1ex should equal .5em.

Test layout tweaked by David Barr <[email protected]>.

* fast/css/ex-unit-with-no-x-height-expected.txt: Added.
* fast/css/ex-unit-with-no-x-height.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (130436 => 130437)


--- trunk/LayoutTests/ChangeLog	2012-10-05 00:34:19 UTC (rev 130436)
+++ trunk/LayoutTests/ChangeLog	2012-10-05 00:35:56 UTC (rev 130437)
@@ -1,3 +1,17 @@
+2012-10-04  Tab Atkins  <[email protected]>
+
+        1ex should equal .5em when the font has no x-height metric
+        https://bugs.webkit.org/show_bug.cgi?id=80360
+
+        Reviewed by Eric Seidel.
+
+        If a font has no x-height metric, 1ex should equal .5em.
+
+        Test layout tweaked by David Barr <[email protected]>.
+
+        * fast/css/ex-unit-with-no-x-height-expected.txt: Added.
+        * fast/css/ex-unit-with-no-x-height.html: Added.
+
 2012-10-04  Tullio Lucena  <[email protected]>
 
         [Qt] New test introduced in r129346 inspector-protocol/css-getSupportedCSSProperties.html fails

Added: trunk/LayoutTests/fast/css/ex-unit-with-no-x-height-expected.txt (0 => 130437)


--- trunk/LayoutTests/fast/css/ex-unit-with-no-x-height-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/css/ex-unit-with-no-x-height-expected.txt	2012-10-05 00:35:56 UTC (rev 130437)
@@ -0,0 +1,10 @@
+This test ensures that the CSS 'ex' unit is treated as half the size of the CSS 'em' unit when a font has no x-height information.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS measureExBox(); is '50px'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/css/ex-unit-with-no-x-height.html (0 => 130437)


--- trunk/LayoutTests/fast/css/ex-unit-with-no-x-height.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css/ex-unit-with-no-x-height.html	2012-10-05 00:35:56 UTC (rev 130437)
@@ -0,0 +1,38 @@
+<!doctype html>
+<svg xmlns = 'http://www.w3.org/2000/svg' style='display:none'>
+  <defs>
+    <font id="Font1">
+      <font-face font-family="block" />
+    </font>
+  </defs>
+</svg>
+
+<style>
+.em { height: .5em; width: .5em; }
+.ex { height: 1ex; width: 1ex; }
+.cover { background: green; }
+.back { background: red; }
+.one { left: 10px; }
+.two { left: 70px; }
+#test > div { font-family: block; font-size: 100px; position: absolute; top: 10px; }
+#description { margin-top: 70px; }
+</style>
+
+<div id='test'>
+  <div class='back em one'></div>
+  <div class='cover ex one' id='ex'></div>
+
+  <div class='back ex two'></div>
+  <div class='cover em two'></div>
+</div>
+<script src=""
+<script>
+description("This test ensures that the CSS 'ex' unit is treated as half the size of the CSS 'em' unit when a font has no x-height information.")
+
+function measureExBox() {
+  return getComputedStyle(document.getElementById('ex')).width;
+}
+
+shouldBe("measureExBox();", "'50px'")
+</script>
+<script src=""

Modified: trunk/Source/WebCore/ChangeLog (130436 => 130437)


--- trunk/Source/WebCore/ChangeLog	2012-10-05 00:34:19 UTC (rev 130436)
+++ trunk/Source/WebCore/ChangeLog	2012-10-05 00:35:56 UTC (rev 130437)
@@ -1,3 +1,30 @@
+2012-10-04  Tab Atkins  <[email protected]>
+
+        1ex should equal .5em when the font has no x-height metric
+        https://bugs.webkit.org/show_bug.cgi?id=80360
+
+        Reviewed by Eric Seidel.
+
+        Updated FontMetrics and CSSPrimitiveValue to have/use an explicit "hasXHeight" flag to determine how to size an 'ex' unit.
+
+        Updated a few of the platform font files to set the flag properly.
+
+        Patch cleanup by David Barr <[email protected]>.
+
+        Test: fast/css/ex-unit-with-no-x-height.html
+
+        * css/CSSPrimitiveValue.cpp:
+        (WebCore::CSSPrimitiveValue::computeLengthDouble):
+        * platform/graphics/FontMetrics.h:
+        (WebCore::FontMetrics::FontMetrics):
+        (WebCore::FontMetrics::setXHeight):
+        (FontMetrics):
+        (WebCore::FontMetrics::hasXHeight):
+        (WebCore::FontMetrics::setHasXHeight):
+        (WebCore::FontMetrics::reset):
+        * platform/graphics/skia/SimpleFontDataSkia.cpp:
+        (WebCore::SimpleFontData::platformInit):
+
 2012-10-04  Ryosuke Niwa  <[email protected]>
 
         Build fix after r130411. Add the right offset.

Modified: trunk/Source/WebCore/css/CSSPrimitiveValue.cpp (130436 => 130437)


--- trunk/Source/WebCore/css/CSSPrimitiveValue.cpp	2012-10-05 00:34:19 UTC (rev 130436)
+++ trunk/Source/WebCore/css/CSSPrimitiveValue.cpp	2012-10-05 00:35:56 UTC (rev 130437)
@@ -522,7 +522,10 @@
             // FIXME: We have a bug right now where the zoom will be applied twice to EX units.
             // We really need to compute EX using fontMetrics for the original specifiedSize and not use
             // our actual constructed rendering font.
-            factor = style->fontMetrics().xHeight();
+            if (style->fontMetrics().hasXHeight())
+                factor = style->fontMetrics().xHeight();
+            else
+                factor = (computingFontSize ? style->fontDescription().specifiedSize() : style->fontDescription().computedSize()) / 2.0;
             break;
         case CSS_REMS:
             if (rootStyle)

Modified: trunk/Source/WebCore/platform/graphics/FontMetrics.h (130436 => 130437)


--- trunk/Source/WebCore/platform/graphics/FontMetrics.h	2012-10-05 00:34:19 UTC (rev 130436)
+++ trunk/Source/WebCore/platform/graphics/FontMetrics.h	2012-10-05 00:35:56 UTC (rev 130437)
@@ -36,6 +36,7 @@
         , m_lineGap(0)
         , m_lineSpacing(0)
         , m_xHeight(0)
+        , m_hasXHeight(false)
     {
     }
 
@@ -72,8 +73,15 @@
     void setLineSpacing(float lineSpacing) { m_lineSpacing = lineSpacing; }
 
     float xHeight() const { return m_xHeight; }
-    void setXHeight(float xHeight) { m_xHeight = xHeight; }
+    void setXHeight(float xHeight) 
+    { 
+        m_xHeight = xHeight;
+        m_hasXHeight = true;
+    }
 
+    bool hasXHeight() const { return m_hasXHeight && m_xHeight > 0; }
+    void setHasXHeight(bool hasXHeight) { m_hasXHeight = hasXHeight; }
+
     // Integer variants of certain metrics, used for HTML rendering.
     int ascent(FontBaseline baselineType = AlphabeticBaseline) const
     {
@@ -113,6 +121,7 @@
         m_lineGap = 0;
         m_lineSpacing = 0;
         m_xHeight = 0;
+        m_hasXHeight = false;
     }
 
     unsigned m_unitsPerEm;
@@ -121,6 +130,7 @@
     float m_lineGap;
     float m_lineSpacing;
     float m_xHeight;
+    bool m_hasXHeight;
 };
 
 static inline float scaleEmToUnits(float x, unsigned unitsPerEm)

Modified: trunk/Source/WebCore/platform/graphics/skia/SimpleFontDataSkia.cpp (130436 => 130437)


--- trunk/Source/WebCore/platform/graphics/skia/SimpleFontDataSkia.cpp	2012-10-05 00:34:19 UTC (rev 130436)
+++ trunk/Source/WebCore/platform/graphics/skia/SimpleFontDataSkia.cpp	2012-10-05 00:35:56 UTC (rev 130437)
@@ -112,16 +112,18 @@
     m_fontMetrics.setDescent(descent);
 
     float xHeight;
-    if (metrics.fXHeight)
+    if (metrics.fXHeight) {
         xHeight = metrics.fXHeight;
-    else {
-        // hack taken from the Windows port
-        xHeight = ascent * 0.56f;
+        m_fontMetrics.setXHeight(xHeight);
+    } else {
+        xHeight = ascent * 0.56; // Best guess from Windows font metrics.
+        m_fontMetrics.setXHeight(xHeight);
+        m_fontMetrics.setHasXHeight(false);
     }
 
+
     float lineGap = SkScalarToFloat(metrics.fLeading);
     m_fontMetrics.setLineGap(lineGap);
-    m_fontMetrics.setXHeight(xHeight);
     m_fontMetrics.setLineSpacing(lroundf(ascent) + lroundf(descent) + lroundf(lineGap));
 
     if (platformData().orientation() == Vertical && !isTextOrientationFallback()) {
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to