[gimp/gimp-2-6] Bug 565001 - Text-Tool crashes when edit a 2.4.2 version xcf



commit ded453fc885bd58e2d2f2d2c15eb14d27d7bc338
Author: Michael Natterer <mitch gimp org>
Date:   Sun Feb 21 14:31:15 2010 +0100

    Bug 565001 - Text-Tool crashes when edit a 2.4.2 version xcf
    
    Convert the rectangle size from pixels to units before setting it as
    box-width and box-height on the text object.

 app/tools/gimptexttool.c |   49 ++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 45 insertions(+), 4 deletions(-)
---
diff --git a/app/tools/gimptexttool.c b/app/tools/gimptexttool.c
index 40145e8..e5716bd 100644
--- a/app/tools/gimptexttool.c
+++ b/app/tools/gimptexttool.c
@@ -42,6 +42,7 @@
 #include "core/gimplist.h"
 #include "core/gimptoolinfo.h"
 #include "core/gimpundostack.h"
+#include "core/gimpunit.h"
 
 #include "text/gimptext.h"
 #include "text/gimptext-vectors.h"
@@ -838,6 +839,27 @@ gimp_text_tool_create_vectors_warped (GimpTextTool *text_tool)
   gimp_image_flush (text_tool->image);
 }
 
+static gdouble
+pixels_to_units (Gimp    *gimp,
+                 gdouble  pixels,
+                 GimpUnit unit,
+                 gdouble  resolution)
+{
+  gdouble factor;
+
+  switch (unit)
+    {
+    case GIMP_UNIT_PIXEL:
+      return pixels;
+
+    default:
+      factor = _gimp_unit_get_factor (gimp, unit);
+
+      return pixels * factor / resolution;
+      break;
+    }
+}
+
 static void
 gimp_text_tool_create_layer (GimpTextTool *text_tool,
                              GimpText     *text)
@@ -901,6 +923,9 @@ gimp_text_tool_create_layer (GimpTextTool *text_tool,
       GimpRectangleTool *rect_tool = GIMP_RECTANGLE_TOOL (text_tool);
       GimpItem          *item      = GIMP_ITEM (layer);
       gint               x1, y1, x2, y2;
+      gdouble            xres, yres;
+
+      gimp_image_get_resolution (text_tool->image, &xres, &yres);
 
       g_object_get (rect_tool,
                     "x1", &x1,
@@ -910,8 +935,14 @@ gimp_text_tool_create_layer (GimpTextTool *text_tool,
                     NULL);
       g_object_set (text_tool->proxy,
                     "box-mode",   GIMP_TEXT_BOX_FIXED,
-                    "box-width",  (gdouble) (x2 - x1),
-                    "box-height", (gdouble) (y2 - y1),
+                    "box-width",  pixels_to_units (text_tool->image->gimp,
+                                                   x2 - x1,
+                                                   text_tool->proxy->unit,
+                                                   xres),
+                    "box-height", pixels_to_units (text_tool->image->gimp,
+                                                   y2 - y1,
+                                                   text_tool->proxy->unit,
+                                                   yres),
                     NULL);
       gimp_item_translate (item,
                            x1 - item->offset_x,
@@ -1285,6 +1316,10 @@ gimp_text_tool_rectangle_change_complete (GimpRectangleTool *rect_tool)
 
   if (text_tool->handle_rectangle_change_complete)
     {
+      gdouble xres, yres;
+
+      gimp_image_get_resolution (image, &xres, &yres);
+
       g_object_get (rect_tool,
                     "x1", &x1,
                     "y1", &y1,
@@ -1307,8 +1342,14 @@ gimp_text_tool_rectangle_change_complete (GimpRectangleTool *rect_tool)
 
       g_object_set (text_tool->proxy,
                     "box-mode",   GIMP_TEXT_BOX_FIXED,
-                    "box-width",  (gdouble) (x2 - x1),
-                    "box-height", (gdouble) (y2 - y1),
+                    "box-width",  pixels_to_units (image->gimp,
+                                                   x2 - x1,
+                                                   text_tool->proxy->unit,
+                                                   xres),
+                    "box-height", pixels_to_units (image->gimp,
+                                                   y2 - y1,
+                                                   text_tool->proxy->unit,
+                                                   yres),
                     NULL);
 
       gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_TEXT,



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