[vte/wip/egmont/bidi: 9/16] bidi: Add API to enable or disable bidirectional text support



commit b57d213e4b8998a171910b3e2291ce9a7f456cf0
Author: Egmont Koblinger <egmont gmail com>
Date:   Tue Jun 4 11:05:09 2019 +0200

    bidi: Add API to enable or disable bidirectional text support

 doc/reference/vte-sections.txt |   4 ++
 src/app/app.cc                 |   8 +++
 src/vte.cc                     |  36 ++++++++++++++
 src/vte/vteterminal.h          |  13 +++++
 src/vtegtk.cc                  | 108 +++++++++++++++++++++++++++++++++++++++++
 src/vtegtk.hh                  |   2 +
 src/vteinternal.hh             |   4 ++
 7 files changed, 175 insertions(+)
---
diff --git a/doc/reference/vte-sections.txt b/doc/reference/vte-sections.txt
index f58b9b3f..8b67f283 100644
--- a/doc/reference/vte-sections.txt
+++ b/doc/reference/vte-sections.txt
@@ -62,6 +62,10 @@ vte_terminal_set_backspace_binding
 vte_terminal_set_delete_binding
 vte_terminal_set_mouse_autohide
 vte_terminal_get_mouse_autohide
+vte_terminal_set_enable_bidi
+vte_terminal_get_enable_bidi
+vte_terminal_set_enable_shaping
+vte_terminal_get_enable_shaping
 vte_terminal_reset
 vte_terminal_get_text
 vte_terminal_get_text_range
diff --git a/src/app/app.cc b/src/app/app.cc
index 529b584d..d845b5ce 100644
--- a/src/app/app.cc
+++ b/src/app/app.cc
@@ -48,6 +48,7 @@ public:
         gboolean icon_title{false};
         gboolean keep{false};
         gboolean no_argb_visual{false};
+        gboolean no_bidi{false};
         gboolean no_bold{false};
         gboolean no_builtin_dingus{false};
         gboolean no_context_menu{false};
@@ -55,6 +56,7 @@ public:
         gboolean no_geometry_hints{false};
         gboolean no_hyperlink{false};
         gboolean no_rewrap{false};
+        gboolean no_shaping{false};
         gboolean no_shell{false};
         gboolean object_notifications{false};
         gboolean reverse{false};
@@ -383,6 +385,8 @@ public:
                           "Live on after the command exits", nullptr },
                         { "no-argb-visual", 0, 0, G_OPTION_ARG_NONE, &no_argb_visual,
                           "Don't use an ARGB visual", nullptr },
+                        { "no-bidi", 0, 0, G_OPTION_ARG_NONE, &no_bidi,
+                          "Disable BiDi", nullptr },
                         { "no-bold", 0, 0, G_OPTION_ARG_NONE, &no_bold,
                           "Disable bold", nullptr },
                         { "no-builtin-dingus", 0, 0, G_OPTION_ARG_NONE, &no_builtin_dingus,
@@ -397,6 +401,8 @@ public:
                           "Disable hyperlinks", nullptr },
                         { "no-rewrap", 'R', 0, G_OPTION_ARG_NONE, &no_rewrap,
                           "Disable rewrapping on resize", nullptr },
+                        { "no-shaping", 0, 0, G_OPTION_ARG_NONE, &no_shaping,
+                          "Disable Arabic shaping", nullptr },
                         { "no-shell", 'S', 0, G_OPTION_ARG_NONE, &no_shell,
                           "Disable spawning a shell inside the terminal", nullptr },
                         { "object-notifications", 'N', 0, G_OPTION_ARG_NONE, &object_notifications,
@@ -1925,6 +1931,8 @@ vteapp_window_constructed(GObject *object)
         vte_terminal_set_cjk_ambiguous_width(window->terminal, options.cjk_ambiguous_width);
         vte_terminal_set_cursor_blink_mode(window->terminal, options.cursor_blink_mode);
         vte_terminal_set_cursor_shape(window->terminal, options.cursor_shape);
+        vte_terminal_set_enable_bidi(window->terminal, !options.no_bidi);
+        vte_terminal_set_enable_shaping(window->terminal, !options.no_shaping);
         vte_terminal_set_mouse_autohide(window->terminal, true);
         vte_terminal_set_rewrap_on_resize(window->terminal, !options.no_rewrap);
         vte_terminal_set_scroll_on_output(window->terminal, false);
diff --git a/src/vte.cc b/src/vte.cc
index 5971a15a..717ad96d 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -9806,6 +9806,42 @@ Terminal::set_text_blink_mode(VteTextBlinkMode setting)
         return true;
 }
 
