Title: [122651] trunk
Revision
122651
Author
[email protected]
Date
2012-07-13 17:52:56 -0700 (Fri, 13 Jul 2012)

Log Message

[Chromium] Sometimes bottom of text is truncated when page has a fractional scale
https://bugs.webkit.org/show_bug.cgi?id=88684

Reviewed by Tony Chang.

Source/WebCore:

When the page has a fractional scale, the ascent and descent part of the fonts might be fractional.
If the descent part is rounded down, the bottom of the text might be truncated when displayed
when subpixel text positioning is enabled.
To avoid that, borrow one unit from the ascent when possible.

Test: fast/text/descent-clip-in-scaled-page.html

* platform/graphics/harfbuzz/FontPlatformDataHarfBuzz.cpp:
(WebCore::FontPlatformData::setupPaint): Moved NoPreference handling into querySystemForRenderStyle so that fontRenderStyle() can have actual styles without NoPreference.
(WebCore::FontPlatformData::querySystemForRenderStyle): Added NoPreference handling (moved from setupPaint)
* platform/graphics/harfbuzz/FontPlatformDataHarfBuzz.h:
(FontPlatformData):
(WebCore::FontPlatformData::fontRenderStyle): Added to let SimpleFontDataSkia access the font render styles.
* platform/graphics/skia/SimpleFontDataSkia.cpp:
(WebCore::SimpleFontData::platformInit):

LayoutTests:

New test case.

* fast/text/descent-clip-in-scaled-page-expected.html: Added.
* fast/text/descent-clip-in-scaled-page.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (122650 => 122651)


--- trunk/LayoutTests/ChangeLog	2012-07-14 00:44:47 UTC (rev 122650)
+++ trunk/LayoutTests/ChangeLog	2012-07-14 00:52:56 UTC (rev 122651)
@@ -1,3 +1,15 @@
+2012-07-13  Xianzhu Wang  <[email protected]>
+
+        [Chromium] Sometimes bottom of text is truncated when page has a fractional scale
+        https://bugs.webkit.org/show_bug.cgi?id=88684
+
+        Reviewed by Tony Chang.
+
+        New test case.
+
+        * fast/text/descent-clip-in-scaled-page-expected.html: Added.
+        * fast/text/descent-clip-in-scaled-page.html: Added.
+
 2012-07-13  Filip Pizlo  <[email protected]>
 
         ASSERTION FAILED: use.useKind() != DoubleUse

Added: trunk/LayoutTests/fast/text/descent-clip-in-scaled-page-expected.html (0 => 122651)


--- trunk/LayoutTests/fast/text/descent-clip-in-scaled-page-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text/descent-clip-in-scaled-page-expected.html	2012-07-14 00:52:56 UTC (rev 122651)
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+    div {
+        font-family: ahem;
+        font-size: 16px;
+    }
+</style>
+<script>
+    if (window.layoutTestController && window.layoutTestController.setTextSubpixelPositioning)
+        window.layoutTestController.setTextSubpixelPositioning(true);
+    if (window.internals)
+        window.internals.settings.setPageScaleFactor(1.7, 0, 0);
+</script>
+</head>
+<body>
+    Tests if the bottom of the text is truncated when the page is scaled by a fractional factor.
+    If success, the text in the "overflow: hidden" div (the test case) should be displayed
+    the same as in a normal div (the ref html).
+    'p' is the character in ahem font with only the descent part.
+    <div>&nbsp;pppp&nbsp;</div>
+</body>
+</html>

Added: trunk/LayoutTests/fast/text/descent-clip-in-scaled-page.html (0 => 122651)


--- trunk/LayoutTests/fast/text/descent-clip-in-scaled-page.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text/descent-clip-in-scaled-page.html	2012-07-14 00:52:56 UTC (rev 122651)
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+    div {
+        font-family: ahem;
+        font-size: 16px;
+        overflow: hidden; /* the only difference between the test the the ref html */
+    }
+</style>
+<script>
+    if (window.layoutTestController && window.layoutTestController.setTextSubpixelPositioning)
+        window.layoutTestController.setTextSubpixelPositioning(true);
+    if (window.internals)
+        window.internals.settings.setPageScaleFactor(1.7, 0, 0);
+</script>
+</head>
+<body>
+    Tests if the bottom of the text is truncated when the page is scaled by a fractional factor.
+    If success, the text in the "overflow: hidden" div (the test case) should be displayed
+    the same as in a normal div (the ref html).
+    'p' is the character in ahem font with only the descent part.
+    <div>&nbsp;pppp&nbsp;</div>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (122650 => 122651)


