gimp r27543 - in trunk: . app/text app/tools



Author: neo
Date: Mon Nov  3 23:44:19 2008
New Revision: 27543
URL: http://svn.gnome.org/viewvc/gimp?rev=27543&view=rev

Log:
2008-11-04  Sven Neumann  <sven gimp org>

	* app/text/Makefile.am
	* app/text/gimptext-private.h: removed this header file.

	* app/text/gimptextlayout.[ch]: added getters to access the
	resolution, text and PangoLayout.

	* app/text/gimptextlayout-render.c
	* app/tools/gimptexttool.c: use the new getters instead of 
poking
	into the GimpTextLayout struct.



Removed:
   trunk/app/text/gimptext-private.h
Modified:
   trunk/ChangeLog
   trunk/app/text/Makefile.am
   trunk/app/text/gimptextlayout-render.c
   trunk/app/text/gimptextlayout.c
   trunk/app/text/gimptextlayout.h
   trunk/app/tools/gimptexttool.c

Modified: trunk/app/text/Makefile.am
==============================================================================
--- trunk/app/text/Makefile.am	(original)
+++ trunk/app/text/Makefile.am	Mon Nov  3 23:44:19 2008
@@ -32,7 +32,6 @@
 	gimptext-compat.h		\
 	gimptext-parasite.c		\
 	gimptext-parasite.h		\
-	gimptext-private.h		\
 	gimptext-vectors.c		\
 	gimptext-vectors.h		\
 	gimptext-xlfd.c			\

Modified: trunk/app/text/gimptextlayout-render.c
==============================================================================
--- trunk/app/text/gimptextlayout-render.c	(original)
+++ trunk/app/text/gimptextlayout-render.c	Mon Nov  3 23:44:19 2008
@@ -29,7 +29,6 @@
 #include "base/tile-manager.h"
 
 #include "gimptext.h"
-#include "gimptext-private.h"
 #include "gimptextlayout.h"
 #include "gimptextlayout-render.h"
 
