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



commit a7612397f276225b3325bc982d2b1b102a3ad616
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 05776552..d37ff046 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -2787,7 +2787,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 */
@@ -2857,6 +2857,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 =
@@ -2998,6 +3003,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,
@@ -8735,6 +8781,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. */
@@ -8769,14 +8820,14 @@ Terminal::draw_rows(VteScreen *screen_,
                 /* Walk the line. */
                 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 < m_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. */
@@ -8816,7 +8867,7 @@ Terminal::draw_rows(VteScreen *screen_,
                 item_count = 0;
                 for (col = 0; col < m_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;
@@ -9890,6 +9941,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 e3f742f0..f78feee4 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -630,7 +630,8 @@ public:
         long m_hyperlink_auto_id;
 
         /* BiDi */
-        gboolean m_bidi_rtl : 1;
+        guint m_bidi_rtl  : 1;
+        guint m_bidi_auto : 1;
 
 public:
 
@@ -680,6 +681,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 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 7dc0557a..a6e62bc2 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
@@ -7293,6 +7294,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]