[gimp] app: use gimp_text_layout_get_offsets()



commit 2934095816dae2f8a151d6eece3aa36c3accfef7
Author: Michael Natterer <mitch gimp org>
Date:   Sun Mar 7 00:11:05 2010 +0100

    app: use gimp_text_layout_get_offsets()
    
    instead of duplicating GimpTextLayout's positioning logic in two
    different incomplete ways. Also gets rid of the unrelated offset
    return values of gimp_text_tool_editor_get_cursor_rect().

 app/tools/gimptexttool-editor.c |   68 ++++++++++++++------------------------
 app/tools/gimptexttool-editor.h |    4 +--
 app/tools/gimptexttool.c        |   37 ++++++++++-----------
 3 files changed, 43 insertions(+), 66 deletions(-)
---
diff --git a/app/tools/gimptexttool-editor.c b/app/tools/gimptexttool-editor.c
index 59a8cd9..6714d74 100644
--- a/app/tools/gimptexttool-editor.c
+++ b/app/tools/gimptexttool-editor.c
@@ -506,47 +506,34 @@ gimp_text_tool_reset_im_context (GimpTextTool *text_tool)
 
 void
 gimp_text_tool_editor_get_cursor_rect (GimpTextTool   *text_tool,
-                                       PangoRectangle *cursor_rect,
-                                       gint           *logical_off_x,
-                                       gint           *logical_off_y)
+                                       PangoRectangle *cursor_rect)
 {
-  GtkTextBuffer  *buffer = GTK_TEXT_BUFFER (text_tool->buffer);
-  PangoLayout    *layout;
-  PangoRectangle  ink_extents;
-  PangoRectangle  logical_extents;
-  GtkTextIter     cursor;
-  gint            cursor_index;
+  GtkTextBuffer *buffer = GTK_TEXT_BUFFER (text_tool->buffer);
+  PangoLayout   *layout;
+  gint           offset_x;
+  gint           offset_y;
+  GtkTextIter    cursor;
+  gint           cursor_index;
 
   g_return_if_fail (GIMP_IS_TEXT_TOOL (text_tool));
   g_return_if_fail (cursor_rect != NULL);
 
-  gimp_text_tool_ensure_layout (text_tool);
-
-  layout = gimp_text_layout_get_pango_layout (text_tool->layout);
-
-  pango_layout_get_pixel_extents (layout, &ink_extents, &logical_extents);
-  gimp_text_layout_transform_rect (text_tool->layout, &logical_extents);
-
-  if (ink_extents.x < 0)
-    *logical_off_x = -ink_extents.x;
-  else
-    *logical_off_x = 0;
-
-  if (ink_extents.y < 0)
-    *logical_off_y = -ink_extents.y;
-  else
-    *logical_off_y = 0;
-
   gtk_text_buffer_get_iter_at_mark (buffer, &cursor,
                                     gtk_text_buffer_get_insert (buffer));
   cursor_index = gimp_text_buffer_get_iter_index (text_tool->buffer, &cursor,
                                                   TRUE);
 
+  gimp_text_tool_ensure_layout (text_tool);
+
+  layout = gimp_text_layout_get_pango_layout (text_tool->layout);
+
+  gimp_text_layout_get_offsets (text_tool->layout, &offset_x, &offset_y);
+
   pango_layout_index_to_pos (layout, cursor_index, cursor_rect);
   gimp_text_layout_transform_rect (text_tool->layout, cursor_rect);
 
-  cursor_rect->x      = PANGO_PIXELS (cursor_rect->x) + *logical_off_x;
-  cursor_rect->y      = PANGO_PIXELS (cursor_rect->y) + *logical_off_y;
+  cursor_rect->x      = PANGO_PIXELS (cursor_rect->x) + offset_x;
+  cursor_rect->y      = PANGO_PIXELS (cursor_rect->y) + offset_y;
   cursor_rect->width  = PANGO_PIXELS (cursor_rect->width);
   cursor_rect->height = PANGO_PIXELS (cursor_rect->height);
 }
