[gimp] app: fix insert and overwrite cursors for RTL text



commit 852196eb3dc29d5568f63f51a451b5c188757a04
Author: Michael Natterer <mitch gimp org>
Date:   Thu Oct 14 02:45:32 2010 +0200

    app: fix insert and overwrite cursors for RTL text
    
    by using the right function to figure the location of both kinds of
    cursors. Also fix crash in my last cursor movement commit: check for
    error values returned by pango_layout_move_cursor_visually() and don't
    try to move the cursor beyond the buffer boundaries.

 app/tools/gimptexttool-editor.c |   29 ++++++++++++++++++++++++-----
 app/tools/gimptexttool-editor.h |    1 +
 app/tools/gimptexttool.c        |    6 ++++--
 3 files changed, 29 insertions(+), 7 deletions(-)
---
diff --git a/app/tools/gimptexttool-editor.c b/app/tools/gimptexttool-editor.c
index 63dff30..025687f 100644
--- a/app/tools/gimptexttool-editor.c
+++ b/app/tools/gimptexttool-editor.c
@@ -515,6 +515,7 @@ gimp_text_tool_reset_im_context (GimpTextTool *text_tool)
 
 void
 gimp_text_tool_editor_get_cursor_rect (GimpTextTool   *text_tool,
+                                       gboolean        overwrite,
                                        PangoRectangle *cursor_rect)
 {
   GtkTextBuffer *buffer = GTK_TEXT_BUFFER (text_tool->buffer);
@@ -538,7 +539,11 @@ gimp_text_tool_editor_get_cursor_rect (GimpTextTool   *text_tool,
 
   gimp_text_layout_get_offsets (text_tool->layout, &offset_x, &offset_y);
 
-  pango_layout_index_to_pos (layout, cursor_index, cursor_rect);
+  if (overwrite)
+    pango_layout_index_to_pos (layout, cursor_index, cursor_rect);
+  else
+    pango_layout_get_cursor_pos (layout, cursor_index, cursor_rect, NULL);
+
   gimp_text_layout_transform_rect (text_tool->layout, cursor_rect);
 
   cursor_rect->x      = PANGO_PIXELS (cursor_rect->x) + offset_x;
@@ -686,17 +691,29 @@ gimp_text_tool_move_cursor (GimpTextTool    *text_tool,
 
           while (count != 0)
             {
-              if (count > 0)
+              gint new_index;
+
+             if (count > 0)
                 {
                   pango_layout_move_cursor_visually (layout, TRUE, index, 0, 1,
-                                                     &index, &trailing);
+                                                     &new_index, &trailing);
                   count--;
+
+                  if (new_index != G_MAXINT)
+                    index = new_index;
+                  else
+                    break;
                 }
               else
                 {
                   pango_layout_move_cursor_visually (layout, TRUE, index, 0, -1,
-                                                     &index, &trailing);
+                                                     &new_index, &trailing);
                   count++;
+
+                  if (new_index != -1)
+                    index = new_index;
+                  else
+                    break;
                 }
             }
 
@@ -1250,7 +1267,9 @@ gimp_text_tool_im_preedit_start (GtkIMContext *context,
   gint              off_x, off_y;
 
   if (text_tool->text)
-    gimp_text_tool_editor_get_cursor_rect (text_tool, &cursor_rect);
+    gimp_text_tool_editor_get_cursor_rect (text_tool,
+                                           text_tool->overwrite_mode,
+                                           &cursor_rect);
 
   g_object_get (text_tool, "x1", &off_x, "y1", &off_y, NULL);
 
diff --git a/app/tools/gimptexttool-editor.h b/app/tools/gimptexttool-editor.h
index 16ec291..ded830c 100644
--- a/app/tools/gimptexttool-editor.h
+++ b/app/tools/gimptexttool-editor.h
@@ -47,6 +47,7 @@ gboolean   gimp_text_tool_editor_key_release     (GimpTextTool        *text_tool
 void       gimp_text_tool_reset_im_context       (GimpTextTool        *text_tool);
 
 void       gimp_text_tool_editor_get_cursor_rect (GimpTextTool        *text_tool,
+                                                  gboolean             overwrite,
                                                   PangoRectangle      *cursor_rect);
 
 
diff --git a/app/tools/gimptexttool.c b/app/tools/gimptexttool.c
index b377126..1d36e0a 100644
--- a/app/tools/gimptexttool.c
+++ b/app/tools/gimptexttool.c
@@ -806,13 +806,15 @@ gimp_text_tool_draw (GimpDrawTool *draw_tool)
       gint           off_x, off_y;
       gboolean       overwrite;
 
-      gimp_text_tool_editor_get_cursor_rect (text_tool, &cursor_rect);
+      gimp_text_tool_editor_get_cursor_rect (text_tool,
+                                             text_tool->overwrite_mode,
+                                             &cursor_rect);
 
       gimp_item_get_offset (GIMP_ITEM (text_tool->layer), &off_x, &off_y);
       cursor_rect.x += off_x;
       cursor_rect.y += off_y;
 
-      overwrite = text_tool->overwrite_mode && cursor_rect.width > 0;
+      overwrite = text_tool->overwrite_mode && cursor_rect.width != 0;
 
       gimp_draw_tool_add_text_cursor (draw_tool, &cursor_rect, overwrite);
     }



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