--- trunk/Source/WebCore/ChangeLog	2012-07-14 00:44:47 UTC (rev 122650)
+++ trunk/Source/WebCore/ChangeLog	2012-07-14 00:52:56 UTC (rev 122651)
@@ -1,3 +1,26 @@
+2012-07-13  Xianzhu Wang  <[email protected]>
+
+        [Chromium] Sometimes bottom of text is truncated when page has a fractional scale
+        https://bugs.webkit.org/show_bug.cgi?id=88684
+
+        Reviewed by Tony Chang.
+
+        When the page has a fractional scale, the ascent and descent part of the fonts might be fractional.
+        If the descent part is rounded down, the bottom of the text might be truncated when displayed
+        when subpixel text positioning is enabled.
+        To avoid that, borrow one unit from the ascent when possible.
+
+        Test: fast/text/descent-clip-in-scaled-page.html
+
+        * platform/graphics/harfbuzz/FontPlatformDataHarfBuzz.cpp:
+        (WebCore::FontPlatformData::setupPaint): Moved NoPreference handling into querySystemForRenderStyle so that fontRenderStyle() can have actual styles without NoPreference.
+        (WebCore::FontPlatformData::querySystemForRenderStyle): Added NoPreference handling (moved from setupPaint)
+        * platform/graphics/harfbuzz/FontPlatformDataHarfBuzz.h:
+        (FontPlatformData):
+        (WebCore::FontPlatformData::fontRenderStyle): Added to let SimpleFontDataSkia access the font render styles.
+        * platform/graphics/skia/SimpleFontDataSkia.cpp:
+        (WebCore::SimpleFontData::platformInit):
+
 2012-07-13  Ryosuke Niwa  <[email protected]>
 
         Remove an assertion after r122637.

Modified: trunk/Source/WebCore/platform/graphics/harfbuzz/FontPlatformDataHarfBuzz.cpp (122650 => 122651)


--- trunk/Source/WebCore/platform/graphics/harfbuzz/FontPlatformDataHarfBuzz.cpp	2012-07-14 00:44:47 UTC (rev 122650)
+++ trunk/Source/WebCore/platform/graphics/harfbuzz/FontPlatformDataHarfBuzz.cpp	2012-07-14 00:52:56 UTC (rev 122651)
@@ -175,31 +175,19 @@
 
 void FontPlatformData::setupPaint(SkPaint* paint) const
 {
+    paint->setAntiAlias(m_style.useAntiAlias);
+    paint->setHinting(static_cast<SkPaint::Hinting>(m_style.hintStyle));
+    paint->setEmbeddedBitmapText(m_style.useBitmaps);
+    paint->setAutohinted(m_style.useAutoHint);
+    paint->setSubpixelText(m_style.useSubpixelPositioning);
+    if (m_style.useAntiAlias)
+        paint->setLCDRenderText(m_style.useSubpixelRendering);
+
     const float ts = m_textSize >= 0 ? m_textSize : 12;
-
-    paint->setAntiAlias(m_style.useAntiAlias == FontRenderStyle::NoPreference ? useSkiaAntiAlias : m_style.useAntiAlias);
-    switch (m_style.useHinting) {
-    case FontRenderStyle::NoPreference:
-        paint->setHinting(skiaHinting);
-        break;
-    case 0:
-        paint->setHinting(SkPaint::kNo_Hinting);
-        break;
-    default:
-        paint->setHinting(static_cast<SkPaint::Hinting>(m_style.hintStyle));
-        break;
-    }
-
-    paint->setEmbeddedBitmapText(m_style.useBitmaps == FontRenderStyle::NoPreference ? useSkiaBitmaps : m_style.useBitmaps);
     paint->setTextSize(SkFloatToScalar(ts));
     paint->setTypeface(m_typeface);
     paint->setFakeBoldText(m_fakeBold);
     paint->setTextSkewX(m_fakeItalic ? -SK_Scalar1 / 4 : 0);
-    paint->setAutohinted(m_style.useAutoHint == FontRenderStyle::NoPreference ? useSkiaAutoHint : m_style.useAutoHint);
-    paint->setSubpixelText(m_style.useSubpixelPositioning == FontRenderStyle::NoPreference ? useSkiaSubpixelPositioning : m_style.useSubpixelPositioning);
-
-    if (m_style.useAntiAlias == 1 || (m_style.useAntiAlias == FontRenderStyle::NoPreference && useSkiaAntiAlias))
-        paint->setLCDRenderText(m_style.useSubpixelRendering == FontRenderStyle::NoPreference ? useSkiaSubpixelRendering : m_style.useSubpixelRendering);
 }
 
 SkFontID FontPlatformData::uniqueID() const
