Bug 635040 - Edit -> Stroke Path performs no action on an incomplete path

Add error reporting to gimp_drawable_stroke_vectors() and produce the
same warning as the paint core when trying to stroke a path with zero
or one points only.
This commit is contained in:
Michael Natterer
2010-11-25 11:31:40 +01:00
parent 77a5999f13
commit d46b53f63d
4 changed files with 84 additions and 59 deletions

View File

@ -39,6 +39,7 @@
#include "gimpchannel.h" #include "gimpchannel.h"
#include "gimpcontext.h" #include "gimpcontext.h"
#include "gimpdrawable-stroke.h" #include "gimpdrawable-stroke.h"
#include "gimperror.h"
#include "gimpimage.h" #include "gimpimage.h"
#include "gimppattern.h" #include "gimppattern.h"
#include "gimpscanconvert.h" #include "gimpscanconvert.h"
@ -59,7 +60,8 @@ static GimpScanConvert * gimp_drawable_render_boundary (GimpDrawable *dra
gint offset_y); gint offset_y);
static GimpScanConvert * gimp_drawable_render_vectors (GimpDrawable *drawable, static GimpScanConvert * gimp_drawable_render_vectors (GimpDrawable *drawable,
GimpVectors *vectors, GimpVectors *vectors,
gboolean do_stroke); gboolean do_stroke,
GError **error);
static void gimp_drawable_stroke_scan_convert (GimpDrawable *drawable, static void gimp_drawable_stroke_scan_convert (GimpDrawable *drawable,
GimpFillOptions *options, GimpFillOptions *options,
GimpScanConvert *scan_convert, GimpScanConvert *scan_convert,
@ -129,54 +131,68 @@ gimp_drawable_stroke_boundary (GimpDrawable *drawable,
} }
} }
void gboolean
gimp_drawable_fill_vectors (GimpDrawable *drawable, gimp_drawable_fill_vectors (GimpDrawable *drawable,
GimpFillOptions *options, GimpFillOptions *options,
GimpVectors *vectors, GimpVectors *vectors,
gboolean push_undo) gboolean push_undo,
GError **error)
{ {
GimpScanConvert *scan_convert; GimpScanConvert *scan_convert;
g_return_if_fail (GIMP_IS_DRAWABLE (drawable)); g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable))); g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), FALSE);
g_return_if_fail (GIMP_IS_FILL_OPTIONS (options)); g_return_val_if_fail (GIMP_IS_FILL_OPTIONS (options), FALSE);
g_return_if_fail (GIMP_IS_VECTORS (vectors)); g_return_val_if_fail (GIMP_IS_VECTORS (vectors), FALSE);
g_return_if_fail (options->style != GIMP_FILL_STYLE_PATTERN || g_return_val_if_fail (options->style != GIMP_FILL_STYLE_PATTERN ||
gimp_context_get_pattern (GIMP_CONTEXT (options)) != NULL); gimp_context_get_pattern (GIMP_CONTEXT (options)) != NULL,
FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
scan_convert = gimp_drawable_render_vectors (drawable, vectors, FALSE); scan_convert = gimp_drawable_render_vectors (drawable, vectors, FALSE, error);
if (scan_convert) if (scan_convert)
{ {
gimp_drawable_stroke_scan_convert (drawable, options, gimp_drawable_stroke_scan_convert (drawable, options,
scan_convert, FALSE, push_undo); scan_convert, FALSE, push_undo);
gimp_scan_convert_free (scan_convert); gimp_scan_convert_free (scan_convert);
return TRUE;
} }
return FALSE;
} }
void gboolean
gimp_drawable_stroke_vectors (GimpDrawable *drawable, gimp_drawable_stroke_vectors (GimpDrawable *drawable,
GimpStrokeOptions *options, GimpStrokeOptions *options,
GimpVectors *vectors, GimpVectors *vectors,
gboolean push_undo) gboolean push_undo,
GError **error)
{ {
GimpScanConvert *scan_convert; GimpScanConvert *scan_convert;
g_return_if_fail (GIMP_IS_DRAWABLE (drawable)); g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable))); g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), FALSE);
g_return_if_fail (GIMP_IS_STROKE_OPTIONS (options)); g_return_val_if_fail (GIMP_IS_STROKE_OPTIONS (options), FALSE);
g_return_if_fail (GIMP_IS_VECTORS (vectors)); g_return_val_if_fail (GIMP_IS_VECTORS (vectors), FALSE);
g_return_if_fail (GIMP_FILL_OPTIONS (options)->style != GIMP_FILL_STYLE_PATTERN || g_return_val_if_fail (GIMP_FILL_OPTIONS (options)->style != GIMP_FILL_STYLE_PATTERN ||
gimp_context_get_pattern (GIMP_CONTEXT (options)) != NULL); gimp_context_get_pattern (GIMP_CONTEXT (options)) != NULL,
FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
scan_convert = gimp_drawable_render_vectors (drawable, vectors, TRUE); scan_convert = gimp_drawable_render_vectors (drawable, vectors, TRUE, error);
if (scan_convert) if (scan_convert)
{ {
gimp_drawable_stroke_scan_convert (drawable, GIMP_FILL_OPTIONS (options), gimp_drawable_stroke_scan_convert (drawable, GIMP_FILL_OPTIONS (options),
scan_convert, TRUE, push_undo); scan_convert, TRUE, push_undo);
gimp_scan_convert_free (scan_convert); gimp_scan_convert_free (scan_convert);
return TRUE;
} }
return FALSE;
} }
@ -254,9 +270,10 @@ gimp_drawable_render_boundary (GimpDrawable *drawable,
} }
static GimpScanConvert * static GimpScanConvert *
gimp_drawable_render_vectors (GimpDrawable *drawable, gimp_drawable_render_vectors (GimpDrawable *drawable,
GimpVectors *vectors, GimpVectors *vectors,
gboolean do_stroke) gboolean do_stroke,
GError **error)
{ {
GimpScanConvert *scan_convert; GimpScanConvert *scan_convert;
GimpStroke *stroke; GimpStroke *stroke;
@ -306,6 +323,9 @@ gimp_drawable_render_vectors (GimpDrawable *drawable,
gimp_scan_convert_free (scan_convert); gimp_scan_convert_free (scan_convert);
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
_("Not enough points to stroke"));
return NULL; return NULL;
} }

