RenderText::computePreferredLogicalWidths() should measure words with trailing spaces
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Aug 2011 20:43:48 +0000 (20:43 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Aug 2011 20:43:48 +0000 (20:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=66733

Source/WebCore:

Patch by Ned Holbrook <nholbrook@apple.com> on 2011-08-26
Reviewed by Dan Bernstein.

Test: fast/text/complex-preferred-logical-widths.html

* rendering/RenderText.cpp:
(WebCore::RenderText::computePreferredLogicalWidths): Apply logic from RenderBlock::LineBreaker::nextLineBreak().

LayoutTests:

* fast/text/complex-preferred-logical-widths.html: Added.
* platform/mac/fast/text/complex-preferred-logical-widths-expected.txt: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@93909 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/text/complex-preferred-logical-widths.html [new file with mode: 0644]
LayoutTests/platform/mac/fast/text/complex-preferred-logical-widths-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/fast/text/complex-preferred-logical-widths-expected.txt [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderText.cpp

index 3d417ef51d85d39776df6564ba6a787a9bbf5894..cf54311bd73852ae48e8f86cbb3625ba77a88275 100644 (file)
@@ -1,3 +1,11 @@
+2011-08-26  Dan Bernstein  <mitz@apple.com>
+
+        RenderText::computePreferredLogicalWidths() should measure words with trailing spaces
+        https://bugs.webkit.org/show_bug.cgi?id=66733
+
+        * fast/text/complex-preferred-logical-widths.html: Added.
+        * platform/mac/fast/text/complex-preferred-logical-widths-expected.txt: Added.
+
 2011-08-26  Tony Chang  <tony@chromium.org>
 
         Add CSS parsing for -webkit-flex-align
diff --git a/LayoutTests/fast/text/complex-preferred-logical-widths.html b/LayoutTests/fast/text/complex-preferred-logical-widths.html
new file mode 100644 (file)
index 0000000..ddce3e5
--- /dev/null
@@ -0,0 +1 @@
+<div style="font-family: baskerville; border: solid blue; text-rendering: optimizelegibility; float: left;">The number of lines in this box should be one.</div>
diff --git a/LayoutTests/platform/mac/fast/text/complex-preferred-logical-widths-expected.png b/LayoutTests/platform/mac/fast/text/complex-preferred-logical-widths-expected.png
new file mode 100644 (file)
index 0000000..0d53edd
Binary files /dev/null and b/LayoutTests/platform/mac/fast/text/complex-preferred-logical-widths-expected.png differ
diff --git a/LayoutTests/platform/mac/fast/text/complex-preferred-logical-widths-expected.txt b/LayoutTests/platform/mac/fast/text/complex-preferred-logical-widths-expected.txt
new file mode 100644 (file)
index 0000000..a2392fd
--- /dev/null
@@ -0,0 +1,8 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock (floating) {DIV} at (0,0) size 308x24 [border: (3px solid #0000FF)]
+        RenderText {#text} at (3,3) size 302x18
+          text run at (3,3) width 302: "The number of lines in this box should be one."
index 803408b24d0de57b86fb07eaf56215675de4b3f1..f2a697094e721ab4f90daac6e5824a41a8ebdefc 100644 (file)
@@ -1,3 +1,15 @@
+2011-08-26  Ned Holbrook  <nholbrook@apple.com>
+
+        RenderText::computePreferredLogicalWidths() should measure words with trailing spaces
+        https://bugs.webkit.org/show_bug.cgi?id=66733
+
+        Reviewed by Dan Bernstein.
+
+        Test: fast/text/complex-preferred-logical-widths.html
+
+        * rendering/RenderText.cpp:
+        (WebCore::RenderText::computePreferredLogicalWidths): Apply logic from RenderBlock::LineBreaker::nextLineBreak().
+
 2011-08-26  Tony Chang  <tony@chromium.org>
 
         Add CSS parsing for -webkit-flex-align
index 1ad301491f714031e628cbdf6c08f7c0ad1b5356..64cbda106bdb1af4107ee036a3fbc9794e99bfff 100644 (file)
@@ -914,6 +914,10 @@ void RenderText::computePreferredLogicalWidths(float leadWidth, HashSet<const Si
     int nextBreakable = -1;
     int lastWordBoundary = 0;
 
+    // Non-zero only when kerning is enabled, in which case we measure words with their trailing
+    // space, then subtract its width.
+    float wordTrailingSpaceWidth = f.typesettingFeatures() & Kerning ? f.width(RenderBlock::constructTextRun(this, f, &space, 1, style())) : 0;
+
     int firstGlyphLeftOverflow = -1;
 
     bool breakNBSP = style()->autoWrap() && style()->nbspMode() == SPACE;
@@ -983,7 +987,13 @@ void RenderText::computePreferredLogicalWidths(float leadWidth, HashSet<const Si
 
         int wordLen = j - i;
         if (wordLen) {
-            float w = widthFromCache(f, i, wordLen, leadWidth + currMaxWidth, &fallbackFonts, &glyphOverflow);
+            bool isSpace = (j < len) && isSpaceAccordingToStyle(c, style());
+            float w;
+            if (wordTrailingSpaceWidth && isSpace)
+                w = widthFromCache(f, i, wordLen + 1, leadWidth + currMaxWidth, &fallbackFonts, &glyphOverflow) - wordTrailingSpaceWidth;
+            else
+                w = widthFromCache(f, i, wordLen, leadWidth + currMaxWidth, &fallbackFonts, &glyphOverflow);
+
             if (firstGlyphLeftOverflow < 0)
                 firstGlyphLeftOverflow = glyphOverflow.left;
             currMinWidth += w;
@@ -995,7 +1005,6 @@ void RenderText::computePreferredLogicalWidths(float leadWidth, HashSet<const Si
                 lastWordBoundary = j;
             }
 
-            bool isSpace = (j < len) && isSpaceAccordingToStyle(c, style());
             bool isCollapsibleWhiteSpace = (j < len) && style()->isCollapsibleWhiteSpace(c);
             if (j < len && style()->autoWrap())
                 m_hasBreakableChar = true;