@@ -43,6 +42,7 @@
                          cairo_t        *cr,
                          gboolean        path)
 {
+  PangoLayout    *pango_layout;
   cairo_matrix_t  trafo;
   gint            x, y;
 
@@ -51,26 +51,28 @@
 
   gimp_text_layout_get_offsets (layout, &x, &y);
 
+  pango_layout = gimp_text_layout_get_pango_layout (layout);
+
   /* If the width of the layout is > 0, then the text-box is FIXED
    * and the layout position should be offset if the alignment
    * is centered or right-aligned*/
-  if (pango_layout_get_width (layout->layout) > 0)
+  if (pango_layout_get_width (pango_layout) > 0)
     {
       gint width;
 
-      pango_layout_get_pixel_size (layout->layout, &width, NULL);
+      pango_layout_get_pixel_size (pango_layout, &width, NULL);
 
-      switch (pango_layout_get_alignment (layout->layout))
+      switch (pango_layout_get_alignment (pango_layout))
         {
         case PANGO_ALIGN_LEFT:
           break;
 
         case PANGO_ALIGN_RIGHT:
-          x += PANGO_PIXELS (pango_layout_get_width (layout->layout)) - width;
+          x += PANGO_PIXELS (pango_layout_get_width (pango_layout)) - width;
           break;
 
         case PANGO_ALIGN_CENTER:
-          x += (PANGO_PIXELS (pango_layout_get_width (layout->layout))
+          x += (PANGO_PIXELS (pango_layout_get_width (pango_layout))
                 - width) / 2;
           break;
         }
@@ -82,9 +84,9 @@
   cairo_transform (cr, &trafo);
 
   if (path)
-    pango_cairo_layout_path (cr, layout->layout);
+    pango_cairo_layout_path (cr, pango_layout);
   else
-    pango_cairo_show_layout (cr, layout->layout);
+    pango_cairo_show_layout (cr, pango_layout);
 }
 
 
@@ -92,8 +94,14 @@
 gimp_text_layout_render_trafo (GimpTextLayout *layout,
                                cairo_matrix_t *trafo)
 {
-  GimpText      *text = layout->text;
-  const gdouble  norm = 1.0 / layout->yres * layout->xres;
+  GimpText *text = gimp_text_layout_get_text (layout);
+  gdouble   xres;
+  gdouble   yres;
+  gdouble   norm;
+
+  gimp_text_layout_get_resolution (layout, &xres, &yres);
+
+  norm = 1.0 / yres * xres;
 
   trafo->xx = text->transformation.coeff[0][0] * norm;
   trafo->xy = text->transformation.coeff[0][1] * 1.0;

Modified: trunk/app/text/gimptextlayout.c
==============================================================================
--- trunk/app/text/gimptextlayout.c	(original)
+++ trunk/app/text/gimptextlayout.c	Mon Nov  3 23:44:19 2008
@@ -32,10 +32,21 @@
 #include "core/gimpunit.h"
 
 #include "gimptext.h"
-#include "gimptext-private.h"
 #include "gimptextlayout.h"
 
 
+struct _GimpTextLayout
+{
+  GObject         object;
+
+  GimpText       *text;
+  gdouble         xres;
+  gdouble         yres;
+  PangoLayout    *layout;
+  PangoRectangle  extents;
+};
+
+
 static void           gimp_text_layout_finalize   (GObject        *object);
 
 static void           gimp_text_layout_position   (GimpTextLayout *layout);
@@ -228,6 +239,7 @@
 
   if (width)
     *width = layout->extents.width;
+
   if (height)
     *height = layout->extents.height;
 
@@ -243,10 +255,41 @@
 
   if (x)
     *x = layout->extents.x;
+
   if (y)
     *y = layout->extents.y;
 }
 
+void
+gimp_text_layout_get_resolution (GimpTextLayout *layout,
+                                 gdouble        *xres,
+                                 gdouble        *yres)
+{
+  g_return_if_fail (GIMP_IS_TEXT_LAYOUT (layout));
+
+  if (xres)
+    *xres = layout->xres;
+
+  if (yres)
+    *yres = layout->yres;
+}
+
+GimpText *
+gimp_text_layout_get_text (GimpTextLayout *layout)
+{
+  g_return_val_if_fail (GIMP_IS_TEXT_LAYOUT (layout), NULL);
+
+  return layout->text;
+}
+
+PangoLayout *
+gimp_text_layout_get_pango_layout (GimpTextLayout *layout)
+{
+  g_return_val_if_fail (GIMP_IS_TEXT_LAYOUT (layout), NULL);
+
+  return layout->layout;
+}
+
 static void
 gimp_text_layout_position (GimpTextLayout *layout)
 {

Modified: trunk/app/text/gimptextlayout.h
==============================================================================
--- trunk/app/text/gimptextlayout.h	(original)
+++ trunk/app/text/gimptextlayout.h	Mon Nov  3 23:44:19 2008
@@ -30,17 +30,28 @@
 
 typedef struct _GimpTextLayoutClass GimpTextLayoutClass;
 
+struct _GimpTextLayoutClass
+{
+  GObjectClass   parent_class;
+};
+
+
+GType            gimp_text_layout_get_type         (void) G_GNUC_CONST;
+
+GimpTextLayout * gimp_text_layout_new              (GimpText       *text,
+                                                    GimpImage      *image);
+gboolean         gimp_text_layout_get_size         (GimpTextLayout *layout,
+                                                    gint           *width,
+                                                    gint           *heigth);
+void             gimp_text_layout_get_offsets      (GimpTextLayout *layout,
+                                                    gint           *x,
+                                                    gint           *y);
+void             gimp_text_layout_get_resolution   (GimpTextLayout *layout,
+                                                    gdouble        *xres,
+                                                    gdouble        *yres);
 
-GType            gimp_text_layout_get_type    (void) G_GNUC_CONST;
-
-GimpTextLayout * gimp_text_layout_new         (GimpText       *text,
-                                               GimpImage      *image);
-gboolean         gimp_text_layout_get_size    (GimpTextLayout *layout,
-                                               gint           *width,
-                                               gint           *heigth);
-void             gimp_text_layout_get_offsets (GimpTextLayout *layout,
-                                               gint           *x,
-                                               gint           *y);
+GimpText       * gimp_text_layout_get_text         (GimpTextLayout *layout);
+PangoLayout    * gimp_text_layout_get_pango_layout (GimpTextLayout *layout);
 
 
 #endif /* __GIMP_TEXT_LAYOUT_H__ */

Modified: trunk/app/tools/gimptexttool.c
==============================================================================
--- trunk/app/tools/gimptexttool.c	(original)
+++ trunk/app/tools/gimptexttool.c	Mon Nov  3 23:44:19 2008
@@ -44,7 +44,6 @@
 #include "text/gimptextlayer.h"
 #include "text/gimptextlayout.h"
 #include "text/gimptextundo.h"
-#include "text/gimptext-private.h"
 
 #include "vectors/gimpvectors-warp.h"
 
@@ -794,18 +793,21 @@
     case GDK_Down:
     case GDK_KP_Down:
       {
-        gint             line;
-        gint             line_index;
-        gint             trailing;
+        PangoLayout     *layout;
         PangoLayoutLine *layout_line;
         PangoLayoutIter *layout_iter;
         PangoRectangle   logical;
+        gint             line;
+        gint             line_index;
+        gint             trailing;
         gint             i;
 
+        layout = gimp_text_layout_get_pango_layout (text_tool->layout);
+
         line       = gtk_text_iter_get_line (&selection);
         line_index = gtk_text_iter_get_line_index (&selection);
 
-        layout_iter = pango_layout_get_iter (text_tool->layout->layout);
+        layout_iter = pango_layout_get_iter (layout);
         for (i = 0; i < line; i++)
           pango_layout_iter_next_line (layout_iter);
 
@@ -844,8 +846,7 @@
             line++;
           }
 
-        layout_line = pango_layout_get_line_readonly (text_tool->layout->layout,
-                                                      line);
+        layout_line = pango_layout_get_line_readonly (layout, line);
 
         if (! layout_line)
           {
@@ -865,7 +866,7 @@
             break;
           }
 
-        layout_iter = pango_layout_get_iter (text_tool->layout->layout);
+        layout_iter = pango_layout_get_iter (layout);
         for (i = 0; i < line; i++)
           pango_layout_iter_next_line (layout_iter);
 
@@ -1032,6 +1033,7 @@
   gint            y1, y2;
   gint            logical_off_x = 0;
   gint            logical_off_y = 0;
+  PangoLayout    *layout;
   PangoRectangle  ink_extents;
   PangoRectangle  logical_extents;
   GtkTextIter     start;
@@ -1064,8 +1066,9 @@
   cliprect.height = y2 - y1;
   gimp_draw_tool_set_clip_rect (draw_tool, &cliprect, FALSE);
 
-  pango_layout_get_pixel_extents (text_tool->layout->layout,
-                                  &ink_extents, &logical_extents);
+  layout = gimp_text_layout_get_pango_layout (text_tool->layout);
+
+  pango_layout_get_pixel_extents (layout, &ink_extents, &logical_extents);
 
   if (ink_extents.x < 0)
     logical_off_x = -ink_extents.x;
@@ -1099,7 +1102,7 @@
 
       g_free (string);
 
-      pango_layout_index_to_pos (text_tool->layout->layout, cursorx, &crect);
+      pango_layout_index_to_pos (layout, cursorx, &crect);
 
       crect.x      = PANGO_PIXELS (crect.x) + logical_off_x;
       crect.y      = PANGO_PIXELS (crect.y) + logical_off_y;
@@ -1148,7 +1151,7 @@
 
   max = min + text_tool->preedit_len;
 
-  layout = text_tool->layout->layout;
+  layout = gimp_text_layout_get_pango_layout (text_tool->layout);
   line_iter = pango_layout_get_iter (layout);
   i = 0;
 
@@ -1243,7 +1246,7 @@
   max = strlen (string);
   g_free (string);
 
-  layout = text_tool->layout->layout;
+  layout = gimp_text_layout_get_pango_layout (text_tool->layout);
   line_iter = pango_layout_get_iter (layout);
   i = 0;
 
@@ -2229,15 +2232,16 @@
                              gdouble       x,
                              gdouble       y)
 {
-  PangoRectangle  ink_extents;
   GtkTextIter     start, end;
+  PangoLayout    *layout;
+  PangoRectangle  ink_extents;
   gchar          *string;
   gint            offset;
   gint            trailing;
 
   /*  adjust to offset of logical rect  */
-  pango_layout_get_pixel_extents (text_tool->layout->layout,
-                                  &ink_extents, NULL);
+  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;
@@ -2249,7 +2253,7 @@
   string = gtk_text_buffer_get_text (text_tool->text_buffer,
                                      &start, &end, TRUE);
 
-  pango_layout_xy_to_index (text_tool->layout->layout,
+  pango_layout_xy_to_index (layout,
                             x * PANGO_SCALE,
                             y * PANGO_SCALE,
                             &offset, &trailing);



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