+bool
+Terminal::set_enable_bidi(bool setting)
+{
+        if (setting == m_enable_bidi)
+                return false;
+
+        m_enable_bidi = setting;
+        m_ringview.invalidate();
+        invalidate_all();
+
+        /* Chances are that we can free up some BiDi/shaping buffers that we
+         * won't need for a while. */
+        if (!setting)
+                m_ringview.pause();
+
+        return true;
+}
+
+bool
+Terminal::set_enable_shaping(bool setting)
+{
+        if (setting == m_enable_shaping)
+                return false;
+
+        m_enable_shaping = setting;
+        m_ringview.invalidate();
+        invalidate_all();
+
+        /* Chances are that we can free up some BiDi/shaping buffers that we
+         * won't need for a while. */
+        if (!setting)
+                m_ringview.pause();
+
+        return true;
+}
+
 bool
 Terminal::set_allow_bold(bool setting)
 {
diff --git a/src/vte/vteterminal.h b/src/vte/vteterminal.h
index db82d9e4..569dbc5b 100644
--- a/src/vte/vteterminal.h
+++ b/src/vte/vteterminal.h
@@ -332,6 +332,19 @@ _VTE_PUBLIC
 void vte_terminal_set_delete_binding(VteTerminal *terminal,
                                     VteEraseBinding binding) _VTE_GNUC_NONNULL(1);
 
+/* BiDi and shaping */
+_VTE_PUBLIC
+void vte_terminal_set_enable_bidi(VteTerminal *terminal,
+                                  gboolean enable_bidi) _VTE_GNUC_NONNULL(1);
+_VTE_PUBLIC
+gboolean vte_terminal_get_enable_bidi(VteTerminal *terminal) _VTE_GNUC_NONNULL(1);
+
+_VTE_PUBLIC
+void vte_terminal_set_enable_shaping(VteTerminal *terminal,
+                                     gboolean enable_shaping) _VTE_GNUC_NONNULL(1);
+_VTE_PUBLIC
+gboolean vte_terminal_get_enable_shaping(VteTerminal *terminal) _VTE_GNUC_NONNULL(1);
+
 /* Manipulate the autohide setting. */
 _VTE_PUBLIC
 void vte_terminal_set_mouse_autohide(VteTerminal *terminal,
diff --git a/src/vtegtk.cc b/src/vtegtk.cc
index aab8e20d..a6a63e12 100644
--- a/src/vtegtk.cc
+++ b/src/vtegtk.cc
@@ -490,6 +490,12 @@ vte_terminal_get_property (GObject *object,
                 case PROP_DELETE_BINDING:
                         g_value_set_enum (value, impl->m_delete_binding);
                         break;
+                case PROP_ENABLE_BIDI:
+                        g_value_set_boolean (value, vte_terminal_get_enable_bidi (terminal));
+                        break;
+                case PROP_ENABLE_SHAPING:
+                        g_value_set_boolean (value, vte_terminal_get_enable_shaping (terminal));
+                        break;
                 case PROP_ENCODING:
                         g_value_set_string (value, vte_terminal_get_encoding (terminal));
                         break;
@@ -597,6 +603,12 @@ vte_terminal_set_property (GObject *object,
                 case PROP_DELETE_BINDING:
                         vte_terminal_set_delete_binding (terminal, (VteEraseBinding)g_value_get_enum 
(value));
                         break;
+                case PROP_ENABLE_BIDI:
+                        vte_terminal_set_enable_bidi (terminal, g_value_get_boolean (value));
+                        break;
+                case PROP_ENABLE_SHAPING:
+                        vte_terminal_set_enable_shaping (terminal, g_value_get_boolean (value));
+                        break;
                 case PROP_ENCODING:
                         vte_terminal_set_encoding (terminal, g_value_get_string (value), NULL);
                         break;
@@ -1537,6 +1549,30 @@ vte_terminal_class_init(VteTerminalClass *klass)
                                    VTE_ERASE_AUTO,
                                    (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | 
G_PARAM_EXPLICIT_NOTIFY));
 
+        /**
+         * VteTerminal:enable-bidi:
+         *
+         * Controls whether or not the terminal will perform bidirectional text rendering.
+         *
+         * Since: 0.58
+         */
+        pspecs[PROP_ENABLE_BIDI] =
+                g_param_spec_boolean ("enable-bidi", NULL, NULL,
+                                      TRUE,
+                                      (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | 
G_PARAM_EXPLICIT_NOTIFY));
+
+        /**
+         * VteTerminal:enable-shaping:
+         *
+         * Controls whether or not the terminal will shape Arabic text.
+         *
+         * Since: 0.58
+         */
+        pspecs[PROP_ENABLE_SHAPING] =
+                g_param_spec_boolean ("enable-shaping", NULL, NULL,
+                                      TRUE,
+                                      (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | 
G_PARAM_EXPLICIT_NOTIFY));
+
         /**
          * VteTerminal:font-scale:
          *
@@ -3692,6 +3728,78 @@ vte_terminal_set_delete_binding(VteTerminal *terminal,
                 g_object_notify_by_pspec(G_OBJECT(terminal), pspecs[PROP_DELETE_BINDING]);
 }
 
+/**
+ * vte_terminal_get_enable_bidi:
+ * @terminal: a #VteTerminal
+ *
+ * Checks whether the terminal performs bidirectional text rendering.
+ *
+ * Returns: %TRUE if BiDi is enabled, %FALSE if not
+ *
+ * Since: 0.58
+ */
+gboolean
+vte_terminal_get_enable_bidi(VteTerminal *terminal)
+{
+        g_return_val_if_fail(VTE_IS_TERMINAL(terminal), FALSE);
+        return IMPL(terminal)->m_enable_bidi;
+}
+
+/**
+ * vte_terminal_set_enable_bidi:
+ * @terminal: a #VteTerminal
+ * @enable_bidi: %TRUE to enable BiDi support
+ *
+ * Controls whether or not the terminal will perform bidirectional text rendering.
+ *
+ * Since: 0.58
+ */
+void
+vte_terminal_set_enable_bidi(VteTerminal *terminal,
+                             gboolean enable_bidi)
+{
+        g_return_if_fail(VTE_IS_TERMINAL(terminal));
+
+        if (IMPL(terminal)->set_enable_bidi(enable_bidi != FALSE))
+                g_object_notify_by_pspec(G_OBJECT(terminal), pspecs[PROP_ENABLE_BIDI]);
+}
+
+/**
+ * vte_terminal_get_enable_shaping:
+ * @terminal: a #VteTerminal
+ *
+ * Checks whether the terminal shapes Arabic text.
+ *
+ * Returns: %TRUE if Arabic shaping is enabled, %FALSE if not
+ *
+ * Since: 0.58
+ */
+gboolean
+vte_terminal_get_enable_shaping(VteTerminal *terminal)
+{
+        g_return_val_if_fail(VTE_IS_TERMINAL(terminal), FALSE);
+        return IMPL(terminal)->m_enable_shaping;
+}
+
+/**
+ * vte_terminal_set_enable_shaping:
+ * @terminal: a #VteTerminal
+ * @enable_shaping: %TRUE to enable Arabic shaping
+ *
+ * Controls whether or not the terminal will shape Arabic text.
+ *
+ * Since: 0.58
+ */
+void
+vte_terminal_set_enable_shaping(VteTerminal *terminal,
+                                gboolean enable_shaping)
+{
+        g_return_if_fail(VTE_IS_TERMINAL(terminal));
+
+        if (IMPL(terminal)->set_enable_shaping(enable_shaping != FALSE))
+                g_object_notify_by_pspec(G_OBJECT(terminal), pspecs[PROP_ENABLE_SHAPING]);
+}
+
 /**
  * vte_terminal_get_encoding:
  * @terminal: a #VteTerminal
diff --git a/src/vtegtk.hh b/src/vtegtk.hh
index c49754ef..e2515b34 100644
--- a/src/vtegtk.hh
+++ b/src/vtegtk.hh
@@ -76,6 +76,8 @@ enum {
         PROP_CURRENT_DIRECTORY_URI,
         PROP_CURRENT_FILE_URI,
         PROP_DELETE_BINDING,
+        PROP_ENABLE_BIDI,
+        PROP_ENABLE_SHAPING,
         PROP_ENCODING,
         PROP_FONT_DESC,
         PROP_FONT_SCALE,
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index 28c65d1f..9c135ffc 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -615,6 +615,8 @@ public:
 
         /* RingView and friends */
         vte::base::RingView m_ringview;
+        bool m_enable_bidi{true};
+        bool m_enable_shaping{true};
 
         /* BiDi parameters outside of ECMA and DEC private modes */
         guint m_bidi_rtl : 1;
@@ -1173,6 +1175,8 @@ public:
         bool set_cursor_shape(VteCursorShape shape);
         bool set_cursor_style(VteCursorStyle style);
         bool set_delete_binding(VteEraseBinding binding);
+        bool set_enable_bidi(bool setting);
+        bool set_enable_shaping(bool setting);
         bool set_encoding(char const* codeset);
         bool set_font_desc(PangoFontDescription const* desc);
         bool set_font_scale(double scale);


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