@@ -1161,24 +1148,21 @@ gimp_text_tool_xy_to_iter (GimpTextTool *text_tool,
                            gdouble       y,
                            GtkTextIter  *iter)
 {
-  PangoLayout    *layout;
-  PangoRectangle  ink_extents;
-  gint            index;
-  gint            trailing;
+  PangoLayout *layout;
+  gint         offset_x;
+  gint         offset_y;
+  gint         index;
+  gint         trailing;
 
   gimp_text_tool_ensure_layout (text_tool);
 
   gimp_text_layout_untransform_point (text_tool->layout, &x, &y);
 
-  /*  adjust to offset of logical rect  */
-  layout = gimp_text_layout_get_pango_layout (text_tool->layout);
-  pango_layout_get_pixel_extents (layout, &ink_extents, NULL);
-
-  if (ink_extents.x < 0)
-    x += ink_extents.x;
+  gimp_text_layout_get_offsets (text_tool->layout, &offset_x, &offset_y);
+  x -= offset_x;
+  y -= offset_y;
 
-  if (ink_extents.y < 0)
-    y += ink_extents.y;
+  layout = gimp_text_layout_get_pango_layout (text_tool->layout);
 
   pango_layout_xy_to_index (layout,
                             x * PANGO_SCALE,
@@ -1209,12 +1193,10 @@ gimp_text_tool_im_preedit_start (GtkIMContext *context,
   GtkWidget        *frame;
   GtkWidget        *ebox;
   PangoRectangle    cursor_rect = { 0, };
-  gint              unused1, unused2;
   gint              off_x, off_y;
 
   if (text_tool->text)
-    gimp_text_tool_editor_get_cursor_rect (text_tool, &cursor_rect,
-                                           &unused1, &unused2);
+    gimp_text_tool_editor_get_cursor_rect (text_tool, &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 59d4992..16ec291 100644
--- a/app/tools/gimptexttool-editor.h
+++ b/app/tools/gimptexttool-editor.h
@@ -47,9 +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,
-                                                  PangoRectangle      *cursor_rect,
-                                                  gint                *logical_off_x,
-                                                  gint                *logical_off_y);
+                                                  PangoRectangle      *cursor_rect);
 
 
 #endif /* __GIMP_TEXT_TOOL_EDITOR_H__ */
diff --git a/app/tools/gimptexttool.c b/app/tools/gimptexttool.c
index 5fddfe8..a48b710 100644
--- a/app/tools/gimptexttool.c
+++ b/app/tools/gimptexttool.c
@@ -122,9 +122,7 @@ static GimpUIManager * gimp_text_tool_get_popup (GimpTool          *tool,
                                                  const gchar      **ui_path);
 
 static void      gimp_text_tool_draw            (GimpDrawTool      *draw_tool);
-static void      gimp_text_tool_draw_selection  (GimpDrawTool      *draw_tool,
-                                                 gint               logical_off_x,
-                                                 gint               logical_off_y);
+static void      gimp_text_tool_draw_selection  (GimpDrawTool      *draw_tool);
 
 static void      gimp_text_tool_frame_item      (GimpTextTool      *text_tool);
 
@@ -729,11 +727,7 @@ gimp_text_tool_get_popup (GimpTool         *tool,
 static void
 gimp_text_tool_draw (GimpDrawTool *draw_tool)
 {
-  GimpTextTool   *text_tool = GIMP_TEXT_TOOL (draw_tool);
-  GtkTextBuffer  *buffer    = GTK_TEXT_BUFFER (text_tool->buffer);
-  PangoRectangle  cursor_rect;
-  gint            logical_offset_x;
-  gint            logical_offset_y;
+  GimpTextTool *text_tool = GIMP_TEXT_TOOL (draw_tool);
 
   g_object_set (text_tool,
                 "narrow-mode", TRUE,
@@ -746,21 +740,22 @@ gimp_text_tool_draw (GimpDrawTool *draw_tool)
       ! text_tool->layer->text)
     return;
 
-  gimp_text_tool_editor_get_cursor_rect (text_tool, &cursor_rect,
-                                         &logical_offset_x, &logical_offset_y);
-
-  if (gtk_text_buffer_get_has_selection (buffer))
+  if (gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (text_tool->buffer)))
     {
       /* If the text buffer has a selection, highlight the selected letters */
 
-      gimp_text_tool_draw_selection (draw_tool,
-                                     logical_offset_x, logical_offset_y);
+      gimp_text_tool_draw_selection (draw_tool);
     }
   else
     {
       /* If the text buffer has no selection, draw the text cursor */
 
-      gboolean overwrite = text_tool->overwrite_mode && cursor_rect.width > 0;
+      PangoRectangle cursor_rect;
+      gboolean       overwrite;
+
+      gimp_text_tool_editor_get_cursor_rect (text_tool, &cursor_rect);
+
+      overwrite = text_tool->overwrite_mode && cursor_rect.width > 0;
 
       gimp_draw_tool_draw_text_cursor (draw_tool,
                                        cursor_rect.x,
@@ -775,13 +770,13 @@ gimp_text_tool_draw (GimpDrawTool *draw_tool)
 }
 
 static void
-gimp_text_tool_draw_selection (GimpDrawTool *draw_tool,
-                               gint          logical_off_x,
-                               gint          logical_off_y)
+gimp_text_tool_draw_selection (GimpDrawTool *draw_tool)
 {
   GimpTextTool    *text_tool = GIMP_TEXT_TOOL (draw_tool);
   GtkTextBuffer   *buffer    = GTK_TEXT_BUFFER (text_tool->buffer);
   PangoLayout     *layout;
+  gint             offset_x;
+  gint             offset_y;
   PangoLayoutIter *iter;
   GtkTextIter      sel_start, sel_end;
   gint             min, max;
@@ -794,6 +789,8 @@ gimp_text_tool_draw_selection (GimpDrawTool *draw_tool,
 
   layout = gimp_text_layout_get_pango_layout (text_tool->layout);
 
+  gimp_text_layout_get_offsets (text_tool->layout, &offset_x, &offset_y);
+
   iter = pango_layout_get_iter (layout);
 
   do
@@ -818,8 +815,8 @@ gimp_text_tool_draw_selection (GimpDrawTool *draw_tool,
 
           gimp_text_layout_transform_rect (text_tool->layout, &rect);
 
-          rect.x += logical_off_x;
-          rect.y += logical_off_y;
+          rect.x += offset_x;
+          rect.y += offset_y;
 
           gimp_draw_tool_draw_rectangle (draw_tool, TRUE,
                                          rect.x, rect.y,



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