Title: [285863] trunk/Source/WebCore
Revision
285863
Author
[email protected]
Date
2021-11-16 08:38:52 -0800 (Tue, 16 Nov 2021)

Log Message

[LFC][IFC] Fix fast/text/basic/005.html
https://bugs.webkit.org/show_bug.cgi?id=233150

Reviewed by Antti Koivisto.

Negative word-spacing acts as negative margin, pulling the content to the left. In this patch we account for such negative values when
computing the overall content width.

Note that this patch is in preparation for enabling IFC preferred width computation.

* layout/formattingContexts/inline/InlineLine.cpp:
(WebCore::Layout::Line::appendTextContent):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (285862 => 285863)


--- trunk/Source/WebCore/ChangeLog	2021-11-16 16:37:05 UTC (rev 285862)
+++ trunk/Source/WebCore/ChangeLog	2021-11-16 16:38:52 UTC (rev 285863)
@@ -1,3 +1,18 @@
+2021-11-16  Alan Bujtas  <[email protected]>
+
+        [LFC][IFC] Fix fast/text/basic/005.html
+        https://bugs.webkit.org/show_bug.cgi?id=233150
+
+        Reviewed by Antti Koivisto.
+
+        Negative word-spacing acts as negative margin, pulling the content to the left. In this patch we account for such negative values when
+        computing the overall content width.
+
+        Note that this patch is in preparation for enabling IFC preferred width computation.
+
+        * layout/formattingContexts/inline/InlineLine.cpp:
+        (WebCore::Layout::Line::appendTextContent):
+
 2021-11-16  Wenson Hsieh  <[email protected]>
 
         Add support for injecting and rendering text recognition blocks

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineLine.cpp (285862 => 285863)


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineLine.cpp	2021-11-16 16:37:05 UTC (rev 285862)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineLine.cpp	2021-11-16 16:38:52 UTC (rev 285863)
@@ -343,17 +343,27 @@
         auto contentLogicalRight = runLogicalLeft + logicalWidth + m_clonedEndDecorationWidthForInlineBoxRuns;
         m_contentLogicalWidth = std::max(oldContentLogicalWidth, contentLogicalRight);
     } else if (style.letterSpacing() >= 0) {
-        m_runs.last().expand(inlineTextItem, logicalWidth);
-        m_contentLogicalWidth += logicalWidth;
+        auto& lastRun = m_runs.last();
+        lastRun.expand(inlineTextItem, logicalWidth);
+        // Ensure that property values that act like negative margin are not making the line wider.
+        m_contentLogicalWidth = std::max(oldContentLogicalWidth, lastRun.logicalRight());
     } else {
         auto& lastRun = m_runs.last();
         ASSERT(lastRun.isText());
         // Negative letter spacing should only shorten the content to the boundary of the previous run.
         // FIXME: We may need to traverse all the way to the previous non-text run (or even across inline boxes).
-        auto lastRunLogicalWidth = lastRun.logicalWidth();
-        auto contentWidthWithoutLastTextRun = m_contentLogicalWidth - std::max(0.f, lastRunLogicalWidth);
+        auto contentWidthWithoutLastTextRun = [&] {
+            if (style.fontCascade().wordSpacing() >= 0)
+                return m_contentLogicalWidth - std::max(0.f, lastRun.logicalWidth());
+            // FIXME: Let's see if we need to optimize for this is the rare case of both letter and word spacing being negative.
+            auto rightMostPosition = InlineLayoutUnit { };
+            for (auto& run : makeReversedRange(m_runs))
+                rightMostPosition = std::max(rightMostPosition, run.logicalRight());
+            return std::max(0.f, rightMostPosition);
+        }();
+        auto lastRunLogicalRight = lastRun.logicalRight();
         lastRun.expand(inlineTextItem, logicalWidth);
-        m_contentLogicalWidth = std::max(contentWidthWithoutLastTextRun, lastRunLogicalWidth + logicalWidth);
+        m_contentLogicalWidth = std::max(contentWidthWithoutLastTextRun, lastRunLogicalRight + logicalWidth);
     }
 
     // Handle trailing content, specifically whitespace and letter spacing.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to