@@ -272,6 +260,26 @@
 void FontPlatformData::querySystemForRenderStyle()
 {
     PlatformSupport::getRenderStyleForStrike(m_family.data(), (((int)m_textSize) << 2) | (m_typeface->style() & 3), &m_style);
+
+    // Fix FontRenderStyle::NoPreference to actual styles.
+    if (m_style.useAntiAlias == FontRenderStyle::NoPreference)
+         m_style.useAntiAlias = useSkiaAntiAlias;
+
+    if (!m_style.useHinting)
+        m_style.hintStyle = SkPaint::kNo_Hinting;
+    else if (m_style.useHinting == FontRenderStyle::NoPreference)
+        m_style.hintStyle = skiaHinting;
+
+    if (m_style.useBitmaps == FontRenderStyle::NoPreference)
+        m_style.useBitmaps = useSkiaBitmaps;
+    if (m_style.useAutoHint == FontRenderStyle::NoPreference)
+        m_style.useAutoHint = useSkiaAutoHint;
+    if (m_style.useSubpixelPositioning == FontRenderStyle::NoPreference)
+        m_style.useSubpixelPositioning = useSkiaSubpixelPositioning;
+    if (m_style.useAntiAlias == FontRenderStyle::NoPreference)
+        m_style.useAntiAlias = useSkiaAntiAlias;
+    if (m_style.useSubpixelRendering == FontRenderStyle::NoPreference)
+        m_style.useSubpixelRendering = useSkiaSubpixelRendering;
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/harfbuzz/FontPlatformDataHarfBuzz.h (122650 => 122651)


--- trunk/Source/WebCore/platform/graphics/harfbuzz/FontPlatformDataHarfBuzz.h	2012-07-14 00:44:47 UTC (rev 122650)
+++ trunk/Source/WebCore/platform/graphics/harfbuzz/FontPlatformDataHarfBuzz.h	2012-07-14 00:52:56 UTC (rev 122651)
@@ -139,6 +139,9 @@
     HarfbuzzFace* harfbuzzFace() const;
 #endif
 
+    // The returned styles are all actual styles without FontRenderStyle::NoPreference.
+    const FontRenderStyle& fontRenderStyle() const { return m_style; }
+
     // -------------------------------------------------------------------------
     // Global font preferences...
 

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


--- trunk/Source/WebCore/platform/graphics/skia/SimpleFontDataSkia.cpp	2012-07-14 00:44:47 UTC (rev 122650)
+++ trunk/Source/WebCore/platform/graphics/skia/SimpleFontDataSkia.cpp	2012-07-14 00:52:56 UTC (rev 122651)
@@ -86,7 +86,7 @@
     float descent;
 
     // Beware those who step here: This code is designed to match Win32 font
-    // metrics *exactly*.
+    // metrics *exactly* (except the adjustment of ascent/descent on Linux/Android).
     if (isVDMXValid) {
         ascent = vdmxAscent;
         descent = -vdmxDescent;
@@ -94,6 +94,16 @@
         SkScalar height = -metrics.fAscent + metrics.fDescent + metrics.fLeading;
         ascent = SkScalarRound(-metrics.fAscent);
         descent = SkScalarRound(height) - ascent;
+#if OS(LINUX) || OS(ANDROID)
+        // When subpixel positioning is enabled, if the descent is rounded down, the descent part
+        // of the glyph may be truncated when displayed in a 'overflow: hidden' container.
+        // To avoid that, borrow 1 unit from the ascent when possible.
+        // FIXME: This can be removed if sub-pixel ascent/descent is supported.
+        if (platformData().fontRenderStyle().useSubpixelPositioning && descent < SkScalarToFloat(metrics.fDescent) && ascent >= 1) {
+            ++descent;
+            --ascent;
+        }
+#endif
     }
 
     m_fontMetrics.setAscent(ascent);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to