[LFC][IFC] Many render tree dump tests show 1px too narrow runs
https://bugs.webkit.org/show_bug.cgi?id=204885

Reviewed by Zalan Bujtas.

Width measurement is currently clamping the measured (float) text widths to layout units. Use rounding instead.

This doesn't solve the fundamental problem of loss of precision but it allows many more render tree dump
based layout tests to pass.

* layout/inlineformatting/text/TextUtil.cpp:
(WebCore::Layout::TextUtil::width):
(WebCore::Layout::TextUtil::fixedPitchWidth):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@253151 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 652f8b7..c92a3bc 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,19 @@
+2019-12-05  Antti Koivisto  <antti@apple.com>
+
+        [LFC][IFC] Many render tree dump tests show 1px too narrow runs
+        https://bugs.webkit.org/show_bug.cgi?id=204885
+
+        Reviewed by Zalan Bujtas.
+
+        Width measurement is currently clamping the measured (float) text widths to layout units. Use rounding instead.
+
+        This doesn't solve the fundamental problem of loss of precision but it allows many more render tree dump
+        based layout tests to pass.
+
+        * layout/inlineformatting/text/TextUtil.cpp:
+        (WebCore::Layout::TextUtil::width):
+        (WebCore::Layout::TextUtil::fixedPitchWidth):
+
 2019-12-05  youenn fablet  <youenn@apple.com>
 
         inspector/page/overrideSetting-MockCaptureDevicesEnabled.html is failing after removal of internals.setMockMediaCaptureDevicesEnabled API
diff --git a/Source/WebCore/layout/inlineformatting/text/TextUtil.cpp b/Source/WebCore/layout/inlineformatting/text/TextUtil.cpp
index 1020771..2529087 100644
--- a/Source/WebCore/layout/inlineformatting/text/TextUtil.cpp
+++ b/Source/WebCore/layout/inlineformatting/text/TextUtil.cpp
@@ -71,7 +71,7 @@
     if (measureWithEndSpace)
         width -= (font.spaceWidth() + font.wordSpacing());
 
-    return std::max(0_lu, LayoutUnit { width });
+    return std::max(0_lu, LayoutUnit::fromFloatRound(width));
 }
 
 LayoutUnit TextUtil::fixedPitchWidth(const StringView& text, const RenderStyle& style, unsigned from, unsigned to, LayoutUnit contentLogicalLeft)
@@ -90,7 +90,7 @@
             width += font.wordSpacing();
     }
 
-    return std::max(0_lu, LayoutUnit { width });
+    return std::max(0_lu, LayoutUnit::fromFloatRound(width));
 }
 
 TextUtil::SplitData TextUtil::split(const Box& inlineBox, unsigned startPosition, unsigned length, LayoutUnit textWidth, LayoutUnit availableWidth, LayoutUnit contentLogicalLeft)