Title: [213143] releases/WebKitGTK/webkit-2.16
Revision
213143
Author
carlo...@webkit.org
Date
2017-02-28 01:48:50 -0800 (Tue, 28 Feb 2017)

Log Message

Merge r213008 - Text might wrap when its preferred logical width is used for sizing the containing block.
https://bugs.webkit.org/show_bug.cgi?id=168864
<rdar://problem/30690734>

Reviewed by Antti Koivisto.

Source/WebCore:

In certain cases we end up measuring a text run in 2 different ways.
1. preferred width computation -> slow path FontCascade::width()
2. line breaking logic -> fast path FontCascade::widthForSimpleText()

FontCascade::width() and ::widthForSimpleText() might return different results for the same run even when
the individual glyph widths are measured to be the same. It's because they run diffrent set of
arithmetics on the float values and for certain values these arithmetics produce different results due to the floating point
precision.
Since RenderText::computePreferredLogicalWidths() currently forces us to use the slow path
(to retrieve fontfallback and glyph overflow information) the only alternative solution is to turn off the fast path
for all runs that have been already measured using the slow path (which would be just wasteful).

Test: fast/text/fast-run-width-vs-slow-run-width.html

* platform/graphics/FontCascade.cpp:
(WebCore::FontCascade::widthForSimpleText): Mimics WidthIterator::applyFontTransforms. Use the same set of arithmetics here.

LayoutTests:

* fast/text/fast-run-width-vs-slow-run-width-expected.html: Added.
* fast/text/fast-run-width-vs-slow-run-width.html: Added.

Modified Paths

Added Paths

Diff

Modified: releases/WebKitGTK/webkit-2.16/LayoutTests/ChangeLog (213142 => 213143)


--- releases/WebKitGTK/webkit-2.16/LayoutTests/ChangeLog	2017-02-28 09:47:45 UTC (rev 213142)
+++ releases/WebKitGTK/webkit-2.16/LayoutTests/ChangeLog	2017-02-28 09:48:50 UTC (rev 213143)
@@ -1,3 +1,14 @@
+2017-02-25  Zalan Bujtas <za...@apple.com>
+
+        Text might wrap when its preferred logical width is used for sizing the containing block.
+        https://bugs.webkit.org/show_bug.cgi?id=168864
+        <rdar://problem/30690734>
+
+        Reviewed by Antti Koivisto.
+
+        * fast/text/fast-run-width-vs-slow-run-width-expected.html: Added.
+        * fast/text/fast-run-width-vs-slow-run-width.html: Added.
+
 2017-02-24  Alex Christensen  <achristen...@webkit.org>
 
         .. should not remove windows drive letters in paths of file URLs

Added: releases/WebKitGTK/webkit-2.16/LayoutTests/fast/text/fast-run-width-vs-slow-run-width-expected.html (0 => 213143)


--- releases/WebKitGTK/webkit-2.16/LayoutTests/fast/text/fast-run-width-vs-slow-run-width-expected.html	                        (rev 0)
+++ releases/WebKitGTK/webkit-2.16/LayoutTests/fast/text/fast-run-width-vs-slow-run-width-expected.html	2017-02-28 09:48:50 UTC (rev 213143)
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<head>
+<title>This tests that fast and slow run width functions produce the same results.</title>
+<style>
+html {
+    font-family: "Helvetica Neue";
+    font-size: 62%;
+}
+
+div {
+    font-weight: 400;
+    font-size: 2.5rem;
+}
+</style>
+</head>
+<body>
+The text below should not wrap.<br>
+<div>alignment-baseline</div>
+</body>
+</html>

Added: releases/WebKitGTK/webkit-2.16/LayoutTests/fast/text/fast-run-width-vs-slow-run-width.html (0 => 213143)


