With word-break: break-all, words do not break correctly before a surrogate pair
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 26 Jun 2011 16:09:33 +0000 (16:09 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 26 Jun 2011 16:09:33 +0000 (16:09 +0000)
https://bugs.webkit.org/show_bug.cgi?id=63401

Reviewed by Darin Adler.

Source/WebCore:

The code to check for mid-word breaks accumulates width one character at a time. It was actually
measuring the two parts of the surrogate pair individually, so they appeared to have zero width.
Fixed by checking for surrogate pairs and measuring the pair as one unit.

Test: fast/text/midword-break-before-surrogate-pair.html

* rendering/RenderBlockLineLayout.cpp:
(WebCore::RenderBlock::LineBreaker::nextLineBreak):

LayoutTests:

* fast/text/midword-break-before-surrogate-pair.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/text/midword-break-before-surrogate-pair.html [new file with mode: 0644]
LayoutTests/platform/mac/fast/text/midword-break-before-surrogate-pair-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/fast/text/midword-break-before-surrogate-pair-expected.txt [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderBlockLineLayout.cpp

index 702984c..c3f9973 100644 (file)
@@ -1,3 +1,12 @@
+2011-06-26  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Darin Adler.
+
+        With word-break: break-all, words do not break correctly before a surrogate pair
+        https://bugs.webkit.org/show_bug.cgi?id=63401
+
+        * fast/text/midword-break-before-surrogate-pair.html: Added.
+
 2011-06-26  Adam Barth  <abarth@webkit.org>
 
         Note that this test ASSERTs on Linux Debug.
diff --git a/LayoutTests/fast/text/midword-break-before-surrogate-pair.html b/LayoutTests/fast/text/midword-break-before-surrogate-pair.html
new file mode 100644 (file)
index 0000000..b87647a
--- /dev/null
@@ -0,0 +1,3 @@
+<div style="word-break: break-all; border: solid blue; font-size: 36px; width: 5em;">
+    &#x1d110;&#x1d110;&#x1d110;&#x1d110;&#x1d110;&#x1d110;&#x1d110;&#x1d110;&#x1d110;&#x1d110;
+</div>
diff --git a/LayoutTests/platform/mac/fast/text/midword-break-before-surrogate-pair-expected.png b/LayoutTests/platform/mac/fast/text/midword-break-before-surrogate-pair-expected.png
new file mode 100644 (file)
index 0000000..1c6514d
Binary files /dev/null and b/LayoutTests/platform/mac/fast/text/midword-break-before-surrogate-pair-expected.png differ
diff --git a/LayoutTests/platform/mac/fast/text/midword-break-before-surrogate-pair-expected.txt b/LayoutTests/platform/mac/fast/text/midword-break-before-surrogate-pair-expected.txt
new file mode 100644 (file)
index 0000000..5ca7b73
--- /dev/null
@@ -0,0 +1,9 @@
+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 {DIV} at (0,0) size 186x92 [border: (3px solid #0000FF)]
+        RenderText {#text} at (3,3) size 168x84
+          text run at (3,3) width 168: "\x{D834}\x{DD10}\x{D834}\x{DD10}\x{D834}\x{DD10}\x{D834}\x{DD10}\x{D834}\x{DD10}\x{D834}\x{DD10}\x{D834}\x{DD10}"
+          text run at (3,46) width 72: "\x{D834}\x{DD10}\x{D834}\x{DD10}\x{D834}\x{DD10}"
index f231075..8eb564e 100644 (file)
@@ -1,3 +1,19 @@
+2011-06-26  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Darin Adler.
+
+        With word-break: break-all, words do not break correctly before a surrogate pair
+        https://bugs.webkit.org/show_bug.cgi?id=63401
+
+        The code to check for mid-word breaks accumulates width one character at a time. It was actually
+        measuring the two parts of the surrogate pair individually, so they appeared to have zero width.
+        Fixed by checking for surrogate pairs and measuring the pair as one unit.
+
+        Test: fast/text/midword-break-before-surrogate-pair.html
+
+        * rendering/RenderBlockLineLayout.cpp:
+        (WebCore::RenderBlock::LineBreaker::nextLineBreak):
+
 2011-06-26  Dirk Schulze  <krit@webkit.org>
 
         Reviewed by Nikolas Zimmermann.
index 1dadea5..76bac49 100644 (file)
@@ -2102,9 +2102,11 @@ InlineIterator RenderBlock::LineBreaker::nextLineBreak(InlineBidiResolver& resol
 
                 currentCharacterIsWS = currentCharacterIsSpace || (breakNBSP && c == noBreakSpace);
 
+                bool midWordBreakIsBeforeSurrogatePair = false;
                 if ((breakAll || breakWords) && !midWordBreak) {
                     wrapW += charWidth;
-                    charWidth = textWidth(t, current.m_pos, 1, f, width.committedWidth() + wrapW, isFixedPitch, collapseWhiteSpace);
+                    midWordBreakIsBeforeSurrogatePair = U16_IS_LEAD(c) && current.m_pos + 1 < t->textLength() && U16_IS_TRAIL(t->characters()[current.m_pos + 1]);
+                    charWidth = textWidth(t, current.m_pos, midWordBreakIsBeforeSurrogatePair ? 2 : 1, f, width.committedWidth() + wrapW, isFixedPitch, collapseWhiteSpace);
                     midWordBreak = width.committedWidth() + wrapW + charWidth > width.availableWidth();
                 }
 
@@ -2221,6 +2223,8 @@ InlineIterator RenderBlock::LineBreaker::nextLineBreak(InlineBidiResolver& resol
                         // adding the end width forces a break.
                         lBreak.moveTo(current.m_obj, current.m_pos, current.m_nextBreakablePosition);
                         midWordBreak &= (breakWords || breakAll);
+                        if (midWordBreakIsBeforeSurrogatePair)
+                            current.fastIncrementInTextNode();
                     }
 
                     if (betweenWords) {