[vte/wip/egmont/bidi: 35/73] refactor box mirroring



commit dc7877f7852ccb43e2d299c05292ce9691806da4
Author: Egmont Koblinger <egmont gmail com>
Date:   Sat Aug 25 02:59:38 2018 +0200

    refactor box mirroring

 src/bidi.cc    | 30 ++++++++++++++++++++++++++++++
 src/bidi.hh    |  2 ++
 src/vtedraw.cc | 32 ++++++++++----------------------
 3 files changed, 42 insertions(+), 22 deletions(-)
---
diff --git a/src/bidi.cc b/src/bidi.cc
index e7713912..032e7e51 100644
--- a/src/bidi.cc
+++ b/src/bidi.cc
@@ -467,3 +467,33 @@ next_line:
 
 #endif /* !WITH_FRIBIDI */
 }
+
+gboolean vte_bidi_get_mirror_char (gunichar ch, gboolean mirror_box_drawing, gunichar *mirrored_ch)
+{
+        unsigned char mirrored_2500[0x80] = {
+                0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x10, 0x11, 0x12, 
0x13,
+                0x0c, 0x0d, 0x0e, 0x0f, 0x18, 0x19, 0x1a, 0x1b, 0x14, 0x15, 0x16, 0x17, 0x24, 0x25, 0x26, 
0x27,
+                0x28, 0x29, 0x2a, 0x2b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x2c, 0x2e, 0x2d, 
0x2f,
+                0x30, 0x32, 0x31, 0x33, 0x34, 0x36, 0x35, 0x37, 0x38, 0x3a, 0x39, 0x3b, 0x3c, 0x3e, 0x3d, 
0x3f,
+                0x40, 0x4a, 0x42, 0x44, 0x43, 0x46, 0x45, 0x47, 0x48, 0x4a, 0x49, 0x4b, 0x4c, 0x4d, 0x4e, 
0x4f,
+                0x50, 0x51, 0x55, 0x56, 0x57, 0x52, 0x53, 0x54, 0x5b, 0x5c, 0x5d, 0x58, 0x59, 0x5a, 0x61, 
0x62,
+                0x63, 0x5e, 0x5f, 0x60, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6e, 0x6d, 
0x70,
+                0x6f, 0x72, 0x71, 0x73, 0x76, 0x75, 0x74, 0x77, 0x7a, 0x79, 0x78, 0x7b, 0x7e, 0x7d, 0x7c, 
0x7f };
+
+        if (G_UNLIKELY (mirror_box_drawing && ch >= 0x2500 && ch < 0x2580)) {
+                gunichar mir = 0x2500 + mirrored_2500[ch - 0x2500];
+                if (mirrored_ch)
+                        *mirrored_ch = mir;
+                return mir == ch;
+        }
+
+#ifdef WITH_FRIBIDI
+        /* Prefer the FriBidi variant as that's more likely
+         * to be in sync with the rest of our BiDi stuff. */
+        return fribidi_get_mirror_char (ch, mirrored_ch);
+#else
+        /* Fall back to glib, so that we still get mirrored
+         * characters in explicit RTL mode. */
+        return g_unichar_get_mirror_char (ch, mirrored_ch);
+#endif
+}
diff --git a/src/bidi.hh b/src/bidi.hh
index ed53d472..46a73bf4 100644
--- a/src/bidi.hh
+++ b/src/bidi.hh
@@ -86,4 +86,6 @@ private:
 
 G_BEGIN_DECLS
 
+gboolean vte_bidi_get_mirror_char (gunichar ch, gboolean mirror_box_drawing, gunichar *mirrored_ch);
+
 G_END_DECLS
diff --git a/src/vtedraw.cc b/src/vtedraw.cc
index c3f9b7ff..83b87e39 100644
--- a/src/vtedraw.cc
+++ b/src/vtedraw.cc
@@ -26,10 +26,7 @@
 #include <glib.h>
 #include <gtk/gtk.h>
 
-#ifdef WITH_FRIBIDI
-#include <fribidi.h>
-#endif
-
+#include "bidi.hh"
 #include "vtedraw.hh"
 #include "vtedefines.hh"
 #include "debug.h"
@@ -997,7 +994,7 @@ _vte_draw_unichar_is_local_graphic(vteunistr c)
 /* Draw the graphic representation of a line-drawing or special graphics
  * character. */
 static void
-_vte_draw_terminal_draw_graphic(struct _vte_draw *draw, vteunistr c, gboolean mirror, vte::color::rgb const* 
fg,
+_vte_draw_terminal_draw_graphic(struct _vte_draw *draw, vteunistr c, vte::color::rgb const* fg,
                                 gint x, gint y,
                                 gint font_width, gint columns, gint font_height)
 {
@@ -1165,16 +1162,15 @@ _vte_draw_terminal_draw_graphic(struct _vte_draw *draw, vteunistr c, gboolean mi
                                        upper_half - light_line_width / 2 + light_line_width,
                                        upper_half - heavy_line_width / 2 + heavy_line_width,
                                        height};
-                int xi, xi_bidi, yi;
+                int xi, yi;
                 cairo_set_line_width(cr, 0);
                 for (yi = 4; yi >= 0; yi--) {
                         for (xi = 4; xi >= 0; xi--) {
                                 if (bitmap & 1) {
-                                        xi_bidi = mirror ? 4 - xi : xi;
                                         cairo_rectangle(cr,
-                                                        x + xboundaries[xi_bidi],
+                                                        x + xboundaries[xi],
                                                         y + yboundaries[yi],
-                                                        xboundaries[xi_bidi + 1] - xboundaries[xi_bidi],
+                                                        xboundaries[xi + 1] - xboundaries[xi],
                                                         yboundaries[yi + 1] - yboundaries[yi]);
                                         cairo_fill(cr);
                                 }
@@ -1247,7 +1243,7 @@ _vte_draw_terminal_draw_graphic(struct _vte_draw *draw, vteunistr c, gboolean mi
         case 0x256f: /* box drawings light arc up and left */
         case 0x2570: /* box drawings light arc up and right */
         {
-                const guint v = (c - 0x256d) ^ (mirror ? 1 : 0);
+                const guint v = c - 0x256d;
                 int line_width;
                 int radius;
 
@@ -1297,12 +1293,12 @@ _vte_draw_terminal_draw_graphic(struct _vte_draw *draw, vteunistr c, gboolean mi
                 cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
                 cairo_set_line_width(cr, light_line_width);
                 adjust = light_line_width / 2.;
-                if (c != (mirror ? 0x2572 : 0x2571)) {
+                if (c != 0x2571) {
                         cairo_move_to(cr, x + adjust, y + adjust);
                         cairo_line_to(cr, xright - adjust, ybottom - adjust);
                         cairo_stroke(cr);
                 }
-                if (c != (mirror ? 0x2571 : 0x2572)) {
+                if (c != 0x2572) {
                         cairo_move_to(cr, xright - adjust, y + adjust);
                         cairo_line_to(cr, x + adjust, ybottom - adjust);
                         cairo_stroke(cr);
@@ -1479,15 +1475,7 @@ _vte_draw_text_internal (struct _vte_draw *draw,
 
                 if (G_UNLIKELY (requests[i].mirror)) {
                         // FIXME what if 'c' is actually a real vteunistr?
-#ifdef WITH_FRIBIDI
-                        /* Prefer the FriBidi variant as that's more likely
-                         * to be in sync with the rest of our BiDi stuff. */
-                        fribidi_get_mirror_char (c, &c);
-#else
-                        /* Fall back to glib, so that we still get mirrored
-                         * characters in explicit RTL mode. */
-                        g_unichar_get_mirror_char (c, &c);
-#endif
+                        vte_bidi_get_mirror_char (c, requests[i].box_mirror, &c);
                 }
 
                struct unistr_info *uinfo = font_info_get_unistr_info (font, c);
@@ -1499,7 +1487,7 @@ _vte_draw_text_internal (struct _vte_draw *draw,
                 y = requests[i].y + draw->char_spacing.top + font->ascent;
 
                 if (_vte_draw_unichar_is_local_graphic(c)) {
-                        _vte_draw_terminal_draw_graphic(draw, c, requests[i].mirror && 
requests[i].box_mirror, color,
+                        _vte_draw_terminal_draw_graphic(draw, c, color,
                                                         requests[i].x, requests[i].y,
                                                         font->width, requests[i].columns, font->height);
                         continue;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]