WebCore:
authorggaren <ggaren@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Jul 2005 17:44:10 +0000 (17:44 +0000)
committerggaren <ggaren@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Jul 2005 17:44:10 +0000 (17:44 +0000)
        Added layout test for
        http://bugzilla.opendarwin.org/show_bug.cgi?id=3435
        Parentheses are backwards in Hebrew text (no bidi mirroring?)

        Test is manual because results only reflect visually -
        the layout is the same either way.

        Test cases added:
        * manual-tests/bidi-parens.html: Added.

WebKit:

        -rolled in patch by opendarwin.org@mitzpettel.com
        for http://bugzilla.opendarwin.org/show_bug.cgi?id=3435
        Parentheses are backwards in Hebrew text (no bidi mirroring?)

        Reviewed by mjs.

        Layout test added to WebCore.

        * WebCoreSupport.subproj/WebTextRenderer.h:
        * WebCoreSupport.subproj/WebTextRenderer.m:
        (-[WebTextRenderer _initializeATSUStyle]):
        (applyMirroringToRun):
        (-[WebTextRenderer _ATSU_drawHighlightForRun:style:geometry:]):
        (-[WebTextRenderer _ATSU_drawRun:style:geometry:]):
        (-[WebTextRenderer _ATSU_pointToOffset:style:position:reversed:includePartialGlyphs:]):

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

WebCore/ChangeLog-2005-08-23
WebCore/manual-tests/bidi-parens.html [new file with mode: 0644]
WebKit/ChangeLog
WebKit/WebCoreSupport.subproj/WebTextRenderer.h
WebKit/WebCoreSupport.subproj/WebTextRenderer.m

index 1e2a5a384692bde54282b1e3d599d3b57c0ef94a..84396a16924350c09ca736a759c3701e6c83917d 100644 (file)
@@ -1,3 +1,15 @@
+2005-07-12  Geoffrey Garen  <ggaren@apple.com>
+
+        Added layout test for 
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=3435
+        Parentheses are backwards in Hebrew text (no bidi mirroring?)
+
+        Test is manual because results only reflect visually -
+        the layout is the same either way.
+        
+        Test cases added:
+        * manual-tests/bidi-parens.html: Added.
+
 2005-07-12  Ken Kocienda  <kocienda@apple.com>
 
         Reviewed by me
diff --git a/WebCore/manual-tests/bidi-parens.html b/WebCore/manual-tests/bidi-parens.html
new file mode 100644 (file)
index 0000000..4f72032
--- /dev/null
@@ -0,0 +1,18 @@
+<html>
+<head>
+<style>
+.console {
+       font-family: Arial, Times New Roman
+}
+</style>
+</head>
+<body>
+<p>This test checks for a regression against <a href="http://bugzilla.opendarwin.org/show_bug.cgi?id=3435">3435 Parentheses are backwards in Hebrew text (no bidi mirroring?)</a>.</p>
+<p>Success: parentheses encapsulate word.</p>
+<p>Failure: parentheses face away from word.</p>
+<hr>
+<p id="console" dir="rtl">
+(למדינות)
+</p>
+</body>
+</html>
\ No newline at end of file
index 299e7156f8b254aa2aa61c2534682509ed42ae3c..ef2da54cfbdfaedcf107ad3909ca809fe87228b5 100644 (file)
@@ -1,3 +1,21 @@
+2005-07-12  Geoffrey Garen  <ggaren@apple.com>
+
+        -rolled in patch by opendarwin.org@mitzpettel.com 
+        for http://bugzilla.opendarwin.org/show_bug.cgi?id=3435
+        Parentheses are backwards in Hebrew text (no bidi mirroring?)
+        
+        Reviewed by mjs.
+
+        Layout test added to WebCore.
+
+        * WebCoreSupport.subproj/WebTextRenderer.h:
+        * WebCoreSupport.subproj/WebTextRenderer.m:
+        (-[WebTextRenderer _initializeATSUStyle]):
+        (applyMirroringToRun):
+        (-[WebTextRenderer _ATSU_drawHighlightForRun:style:geometry:]):
+        (-[WebTextRenderer _ATSU_drawRun:style:geometry:]):
+        (-[WebTextRenderer _ATSU_pointToOffset:style:position:reversed:includePartialGlyphs:]):
+
 2005-07-12  Ken Kocienda  <kocienda@apple.com>
 
         Reviewed by Chris Blumenberg
index 3c02d4c72373e01414b9822f455658cc7475590a..8fb8acf991cd7a2b3466938f3566bf09bd1f9cbb 100644 (file)
@@ -70,6 +70,7 @@ typedef struct CharacterWidthIterator CharacterWidthIterator;
     NSFont *smallCapsFont;
     ATSUStyle _ATSUSstyle;
     BOOL ATSUStyleInitialized;
+    BOOL ATSUMirrors;
 }
 
 + (BOOL)shouldBufferTextDrawing;
