Title: [215293] branches/safari-603-branch

Diff

Modified: branches/safari-603-branch/Source/WebCore/ChangeLog (215292 => 215293)


--- branches/safari-603-branch/Source/WebCore/ChangeLog	2017-04-12 21:22:14 UTC (rev 215292)
+++ branches/safari-603-branch/Source/WebCore/ChangeLog	2017-04-12 21:34:46 UTC (rev 215293)
@@ -1,3 +1,26 @@
+2017-04-12  Myles C. Maxfield  <[email protected]>
+
+     REGRESSION(r211382): Complex text with justification erroneously overflows containers
+     https://bugs.webkit.org/show_bug.cgi?id=170399
+     <rdar://problem/31442008>
+
+     When we perform justification, we adjust glyphs' advances to add extra space between words.
+     ComplexTextController maintains an invariant where m_totalWidth is equal to the sum of these
+     advances. However, in RTL text, inserting extra justification space to the left of a glyph
+     would break that invariant, and would increase the advances of two glyphs instead of just
+     one. Then, when we go to draw the text, the sum of the advances is wider than m_totalWidth,
+     which means the glyphs would be drawn outside of their container.
+
+     This regressed in r211382 simply because of an oversight and because there were no tests for
+     this codepath.
+
+     Test: ComplexTextControllerTest.TotalWidthWithJustification
+
+     * platform/graphics/ComplexTextController.cpp:
+     (WebCore::ComplexTextController::adjustGlyphsAndAdvances):
+     * rendering/InlineBox.h:
+     (WebCore::InlineBox::InlineBox):
+
 2017-04-11  Jason Marcell  <[email protected]>
 
         Cherry-pick 214358. rdar://problem/31502340

Modified: branches/safari-603-branch/Source/WebCore/platform/graphics/mac/ComplexTextController.cpp (215292 => 215293)


--- branches/safari-603-branch/Source/WebCore/platform/graphics/mac/ComplexTextController.cpp	2017-04-12 21:22:14 UTC (rev 215292)
+++ branches/safari-603-branch/Source/WebCore/platform/graphics/mac/ComplexTextController.cpp	2017-04-12 21:34:46 UTC (rev 215293)
@@ -661,7 +661,6 @@
 void ComplexTextController::adjustGlyphsAndAdvances()
 {
     bool afterExpansion = (m_run.expansionBehavior() & LeadingExpansionMask) == ForbidLeadingExpansion;
-    CGFloat widthSinceLastCommit = 0;
     size_t runCount = m_complexTextRuns.size();
     bool hasExtraSpacing = (m_font.letterSpacing() || m_font.wordSpacing() || m_expansion) && !m_run.spacingDisabled();
     bool runForcesLeadingExpansion = (m_run.expansionBehavior() & LeadingExpansionMask) == ForceLeadingExpansion;
@@ -712,7 +711,7 @@
             CGSize advance = treatAsSpace ? CGSizeMake(spaceWidth, advances[i].height) : advances[i];
 
             if (ch == '\t' && m_run.allowTabs())
-                advance.width = m_font.tabWidth(font, m_run.tabSize(), m_run.xPos() + m_totalWidth + widthSinceLastCommit);
+                advance.width = m_font.tabWidth(font, m_run.tabSize(), m_run.xPos() + m_totalWidth);
             else if (FontCascade::treatAsZeroWidthSpace(ch) && !treatAsSpace) {
                 advance.width = 0;
                 glyph = font.spaceGlyph();
@@ -758,17 +757,22 @@
                     if (m_expansion) {
                         bool expandLeft, expandRight;
                         std::tie(expandLeft, expandRight) = expansionLocation(ideograph, treatAsSpace, m_run.ltr(), afterExpansion, forbidLeadingExpansion, forbidTrailingExpansion, forceLeadingExpansion, forceTrailingExpansion);
-                        m_expansion -= m_expansionPerOpportunity;
-                        advance.width += m_expansionPerOpportunity;
                         if (expandLeft) {
+                            m_expansion -= m_expansionPerOpportunity;
                             // Increase previous width
-                            if (m_adjustedBaseAdvances.isEmpty())
+                            if (m_adjustedBaseAdvances.isEmpty()) {
+                                advance.width += m_expansionPerOpportunity;
                                 complexTextRun.growInitialAdvanceHorizontally(m_expansionPerOpportunity);
-                            else
+                            } else {
                                 m_adjustedBaseAdvances.last().width += m_expansionPerOpportunity;
+                                m_totalWidth += m_expansionPerOpportunity;
+                            }
                         }
-                        if (expandRight)
+                        if (expandRight) {
+                            m_expansion -= m_expansionPerOpportunity;
+                            advance.width += m_expansionPerOpportunity;
                             afterExpansion = true;
+                        }
                     } else
                         afterExpansion = false;
 
@@ -779,7 +783,7 @@
                     afterExpansion = false;
             }
 
-            widthSinceLastCommit += advance.width; 
+            m_totalWidth += advance.width; 
 
             // FIXME: Combining marks should receive a text emphasis mark if they are combine with a space.
             if (m_forTextEmphasis && (!FontCascade::canReceiveTextEmphasis(ch) || (U_GET_GC_MASK(ch) & U_GC_M_MASK)))
@@ -808,8 +812,6 @@
         if (!isMonotonic)
             complexTextRun.setIsNonMonotonic();
     }
