[gtk+/gtk-2-24] TextView: Get line direction in more efficient way



commit 4e149261536031ec9d6c1aba7590e148025351db
Author: Daniel Boles <dboles src gnome org>
Date:   Sun Mar 26 16:28:20 2017 +0100

    TextView: Get line direction in more efficient way
    
    We do not need to go through the heavyweight process of constructing a
    TextLineDisplay just to get the direction out of it, when we can simply
    use TextIter API to get the text and then get its direction using Pango.
    
    Adapted from a patch by Mehdi Sadeghi for GtkSourceView:
    
    https://bugzilla.gnome.org/show_bug.cgi?id=779081#c20

 gtk/gtktextview.c |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 87f0cb9..a869fb0 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -5068,15 +5068,21 @@ move_cursor (GtkTextView       *text_view,
 }
 
 static gboolean
-iter_line_is_rtl (GtkTextIter *iter, GtkTextLayout *layout)
+iter_line_is_rtl (GtkTextIter *iter)
 {
-  GtkTextLine *line = _gtk_text_iter_get_text_line (iter);
-  GtkTextLineDisplay *display = gtk_text_layout_get_line_display (layout, line, FALSE);
-  GtkTextDirection direction = display->direction;
+  GtkTextIter start, end;
+  char *text;
+  PangoDirection direction;
 
-  gtk_text_layout_free_line_display (layout, display);
+  start = end = *iter;
+  gtk_text_iter_set_line_offset (&start, 0);
+  gtk_text_iter_forward_line (&end);
+  text = gtk_text_iter_get_visible_text (&start, &end);
+  direction = pango_find_base_dir (text, -1);
+
+  g_free (text);
 
-  return direction == GTK_TEXT_DIR_RTL;
+  return direction == PANGO_DIRECTION_RTL;
 }
 
 static void
@@ -5173,7 +5179,7 @@ gtk_text_view_move_cursor_internal (GtkTextView     *text_view,
       gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &sel_bound,
                                         gtk_text_buffer_get_selection_bound (get_buffer (text_view)));
 
-      if (iter_line_is_rtl (&insert, text_view->layout))
+      if (iter_line_is_rtl (&insert))
         move_forward = !move_forward;
 
       /* if we move forward, assume the cursor is at the end of the selection;
@@ -5211,7 +5217,7 @@ gtk_text_view_move_cursor_internal (GtkTextView     *text_view,
       break;
 
     case GTK_MOVEMENT_WORDS:
-      if (iter_line_is_rtl (&newplace, text_view->layout))
+      if (iter_line_is_rtl (&newplace))
         count *= -1;
 
       if (count < 0)


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