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.
This commit is contained in:
Michael Natterer 2010-02-21 14:33:33 +01:00
parent e5e6638c32
commit 41a277f040
1 changed files with 46 additions and 4 deletions

View File

@ -38,6 +38,7 @@
#include "core/gimplayer-floating-sel.h"
#include "core/gimpmarshal.h"
#include "core/gimptoolinfo.h"
#include "core/gimpunit.h"
#include "text/gimptext.h"
#include "text/gimptext-vectors.h"
@ -865,6 +866,27 @@ gimp_text_tool_frame_item (GimpTextTool *text_tool)
text_tool->handle_rectangle_change_complete = TRUE;
}
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 gboolean
gimp_text_tool_rectangle_change_complete (GimpRectangleTool *rect_tool)
{
@ -900,10 +922,20 @@ gimp_text_tool_rectangle_change_complete (GimpRectangleTool *rect_tool)
(x2 - x1) != gimp_item_get_width (item) ||
(y2 - y1) != gimp_item_get_height (item))
{
gdouble xres, yres;
gimp_image_get_resolution (text_tool->image, &xres, &yres);
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_image_undo_group_start (text_tool->image, GIMP_UNDO_GROUP_TEXT,
@ -1312,10 +1344,20 @@ gimp_text_tool_create_layer (GimpTextTool *text_tool,
if (text_tool->text_box_fixed)
{
gdouble xres, yres;
gimp_image_get_resolution (image, &xres, &yres);
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);
}
else