Title: [121050] trunk
Revision
121050
Author
[email protected]
Date
2012-06-22 13:06:54 -0700 (Fri, 22 Jun 2012)

Log Message

RenderText’s minimum preferred width is incorrect when soft hyphens are used
https://bugs.webkit.org/show_bug.cgi?id=89775

Reviewed by Simon Fraser.

Source/WebCore: 

Test: fast/text/soft-hyphen-min-preferred-width.html

* rendering/RenderText.cpp:
(WebCore::hyphenWidth): Added this helper function.
(WebCore::RenderText::computePreferredLogicalWidths): In places where this function tests
for the soft hyphen character, added a check that the 'hyphens' style property is not set
to 'none', because in that case soft hyphens are not break opportunities. Also added an
explicit check to suppress break opportunities from isBreakable() if the occur after a
soft hyphen and 'hyphens' is set to 'none'. Finally, when measuring text up to a potential
line break, added the width of the hyphen string when needed.

LayoutTests: 

* fast/text/soft-hyphen-min-preferred-width-expected.html: Added.
* fast/text/soft-hyphen-min-preferred-width.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (121049 => 121050)


--- trunk/LayoutTests/ChangeLog	2012-06-22 19:16:28 UTC (rev 121049)
+++ trunk/LayoutTests/ChangeLog	2012-06-22 20:06:54 UTC (rev 121050)
@@ -1,3 +1,13 @@
+2012-06-22  Dan Bernstein  <[email protected]>
+
+        RenderText’s minimum preferred width is incorrect when soft hyphens are used
+        https://bugs.webkit.org/show_bug.cgi?id=89775
+
+        Reviewed by Simon Fraser.
+
+        * fast/text/soft-hyphen-min-preferred-width-expected.html: Added.
+        * fast/text/soft-hyphen-min-preferred-width.html: Added.
+
 2012-06-22  Jan Keromnes  <[email protected]>
 
         Web Inspector: ExtensionPanel.onSearch listener doesn't work

Added: trunk/LayoutTests/fast/text/soft-hyphen-min-preferred-width-expected.html (0 => 121050)


--- trunk/LayoutTests/fast/text/soft-hyphen-min-preferred-width-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text/soft-hyphen-min-preferred-width-expected.html	2012-06-22 20:06:54 UTC (rev 121050)
@@ -0,0 +1,29 @@
+<style>
+    div {
+        outline: dashed thin lightblue;
+         -webkit-hyphenate-character: "-";
+    }
+</style>
+<p>
+    There should be a hyphen at the end of the first line, and it should not
+    overflow the box.
+</p>
+<table cellspacing=0 cellpadding=0>
+    <tr>
+        <td>
+            <div>extraordinar<span>-</span><br>ily</div>
+        </td>
+        <td style="width: 100%"></td>
+    </tr>
+</table>
+<p>
+    The text should not overflow the box.
+</p>
+<table cellspacing=0 cellpadding=0>
+    <tr>
+        <td>
+            <div>extraordinar<span></span>ily</div>
+        </td>
+        <td style="width: 100%"></td>
+    </tr>
+</table>

Added: trunk/LayoutTests/fast/text/soft-hyphen-min-preferred-width.html (0 => 121050)


--- trunk/LayoutTests/fast/text/soft-hyphen-min-preferred-width.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text/soft-hyphen-min-preferred-width.html	2012-06-22 20:06:54 UTC (rev 121050)
@@ -0,0 +1,29 @@
+<style>
+    div {
+        outline: dashed thin lightblue;
+         -webkit-hyphenate-character: "-";
+    }
+</style>
+<p>
+    There should be a hyphen at the end of the first line, and it should not
+    overflow the box.
+</p>
+<table cellspacing=0 cellpadding=0>
+    <tr>
+        <td>
+            <div style="-webkit-hyphens: manual;">extraordinar&shy;ily</div>
+        </td>
+        <td style="width: 100%"></td>
+    </tr>
+</table>
+<p>
+    The text should not overflow the box.
+</p>
+<table cellspacing=0 cellpadding=0>
+    <tr>
+        <td>
+            <div style="-webkit-hyphens: none;">extraordinar&shy;ily</div>
+        </td>
+        <td style="width: 100%"></td>
+    </tr>
+</table>

Modified: trunk/Source/WebCore/ChangeLog (121049 => 121050)


