[vte/wip/egmont/bidi: 9/21] etap5



commit b535d3aac07d48d9d69b7134ad759d837bf6a8bc
Author: Egmont Koblinger <egmont gmail com>
Date:   Fri May 24 12:12:25 2019 +0200

    etap5

 src/bidi.cc | 73 +++++++++++++++++++++++++++++++++----------------------------
 src/bidi.hh |  7 +++++-
 2 files changed, 45 insertions(+), 35 deletions(-)
---
diff --git a/src/bidi.cc b/src/bidi.cc
index 719b213b..ded325aa 100644
--- a/src/bidi.cc
+++ b/src/bidi.cc
@@ -160,17 +160,17 @@ BidiRunner::BidiRunner(RingView *ringview)
 
 BidiRunner::~BidiRunner() {}
 
+#ifdef WITH_FRIBIDI
 bool BidiRunner::is_arabic(gunichar c)
 {
-        const gunichar MIN_ARABIC = 0x0600;
-        const gunichar MAX_ARABIC = 0x06ff;
-
-        return c >= MIN_ARABIC && c <= MAX_ARABIC;
+        return FRIBIDI_IS_ARABIC (fribidi_get_bidi_type (c));
 }
+#endif /* WITH_FRIBIDI */
 
 /* Returns whether there's an Arabic character in the row so that shaping might be required. */
 bool BidiRunner::needs_shaping(vte::grid::row_t row)
 {
+#ifdef WITH_FRIBIDI
         const VteRowData *row_data = m_ringview->get_row(row);
 
         for (int i = 0; i < row_data->len; i++) {
@@ -181,9 +181,11 @@ bool BidiRunner::needs_shaping(vte::grid::row_t row)
                                 return true;
                 }
         }
+#endif /* WITH_FRIBIDI */
         return false;
 }
 
+#ifdef WITH_FRIBIDI
 /* Perform Arabic shaping on an explicit line (which could be explicit LTR or explicit RTL),
  * using presentational form characters.
  *
@@ -220,7 +222,7 @@ void BidiRunner::explicit_line_shape(vte::grid::row_t row)
         const VteCell *cell;
         gunichar c;
         gunichar base;
-        int i, j;
+        int i, j;  /* visual columns */
 
         fribidi_chars_array = g_array_new (FALSE, FALSE, sizeof (FriBidiChar));
 
@@ -271,11 +273,12 @@ void BidiRunner::explicit_line_shape(vte::grid::row_t row)
                fribidi_get_joining_types (fribidi_chars, count, fribidi_joiningtypes);
                level = fribidi_get_par_embedding_levels_ex (fribidi_chartypes, fribidi_brackettypes, count, 
&pbase_dir, fribidi_levels);
                 if (level == 0) {
-                        /* Error. Just skip shaping this word. */
+                        /* Error. Skip shaping this word. */
                         i = j - 1;
                         continue;
                 }
 
+                /* Shaping. */
                fribidi_join_arabic (fribidi_chartypes, count, fribidi_levels, fribidi_joiningtypes);
                fribidi_shape_arabic (FRIBIDI_FLAGS_ARABIC, fribidi_levels, count, fribidi_joiningtypes, 
fribidi_chars);
 
@@ -296,11 +299,13 @@ void BidiRunner::explicit_line_shape(vte::grid::row_t row)
                         j--;
                 }
 
-                /* Ready to look for the next word. Tiny speedup by skipping the stop char which isn't 
Arabic. */
+                /* Ready to look for the next word. Skip the stop char which isn't Arabic. */
                 i = j - 1;
         }
+
         g_array_free (fribidi_chars_array, TRUE);
 }
