]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Suppress Pango's bidi, by displaying RTL characters one at a time. I
authorSimon Tatham <anakin@pobox.com>
Fri, 16 Sep 2011 19:18:58 +0000 (19:18 +0000)
committerSimon Tatham <anakin@pobox.com>
Fri, 16 Sep 2011 19:18:58 +0000 (19:18 +0000)
hadn't previously noticed, but Pango was helpfully re-reversing text
that PuTTY's own bidi module had already reversed, leading to Arabic
text being wrongly displayed and also total chaos when you move the
cursor over it or try to cut and paste it.

[originally from svn r9294]

unix/gtkfont.c

index e80d7acb21e3e2f6f12060396c41d5316ceb18d3..af577bda066aea6a6399305ef6c969f6a7a57d4c 100644 (file)
@@ -1114,34 +1114,42 @@ static void pangofont_draw_text(GdkDrawable *target, GdkGC *gc, unifont *font,
            clen++;
        n = 1;
 
-       /*
-        * See if that character has the width we expect.
-        */
-       pango_layout_set_text(layout, utfptr, clen);
-       pango_layout_get_pixel_extents(layout, NULL, &rect);
+        /*
+         * If it's a right-to-left character, we must display it on
+         * its own, to stop Pango helpfully re-reversing our already
+         * reversed text.
+         */
+        if (!is_rtl(string[0])) {
 
-       if (rect.width == cellwidth) {
-           /*
-            * Try extracting more characters, for as long as they
-            * stay well-behaved.
-            */
-           while (clen < utflen) {
-               int oldclen = clen;
-               clen++;                /* skip UTF-8 introducer byte */
-               while (clen < utflen &&
-                      (unsigned char)utfptr[clen] >= 0x80 &&
-                      (unsigned char)utfptr[clen] < 0xC0)
-                   clen++;
-               n++;
-               pango_layout_set_text(layout, utfptr, clen);
-               pango_layout_get_pixel_extents(layout, NULL, &rect);
-               if (rect.width != n * cellwidth) {
-                   clen = oldclen;
-                   n--;
-                   break;
-               }
-           }
-       }
+            /*
+             * See if that character has the width we expect.
+             */
+            pango_layout_set_text(layout, utfptr, clen);
+            pango_layout_get_pixel_extents(layout, NULL, &rect);
+
+            if (rect.width == cellwidth) {
+                /*
+                 * Try extracting more characters, for as long as they
+                 * stay well-behaved.
+                 */
+                while (clen < utflen) {
+                    int oldclen = clen;
+                    clen++;                   /* skip UTF-8 introducer byte */
+                    while (clen < utflen &&
+                           (unsigned char)utfptr[clen] >= 0x80 &&
+                           (unsigned char)utfptr[clen] < 0xC0)
+                        clen++;
+                    n++;
+                    pango_layout_set_text(layout, utfptr, clen);
+                    pango_layout_get_pixel_extents(layout, NULL, &rect);
+                    if (rect.width != n * cellwidth) {
+                        clen = oldclen;
+                        n--;
+                        break;
+                    }
+                }
+            }
+        }
 
        pango_layout_set_text(layout, utfptr, clen);
        pango_layout_get_pixel_extents(layout, NULL, &rect);
@@ -1153,6 +1161,7 @@ static void pangofont_draw_text(GdkDrawable *target, GdkGC *gc, unifont *font,
 
        utflen -= clen;
        utfptr += clen;
+        string += n;
        x += n * cellwidth;
     }