--- trunk/Source/WebCore/ChangeLog	2012-06-22 19:16:28 UTC (rev 121049)
+++ trunk/Source/WebCore/ChangeLog	2012-06-22 20:06:54 UTC (rev 121050)
@@ -1,3 +1,21 @@
+2012-06-22  Dan Bernstein  <[email protected]>
+
+        RenderText’s minimum preferred width is incorrect when soft hyphens are used
+        https://bugs.webkit.org/show_bug.cgi?id=89775
+
+        Reviewed by Simon Fraser.
+
+        Test: fast/text/soft-hyphen-min-preferred-width.html
+
+        * rendering/RenderText.cpp:
+        (WebCore::hyphenWidth): Added this helper function.
+        (WebCore::RenderText::computePreferredLogicalWidths): In places where this function tests
+        for the soft hyphen character, added a check that the 'hyphens' style property is not set
+        to 'none', because in that case soft hyphens are not break opportunities. Also added an
+        explicit check to suppress break opportunities from isBreakable() if the occur after a
+        soft hyphen and 'hyphens' is set to 'none'. Finally, when measuring text up to a potential
+        line break, added the width of the hyphen string when needed.
+
 2012-06-22  Dean Jackson  <[email protected]>
 
         BitmapImage duplicates code to calculate size

Modified: trunk/Source/WebCore/rendering/RenderText.cpp (121049 => 121050)


--- trunk/Source/WebCore/rendering/RenderText.cpp	2012-06-22 19:16:28 UTC (rev 121049)
+++ trunk/Source/WebCore/rendering/RenderText.cpp	2012-06-22 20:06:54 UTC (rev 121050)
@@ -882,6 +882,12 @@
         m_knownToHaveNoOverflowAndNoFallbackFonts = true;
 }
 
+static inline float hyphenWidth(RenderText* renderer, const Font& font)
+{
+    RenderStyle* style = renderer->style();
+    return font.width(RenderBlock::constructTextRun(renderer, font, style->hyphenString().string(), style));
+}
+
 void RenderText::computePreferredLogicalWidths(float leadWidth, HashSet<const SimpleFontData*>& fallbackFonts, GlyphOverflow& glyphOverflow)
 {
     ASSERT(m_hasTab || preferredLogicalWidthsDirty() || !m_knownToHaveNoOverflowAndNoFallbackFonts);
@@ -963,7 +969,7 @@
             ASSERT(lastWordBoundary == i);
             lastWordBoundary++;
             continue;
-        } else if (c == softHyphen) {
+        } else if (c == softHyphen && styleToUse->hyphens() != HyphensNone) {
             currMaxWidth += widthFromCache(f, lastWordBoundary, i - lastWordBoundary, leadWidth + currMaxWidth, &fallbackFonts, &glyphOverflow);
             if (firstGlyphLeftOverflow < 0)
                 firstGlyphLeftOverflow = glyphOverflow.left;
@@ -974,12 +980,12 @@
         bool hasBreak = breakAll || isBreakable(breakIterator, i, nextBreakable, breakNBSP);
         bool betweenWords = true;
         int j = i;
-        while (c != '\n' && !isSpaceAccordingToStyle(c, styleToUse) && c != '\t' && c != softHyphen) {
+        while (c != '\n' && !isSpaceAccordingToStyle(c, styleToUse) && c != '\t' && (c != softHyphen || styleToUse->hyphens() == HyphensNone)) {
             j++;
             if (j == len)
                 break;
             c = txt[j];
-            if (isBreakable(breakIterator, j, nextBreakable, breakNBSP))
+            if (isBreakable(breakIterator, j, nextBreakable, breakNBSP) && txt[j - 1] != softHyphen)
                 break;
             if (breakAll) {
                 betweenWords = false;
@@ -993,8 +999,11 @@
             float w;
             if (wordTrailingSpaceWidth && isSpace)
                 w = widthFromCache(f, i, wordLen + 1, leadWidth + currMaxWidth, &fallbackFonts, &glyphOverflow) - wordTrailingSpaceWidth;
-            else
+            else {
                 w = widthFromCache(f, i, wordLen, leadWidth + currMaxWidth, &fallbackFonts, &glyphOverflow);
+                if (c == softHyphen && styleToUse->hyphens() != HyphensNone)
+                    currMinWidth += hyphenWidth(this, f);
+            }
 
             if (firstGlyphLeftOverflow < 0)
                 firstGlyphLeftOverflow = glyphOverflow.left;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to