Reviewed by me, patch by Mitz Pettel.
authordarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 May 2005 01:17:32 +0000 (01:17 +0000)
committerdarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 May 2005 01:17:32 +0000 (01:17 +0000)
        - fixed <rdar://problem/4106907> bidi algorithm bug fixed for KHTML should be fixed in WebCore too

        * khtml/rendering/bidi.cpp: (khtml::RenderBlock::bidiReorderLine): Integrated the patch that Mitz did
        for the KDE bug, details at <http://www.mitzpettel.com/software/WebCorePatch2.html>.

        Test cases added:
        * layout-tests/fast/text/international/bidi-neutral-directionality-paragraph-start-expected.txt: Added.
        * layout-tests/fast/text/international/bidi-neutral-directionality-paragraph-start.html: Added.

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

LayoutTests/fast/text/international/bidi-neutral-directionality-paragraph-start-expected.txt [new file with mode: 0644]
LayoutTests/fast/text/international/bidi-neutral-directionality-paragraph-start.html [new file with mode: 0644]
WebCore/ChangeLog-2005-08-23
WebCore/khtml/rendering/bidi.cpp

diff --git a/LayoutTests/fast/text/international/bidi-neutral-directionality-paragraph-start-expected.txt b/LayoutTests/fast/text/international/bidi-neutral-directionality-paragraph-start-expected.txt
new file mode 100644 (file)
index 0000000..a67a162
--- /dev/null
@@ -0,0 +1,35 @@
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x576
+      RenderBlock {P} at (0,0) size 784x18
+        RenderText {TEXT} at (0,0) size 569x18
+          text run at (0,0) width 569: "Mitz Pettel contributed this fix to KDE, and now we're rolling it in. Here's his explanation:"
+      RenderBlock {P} at (0,34) size 784x72
+        RenderText {TEXT} at (0,0) size 777x72
+          text run at (0,0) width 766: "The directionality of a neutral character at the beginning of a paragraph (or after a hard line break) is decided incorrectly if"
+          text run at (0,18) width 777: "the first non-neutral character in the paragraph has directionality opposite to the paragraph directionality. For example, if the"
+          text run at (0,36) width 768: "paragraph direction is LTR, the first character on the paragraph is a question mark and the next one is a Hebrew character,"
+          text run at (0,54) width 643: "then the question mark will is considered right-to-left and appears to the right of the Hebrew character."
+      RenderBlock {P} at (0,122) size 784x36
+        RenderText {TEXT} at (0,0) size 508x18
+          text run at (0,0) width 508: "The rule to follow is 3.3.4.N2 in the Unicode Standard's Bidirectional Algorithm"
+        RenderInline {A} at (0,0) size 397x18 [color=#0000EE]
+          RenderText {TEXT} at (0,18) size 397x18
+            text run at (0,18) width 397: "http://www.unicode.org/reports/tr9/#Resolving_Neutral_Types"
+        RenderText {TEXT} at (397,18) size 4x18
+          text run at (397,18) width 4: "."
+      RenderBlock {P} at (0,174) size 784x18
+        RenderText {TEXT} at (0,0) size 676x18
+          text run at (0,0) width 676: "If the test is successful, the question marks should be on the far left and far right of the next two paragraphs."
+      RenderBlock {P} at (0,208) size 784x18
+        RenderText {TEXT} at (0,0) size 65x18
+          text run at (0,0) width 11: "? "
+          text run at (11,0) width 23: "\x{FEB2} \x{FEED}"
+          text run at (34,0) width 31: "hello"
+      RenderBlock {P} at (0,242) size 784x18
+        RenderText {TEXT} at (715,0) size 69x18
+          text run at (715,0) width 27: " \x{FEB2} \x{FEED}"
+          text run at (742,0) width 31: "hello"
+          text run at (773,0) width 11: "? "
diff --git a/LayoutTests/fast/text/international/bidi-neutral-directionality-paragraph-start.html b/LayoutTests/fast/text/international/bidi-neutral-directionality-paragraph-start.html
new file mode 100644 (file)
index 0000000..4c56c77
--- /dev/null
@@ -0,0 +1,17 @@
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=UTF-8">
+</head>
+<body>
+<p>Mitz Pettel contributed this fix to KDE, and now we're rolling it in. Here's his explanation:</p>
+<p>The directionality of a neutral character at the beginning of a paragraph (or after a hard line break) is decided incorrectly if the first non-neutral character in the paragraph has directionality opposite to the paragraph directionality. For example, if the paragraph direction is LTR, the first character on the paragraph is a question mark and the next one is a Hebrew character, then the question mark will is considered right-to-left and appears to the right of the Hebrew character.</p>
+<p>The rule to follow is 3.3.4.N2 in the Unicode Standard's Bidirectional Algorithm <a href="http://www.unicode.org/reports/tr9/#Resolving_Neutral_Types">http://www.unicode.org/reports/tr9/#Resolving_Neutral_Types</a>.</p>
+<p>If the test is successful, the question marks should be on the far left and far right of the next two paragraphs.</p>
+<p dir="ltr"> 
+? ﺲ ﻭhello 
+</p>
+<p dir="rtl"> 
+? hello ﺲ ﻭ 
+</p>
+</body>
+</html>
index c9f3c0eae814ea41ffe9cc2666183be193bb9169..322f4737d0289e18d1f9dab82e09c7da57f79e44 100644 (file)
@@ -1,3 +1,16 @@
+2005-05-26  Darin Adler  <darin@apple.com>
+
+        Reviewed by me, patch by Mitz Pettel.
+
+        - fixed <rdar://problem/4106907> bidi algorithm bug fixed for KHTML should be fixed in WebCore too
+
+        * khtml/rendering/bidi.cpp: (khtml::RenderBlock::bidiReorderLine): Integrated the patch that Mitz did
+        for the KDE bug, details at <http://www.mitzpettel.com/software/WebCorePatch2.html>.
+
+        Test cases added:
+        * layout-tests/fast/text/international/bidi-neutral-directionality-paragraph-start-expected.txt: Added.
+        * layout-tests/fast/text/international/bidi-neutral-directionality-paragraph-start.html: Added.
+
 2005-05-26  Darin Adler  <darin@apple.com>
 
         Reviewed by Richard and Dave Harrison.
index 921af1209e27bac9c9c00925dc30fe8b78dd29e7..016bbb54a515865cf3214cf2d1f883671f2caf99 100644 (file)
@@ -943,26 +943,25 @@ void RenderBlock::bidiReorderLine(const BidiIterator &start, const BidiIterator
                 case QChar::DirS:
                 case QChar::DirWS:
                 case QChar::DirON:
-                    if(dir != QChar::DirL) {
+                    if( bidi.status.eor != QChar::DirL ) {
                         //last stuff takes embedding dir
-                        if( bidi.context->dir == QChar::DirR ) {
-                            if(!(bidi.status.eor == QChar::DirR)) {
-                                // AN or EN
-                                appendRun( bidi );
-                                dir = QChar::DirR;
-                            }
-                            else
-                                bidi.eor = bidi.last;
+                        if(bidi.context->dir == QChar::DirL || bidi.status.lastStrong == QChar::DirL) { 
+                            if ( bidi.status.eor != QChar::DirEN && bidi.status.eor != QChar::DirAN && bidi.status.eor != QChar::DirON ) 
                             appendRun( bidi );
                             dir = QChar::DirL;
+                            bidi.eor = bidi.current; 
                             bidi.status.eor = QChar::DirL;
                         } else {
-                            if(bidi.status.eor == QChar::DirR) {
+                            if ( bidi.status.eor == QChar::DirEN || bidi.status.eor == QChar::DirAN ) 
+                            { 
+                                dir = bidi.status.eor; 
                                 appendRun( bidi );
-                                dir = QChar::DirL;
-                            } else {
-                                bidi.eor = bidi.current; bidi.status.eor = QChar::DirL; break;
                             }
+                            dir = QChar::DirR; 
+                            bidi.eor = bidi.last; 
+                            appendRun( bidi ); 
+                            dir = QChar::DirL; 
+                            bidi.status.eor = QChar::DirL; 
                         }
                     } else {
                         bidi.eor = bidi.current; bidi.status.eor = QChar::DirL;
@@ -998,12 +997,14 @@ void RenderBlock::bidiReorderLine(const BidiIterator &start, const BidiIterator
                 case QChar::DirON:
                     if( !(bidi.status.eor == QChar::DirR) && !(bidi.status.eor == QChar::DirAL) ) {
                         //last stuff takes embedding dir
-                        if(bidi.context->dir == QChar::DirR || bidi.status.lastStrong == QChar::DirR) {
+                        if(bidi.context->dir == QChar::DirR || bidi.status.lastStrong == QChar::DirR 
+                            || bidi.status.lastStrong == QChar::DirAL) { 
                             appendRun( bidi );
                             dir = QChar::DirR;
                             bidi.eor = bidi.current;
                            bidi.status.eor = QChar::DirR;
                         } else {
+                            dir = QChar::DirL; 
                             bidi.eor = bidi.last;
                             appendRun( bidi );
                             dir = QChar::DirR;
@@ -1027,9 +1028,6 @@ void RenderBlock::bidiReorderLine(const BidiIterator &start, const BidiIterator
             if(!(bidi.status.lastStrong == QChar::DirAL)) {
                 // if last strong was AL change EN to AN
                 if(dir == QChar::DirON) {
-                    if(bidi.status.lastStrong == QChar::DirAL)
-                        dir = QChar::DirAN;
-                    else
                         dir = QChar::DirL;
                 }
                 switch(bidi.status.last)
@@ -1202,7 +1200,6 @@ void RenderBlock::bidiReorderLine(const BidiIterator &start, const BidiIterator
                 break;
             case QChar::DirEN:
                 if ( bidi.status.last == QChar::DirL ) {
-                    bidi.status.last = QChar::DirL;
                     break;
                 }
                 // fall through