index 9e72ef034bffcd8c42579a1d009d1bb4809671c9..82ce092a476b6152e83514dbd1f949cb02769f5b 100644 (file)
@@ -1453,6 +1453,7 @@ static const char *joiningNames[] = {
 
     if (!ATSUStyleInitialized){
         OSStatus status;
+        ByteCount propTableSize;
         
         status = ATSUCreateStyle(&_ATSUSstyle);
         if(status != noErr)
@@ -1473,6 +1474,13 @@ static const char *joiningNames[] = {
         status = ATSUSetAttributes (_ATSUSstyle, 3, styleTags, styleSizes, styleValues);
         if(status != noErr)
             FATAL_ALWAYS ("ATSUSetAttributes failed (%d)", status);
+        status = ATSFontGetTable(fontID, 'prop', 0, 0, 0, &propTableSize);
+        if (status == noErr)    // naively assume that if a 'prop' table exists then it contains mirroring info
+            ATSUMirrors = YES;
+        else if (status == kATSInvalidFontTableAccess)
+            ATSUMirrors = NO;
+        else
+            FATAL_ALWAYS ("ATSFontGetTable failed (%d)", status);
 
         ATSUStyleInitialized = YES;
     }
@@ -1602,6 +1610,25 @@ static WebCoreTextRun reverseCharactersInRun(const WebCoreTextRun *run)
     return swappedRun;
 }
 
+// Be sure to free the run.characters allocated by this function.
+static WebCoreTextRun applyMirroringToRun(const WebCoreTextRun *run)
+{
+    WebCoreTextRun swappedRun;
+    unsigned int i;
+    
+    UniChar *swappedCharacters = (UniChar *)malloc(sizeof(UniChar)*(run->length));
+    for (i=0; i < run->length; i++) {
+        // will choke on surrogate pairs?
+        swappedCharacters[i] = u_charMirror(run->characters[i]);
+    }
+    swappedRun.from = run->from;
+    swappedRun.to = run->to;
+    swappedRun.length = run->length;
+    swappedRun.characters = swappedCharacters;
+
+    return swappedRun;
+}
+
 - (void)_ATSU_drawHighlightForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style geometry:(const WebCoreTextGeometry *)geometry
 {
     // The only Cocoa calls made here are to NSColor and NSBezierPath,
@@ -1620,6 +1647,9 @@ static WebCoreTextRun reverseCharactersInRun(const WebCoreTextRun *run)
     if (style->visuallyOrdered) {
         swappedRun = reverseCharactersInRun(run);
         aRun = &swappedRun;
+    } else if (style->rtl && !ATSUMirrors) {
+        swappedRun = applyMirroringToRun(run);
+        aRun = &swappedRun;
     }
 
     from = aRun->from;
@@ -1672,7 +1702,7 @@ static WebCoreTextRun reverseCharactersInRun(const WebCoreTextRun *run)
 
     ATSUDisposeTextLayout (layout); // Ignore the error.  Nothing we can do anyway.
 
-    if (style->visuallyOrdered)
+    if (style->visuallyOrdered || (style->rtl && !ATSUMirrors))
         free ((void *)swappedRun.characters);
 }
 
@@ -1692,6 +1722,9 @@ static WebCoreTextRun reverseCharactersInRun(const WebCoreTextRun *run)
     if (style->visuallyOrdered) {
         swappedRun = reverseCharactersInRun(run);
         aRun = &swappedRun;
+    } else if (style->rtl && !ATSUMirrors) {
+        swappedRun = applyMirroringToRun(run);
+        aRun = &swappedRun;
     }
 
     from = aRun->from;
@@ -1725,7 +1758,7 @@ static WebCoreTextRun reverseCharactersInRun(const WebCoreTextRun *run)
 
     ATSUDisposeTextLayout (layout); // Ignore the error.  Nothing we can do anyway.
     
-    if (style->visuallyOrdered)
+    if (style->visuallyOrdered || (style->rtl && !ATSUMirrors))
         free ((void *)swappedRun.characters);
 }
 
@@ -1747,6 +1780,9 @@ static WebCoreTextRun reverseCharactersInRun(const WebCoreTextRun *run)
     if (style->visuallyOrdered) {
         swappedRun = reverseCharactersInRun(run);
         aRun = &swappedRun;
+    } else if (style->rtl && !ATSUMirrors) {
+        swappedRun = applyMirroringToRun(run);
+        aRun = &swappedRun;
     }
 
     layout = [self _createATSUTextLayoutForRun:aRun style:style];
@@ -1763,7 +1799,7 @@ static WebCoreTextRun reverseCharactersInRun(const WebCoreTextRun *run)
         // Failed to find offset!  Return 0 offset.
     }
        
-    if (style->visuallyOrdered) {
+    if (style->visuallyOrdered || (style->rtl && !ATSUMirrors)) {
         free ((void *)swappedRun.characters);
     }