+#endif /* WITH_FRIBIDI */
 
 /* Set up the mapping according to explicit mode for a given line.
  *
@@ -344,7 +349,26 @@ void BidiRunner::explicit_line(vte::grid::row_t row, bool rtl, bool shape)
                         return;
                }
         }
+
+#ifdef WITH_FRIBIDI
         explicit_line_shape(row);
+#endif
+}
+
+/* Figure out the mapping for the paragraph between the given rows. */
+void BidiRunner::paragraph(vte::grid::row_t start, vte::grid::row_t end)
+{
+        const VteRowData *row_data = m_ringview->get_row(start);
+
+#ifdef WITH_FRIBIDI
+        if ((row_data->attr.bidi_flags & VTE_BIDI_IMPLICIT) &&
+            end - start <= VTE_RINGVIEW_PARAGRAPH_LENGTH_MAX) {
+                if (implicit_paragraph(start, end))
+                        return;
+        }
+#endif
+
+        explicit_paragraph(start, end, row_data->attr.bidi_flags & VTE_BIDI_RTL, false);
 }
 
 /* Set up the mapping according to explicit mode, for all the lines
@@ -356,13 +380,11 @@ void BidiRunner::explicit_paragraph(vte::grid::row_t start, vte::grid::row_t end
         }
 }
 
-/* Figure out the mapping for the paragraph between the given rows. */
-void BidiRunner::paragraph(vte::grid::row_t start, vte::grid::row_t end)
+#ifdef WITH_FRIBIDI
+/* Figure out the mapping for the implicit paragraph between the given rows.
+ * Returns success. */
+bool BidiRunner::implicit_paragraph(vte::grid::row_t start, vte::grid::row_t end)
 {
-#ifndef WITH_FRIBIDI
-        const VteRowData *row_data = m_ringview->get_row(start);
-        explicit_paragraph(start, end, row_data->attr.bidi_flags & VTE_BIDI_RTL, false);
-#else
         const VteCell *cell;
         const VteRowData *row_data;
         bool rtl;
@@ -382,12 +404,6 @@ void BidiRunner::paragraph(vte::grid::row_t start, vte::grid::row_t end)
         auto width = m_ringview->get_width();
 
         row_data = m_ringview->get_row(start);
-        if (!(row_data->attr.bidi_flags & VTE_BIDI_IMPLICIT) ||
-            end - start > VTE_RINGVIEW_PARAGRAPH_LENGTH_MAX) {
-                explicit_paragraph(start, end, row_data->attr.bidi_flags & VTE_BIDI_RTL, true);
-                return;
-        }
-
         rtl = row_data->attr.bidi_flags & VTE_BIDI_RTL;
         autodir = row_data->attr.bidi_flags & VTE_BIDI_AUTO;
 
@@ -522,17 +538,6 @@ void BidiRunner::paragraph(vte::grid::row_t start, vte::grid::row_t end)
                 lines[++line] = fribidi_chars_array->len;
         }
 
-#if 0
-        if (line == 0) {
-                /* Beyond the end of the ring. */
-                g_array_free (fribidi_chars_array, TRUE);
-                g_array_free (fribidi_map_array, TRUE);
-                g_array_free (fribidi_to_term_array, TRUE);
-                explicit_paragraph (start, end, rtl, true);
-                return;
-        }
-#endif
-
         /* Convenience stuff, we no longer need the auto-growing GArray wrapper. */
         count = fribidi_chars_array->len;
         fribidi_chars = (FriBidiChar *) fribidi_chars_array->data;
@@ -558,8 +563,7 @@ void BidiRunner::paragraph(vte::grid::row_t start, vte::grid::row_t end)
                 g_array_free (fribidi_chars_array, TRUE);
                 g_array_free (fribidi_map_array, TRUE);
                 g_array_free (fribidi_to_term_array, TRUE);
-                explicit_paragraph (start, end, rtl, false);
-                return;
+                return false;
         }
 
         /* Arabic shaping
@@ -592,7 +596,7 @@ void BidiRunner::paragraph(vte::grid::row_t start, vte::grid::row_t end)
                 g_array_free (fribidi_map_array, TRUE);
                 g_array_free (fribidi_to_term_array, TRUE);
                 explicit_paragraph (start, end, false, false);
-                return;
+                return true;
         }
 
         /* Reshuffle line by line. */
@@ -703,8 +707,9 @@ void BidiRunner::paragraph(vte::grid::row_t start, vte::grid::row_t end)
         g_array_free (fribidi_chars_array, TRUE);
         g_array_free (fribidi_map_array, TRUE);
         g_array_free (fribidi_to_term_array, TRUE);
-#endif /* !WITH_FRIBIDI */
+        return true;
 }
+#endif /* WITH_FRIBIDI */
 
 
 /* Find the mirrored counterpart of a codepoint, just like
diff --git a/src/bidi.hh b/src/bidi.hh
index 3ed29d58..8cddd621 100644
--- a/src/bidi.hh
+++ b/src/bidi.hh
@@ -92,12 +92,17 @@ public:
 private:
         RingView *m_ringview;
 
-        static bool is_arabic(gunichar c);
         bool needs_shaping(vte::grid::row_t row);
+#ifdef WITH_FRIBIDI
+        static bool is_arabic(gunichar c);
         void explicit_line_shape(vte::grid::row_t row);
+#endif
 
         void explicit_line(vte::grid::row_t row, bool rtl, bool shape);
         void explicit_paragraph(vte::grid::row_t start, vte::grid::row_t end, bool rtl, bool shape);
+#ifdef WITH_FRIBIDI
+        bool implicit_paragraph(vte::grid::row_t start, vte::grid::row_t end);
+#endif
 };
 
 }; /* namespace base */


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