--- releases/WebKitGTK/webkit-2.16/LayoutTests/fast/text/fast-run-width-vs-slow-run-width.html	                        (rev 0)
+++ releases/WebKitGTK/webkit-2.16/LayoutTests/fast/text/fast-run-width-vs-slow-run-width.html	2017-02-28 09:48:50 UTC (rev 213143)
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<head>
+<title>This tests that fast and slow run width functions produce the same results.</title>
+<style>
+html {
+    font-family: "Helvetica Neue";
+    font-size: 62%;
+}
+
+div {
+    font-weight: 400;
+    font-size: 2.5rem;
+    display: inline-block;
+}
+</style>
+</head>
+<body>
+The text below should not wrap.<br>
+<div>alignment-baseline</div>
+</body>
+</html>

Modified: releases/WebKitGTK/webkit-2.16/Source/WebCore/ChangeLog (213142 => 213143)


--- releases/WebKitGTK/webkit-2.16/Source/WebCore/ChangeLog	2017-02-28 09:47:45 UTC (rev 213142)
+++ releases/WebKitGTK/webkit-2.16/Source/WebCore/ChangeLog	2017-02-28 09:48:50 UTC (rev 213143)
@@ -1,3 +1,28 @@
+2017-02-25  Zalan Bujtas  <za...@apple.com>
+
+        Text might wrap when its preferred logical width is used for sizing the containing block.
+        https://bugs.webkit.org/show_bug.cgi?id=168864
+        <rdar://problem/30690734>
+
+        Reviewed by Antti Koivisto.
+
+        In certain cases we end up measuring a text run in 2 different ways.
+        1. preferred width computation -> slow path FontCascade::width() 
+        2. line breaking logic -> fast path FontCascade::widthForSimpleText()
+ 
+        FontCascade::width() and ::widthForSimpleText() might return different results for the same run even when
+        the individual glyph widths are measured to be the same. It's because they run diffrent set of
+        arithmetics on the float values and for certain values these arithmetics produce different results due to the floating point
+        precision.
+        Since RenderText::computePreferredLogicalWidths() currently forces us to use the slow path
+        (to retrieve fontfallback and glyph overflow information) the only alternative solution is to turn off the fast path
+        for all runs that have been already measured using the slow path (which would be just wasteful).
+
+        Test: fast/text/fast-run-width-vs-slow-run-width.html
+
+        * platform/graphics/FontCascade.cpp:
+        (WebCore::FontCascade::widthForSimpleText): Mimics WidthIterator::applyFontTransforms. Use the same set of arithmetics here.  
+
 2017-02-24  Zalan Bujtas  <za...@apple.com>
 
         Simple line layout: Re-adjust paginated lines when block height changes.

Modified: releases/WebKitGTK/webkit-2.16/Source/WebCore/platform/graphics/FontCascade.cpp (213142 => 213143)


--- releases/WebKitGTK/webkit-2.16/Source/WebCore/platform/graphics/FontCascade.cpp	2017-02-28 09:47:45 UTC (rev 213142)
+++ releases/WebKitGTK/webkit-2.16/Source/WebCore/platform/graphics/FontCascade.cpp	2017-02-28 09:48:50 UTC (rev 213143)
@@ -382,6 +382,8 @@
 
 float FontCascade::widthForSimpleText(StringView text) const
 {
+    if (text.isNull() || text.isEmpty())
+        return 0;
     ASSERT(codePath(TextRun(text)) != FontCascade::Complex);
     float* cacheEntry = m_fonts->widthCache().add(text, std::numeric_limits<float>::quiet_NaN());
     if (cacheEntry && !std::isnan(*cacheEntry))
@@ -409,9 +411,12 @@
     }
     if (hasKerningOrLigatures) {
         font.applyTransforms(&glyphs[0], &advances[0], glyphs.size(), enableKerning(), requiresShaping());
-        runWidth = 0;
+        // This is needed only to match the result of the slow path. Same glyph widths but different floating point arithmentics can
+        // produce different run width.
+        float runWidthDifferenceWithTransformApplied = -runWidth;
         for (auto& advance : advances)
-            runWidth += advance.width();
+            runWidthDifferenceWithTransformApplied += advance.width();
+        runWidth += runWidthDifferenceWithTransformApplied;
     }
 
     if (cacheEntry)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to