/gimp-2.8.0/app/pdb/vectors-cmds.c
# · C · 2466 lines · 2125 code · 244 blank · 97 comment · 90 complexity · 905b72111582827acab55c4f26acba56 MD5 · raw file
Large files are truncated click here to view the full file
- /* GIMP - The GNU Image Manipulation Program
- * Copyright (C) 1995-2003 Spencer Kimball and Peter Mattis
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /* NOTE: This file is auto-generated by pdbgen.pl. */
- #include "config.h"
- #include <string.h>
- #include <gegl.h>
- #include "pdb-types.h"
- #include "core/gimpimage-undo-push.h"
- #include "core/gimpimage.h"
- #include "core/gimplayer.h"
- #include "core/gimplist.h"
- #include "core/gimpparamspecs.h"
- #include "text/gimptext-vectors.h"
- #include "text/gimptextlayer.h"
- #include "vectors/gimpanchor.h"
- #include "vectors/gimpbezierstroke.h"
- #include "vectors/gimpstroke-new.h"
- #include "vectors/gimpvectors-export.h"
- #include "vectors/gimpvectors-import.h"
- #include "vectors/gimpvectors.h"
- #include "gimppdb.h"
- #include "gimppdb-utils.h"
- #include "gimpprocedure.h"
- #include "internal-procs.h"
- #include "gimp-intl.h"
- static GValueArray *
- vectors_new_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GValueArray *args,
- GError **error)
- {
- gboolean success = TRUE;
- GValueArray *return_vals;
- GimpImage *image;
- const gchar *name;
- GimpVectors *vectors = NULL;
- image = gimp_value_get_image (&args->values[0], gimp);
- name = g_value_get_string (&args->values[1]);
- if (success)
- {
- vectors = gimp_vectors_new (image, name);
- }
- return_vals = gimp_procedure_get_return_values (procedure, success,
- error ? *error : NULL);
- if (success)
- gimp_value_set_vectors (&return_vals->values[1], vectors);
- return return_vals;
- }
- static GValueArray *
- vectors_new_from_text_layer_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GValueArray *args,
- GError **error)
- {
- gboolean success = TRUE;
- GValueArray *return_vals;
- GimpImage *image;
- GimpLayer *layer;
- GimpVectors *vectors = NULL;
- image = gimp_value_get_image (&args->values[0], gimp);
- layer = gimp_value_get_layer (&args->values[1], gimp);
- if (success)
- {
- if (gimp_pdb_layer_is_text_layer (layer, FALSE, error))
- {
- gint x, y;
- vectors = gimp_text_vectors_new (image,
- gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer)));
- gimp_item_get_offset (GIMP_ITEM (layer), &x, &y);
- gimp_item_translate (GIMP_ITEM (vectors), x, y, FALSE);
- }
- else
- {
- success = FALSE;
- }
- }
- return_vals = gimp_procedure_get_return_values (procedure, success,
- error ? *error : NULL);
- if (success)
- gimp_value_set_vectors (&return_vals->values[1], vectors);
- return return_vals;
- }
- static GValueArray *
- vectors_copy_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GValueArray *args,
- GError **error)
- {
- gboolean success = TRUE;
- GValueArray *return_vals;
- GimpVectors *vectors;
- GimpVectors *vectors_copy = NULL;
- vectors = gimp_value_get_vectors (&args->values[0], gimp);
- if (success)
- {
- vectors_copy = GIMP_VECTORS (gimp_item_duplicate (GIMP_ITEM (vectors),
- G_TYPE_FROM_INSTANCE (vectors)));
- if (! vectors_copy)
- success = FALSE;
- }
- return_vals = gimp_procedure_get_return_values (procedure, success,
- error ? *error : NULL);
- if (success)
- gimp_value_set_vectors (&return_vals->values[1], vectors_copy);
- return return_vals;
- }
- static GValueArray *
- vectors_get_strokes_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GValueArray *args,
- GError **error)
- {
- gboolean success = TRUE;
- GValueArray *return_vals;
- GimpVectors *vectors;
- gint32 num_strokes = 0;
- gint32 *stroke_ids = NULL;
- vectors = gimp_value_get_vectors (&args->values[0], gimp);
- if (success)
- {
- num_strokes = gimp_vectors_get_n_strokes (vectors);
- if (num_strokes)
- {
- GimpStroke *cur_stroke;
- gint i = 0;
- stroke_ids = g_new (gint32, num_strokes);
- for (cur_stroke = gimp_vectors_stroke_get_next (vectors, NULL);
- cur_stroke;
- cur_stroke = gimp_vectors_stroke_get_next (vectors, cur_stroke))
- {
- stroke_ids[i] = gimp_stroke_get_ID (cur_stroke);
- i++;
- }
- }
- }
- return_vals = gimp_procedure_get_return_values (procedure, success,
- error ? *error : NULL);
- if (success)
- {
- g_value_set_int (&return_vals->values[1], num_strokes);
- gimp_value_take_int32array (&return_vals->values[2], stroke_ids, num_strokes);
- }
- return return_vals;
- }
- static GValueArray *
- vectors_stroke_get_length_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GValueArray *args,
- GError **error)
- {
- gboolean success = TRUE;
- GValueArray *return_vals;
- GimpVectors *vectors;
- gint32 stroke_id;
- gdouble precision;
- gdouble length = 0.0;
- vectors = gimp_value_get_vectors (&args->values[0], gimp);
- stroke_id = g_value_get_int (&args->values[1]);
- precision = g_value_get_double (&args->values[2]);
- if (success)
- {
- GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, FALSE, error);
- if (stroke)
- length = gimp_stroke_get_length (stroke, precision);
- else
- success = FALSE;
- }
- return_vals = gimp_procedure_get_return_values (procedure, success,
- error ? *error : NULL);
- if (success)
- g_value_set_double (&return_vals->values[1], length);
- return return_vals;
- }
- static GValueArray *
- vectors_stroke_get_point_at_dist_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GValueArray *args,
- GError **error)
- {
- gboolean success = TRUE;
- GValueArray *return_vals;
- GimpVectors *vectors;
- gint32 stroke_id;
- gdouble dist;
- gdouble precision;
- gdouble x_point = 0.0;
- gdouble y_point = 0.0;
- gdouble slope = 0.0;
- gboolean valid = FALSE;
- vectors = gimp_value_get_vectors (&args->values[0], gimp);
- stroke_id = g_value_get_int (&args->values[1]);
- dist = g_value_get_double (&args->values[2]);
- precision = g_value_get_double (&args->values[3]);
- if (success)
- {
- GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, FALSE, error);
- if (stroke)
- {
- GimpCoords coord;
- valid = gimp_stroke_get_point_at_dist (stroke, dist, precision,
- &coord, &slope);
- x_point = valid ? coord.x : 0;
- y_point = valid ? coord.y : 0;
- }
- else
- success = FALSE;
- }
- return_vals = gimp_procedure_get_return_values (procedure, success,
- error ? *error : NULL);
- if (success)
- {
- g_value_set_double (&return_vals->values[1], x_point);
- g_value_set_double (&return_vals->values[2], y_point);
- g_value_set_double (&return_vals->values[3], slope);
- g_value_set_boolean (&return_vals->values[4], valid);
- }
- return return_vals;
- }
- static GValueArray *
- vectors_remove_stroke_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GValueArray *args,
- GError **error)
- {
- gboolean success = TRUE;
- GimpVectors *vectors;
- gint32 stroke_id;
- vectors = gimp_value_get_vectors (&args->values[0], gimp);
- stroke_id = g_value_get_int (&args->values[1]);
- if (success)
- {
- GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
- if (stroke)
- {
- if (gimp_item_is_attached (GIMP_ITEM (vectors)))
- gimp_image_undo_push_vectors_mod (gimp_item_get_image (GIMP_ITEM (vectors)),
- _("Remove path stroke"),
- vectors);
- gimp_vectors_stroke_remove (vectors, stroke);
- }
- else
- success = FALSE;
- }
- return gimp_procedure_get_return_values (procedure, success,
- error ? *error : NULL);
- }
- static GValueArray *
- vectors_stroke_close_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GValueArray *args,
- GError **error)
- {
- gboolean success = TRUE;
- GimpVectors *vectors;
- gint32 stroke_id;
- vectors = gimp_value_get_vectors (&args->values[0], gimp);
- stroke_id = g_value_get_int (&args->values[1]);
- if (success)
- {
- GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
- if (stroke)
- {
- if (gimp_item_is_attached (GIMP_ITEM (vectors)))
- gimp_image_undo_push_vectors_mod (gimp_item_get_image (GIMP_ITEM (vectors)),
- _("Close path stroke"),
- vectors);
- gimp_stroke_close (stroke);
- }
- else
- success = FALSE;
- }
- return gimp_procedure_get_return_values (procedure, success,
- error ? *error : NULL);
- }
- static GValueArray *
- vectors_stroke_translate_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GValueArray *args,
- GError **error)
- {
- gboolean success = TRUE;
- GimpVectors *vectors;
- gint32 stroke_id;
- gint32 off_x;
- gint32 off_y;
- vectors = gimp_value_get_vectors (&args->values[0], gimp);
- stroke_id = g_value_get_int (&args->values[1]);
- off_x = g_value_get_int (&args->values[2]);
- off_y = g_value_get_int (&args->values[3]);
- if (success)
- {
- GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
- if (stroke)
- {
- if (gimp_item_is_attached (GIMP_ITEM (vectors)))
- gimp_image_undo_push_vectors_mod (gimp_item_get_image (GIMP_ITEM (vectors)),
- _("Translate path stroke"),
- vectors);
- gimp_stroke_translate (stroke, off_x, off_y);
- }
- else
- success = FALSE;
- }
- return gimp_procedure_get_return_values (procedure, success,
- error ? *error : NULL);
- }
- static GValueArray *
- vectors_stroke_scale_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GValueArray *args,
- GError **error)
- {
- gboolean success = TRUE;
- GimpVectors *vectors;
- gint32 stroke_id;
- gdouble scale_x;
- gdouble scale_y;
- vectors = gimp_value_get_vectors (&args->values[0], gimp);
- stroke_id = g_value_get_int (&args->values[1]);
- scale_x = g_value_get_double (&args->values[2]);
- scale_y = g_value_get_double (&args->values[3]);
- if (success)
- {
- GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
- if (stroke)
- {
- if (gimp_item_is_attached (GIMP_ITEM (vectors)))
- gimp_image_undo_push_vectors_mod (gimp_item_get_image (GIMP_ITEM (vectors)),
- _("Scale path stroke"),
- vectors);
- gimp_stroke_scale (stroke, scale_x, scale_y);
- }
- else
- success = FALSE;
- }
- return gimp_procedure_get_return_values (procedure, success,
- error ? *error : NULL);
- }
- static GValueArray *
- vectors_stroke_rotate_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GValueArray *args,
- GError **error)
- {
- gboolean success = TRUE;
- GimpVectors *vectors;
- gint32 stroke_id;
- gdouble center_x;
- gdouble center_y;
- gdouble angle;
- vectors = gimp_value_get_vectors (&args->values[0], gimp);
- stroke_id = g_value_get_int (&args->values[1]);
- center_x = g_value_get_double (&args->values[2]);
- center_y = g_value_get_double (&args->values[3]);
- angle = g_value_get_double (&args->values[4]);
- if (success)
- {
- GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
- if (stroke)
- {
- if (gimp_item_is_attached (GIMP_ITEM (vectors)))
- gimp_image_undo_push_vectors_mod (gimp_item_get_image (GIMP_ITEM (vectors)),
- _("Rotate path stroke"),
- vectors);
- gimp_stroke_rotate (stroke, center_x, center_y, angle);
- }
- else
- success = FALSE;
- }
- return gimp_procedure_get_return_values (procedure, success,
- error ? *error : NULL);
- }
- static GValueArray *
- vectors_stroke_flip_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GValueArray *args,
- GError **error)
- {
- gboolean success = TRUE;
- GimpVectors *vectors;
- gint32 stroke_id;
- gint32 flip_type;
- gdouble axis;
- vectors = gimp_value_get_vectors (&args->values[0], gimp);
- stroke_id = g_value_get_int (&args->values[1]);
- flip_type = g_value_get_enum (&args->values[2]);
- axis = g_value_get_double (&args->values[3]);
- if (success)
- {
- GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
- if (stroke)
- {
- if (gimp_item_is_attached (GIMP_ITEM (vectors)))
- gimp_image_undo_push_vectors_mod (gimp_item_get_image (GIMP_ITEM (vectors)),
- _("Flip path stroke"),
- vectors);
- gimp_stroke_flip (stroke, flip_type, axis);
- }
- else
- success = FALSE;
- }
- return gimp_procedure_get_return_values (procedure, success,
- error ? *error : NULL);
- }
- static GValueArray *
- vectors_stroke_flip_free_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GValueArray *args,
- GError **error)
- {
- gboolean success = TRUE;
- GimpVectors *vectors;
- gint32 stroke_id;
- gdouble x1;
- gdouble y1;
- gdouble x2;
- gdouble y2;
- vectors = gimp_value_get_vectors (&args->values[0], gimp);
- stroke_id = g_value_get_int (&args->values[1]);
- x1 = g_value_get_double (&args->values[2]);
- y1 = g_value_get_double (&args->values[3]);
- x2 = g_value_get_double (&args->values[4]);
- y2 = g_value_get_double (&args->values[5]);
- if (success)
- {
- GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
- if (stroke)
- {
- if (gimp_item_is_attached (GIMP_ITEM (vectors)))
- gimp_image_undo_push_vectors_mod (gimp_item_get_image (GIMP_ITEM (vectors)),
- _("Flip path stroke"),
- vectors);
- gimp_stroke_flip_free (stroke, x1, y1, x2, y2);
- }
- else
- success = FALSE;
- }
- return gimp_procedure_get_return_values (procedure, success,
- error ? *error : NULL);
- }
- static GValueArray *
- vectors_stroke_get_points_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GValueArray *args,
- GError **error)
- {
- gboolean success = TRUE;
- GValueArray *return_vals;
- GimpVectors *vectors;
- gint32 stroke_id;
- gint32 type = 0;
- gint32 num_points = 0;
- gdouble *controlpoints = NULL;
- gboolean closed = FALSE;
- vectors = gimp_value_get_vectors (&args->values[0], gimp);
- stroke_id = g_value_get_int (&args->values[1]);
- if (success)
- {
- GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, FALSE, error);
- if (GIMP_IS_BEZIER_STROKE (stroke))
- {
- GArray *points_array;
- gint i;
- points_array = gimp_stroke_control_points_get (stroke, &closed);
- if (points_array)
- {
- num_points = points_array->len;
- controlpoints = g_new (gdouble, num_points * 2);
- type = GIMP_VECTORS_STROKE_TYPE_BEZIER;
- for (i = 0; i < num_points; i++)
- {
- controlpoints[2*i] = g_array_index (points_array,
- GimpAnchor, i).position.x;
- controlpoints[2*i+1] = g_array_index (points_array,
- GimpAnchor, i).position.y;
- }
- g_array_free (points_array, TRUE);
- num_points *= 2;
- }
- else
- success = FALSE;
- }
- else
- success = FALSE;
- }
- return_vals = gimp_procedure_get_return_values (procedure, success,
- error ? *error : NULL);
- if (success)
- {
- g_value_set_enum (&return_vals->values[1], type);
- g_value_set_int (&return_vals->values[2], num_points);
- gimp_value_take_floatarray (&return_vals->values[3], controlpoints, num_points);
- g_value_set_boolean (&return_vals->values[4], closed);
- }
- return return_vals;
- }
- static GValueArray *
- vectors_stroke_new_from_points_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GValueArray *args,
- GError **error)
- {
- gboolean success = TRUE;
- GValueArray *return_vals;
- GimpVectors *vectors;
- gint32 type;
- gint32 num_points;
- const gdouble *controlpoints;
- gboolean closed;
- gint32 stroke_id = 0;
- vectors = gimp_value_get_vectors (&args->values[0], gimp);
- type = g_value_get_enum (&args->values[1]);
- num_points = g_value_get_int (&args->values[2]);
- controlpoints = gimp_value_get_floatarray (&args->values[3]);
- closed = g_value_get_boolean (&args->values[4]);
- if (success)
- {
- GimpStroke *stroke;
- GimpCoords *coords;
- GimpCoords default_coords = GIMP_COORDS_DEFAULT_VALUES;
- gint i;
- success = FALSE;
- if (type == GIMP_VECTORS_STROKE_TYPE_BEZIER &&
- num_points % 6 == 0)
- {
- coords = g_new (GimpCoords, num_points/2);
- for (i = 0; i < num_points/2; i++)
- {
- coords[i] = default_coords;
- coords[i].x = controlpoints[i*2];
- coords[i].y = controlpoints[i*2+1];
- }
- stroke = gimp_stroke_new_from_coords (type, coords, num_points/2, closed);
- if (stroke)
- {
- if (gimp_item_is_attached (GIMP_ITEM (vectors)))
- gimp_image_undo_push_vectors_mod (gimp_item_get_image (GIMP_ITEM (vectors)),
- _("Add path stroke"),
- vectors);
- gimp_vectors_stroke_add (vectors, stroke);
- g_object_unref (stroke);
- stroke_id = gimp_stroke_get_ID (stroke);
- success = TRUE;
- }
- g_free (coords);
- }
- }
- return_vals = gimp_procedure_get_return_values (procedure, success,
- error ? *error : NULL);
- if (success)
- g_value_set_int (&return_vals->values[1], stroke_id);
- return return_vals;
- }
- static GValueArray *
- vectors_stroke_interpolate_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GValueArray *args,
- GError **error)
- {
- gboolean success = TRUE;
- GValueArray *return_vals;
- GimpVectors *vectors;
- gint32 stroke_id;
- gdouble precision;
- gint32 num_coords = 0;
- gdouble *coords = NULL;
- gboolean closed = FALSE;
- vectors = gimp_value_get_vectors (&args->values[0], gimp);
- stroke_id = g_value_get_int (&args->values[1]);
- precision = g_value_get_double (&args->values[2]);
- if (success)
- {
- GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, FALSE, error);
- if (stroke)
- {
- GArray *coords_array;
- gint i;
- coords_array = gimp_stroke_interpolate (stroke, precision, &closed);
- if (coords_array)
- {
- num_coords = coords_array->len;
- coords = g_new (gdouble, num_coords * 2);
- for (i = 0; i < num_coords; i++)
- {
- coords[2*i] = g_array_index (coords_array, GimpCoords, i).x;
- coords[2*i+1] = g_array_index (coords_array, GimpCoords, i).y;
- }
- g_array_free (coords_array, TRUE);
- num_coords *= 2;
- }
- else
- success = FALSE;
- }
- else
- success = FALSE;
- }
- return_vals = gimp_procedure_get_return_values (procedure, success,
- error ? *error : NULL);
- if (success)
- {
- g_value_set_int (&return_vals->values[1], num_coords);
- gimp_value_take_floatarray (&return_vals->values[2], coords, num_coords);
- g_value_set_boolean (&return_vals->values[3], closed);
- }
- return return_vals;
- }
- static GValueArray *
- vectors_bezier_stroke_new_moveto_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GValueArray *args,
- GError **error)
- {
- gboolean success = TRUE;
- GValueArray *return_vals;
- GimpVectors *vectors;
- gdouble x0;
- gdouble y0;
- gint32 stroke_id = 0;
- vectors = gimp_value_get_vectors (&args->values[0], gimp);
- x0 = g_value_get_double (&args->values[1]);
- y0 = g_value_get_double (&args->values[2]);
- if (success)
- {
- if (gimp_pdb_item_is_writable (GIMP_ITEM (vectors), error) &&
- gimp_pdb_item_is_not_group (GIMP_ITEM (vectors), error))
- {
- GimpStroke *stroke;
- GimpCoords coord0 = GIMP_COORDS_DEFAULT_VALUES;
- coord0.x = x0;
- coord0.y = y0;
- stroke = gimp_bezier_stroke_new_moveto (&coord0);
- if (gimp_item_is_attached (GIMP_ITEM (vectors)))
- gimp_image_undo_push_vectors_mod (gimp_item_get_image (GIMP_ITEM (vectors)),
- _("Add path stroke"),
- vectors);
- gimp_vectors_stroke_add (vectors, stroke);
- g_object_unref (stroke);
- stroke_id = gimp_stroke_get_ID (stroke);
- }
- else
- success = FALSE;
- }
- return_vals = gimp_procedure_get_return_values (procedure, success,
- error ? *error : NULL);
- if (success)
- g_value_set_int (&return_vals->values[1], stroke_id);
- return return_vals;
- }
- static GValueArray *
- vectors_bezier_stroke_lineto_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GValueArray *args,
- GError **error)
- {
- gboolean success = TRUE;
- GimpVectors *vectors;
- gint32 stroke_id;
- gdouble x0;
- gdouble y0;
- vectors = gimp_value_get_vectors (&args->values[0], gimp);
- stroke_id = g_value_get_int (&args->values[1]);
- x0 = g_value_get_double (&args->values[2]);
- y0 = g_value_get_double (&args->values[3]);
- if (success)
- {
- GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
- if (stroke)
- {
- GimpCoords coord0 = GIMP_COORDS_DEFAULT_VALUES;
- coord0.x = x0;
- coord0.y = y0;
- if (gimp_item_is_attached (GIMP_ITEM (vectors)))
- gimp_image_undo_push_vectors_mod (gimp_item_get_image (GIMP_ITEM (vectors)),
- _("Extend path stroke"),
- vectors);
- gimp_bezier_stroke_lineto (stroke, &coord0);
- }
- else
- success = FALSE;
- }
- return gimp_procedure_get_return_values (procedure, success,
- error ? *error : NULL);
- }
- static GValueArray *
- vectors_bezier_stroke_conicto_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GValueArray *args,
- GError **error)
- {
- gboolean success = TRUE;
- GimpVectors *vectors;
- gint32 stroke_id;
- gdouble x0;
- gdouble y0;
- gdouble x1;
- gdouble y1;
- vectors = gimp_value_get_vectors (&args->values[0], gimp);
- stroke_id = g_value_get_int (&args->values[1]);
- x0 = g_value_get_double (&args->values[2]);
- y0 = g_value_get_double (&args->values[3]);
- x1 = g_value_get_double (&args->values[4]);
- y1 = g_value_get_double (&args->values[5]);
- if (success)
- {
- GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
- if (stroke)
- {
- GimpCoords coord0 = GIMP_COORDS_DEFAULT_VALUES;
- GimpCoords coord1 = GIMP_COORDS_DEFAULT_VALUES;
- coord0.x = x0;
- coord0.y = y0;
- coord1.x = x1;
- coord1.y = y1;
- if (gimp_item_is_attached (GIMP_ITEM (vectors)))
- gimp_image_undo_push_vectors_mod (gimp_item_get_image (GIMP_ITEM (vectors)),
- _("Extend path stroke"),
- vectors);
- gimp_bezier_stroke_conicto (stroke, &coord0, &coord1);
- }
- else
- success = FALSE;
- }
- return gimp_procedure_get_return_values (procedure, success,
- error ? *error : NULL);
- }
- static GValueArray *
- vectors_bezier_stroke_cubicto_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GValueArray *args,
- GError **error)
- {
- gboolean success = TRUE;
- GimpVectors *vectors;
- gint32 stroke_id;
- gdouble x0;
- gdouble y0;
- gdouble x1;
- gdouble y1;
- gdouble x2;
- gdouble y2;
- vectors = gimp_value_get_vectors (&args->values[0], gimp);
- stroke_id = g_value_get_int (&args->values[1]);
- x0 = g_value_get_double (&args->values[2]);
- y0 = g_value_get_double (&args->values[3]);
- x1 = g_value_get_double (&args->values[4]);
- y1 = g_value_get_double (&args->values[5]);
- x2 = g_value_get_double (&args->values[6]);
- y2 = g_value_get_double (&args->values[7]);
- if (success)
- {
- GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
- if (stroke)
- {
- GimpCoords coord0 = GIMP_COORDS_DEFAULT_VALUES;
- GimpCoords coord1 = GIMP_COORDS_DEFAULT_VALUES;
- GimpCoords coord2 = GIMP_COORDS_DEFAULT_VALUES;
- coord0.x = x0;
- coord0.y = y0;
- coord1.x = x1;
- coord1.y = y1;
- coord2.x = x2;
- coord2.y = y2;
- if (gimp_item_is_attached (GIMP_ITEM (vectors)))
- gimp_image_undo_push_vectors_mod (gimp_item_get_image (GIMP_ITEM (vectors)),
- _("Extend path stroke"),
- vectors);
- gimp_bezier_stroke_cubicto (stroke, &coord0, &coord1, &coord2);
- }
- else
- success = FALSE;
- }
- return gimp_procedure_get_return_values (procedure, success,
- error ? *error : NULL);
- }
- static GValueArray *
- vectors_bezier_stroke_new_ellipse_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GValueArray *args,
- GError **error)
- {
- gboolean success = TRUE;
- GValueArray *return_vals;
- GimpVectors *vectors;
- gdouble x0;
- gdouble y0;
- gdouble radius_x;
- gdouble radius_y;
- gdouble angle;
- gint32 stroke_id = 0;
- vectors = gimp_value_get_vectors (&args->values[0], gimp);
- x0 = g_value_get_double (&args->values[1]);
- y0 = g_value_get_double (&args->values[2]);
- radius_x = g_value_get_double (&args->values[3]);
- radius_y = g_value_get_double (&args->values[4]);
- angle = g_value_get_double (&args->values[5]);
- if (success)
- {
- if (gimp_pdb_item_is_writable (GIMP_ITEM (vectors), error) &&
- gimp_pdb_item_is_not_group (GIMP_ITEM (vectors), error))
- {
- GimpStroke *stroke;
- GimpCoords coord0 = GIMP_COORDS_DEFAULT_VALUES;
- coord0.x = x0;
- coord0.y = y0;
- stroke = gimp_bezier_stroke_new_ellipse (&coord0, radius_x, radius_y, angle);
- if (gimp_item_is_attached (GIMP_ITEM (vectors)))
- gimp_image_undo_push_vectors_mod (gimp_item_get_image (GIMP_ITEM (vectors)),
- _("Add path stroke"),
- vectors);
- gimp_vectors_stroke_add (vectors, stroke);
- g_object_unref (stroke);
- stroke_id = gimp_stroke_get_ID (stroke);
- }
- else
- success = FALSE;
- }
- return_vals = gimp_procedure_get_return_values (procedure, success,
- error ? *error : NULL);
- if (success)
- g_value_set_int (&return_vals->values[1], stroke_id);
- return return_vals;
- }
- static GValueArray *
- vectors_to_selection_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GValueArray *args,
- GError **error)
- {
- gboolean success = TRUE;
- GimpVectors *vectors;
- gint32 operation;
- gboolean antialias;
- gboolean feather;
- gdouble feather_radius_x;
- gdouble feather_radius_y;
- vectors = gimp_value_get_vectors (&args->values[0], gimp);
- operation = g_value_get_enum (&args->values[1]);
- antialias = g_value_get_boolean (&args->values[2]);
- feather = g_value_get_boolean (&args->values[3]);
- feather_radius_x = g_value_get_double (&args->values[4]);
- feather_radius_y = g_value_get_double (&args->values[5]);
- if (success)
- {
- if (gimp_pdb_item_is_attached (GIMP_ITEM (vectors), NULL, FALSE, error))
- gimp_item_to_selection (GIMP_ITEM (vectors),
- operation,
- antialias,
- feather,
- feather_radius_x,
- feather_radius_y);
- else
- success = FALSE;
- }
- return gimp_procedure_get_return_values (procedure, success,
- error ? *error : NULL);
- }
- static GValueArray *
- vectors_import_from_file_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GValueArray *args,
- GError **error)
- {
- gboolean success = TRUE;
- GValueArray *return_vals;
- GimpImage *image;
- const gchar *filename;
- gboolean merge;
- gboolean scale;
- gint32 num_vectors = 0;
- gint32 *vectors_ids = NULL;
- image = gimp_value_get_image (&args->values[0], gimp);
- filename = g_value_get_string (&args->values[1]);
- merge = g_value_get_boolean (&args->values[2]);
- scale = g_value_get_boolean (&args->values[3]);
- if (success)
- {
- GList *list, *vectors_list = NULL;
- /* FIXME tree */
- success = gimp_vectors_import_file (image, filename,
- merge, scale, NULL, -1,
- &vectors_list, error);
- if (success)
- {
- num_vectors = g_list_length (vectors_list);
- if (num_vectors)
- {
- gint i;
- vectors_ids = g_new (gint32, num_vectors);
- list = vectors_list;
- for (i = 0; i < num_vectors; i++, list = g_list_next (list))
- vectors_ids[i] = gimp_item_get_ID (GIMP_ITEM (list->data));
- g_list_free (vectors_list);
- }
- }
- }
- return_vals = gimp_procedure_get_return_values (procedure, success,
- error ? *error : NULL);
- if (success)
- {
- g_value_set_int (&return_vals->values[1], num_vectors);
- gimp_value_take_int32array (&return_vals->values[2], vectors_ids, num_vectors);
- }
- return return_vals;
- }
- static GValueArray *
- vectors_import_from_string_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GValueArray *args,
- GError **error)
- {
- gboolean success = TRUE;
- GValueArray *return_vals;
- GimpImage *image;
- const gchar *string;
- gint32 length;
- gboolean merge;
- gboolean scale;
- gint32 num_vectors = 0;
- gint32 *vectors_ids = NULL;
- image = gimp_value_get_image (&args->values[0], gimp);
- string = g_value_get_string (&args->values[1]);
- length = g_value_get_int (&args->values[2]);
- merge = g_value_get_boolean (&args->values[3]);
- scale = g_value_get_boolean (&args->values[4]);
- if (success)
- {
- GList *list, *vectors_list = NULL;
- /* FIXME tree */
- success = gimp_vectors_import_buffer (image, string, length,
- merge, scale, NULL, -1,
- &vectors_list, error);
- if (success)
- {
- num_vectors = g_list_length (vectors_list);
- if (num_vectors)
- {
- gint i;
- vectors_ids = g_new (gint32, num_vectors);
- list = vectors_list;
- for (i = 0; i < num_vectors; i++, list = g_list_next (list))
- vectors_ids[i] = gimp_item_get_ID (GIMP_ITEM (list->data));
- g_list_free (vectors_list);
- }
- }
- }
- return_vals = gimp_procedure_get_return_values (procedure, success,
- error ? *error : NULL);
- if (success)
- {
- g_value_set_int (&return_vals->values[1], num_vectors);
- gimp_value_take_int32array (&return_vals->values[2], vectors_ids, num_vectors);
- }
- return return_vals;
- }
- static GValueArray *
- vectors_export_to_file_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GValueArray *args,
- GError **error)
- {
- gboolean success = TRUE;
- GimpImage *image;
- const gchar *filename;
- GimpVectors *vectors;
- image = gimp_value_get_image (&args->values[0], gimp);
- filename = g_value_get_string (&args->values[1]);
- vectors = gimp_value_get_vectors (&args->values[2], gimp);
- if (success)
- {
- success = gimp_vectors_export_file (image, vectors, filename, error);
- }
- return gimp_procedure_get_return_values (procedure, success,
- error ? *error : NULL);
- }
- static GValueArray *
- vectors_export_to_string_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GValueArray *args,
- GError **error)
- {
- gboolean success = TRUE;
- GValueArray *return_vals;
- GimpImage *image;
- GimpVectors *vectors;
- gchar *string = NULL;
- image = gimp_value_get_image (&args->values[0], gimp);
- vectors = gimp_value_get_vectors (&args->values[1], gimp);
- if (success)
- {
- string = gimp_vectors_export_string (image, vectors);
- success = (string != NULL);
- }
- return_vals = gimp_procedure_get_return_values (procedure, success,
- error ? *error : NULL);
- if (success)
- g_value_take_string (&return_vals->values[1], string);
- return return_vals;
- }
- void
- register_vectors_procs (GimpPDB *pdb)
- {
- GimpProcedure *procedure;
- /*
- * gimp-vectors-new
- */
- procedure = gimp_procedure_new (vectors_new_invoker);
- gimp_object_set_static_name (GIMP_OBJECT (procedure),
- "gimp-vectors-new");
- gimp_procedure_set_static_strings (procedure,
- "gimp-vectors-new",
- "Creates a new empty vectors object.",
- "Creates a new empty vectors object. The vectors object needs to be added to the image using 'gimp-image-insert-vectors'.",
- "Simon Budig",
- "Simon Budig",
- "2005",
- NULL);
- gimp_procedure_add_argument (procedure,
- gimp_param_spec_image_id ("image",
- "image",
- "The image",
- pdb->gimp, FALSE,
- GIMP_PARAM_READWRITE));
- gimp_procedure_add_argument (procedure,
- gimp_param_spec_string ("name",
- "name",
- "the name of the new vector object.",
- FALSE, FALSE, FALSE,
- NULL,
- GIMP_PARAM_READWRITE));
- gimp_procedure_add_return_value (procedure,
- gimp_param_spec_vectors_id ("vectors",
- "vectors",
- "the current vector object, 0 if no vector exists in the image.",
- pdb->gimp, FALSE,
- GIMP_PARAM_READWRITE));
- gimp_pdb_register_procedure (pdb, procedure);
- g_object_unref (procedure);
- /*
- * gimp-vectors-new-from-text-layer
- */
- procedure = gimp_procedure_new (vectors_new_from_text_layer_invoker);
- gimp_object_set_static_name (GIMP_OBJECT (procedure),
- "gimp-vectors-new-from-text-layer");
- gimp_procedure_set_static_strings (procedure,
- "gimp-vectors-new-from-text-layer",
- "Creates a new vectors object from a text layer.",
- "Creates a new vectors object from a text layer. The vectors object needs to be added to the image using 'gimp-image-insert-vectors'.",
- "Marcus Heese <heese@cip.ifi.lmu.de>",
- "Marcus Heese",
- "2008",
- NULL);
- gimp_procedure_add_argument (procedure,
- gimp_param_spec_image_id ("image",
- "image",
- "The image.",
- pdb->gimp, FALSE,
- GIMP_PARAM_READWRITE));
- gimp_procedure_add_argument (procedure,
- gimp_param_spec_layer_id ("layer",
- "layer",
- "The text layer.",
- pdb->gimp, FALSE,
- GIMP_PARAM_READWRITE));
- gimp_procedure_add_return_value (procedure,
- gimp_param_spec_vectors_id ("vectors",
- "vectors",
- "The vectors of the text layer.",
- pdb->gimp, FALSE,
- GIMP_PARAM_READWRITE));
- gimp_pdb_register_procedure (pdb, procedure);
- g_object_unref (procedure);
- /*
- * gimp-vectors-copy
- */
- procedure = gimp_procedure_new (vectors_copy_invoker);
- gimp_object_set_static_name (GIMP_OBJECT (procedure),
- "gimp-vectors-copy");
- gimp_procedure_set_static_strings (procedure,
- "gimp-vectors-copy",
- "Copy a vectors object.",
- "This procedure copies the specified vectors object and returns the copy.",
- "Barak Itkin <lightningismyname@gmail.com>",
- "Barak Itkin",
- "2008",
- NULL);
- gimp_procedure_add_argument (procedure,
- gimp_param_spec_vectors_id ("vectors",
- "vectors",
- "The vectors object to copy",
- pdb->gimp, FALSE,
- GIMP_PARAM_READWRITE));
- gimp_procedure_add_return_value (procedure,
- gimp_param_spec_vectors_id ("vectors-copy",
- "vectors copy",
- "The newly copied vectors object",
- pdb->gimp, FALSE,
- GIMP_PARAM_READWRITE));
- gimp_pdb_register_procedure (pdb, procedure);
- g_object_unref (procedure);
- /*
- * gimp-vectors-get-strokes
- */
- procedure = gimp_procedure_new (vectors_get_strokes_invoker);
- gimp_object_set_static_name (GIMP_OBJECT (procedure),
- "gimp-vectors-get-strokes");
- gimp_procedure_set_static_strings (procedure,
- "gimp-vectors-get-strokes",
- "List the strokes associated with the passed path.",
- "Returns an Array with the stroke-IDs associated with the passed path.",
- "Simon Budig",
- "Simon Budig",
- "2005",
- NULL);
- gimp_procedure_add_argument (procedure,
- gimp_param_spec_vectors_id ("vectors",
- "vectors",
- "The vectors object",
- pdb->gimp, FALSE,
- GIMP_PARAM_READWRITE));
- gimp_procedure_add_return_value (procedure,
- gimp_param_spec_int32 ("num-strokes",
- "num strokes",
- "The number of strokes returned.",
- 0, G_MAXINT32, 0,
- GIMP_PARAM_READWRITE));
- gimp_procedure_add_return_value (procedure,
- gimp_param_spec_int32_array ("stroke-ids",
- "stroke ids",
- "List of the strokes belonging to the path.",
- GIMP_PARAM_READWRITE));
- gimp_pdb_register_procedure (pdb, procedure);
- g_object_unref (procedure);
- /*
- * gimp-vectors-stroke-get-length
- */
- procedure = gimp_procedure_new (vectors_stroke_get_length_invoker);
- gimp_object_set_static_name (GIMP_OBJECT (procedure),
- "gimp-vectors-stroke-get-length");
- gimp_procedure_set_static_strings (procedure,
- "gimp-vectors-stroke-get-length",
- "Measure the length of the given stroke.",…