-
-    m_totalWidth += widthSinceLastCommit;
 }
 
 } // namespace WebCore

Modified: branches/safari-603-branch/Source/WebCore/rendering/InlineBox.h (215292 => 215293)


--- branches/safari-603-branch/Source/WebCore/rendering/InlineBox.h	2017-04-12 21:22:14 UTC (rev 215292)
+++ branches/safari-603-branch/Source/WebCore/rendering/InlineBox.h	2017-04-12 21:34:46 UTC (rev 215293)
@@ -280,16 +280,16 @@
     float expansion() const { return m_expansion; }
 
 private:
-    InlineBox* m_next; // The next element on the same line as us.
-    InlineBox* m_prev; // The previous element on the same line as us.
+    InlineBox* m_next { nullptr }; // The next element on the same line as us.
+    InlineBox* m_prev { nullptr }; // The previous element on the same line as us.
 
-    InlineFlowBox* m_parent; // The box that contains us.
+    InlineFlowBox* m_parent { nullptr }; // The box that contains us.
 
     RenderObject& m_renderer;
 
 public:
     FloatPoint m_topLeft;
-    float m_logicalWidth;
+    float m_logicalWidth { 0 };
 
 #define ADD_BOOLEAN_BITFIELD(name, Name) \
     private:\
@@ -368,21 +368,12 @@
 #undef ADD_BOOLEAN_BITFIELD
 
 private:
-    float m_expansion;
+    float m_expansion { 0 };
     InlineBoxBitfields m_bitfields;
 
 protected:
     explicit InlineBox(RenderObject& renderer)
-        : m_next(nullptr)
-        , m_prev(nullptr)
-        , m_parent(nullptr)
-        , m_renderer(renderer)
-        , m_logicalWidth(0)
-        , m_expansion(0)
-#if !ASSERT_WITH_SECURITY_IMPLICATION_DISABLED
-        , m_deletionSentinel(deletionSentinelNotDeletedValue)
-        , m_hasBadParent(false)
-#endif
+        : m_renderer(renderer)
     {
     }
 
@@ -393,12 +384,7 @@
         , m_renderer(renderer)
         , m_topLeft(topLeft)
         , m_logicalWidth(logicalWidth)
-        , m_expansion(0)
         , m_bitfields(firstLine, constructed, dirty, extracted, isHorizontal)
-#if !ASSERT_WITH_SECURITY_IMPLICATION_DISABLED
-        , m_deletionSentinel(deletionSentinelNotDeletedValue)
-        , m_hasBadParent(false)
-#endif
     {
     }
 
@@ -427,10 +413,10 @@
 
 #if !ASSERT_WITH_SECURITY_IMPLICATION_DISABLED
 private:
-    static const unsigned deletionSentinelNotDeletedValue = 0xF0F0F0F0U;
-    static const unsigned deletionSentinelDeletedValue = 0xF0DEADF0U;
-    unsigned m_deletionSentinel;
-    bool m_hasBadParent;
+    static constexpr unsigned deletionSentinelNotDeletedValue = 0xF0F0F0F0U;
+    static constexpr unsigned deletionSentinelDeletedValue = 0xF0DEADF0U;
+    unsigned m_deletionSentinel { deletionSentinelNotDeletedValue };
+    bool m_hasBadParent { false };
 #endif
 };
 

Modified: branches/safari-603-branch/Tools/ChangeLog (215292 => 215293)


--- branches/safari-603-branch/Tools/ChangeLog	2017-04-12 21:22:14 UTC (rev 215292)
+++ branches/safari-603-branch/Tools/ChangeLog	2017-04-12 21:34:46 UTC (rev 215293)
@@ -1,3 +1,14 @@
+2017-04-12  Myles C. Maxfield  <[email protected]>
+
+     REGRESSION(r211382): Complex text with justification erroneously overflows containers
+     https://bugs.webkit.org/show_bug.cgi?id=170399
+     <rdar://problem/31442008>
+
+     Check for the invariant that the sum of the advances is equal to m_totalWidth.
+
+     * TestWebKitAPI/Tests/WebCore/ComplexTextController.cpp:
+     (TestWebKitAPI::TEST_F):
+
 2017-04-11  Jason Marcell  <[email protected]>
 
         Cherry-pick 214358. rdar://problem/31502340
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to