View File

@ -22,29 +22,31 @@
#define __GIMP_DRAWABLE_STROKE_H__ #define __GIMP_DRAWABLE_STROKE_H__
void gimp_drawable_fill_boundary (GimpDrawable *drawable, void gimp_drawable_fill_boundary (GimpDrawable *drawable,
GimpFillOptions *options, GimpFillOptions *options,
const BoundSeg *bound_segs, const BoundSeg *bound_segs,
gint n_bound_segs, gint n_bound_segs,
gint offset_x, gint offset_x,
gint offset_y, gint offset_y,
gboolean push_undo); gboolean push_undo);
void gimp_drawable_stroke_boundary (GimpDrawable *drawable, void gimp_drawable_stroke_boundary (GimpDrawable *drawable,
GimpStrokeOptions *options, GimpStrokeOptions *options,
const BoundSeg *bound_segs, const BoundSeg *bound_segs,
gint n_bound_segs, gint n_bound_segs,
gint offset_x, gint offset_x,
gint offset_y, gint offset_y,
gboolean push_undo); gboolean push_undo);
void gimp_drawable_fill_vectors (GimpDrawable *drawable, gboolean gimp_drawable_fill_vectors (GimpDrawable *drawable,
GimpFillOptions *options, GimpFillOptions *options,
GimpVectors *vectors, GimpVectors *vectors,
gboolean push_undo); gboolean push_undo,
void gimp_drawable_stroke_vectors (GimpDrawable *drawable, GError **error);
GimpStrokeOptions *options, gboolean gimp_drawable_stroke_vectors (GimpDrawable *drawable,
GimpVectors *vectors, GimpStrokeOptions *options,
gboolean push_undo); GimpVectors *vectors,
gboolean push_undo,
GError **error);
#endif /* __GIMP_DRAWABLE_STROKE_H__ */ #endif /* __GIMP_DRAWABLE_STROKE_H__ */

View File

@ -1165,7 +1165,7 @@ gimp_rectangle_tool_motion (GimpTool *tool,
aspect_text = g_strdup_printf (" (%.2f:1)", w / (gdouble) h); aspect_text = g_strdup_printf (" (%.2f:1)", w / (gdouble) h);
gimp_tool_push_status_coords (tool, display, gimp_tool_push_status_coords (tool, display,
GIMP_CURSOR_PRECISION_PIXEL_BORDER, gimp_tool_control_get_precision (tool->control),
_("Rectangle: "), _("Rectangle: "),
w, " × ", h, aspect_text); w, " × ", h, aspect_text);
g_free (aspect_text); g_free (aspect_text);
@ -2161,7 +2161,7 @@ gimp_rectangle_tool_start (GimpRectangleTool *rect_tool,
/* initialize the statusbar display */ /* initialize the statusbar display */
gimp_tool_push_status_coords (tool, tool->display, gimp_tool_push_status_coords (tool, tool->display,
GIMP_CURSOR_PRECISION_PIXEL_BORDER, gimp_tool_control_get_precision (tool->control),
_("Rectangle: "), 0, " × ", 0, NULL); _("Rectangle: "), 0, " × ", 0, NULL);
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), tool->display); gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), tool->display);

View File

@ -29,11 +29,12 @@
#include "vectors-types.h" #include "vectors-types.h"
#include "core/gimp.h" #include "core/gimp.h"
#include "core/gimp-transform-utils.h"
#include "core/gimpchannel-select.h" #include "core/gimpchannel-select.h"
#include "core/gimpcontainer.h" #include "core/gimpcontainer.h"
#include "core/gimpcontext.h" #include "core/gimpcontext.h"
#include "core/gimpdrawable-stroke.h" #include "core/gimpdrawable-stroke.h"
#include "core/gimp-transform-utils.h" #include "core/gimperror.h"
#include "core/gimpimage.h" #include "core/gimpimage.h"
#include "core/gimpimage-undo-push.h" #include "core/gimpimage-undo-push.h"
#include "core/gimpmarshal.h" #include "core/gimpmarshal.h"
@ -550,17 +551,19 @@ gimp_vectors_stroke (GimpItem *item,
GimpVectors *vectors = GIMP_VECTORS (item); GimpVectors *vectors = GIMP_VECTORS (item);
gboolean retval = FALSE; gboolean retval = FALSE;
/* return successfully on an empty path, there's nothing to stroke */
if (! vectors->strokes) if (! vectors->strokes)
return TRUE; {
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
_("Not enough points to stroke"));
return FALSE;
}
switch (stroke_options->method) switch (stroke_options->method)
{ {
case GIMP_STROKE_METHOD_LIBART: case GIMP_STROKE_METHOD_LIBART:
gimp_drawable_stroke_vectors (drawable, retval = gimp_drawable_stroke_vectors (drawable,
stroke_options, stroke_options,
vectors, push_undo); vectors, push_undo, error);
retval = TRUE;
break; break;
case GIMP_STROKE_METHOD_PAINT_CORE: case GIMP_STROKE_METHOD_PAINT_CORE: