[vte/wip/egmont/bidi: 16/75] track bidi params (buggy), first explicit rtl attempt (unusable)



commit 02d964f4a5305d542250939ccf1d504802b83e2e
Author: Egmont Koblinger <egmont gmail com>
Date:   Fri Aug 17 22:30:27 2018 +0200

    track bidi params (buggy), first explicit rtl attempt (unusable)

 src/vte.cc         | 76 +++++++++++++++++++++++++++++++++++++++++++++---------
 src/vteinternal.hh |  5 +++-
 src/vterowdata.hh  |  5 +++-
 src/vteseq.cc      |  5 +++-
 4 files changed, 76 insertions(+), 15 deletions(-)
---
diff --git a/src/vte.cc b/src/vte.cc
index 9e497bd1..30e2bfb1 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -2789,7 +2789,7 @@ Terminal::insert_char(gunichar c,
                                 bool invalidate_now)
 {
        VteCellAttr attr;
-       VteRowData *row;
+       VteRowData *row, *row2;
        long col;
        int columns, i;
        bool line_wrapped = false; /* cursor moved before char inserted */
@@ -2859,6 +2859,11 @@ Terminal::insert_char(gunichar c,
                        row = ensure_row();
                        row->attr.soft_wrapped = 1;
                         cursor_down(false);
+
+                        row2 = ensure_row();
+                        row2->attr.bidi_implicit = row->attr.bidi_implicit;
+                        row2->attr.bidi_rtl      = row->attr.bidi_rtl;
+                        row2->attr.bidi_auto     = row->attr.bidi_auto;
                } else {
                        /* Don't wrap, stay at the rightmost column. */
                         col = m_screen->cursor.col =
@@ -3005,6 +3010,47 @@ not_inserted:
         m_line_wrapped = line_wrapped;
 }
 
+/* Apply the BiDi parameters on the current paragraph if the cursor
+ * is at the first position of this paragraph. */
+void
+Terminal::maybe_apply_bidi_attributes()
+{
+        _vte_debug_print(VTE_DEBUG_BIDI,
+                         "Maybe applying BiDi parameters on current paragraph.\n");
+
+        if (m_screen->cursor.col != 0) {
+                _vte_debug_print(VTE_DEBUG_BIDI,
+                                 "No, cursor not in first column.\n");
+                return;
+        }
+
+        auto row = m_screen->cursor.row;
+
+        if (row > 0) {
+                const VteRowData *rowdata = _vte_ring_index (m_screen->row_data, row - 1);
+                if (rowdata != nullptr && rowdata->attr.soft_wrapped) {
+                        _vte_debug_print(VTE_DEBUG_BIDI,
+                                         "No, not after a hard wrap.\n");
+                        return;
+                }
+        }
+
+        _vte_debug_print(VTE_DEBUG_BIDI,
+                         "Yes, applying.\n");
+
+        while (TRUE) {
+                VteRowData *rowdata = _vte_ring_index_writable (m_screen->row_data, row);
+                if (rowdata == nullptr)
+                        return;
+                rowdata->attr.bidi_implicit = m_modes_ecma.BDSM();
+                rowdata->attr.bidi_rtl = m_bidi_rtl;
+                rowdata->attr.bidi_auto = m_bidi_auto;
+                if (!rowdata->attr.soft_wrapped)
+                        return;
+                row++;
+        }
+}
+
 static void
 reaper_child_exited_cb(VteReaper *reaper,
                        int ipid,
@@ -8924,6 +8970,11 @@ Terminal::draw_cells_with_attributes(struct _vte_draw_text_request *items,
 }
 
 
+/* XXX tmp hack */
+#define _vte_row_data_get_bidi(row_data_p, col) \
+    (_vte_row_data_get ((row_data_p), ((row_data_p)->attr.bidi_rtl ? (m_column_count - 1 - (col)) : (col))))
+
+
 /* Paint the contents of a given row at the given location.  Take advantage
  * of multiple-draw APIs by finding runs of characters with identical
  * attributes and bundling them together. */
@@ -8965,16 +9016,16 @@ Terminal::draw_rows(VteScreen *screen_,
                 * making the drawing area a little wider. */
                i = start_column;
                if (row_data != NULL) {
-                       cell = _vte_row_data_get (row_data, i);
+                       cell = _vte_row_data_get_bidi (row_data, i);
                        if (cell != NULL) {
                                while (cell->attr.fragment() && i > 0) {
-                                       cell = _vte_row_data_get (row_data, --i);
+                                       cell = _vte_row_data_get_bidi (row_data, --i);
                                }
                        }
                        /* Walk the line. */
                        do {
                                /* Get the character cell's contents. */
-                               cell = _vte_row_data_get (row_data, i);
+                               cell = _vte_row_data_get_bidi (row_data, i);
                                /* Find the colors for this cell. */
                                selected = cell_is_selected(i, row);
                                 determine_colors(cell, selected, &fore, &back, &deco);
@@ -8983,7 +9034,7 @@ Terminal::draw_rows(VteScreen *screen_,
 
                                while (j < end_column){
                                        /* Retrieve the cell. */
-                                       cell = _vte_row_data_get (row_data, j);
+                                       cell = _vte_row_data_get_bidi (row_data, j);
                                        /* Don't render fragments of multicolumn characters
                                         * which have the same attributes as the initial
                                         * portions. */
@@ -9059,17 +9110,17 @@ Terminal::draw_rows(VteScreen *screen_,
                /* Back up in case this is a multicolumn character,
                 * making the drawing area a little wider. */
                i = start_column;
-               cell = _vte_row_data_get (row_data, i);
+               cell = _vte_row_data_get_bidi (row_data, i);
                if (cell == NULL) {
                        goto fg_skip_row;
                }
                while (cell->attr.fragment() && i > 0)
-                       cell = _vte_row_data_get (row_data, --i);
+                       cell = _vte_row_data_get_bidi (row_data, --i);
 
                /* Walk the line. */
                do {
                        /* Get the character cell's contents. */
-                       cell = _vte_row_data_get (row_data, i);
+                       cell = _vte_row_data_get_bidi (row_data, i);
                        if (cell == NULL) {
                                goto fg_skip_row;
                        }
@@ -9083,7 +9134,7 @@ Terminal::draw_rows(VteScreen *screen_,
                                if (++i >= end_column) {
                                        goto fg_skip_row;
                                }
-                               cell = _vte_row_data_get (row_data, i);
+                               cell = _vte_row_data_get_bidi (row_data, i);
                                if (cell == NULL) {
                                        goto fg_skip_row;
                                }
@@ -9109,7 +9160,7 @@ Terminal::draw_rows(VteScreen *screen_,
                                while (j < end_column &&
                                                item_count < G_N_ELEMENTS(items)) {
                                        /* Retrieve the cell. */
-                                       cell = _vte_row_data_get (row_data, j);
+                                       cell = _vte_row_data_get_bidi (row_data, j);
                                        if (cell == NULL) {
                                                goto fg_next_row;
                                        }
@@ -9198,10 +9249,10 @@ fg_next_row:
                                         * multicolumn character, making the drawing
                                         * area a little wider. */
                                        j = start_column;
-                                       cell = _vte_row_data_get (row_data, j);
+                                       cell = _vte_row_data_get_bidi (row_data, j);
                                } while (cell == NULL);
                                while (cell->attr.fragment() && j > 0) {
-                                       cell = _vte_row_data_get (row_data, --j);
+                                       cell = _vte_row_data_get_bidi (row_data, --j);
                                }
                        } while (TRUE);
 fg_draw:
@@ -10241,6 +10292,7 @@ Terminal::reset(bool clear_tabstops,
         save_cursor(&m_alternate_screen);
         /* BiDi */
         m_bidi_rtl = FALSE;
+        m_bidi_auto = FALSE;
        /* Cause everything to be redrawn (or cleared). */
        invalidate_all();
 
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index c2f91a8e..ca8716cf 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -632,7 +632,8 @@ public:
         long m_hyperlink_auto_id;
 
         /* BiDi */
-        gboolean m_bidi_rtl : 1;
+        guint m_bidi_rtl  : 1;
+        guint m_bidi_auto : 1;
 
 public:
 
@@ -685,6 +686,8 @@ public:
         void invalidate_selection();
         void invalidate_all();
 
+        void maybe_apply_bidi_attributes();
+
         void reset_update_rects();
         bool invalidate_dirty_rects_and_process_updates();
         void time_process_incoming();
diff --git a/src/vterowdata.hh b/src/vterowdata.hh
index 4191cccb..e35f7ab7 100644
--- a/src/vterowdata.hh
+++ b/src/vterowdata.hh
@@ -36,7 +36,10 @@ G_BEGIN_DECLS
  */
 
 typedef struct _VteRowAttr {
-       guint8 soft_wrapped: 1;
+        guint8 soft_wrapped  : 1;
+        guint8 bidi_implicit : 1;
+        guint8 bidi_rtl      : 1;
+        guint8 bidi_auto     : 1;
 } VteRowAttr;
 static_assert(sizeof (VteRowAttr) == 1, "VteRowAttr has wrong size");
 
diff --git a/src/vteseq.cc b/src/vteseq.cc
index c13a9dee..b88700b8 100644
--- a/src/vteseq.cc
+++ b/src/vteseq.cc
@@ -462,7 +462,7 @@ Terminal::set_mode_ecma(vte::parser::Sequence const& seq,
                         _vte_debug_print(VTE_DEBUG_BIDI,
                                          "BiDi %s mode\n",
                                          set ? "implicit" : "explicit");
-                        /* Will need to take immediate action too */
+                        maybe_apply_bidi_attributes();  // FIXME only apply the one that changed here?
                 }
         }
 }
@@ -1023,6 +1023,7 @@ Terminal::line_feed()
 {
         ensure_cursor_is_onscreen();
         cursor_down(true);
+        maybe_apply_bidi_attributes();
 }
 
 void
@@ -7302,6 +7303,8 @@ Terminal::SPD(vte::parser::Sequence const& seq)
                 _vte_debug_print(VTE_DEBUG_BIDI, "BiDi: default direction restored\n");
                 break;
         }
+
+        maybe_apply_bidi_attributes();  // FIXME only apply the one that changed here?
 }
 
 void


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