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



commit b7c5e840d79eb669a6d386545b94d41997543805
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         | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++----
 src/vteinternal.hh |  5 ++++-
 src/vterowdata.hh  |  5 ++++-
 src/vteseq.cc      |  5 ++++-
 4 files changed, 68 insertions(+), 7 deletions(-)
---
diff --git a/src/vte.cc b/src/vte.cc
index e4793c8c..f6218581 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -2774,7 +2774,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 */
@@ -2844,6 +2844,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 =
@@ -2985,6 +2990,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,
@@ -8777,6 +8823,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. */
@@ -8818,14 +8869,14 @@ Terminal::draw_rows(VteScreen *screen_,
                  * Locate runs of identical bg colors within a row, and paint each run as a single 
rectangle. */
                 do {
                         /* Get the first cell's contents. */
-                        cell = row_data ? _vte_row_data_get (row_data, i) : nullptr;
+                        cell = row_data ? _vte_row_data_get_bidi (row_data, i) : nullptr;
                         /* Find the colors for this cell. */
                         selected = cell_is_selected(i, row);
                         determine_colors(cell, selected, &fore, &back, &deco);
 
                         while (++j < column_count) {
                                 /* Retrieve the next cell. */
-                                cell = row_data ? _vte_row_data_get (row_data, j) : nullptr;
+                                cell = row_data ? _vte_row_data_get_bidi (row_data, j) : nullptr;
                                 /* Resolve attributes to colors where possible and
                                  * compare visual attributes to the first character
                                  * in this chunk. */
@@ -8865,7 +8916,7 @@ Terminal::draw_rows(VteScreen *screen_,
                 item_count = 0;
                 for (col = 0; col < column_count; col++) {
                         /* Get the character cell's contents. */
-                        cell = _vte_row_data_get (row_data, col);
+                        cell = _vte_row_data_get_bidi (row_data, col);
                         if (cell == NULL) {
                                 /* There'll be no more real cells in this row. */
                                 break;
@@ -9939,6 +9990,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 fbe9b304..ab396b8b 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -593,7 +593,8 @@ public:
         long m_hyperlink_auto_id;
 
         /* BiDi */
-        gboolean m_bidi_rtl : 1;
+        guint m_bidi_rtl  : 1;
+        guint m_bidi_auto : 1;
 
 public:
 
@@ -643,6 +644,8 @@ public:
         void invalidate_match_span();
         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 9d4b2767..47e6ba30 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 94e55536..45c882ae 100644
--- a/src/vteseq.cc
+++ b/src/vteseq.cc
@@ -461,7 +461,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?
                 }
         }
 }
@@ -1017,6 +1017,7 @@ Terminal::line_feed()
 {
         ensure_cursor_is_onscreen();
         cursor_down(true);
+        maybe_apply_bidi_attributes();
 }
 
 void
@@ -7383,6 +7384,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]