1 /* LIBGIMP - The GIMP Library
2 * Copyright (C) 1995-2003 Peter Mattis and Spencer Kimball
3 *
4 * gimpvectors_pdb.c
5 *
6 * This library is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see
18 * <https://www.gnu.org/licenses/>.
19 */
20
21 /* NOTE: This file is auto-generated by pdbgen.pl */
22
23 #include "config.h"
24
25 #include <string.h>
26
27 #include "gimp.h"
28
29
30 /**
31 * SECTION: gimpvectors
32 * @title: gimpvectors
33 * @short_description: Functions for querying and manipulating vectors.
34 *
35 * Functions for querying and manipulating vectors.
36 **/
37
38
39 /**
40 * gimp_vectors_new:
41 * @image_ID: The image.
42 * @name: the name of the new vector object.
43 *
44 * Creates a new empty vectors object.
45 *
46 * Creates a new empty vectors object. The vectors object needs to be
47 * added to the image using gimp_image_insert_vectors().
48 *
49 * Returns: the current vector object, 0 if no vector exists in the
50 * image.
51 *
52 * Since: 2.4
53 **/
54 gint32
gimp_vectors_new(gint32 image_ID,const gchar * name)55 gimp_vectors_new (gint32 image_ID,
56 const gchar *name)
57 {
58 GimpParam *return_vals;
59 gint nreturn_vals;
60 gint32 vectors_ID = -1;
61
62 return_vals = gimp_run_procedure ("gimp-vectors-new",
63 &nreturn_vals,
64 GIMP_PDB_IMAGE, image_ID,
65 GIMP_PDB_STRING, name,
66 GIMP_PDB_END);
67
68 if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
69 vectors_ID = return_vals[1].data.d_vectors;
70
71 gimp_destroy_params (return_vals, nreturn_vals);
72
73 return vectors_ID;
74 }
75
76 /**
77 * gimp_vectors_new_from_text_layer:
78 * @image_ID: The image.
79 * @layer_ID: The text layer.
80 *
81 * Creates a new vectors object from a text layer.
82 *
83 * Creates a new vectors object from a text layer. The vectors object
84 * needs to be added to the image using gimp_image_insert_vectors().
85 *
86 * Returns: The vectors of the text layer.
87 *
88 * Since: 2.6
89 **/
90 gint32
gimp_vectors_new_from_text_layer(gint32 image_ID,gint32 layer_ID)91 gimp_vectors_new_from_text_layer (gint32 image_ID,
92 gint32 layer_ID)
93 {
94 GimpParam *return_vals;
95 gint nreturn_vals;
96 gint32 vectors_ID = -1;
97
98 return_vals = gimp_run_procedure ("gimp-vectors-new-from-text-layer",
99 &nreturn_vals,
100 GIMP_PDB_IMAGE, image_ID,
101 GIMP_PDB_LAYER, layer_ID,
102 GIMP_PDB_END);
103
104 if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
105 vectors_ID = return_vals[1].data.d_vectors;
106
107 gimp_destroy_params (return_vals, nreturn_vals);
108
109 return vectors_ID;
110 }
111
112 /**
113 * gimp_vectors_copy:
114 * @vectors_ID: The vectors object to copy.
115 *
116 * Copy a vectors object.
117 *
118 * This procedure copies the specified vectors object and returns the
119 * copy.
120 *
121 * Returns: The newly copied vectors object.
122 *
123 * Since: 2.6
124 **/
125 gint32
gimp_vectors_copy(gint32 vectors_ID)126 gimp_vectors_copy (gint32 vectors_ID)
127 {
128 GimpParam *return_vals;
129 gint nreturn_vals;
130 gint32 vectors_copy_ID = -1;
131
132 return_vals = gimp_run_procedure ("gimp-vectors-copy",
133 &nreturn_vals,
134 GIMP_PDB_VECTORS, vectors_ID,
135 GIMP_PDB_END);
136
137 if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
138 vectors_copy_ID = return_vals[1].data.d_vectors;
139
140 gimp_destroy_params (return_vals, nreturn_vals);
141
142 return vectors_copy_ID;
143 }
144
145 /**
146 * gimp_vectors_get_strokes:
147 * @vectors_ID: The vectors object.
148 * @num_strokes: The number of strokes returned.
149 *
150 * List the strokes associated with the passed path.
151 *
152 * Returns an Array with the stroke-IDs associated with the passed
153 * path.
154 *
155 * Returns: List of the strokes belonging to the path.
156 *
157 * Since: 2.4
158 **/
159 gint *
gimp_vectors_get_strokes(gint32 vectors_ID,gint * num_strokes)160 gimp_vectors_get_strokes (gint32 vectors_ID,
161 gint *num_strokes)
162 {
163 GimpParam *return_vals;
164 gint nreturn_vals;
165 gint *stroke_ids = NULL;
166
167 return_vals = gimp_run_procedure ("gimp-vectors-get-strokes",
168 &nreturn_vals,
169 GIMP_PDB_VECTORS, vectors_ID,
170 GIMP_PDB_END);
171
172 *num_strokes = 0;
173
174 if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
175 {
176 *num_strokes = return_vals[1].data.d_int32;
177 stroke_ids = g_new (gint32, *num_strokes);
178 memcpy (stroke_ids,
179 return_vals[2].data.d_int32array,
180 *num_strokes * sizeof (gint32));
181 }
182
183 gimp_destroy_params (return_vals, nreturn_vals);
184
185 return stroke_ids;
186 }
187
188 /**
189 * gimp_vectors_stroke_get_length:
190 * @vectors_ID: The vectors object.
191 * @stroke_id: The stroke ID.
192 * @precision: The precision used for the approximation.
193 *
194 * Measure the length of the given stroke.
195 *
196 * Measure the length of the given stroke.
197 *
198 * Returns: The length (in pixels) of the given stroke.
199 *
200 * Since: 2.4
201 **/
202 gdouble
gimp_vectors_stroke_get_length(gint32 vectors_ID,gint stroke_id,gdouble precision)203 gimp_vectors_stroke_get_length (gint32 vectors_ID,
204 gint stroke_id,
205 gdouble precision)
206 {
207 GimpParam *return_vals;
208 gint nreturn_vals;
209 gdouble length = 0.0;
210
211 return_vals = gimp_run_procedure ("gimp-vectors-stroke-get-length",
212 &nreturn_vals,
213 GIMP_PDB_VECTORS, vectors_ID,
214 GIMP_PDB_INT32, stroke_id,
215 GIMP_PDB_FLOAT, precision,
216 GIMP_PDB_END);
217
218 if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
219 length = return_vals[1].data.d_float;
220
221 gimp_destroy_params (return_vals, nreturn_vals);
222
223 return length;
224 }
225
226 /**
227 * gimp_vectors_stroke_get_point_at_dist:
228 * @vectors_ID: The vectors object.
229 * @stroke_id: The stroke ID.
230 * @dist: The given distance.
231 * @precision: The precision used for the approximation.
232 * @x_point: The x position of the point.
233 * @y_point: The y position of the point.
234 * @slope: The slope (dy / dx) at the specified point.
235 * @valid: Indicator for the validity of the returned data.
236 *
237 * Get point at a specified distance along the stroke.
238 *
239 * This will return the x,y position of a point at a given distance
240 * along the stroke. The distance will be obtained by first digitizing
241 * the curve internally and then walking along the curve. For a closed
242 * stroke the start of the path is the first point on the path that was
243 * created. This might not be obvious. If the stroke is not long
244 * enough, a \"valid\" flag will be FALSE.
245 *
246 * Returns: TRUE on success.
247 *
248 * Since: 2.4
249 **/
250 gboolean
gimp_vectors_stroke_get_point_at_dist(gint32 vectors_ID,gint stroke_id,gdouble dist,gdouble precision,gdouble * x_point,gdouble * y_point,gdouble * slope,gboolean * valid)251 gimp_vectors_stroke_get_point_at_dist (gint32 vectors_ID,
252 gint stroke_id,
253 gdouble dist,
254 gdouble precision,
255 gdouble *x_point,
256 gdouble *y_point,
257 gdouble *slope,
258 gboolean *valid)
259 {
260 GimpParam *return_vals;
261 gint nreturn_vals;
262 gboolean success = TRUE;
263
264 return_vals = gimp_run_procedure ("gimp-vectors-stroke-get-point-at-dist",
265 &nreturn_vals,
266 GIMP_PDB_VECTORS, vectors_ID,
267 GIMP_PDB_INT32, stroke_id,
268 GIMP_PDB_FLOAT, dist,
269 GIMP_PDB_FLOAT, precision,
270 GIMP_PDB_END);
271
272 *x_point = 0.0;
273 *y_point = 0.0;
274 *slope = 0.0;
275 *valid = FALSE;
276
277 success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
278
279 if (success)
280 {
281 *x_point = return_vals[1].data.d_float;
282 *y_point = return_vals[2].data.d_float;
283 *slope = return_vals[3].data.d_float;
284 *valid = return_vals[4].data.d_int32;
285 }
286
287 gimp_destroy_params (return_vals, nreturn_vals);
288
289 return success;
290 }
291
292 /**
293 * gimp_vectors_remove_stroke:
294 * @vectors_ID: The vectors object.
295 * @stroke_id: The stroke ID.
296 *
297 * remove the stroke from a vectors object.
298 *
299 * Remove the stroke from a vectors object.
300 *
301 * Returns: TRUE on success.
302 *
303 * Since: 2.4
304 **/
305 gboolean
gimp_vectors_remove_stroke(gint32 vectors_ID,gint stroke_id)306 gimp_vectors_remove_stroke (gint32 vectors_ID,
307 gint stroke_id)
308 {
309 GimpParam *return_vals;
310 gint nreturn_vals;
311 gboolean success = TRUE;
312
313 return_vals = gimp_run_procedure ("gimp-vectors-remove-stroke",
314 &nreturn_vals,
315 GIMP_PDB_VECTORS, vectors_ID,
316 GIMP_PDB_INT32, stroke_id,
317 GIMP_PDB_END);
318
319 success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
320
321 gimp_destroy_params (return_vals, nreturn_vals);
322
323 return success;
324 }
325
326 /**
327 * gimp_vectors_stroke_close:
328 * @vectors_ID: The vectors object.
329 * @stroke_id: The stroke ID.
330 *
331 * closes the specified stroke.
332 *
333 * Closes the specified stroke.
334 *
335 * Returns: TRUE on success.
336 *
337 * Since: 2.4
338 **/
339 gboolean
gimp_vectors_stroke_close(gint32 vectors_ID,gint stroke_id)340 gimp_vectors_stroke_close (gint32 vectors_ID,
341 gint stroke_id)
342 {
343 GimpParam *return_vals;
344 gint nreturn_vals;
345 gboolean success = TRUE;
346
347 return_vals = gimp_run_procedure ("gimp-vectors-stroke-close",
348 &nreturn_vals,
349 GIMP_PDB_VECTORS, vectors_ID,
350 GIMP_PDB_INT32, stroke_id,
351 GIMP_PDB_END);
352
353 success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
354
355 gimp_destroy_params (return_vals, nreturn_vals);
356
357 return success;
358 }
359
360 /**
361 * gimp_vectors_stroke_translate:
362 * @vectors_ID: The vectors object.
363 * @stroke_id: The stroke ID.
364 * @off_x: Offset in x direction.
365 * @off_y: Offset in y direction.
366 *
367 * translate the given stroke.
368 *
369 * Translate the given stroke.
370 *
371 * Returns: TRUE on success.
372 *
373 * Since: 2.4
374 **/
375 gboolean
gimp_vectors_stroke_translate(gint32 vectors_ID,gint stroke_id,gint off_x,gint off_y)376 gimp_vectors_stroke_translate (gint32 vectors_ID,
377 gint stroke_id,
378 gint off_x,
379 gint off_y)
380 {
381 GimpParam *return_vals;
382 gint nreturn_vals;
383 gboolean success = TRUE;
384
385 return_vals = gimp_run_procedure ("gimp-vectors-stroke-translate",
386 &nreturn_vals,
387 GIMP_PDB_VECTORS, vectors_ID,
388 GIMP_PDB_INT32, stroke_id,
389 GIMP_PDB_INT32, off_x,
390 GIMP_PDB_INT32, off_y,
391 GIMP_PDB_END);
392
393 success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
394
395 gimp_destroy_params (return_vals, nreturn_vals);
396
397 return success;
398 }
399
400 /**
401 * gimp_vectors_stroke_scale:
402 * @vectors_ID: The vectors object.
403 * @stroke_id: The stroke ID.
404 * @scale_x: Scale factor in x direction.
405 * @scale_y: Scale factor in y direction.
406 *
407 * scales the given stroke.
408 *
409 * Scale the given stroke.
410 *
411 * Returns: TRUE on success.
412 *
413 * Since: 2.4
414 **/
415 gboolean
gimp_vectors_stroke_scale(gint32 vectors_ID,gint stroke_id,gdouble scale_x,gdouble scale_y)416 gimp_vectors_stroke_scale (gint32 vectors_ID,
417 gint stroke_id,
418 gdouble scale_x,
419 gdouble scale_y)
420 {
421 GimpParam *return_vals;
422 gint nreturn_vals;
423 gboolean success = TRUE;
424
425 return_vals = gimp_run_procedure ("gimp-vectors-stroke-scale",
426 &nreturn_vals,
427 GIMP_PDB_VECTORS, vectors_ID,
428 GIMP_PDB_INT32, stroke_id,
429 GIMP_PDB_FLOAT, scale_x,
430 GIMP_PDB_FLOAT, scale_y,
431 GIMP_PDB_END);
432
433 success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
434
435 gimp_destroy_params (return_vals, nreturn_vals);
436
437 return success;
438 }
439
440 /**
441 * gimp_vectors_stroke_rotate:
442 * @vectors_ID: The vectors object.
443 * @stroke_id: The stroke ID.
444 * @center_x: X coordinate of the rotation center.
445 * @center_y: Y coordinate of the rotation center.
446 * @angle: angle to rotate about.
447 *
448 * rotates the given stroke.
449 *
450 * Rotates the given stroke around given center by angle (in degrees).
451 *
452 * Returns: TRUE on success.
453 *
454 * Since: 2.4
455 **/
456 gboolean
gimp_vectors_stroke_rotate(gint32 vectors_ID,gint stroke_id,gdouble center_x,gdouble center_y,gdouble angle)457 gimp_vectors_stroke_rotate (gint32 vectors_ID,
458 gint stroke_id,
459 gdouble center_x,
460 gdouble center_y,
461 gdouble angle)
462 {
463 GimpParam *return_vals;
464 gint nreturn_vals;
465 gboolean success = TRUE;
466
467 return_vals = gimp_run_procedure ("gimp-vectors-stroke-rotate",
468 &nreturn_vals,
469 GIMP_PDB_VECTORS, vectors_ID,
470 GIMP_PDB_INT32, stroke_id,
471 GIMP_PDB_FLOAT, center_x,
472 GIMP_PDB_FLOAT, center_y,
473 GIMP_PDB_FLOAT, angle,
474 GIMP_PDB_END);
475
476 success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
477
478 gimp_destroy_params (return_vals, nreturn_vals);
479
480 return success;
481 }
482
483 /**
484 * gimp_vectors_stroke_flip:
485 * @vectors_ID: The vectors object.
486 * @stroke_id: The stroke ID.
487 * @flip_type: Flip orientation, either vertical or horizontal.
488 * @axis: axis coordinate about which to flip, in pixels.
489 *
490 * flips the given stroke.
491 *
492 * Rotates the given stroke around given center by angle (in degrees).
493 *
494 * Returns: TRUE on success.
495 *
496 * Since: 2.4
497 **/
498 gboolean
gimp_vectors_stroke_flip(gint32 vectors_ID,gint stroke_id,GimpOrientationType flip_type,gdouble axis)499 gimp_vectors_stroke_flip (gint32 vectors_ID,
500 gint stroke_id,
501 GimpOrientationType flip_type,
502 gdouble axis)
503 {
504 GimpParam *return_vals;
505 gint nreturn_vals;
506 gboolean success = TRUE;
507
508 return_vals = gimp_run_procedure ("gimp-vectors-stroke-flip",
509 &nreturn_vals,
510 GIMP_PDB_VECTORS, vectors_ID,
511 GIMP_PDB_INT32, stroke_id,
512 GIMP_PDB_INT32, flip_type,
513 GIMP_PDB_FLOAT, axis,
514 GIMP_PDB_END);
515
516 success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
517
518 gimp_destroy_params (return_vals, nreturn_vals);
519
520 return success;
521 }
522
523 /**
524 * gimp_vectors_stroke_flip_free:
525 * @vectors_ID: The vectors object.
526 * @stroke_id: The stroke ID.
527 * @x1: X coordinate of the first point of the flipping axis.
528 * @y1: Y coordinate of the first point of the flipping axis.
529 * @x2: X coordinate of the second point of the flipping axis.
530 * @y2: Y coordinate of the second point of the flipping axis.
531 *
532 * flips the given stroke about an arbitrary axis.
533 *
534 * Flips the given stroke about an arbitrary axis. Axis is defined by
535 * two coordinates in the image (in pixels), through which the flipping
536 * axis passes.
537 *
538 * Returns: TRUE on success.
539 *
540 * Since: 2.4
541 **/
542 gboolean
gimp_vectors_stroke_flip_free(gint32 vectors_ID,gint stroke_id,gdouble x1,gdouble y1,gdouble x2,gdouble y2)543 gimp_vectors_stroke_flip_free (gint32 vectors_ID,
544 gint stroke_id,
545 gdouble x1,
546 gdouble y1,
547 gdouble x2,
548 gdouble y2)
549 {
550 GimpParam *return_vals;
551 gint nreturn_vals;
552 gboolean success = TRUE;
553
554 return_vals = gimp_run_procedure ("gimp-vectors-stroke-flip-free",
555 &nreturn_vals,
556 GIMP_PDB_VECTORS, vectors_ID,
557 GIMP_PDB_INT32, stroke_id,
558 GIMP_PDB_FLOAT, x1,
559 GIMP_PDB_FLOAT, y1,
560 GIMP_PDB_FLOAT, x2,
561 GIMP_PDB_FLOAT, y2,
562 GIMP_PDB_END);
563
564 success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
565
566 gimp_destroy_params (return_vals, nreturn_vals);
567
568 return success;
569 }
570
571 /**
572 * gimp_vectors_stroke_get_points:
573 * @vectors_ID: The vectors object.
574 * @stroke_id: The stroke ID.
575 * @num_points: The number of floats returned.
576 * @controlpoints: List of the control points for the stroke (x0, y0, x1, y1, ...).
577 * @closed: Whether the stroke is closed or not.
578 *
579 * returns the control points of a stroke.
580 *
581 * returns the control points of a stroke. The interpretation of the
582 * coordinates returned depends on the type of the stroke. For Gimp 2.4
583 * this is always a bezier stroke, where the coordinates are the
584 * control points.
585 *
586 * Returns: type of the stroke (always GIMP_VECTORS_STROKE_TYPE_BEZIER
587 * for now).
588 *
589 * Since: 2.4
590 **/
591 GimpVectorsStrokeType
gimp_vectors_stroke_get_points(gint32 vectors_ID,gint stroke_id,gint * num_points,gdouble ** controlpoints,gboolean * closed)592 gimp_vectors_stroke_get_points (gint32 vectors_ID,
593 gint stroke_id,
594 gint *num_points,
595 gdouble **controlpoints,
596 gboolean *closed)
597 {
598 GimpParam *return_vals;
599 gint nreturn_vals;
600 GimpVectorsStrokeType type = 0;
601
602 return_vals = gimp_run_procedure ("gimp-vectors-stroke-get-points",
603 &nreturn_vals,
604 GIMP_PDB_VECTORS, vectors_ID,
605 GIMP_PDB_INT32, stroke_id,
606 GIMP_PDB_END);
607
608 *num_points = 0;
609
610 if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
611 {
612 type = return_vals[1].data.d_int32;
613 *num_points = return_vals[2].data.d_int32;
614 *controlpoints = g_new (gdouble, *num_points);
615 memcpy (*controlpoints,
616 return_vals[3].data.d_floatarray,
617 *num_points * sizeof (gdouble));
618 *closed = return_vals[4].data.d_int32;
619 }
620
621 gimp_destroy_params (return_vals, nreturn_vals);
622
623 return type;
624 }
625
626 /**
627 * gimp_vectors_stroke_new_from_points:
628 * @vectors_ID: The vectors object.
629 * @type: type of the stroke (always GIMP_VECTORS_STROKE_TYPE_BEZIER for now).
630 * @num_points: The number of elements in the array, i.e. the number of controlpoints in the stroke * 2 (x- and y-coordinate).
631 * @controlpoints: List of the x- and y-coordinates of the control points.
632 * @closed: Whether the stroke is to be closed or not.
633 *
634 * Adds a stroke of a given type to the vectors object.
635 *
636 * Adds a stroke of a given type to the vectors object. The coordinates
637 * of the control points can be specified. For now only strokes of the
638 * type GIMP_VECTORS_STROKE_TYPE_BEZIER are supported. The control
639 * points are specified as a pair of float values for the x- and
640 * y-coordinate. The Bezier stroke type needs a multiple of three
641 * control points. Each Bezier segment endpoint (anchor, A) has two
642 * additional control points (C) associated. They are specified in the
643 * order CACCACCAC...
644 *
645 * Returns: The stroke ID of the newly created stroke.
646 *
647 * Since: 2.4
648 **/
649 gint
gimp_vectors_stroke_new_from_points(gint32 vectors_ID,GimpVectorsStrokeType type,gint num_points,const gdouble * controlpoints,gboolean closed)650 gimp_vectors_stroke_new_from_points (gint32 vectors_ID,
651 GimpVectorsStrokeType type,
652 gint num_points,
653 const gdouble *controlpoints,
654 gboolean closed)
655 {
656 GimpParam *return_vals;
657 gint nreturn_vals;
658 gint stroke_id = 0;
659
660 return_vals = gimp_run_procedure ("gimp-vectors-stroke-new-from-points",
661 &nreturn_vals,
662 GIMP_PDB_VECTORS, vectors_ID,
663 GIMP_PDB_INT32, type,
664 GIMP_PDB_INT32, num_points,
665 GIMP_PDB_FLOATARRAY, controlpoints,
666 GIMP_PDB_INT32, closed,
667 GIMP_PDB_END);
668
669 if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
670 stroke_id = return_vals[1].data.d_int32;
671
672 gimp_destroy_params (return_vals, nreturn_vals);
673
674 return stroke_id;
675 }
676
677 /**
678 * gimp_vectors_stroke_interpolate:
679 * @vectors_ID: The vectors object.
680 * @stroke_id: The stroke ID.
681 * @precision: The precision used for the approximation.
682 * @num_coords: The number of floats returned.
683 * @closed: Whether the stroke is closed or not.
684 *
685 * returns polygonal approximation of the stroke.
686 *
687 * returns polygonal approximation of the stroke.
688 *
689 * Returns: List of the coords along the path (x0, y0, x1, y1, ...).
690 *
691 * Since: 2.4
692 **/
693 gdouble *
gimp_vectors_stroke_interpolate(gint32 vectors_ID,gint stroke_id,gdouble precision,gint * num_coords,gboolean * closed)694 gimp_vectors_stroke_interpolate (gint32 vectors_ID,
695 gint stroke_id,
696 gdouble precision,
697 gint *num_coords,
698 gboolean *closed)
699 {
700 GimpParam *return_vals;
701 gint nreturn_vals;
702 gdouble *coords = NULL;
703
704 return_vals = gimp_run_procedure ("gimp-vectors-stroke-interpolate",
705 &nreturn_vals,
706 GIMP_PDB_VECTORS, vectors_ID,
707 GIMP_PDB_INT32, stroke_id,
708 GIMP_PDB_FLOAT, precision,
709 GIMP_PDB_END);
710
711 *num_coords = 0;
712
713 if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
714 {
715 *num_coords = return_vals[1].data.d_int32;
716 coords = g_new (gdouble, *num_coords);
717 memcpy (coords,
718 return_vals[2].data.d_floatarray,
719 *num_coords * sizeof (gdouble));
720 *closed = return_vals[3].data.d_int32;
721 }
722
723 gimp_destroy_params (return_vals, nreturn_vals);
724
725 return coords;
726 }
727
728 /**
729 * gimp_vectors_bezier_stroke_new_moveto:
730 * @vectors_ID: The vectors object.
731 * @x0: The x-coordinate of the moveto.
732 * @y0: The y-coordinate of the moveto.
733 *
734 * Adds a bezier stroke with a single moveto to the vectors object.
735 *
736 * Adds a bezier stroke with a single moveto to the vectors object.
737 *
738 * Returns: The resulting stroke.
739 *
740 * Since: 2.4
741 **/
742 gint
gimp_vectors_bezier_stroke_new_moveto(gint32 vectors_ID,gdouble x0,gdouble y0)743 gimp_vectors_bezier_stroke_new_moveto (gint32 vectors_ID,
744 gdouble x0,
745 gdouble y0)
746 {
747 GimpParam *return_vals;
748 gint nreturn_vals;
749 gint stroke_id = 0;
750
751 return_vals = gimp_run_procedure ("gimp-vectors-bezier-stroke-new-moveto",
752 &nreturn_vals,
753 GIMP_PDB_VECTORS, vectors_ID,
754 GIMP_PDB_FLOAT, x0,
755 GIMP_PDB_FLOAT, y0,
756 GIMP_PDB_END);
757
758 if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
759 stroke_id = return_vals[1].data.d_int32;
760
761 gimp_destroy_params (return_vals, nreturn_vals);
762
763 return stroke_id;
764 }
765
766 /**
767 * gimp_vectors_bezier_stroke_lineto:
768 * @vectors_ID: The vectors object.
769 * @stroke_id: The stroke ID.
770 * @x0: The x-coordinate of the lineto.
771 * @y0: The y-coordinate of the lineto.
772 *
773 * Extends a bezier stroke with a lineto.
774 *
775 * Extends a bezier stroke with a lineto.
776 *
777 * Returns: TRUE on success.
778 *
779 * Since: 2.4
780 **/
781 gboolean
gimp_vectors_bezier_stroke_lineto(gint32 vectors_ID,gint stroke_id,gdouble x0,gdouble y0)782 gimp_vectors_bezier_stroke_lineto (gint32 vectors_ID,
783 gint stroke_id,
784 gdouble x0,
785 gdouble y0)
786 {
787 GimpParam *return_vals;
788 gint nreturn_vals;
789 gboolean success = TRUE;
790
791 return_vals = gimp_run_procedure ("gimp-vectors-bezier-stroke-lineto",
792 &nreturn_vals,
793 GIMP_PDB_VECTORS, vectors_ID,
794 GIMP_PDB_INT32, stroke_id,
795 GIMP_PDB_FLOAT, x0,
796 GIMP_PDB_FLOAT, y0,
797 GIMP_PDB_END);
798
799 success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
800
801 gimp_destroy_params (return_vals, nreturn_vals);
802
803 return success;
804 }
805
806 /**
807 * gimp_vectors_bezier_stroke_conicto:
808 * @vectors_ID: The vectors object.
809 * @stroke_id: The stroke ID.
810 * @x0: The x-coordinate of the control point.
811 * @y0: The y-coordinate of the control point.
812 * @x1: The x-coordinate of the end point.
813 * @y1: The y-coordinate of the end point.
814 *
815 * Extends a bezier stroke with a conic bezier spline.
816 *
817 * Extends a bezier stroke with a conic bezier spline. Actually a cubic
818 * bezier spline gets added that realizes the shape of a conic bezier
819 * spline.
820 *
821 * Returns: TRUE on success.
822 *
823 * Since: 2.4
824 **/
825 gboolean
gimp_vectors_bezier_stroke_conicto(gint32 vectors_ID,gint stroke_id,gdouble x0,gdouble y0,gdouble x1,gdouble y1)826 gimp_vectors_bezier_stroke_conicto (gint32 vectors_ID,
827 gint stroke_id,
828 gdouble x0,
829 gdouble y0,
830 gdouble x1,
831 gdouble y1)
832 {
833 GimpParam *return_vals;
834 gint nreturn_vals;
835 gboolean success = TRUE;
836
837 return_vals = gimp_run_procedure ("gimp-vectors-bezier-stroke-conicto",
838 &nreturn_vals,
839 GIMP_PDB_VECTORS, vectors_ID,
840 GIMP_PDB_INT32, stroke_id,
841 GIMP_PDB_FLOAT, x0,
842 GIMP_PDB_FLOAT, y0,
843 GIMP_PDB_FLOAT, x1,
844 GIMP_PDB_FLOAT, y1,
845 GIMP_PDB_END);
846
847 success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
848
849 gimp_destroy_params (return_vals, nreturn_vals);
850
851 return success;
852 }
853
854 /**
855 * gimp_vectors_bezier_stroke_cubicto:
856 * @vectors_ID: The vectors object.
857 * @stroke_id: The stroke ID.
858 * @x0: The x-coordinate of the first control point.
859 * @y0: The y-coordinate of the first control point.
860 * @x1: The x-coordinate of the second control point.
861 * @y1: The y-coordinate of the second control point.
862 * @x2: The x-coordinate of the end point.
863 * @y2: The y-coordinate of the end point.
864 *
865 * Extends a bezier stroke with a cubic bezier spline.
866 *
867 * Extends a bezier stroke with a cubic bezier spline.
868 *
869 * Returns: TRUE on success.
870 *
871 * Since: 2.4
872 **/
873 gboolean
gimp_vectors_bezier_stroke_cubicto(gint32 vectors_ID,gint stroke_id,gdouble x0,gdouble y0,gdouble x1,gdouble y1,gdouble x2,gdouble y2)874 gimp_vectors_bezier_stroke_cubicto (gint32 vectors_ID,
875 gint stroke_id,
876 gdouble x0,
877 gdouble y0,
878 gdouble x1,
879 gdouble y1,
880 gdouble x2,
881 gdouble y2)
882 {
883 GimpParam *return_vals;
884 gint nreturn_vals;
885 gboolean success = TRUE;
886
887 return_vals = gimp_run_procedure ("gimp-vectors-bezier-stroke-cubicto",
888 &nreturn_vals,
889 GIMP_PDB_VECTORS, vectors_ID,
890 GIMP_PDB_INT32, stroke_id,
891 GIMP_PDB_FLOAT, x0,
892 GIMP_PDB_FLOAT, y0,
893 GIMP_PDB_FLOAT, x1,
894 GIMP_PDB_FLOAT, y1,
895 GIMP_PDB_FLOAT, x2,
896 GIMP_PDB_FLOAT, y2,
897 GIMP_PDB_END);
898
899 success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
900
901 gimp_destroy_params (return_vals, nreturn_vals);
902
903 return success;
904 }
905
906 /**
907 * gimp_vectors_bezier_stroke_new_ellipse:
908 * @vectors_ID: The vectors object.
909 * @x0: The x-coordinate of the center.
910 * @y0: The y-coordinate of the center.
911 * @radius_x: The radius in x direction.
912 * @radius_y: The radius in y direction.
913 * @angle: The angle the x-axis of the ellipse (radians, counterclockwise).
914 *
915 * Adds a bezier stroke describing an ellipse the vectors object.
916 *
917 * Adds a bezier stroke describing an ellipse the vectors object.
918 *
919 * Returns: The resulting stroke.
920 *
921 * Since: 2.4
922 **/
923 gint
gimp_vectors_bezier_stroke_new_ellipse(gint32 vectors_ID,gdouble x0,gdouble y0,gdouble radius_x,gdouble radius_y,gdouble angle)924 gimp_vectors_bezier_stroke_new_ellipse (gint32 vectors_ID,
925 gdouble x0,
926 gdouble y0,
927 gdouble radius_x,
928 gdouble radius_y,
929 gdouble angle)
930 {
931 GimpParam *return_vals;
932 gint nreturn_vals;
933 gint stroke_id = 0;
934
935 return_vals = gimp_run_procedure ("gimp-vectors-bezier-stroke-new-ellipse",
936 &nreturn_vals,
937 GIMP_PDB_VECTORS, vectors_ID,
938 GIMP_PDB_FLOAT, x0,
939 GIMP_PDB_FLOAT, y0,
940 GIMP_PDB_FLOAT, radius_x,
941 GIMP_PDB_FLOAT, radius_y,
942 GIMP_PDB_FLOAT, angle,
943 GIMP_PDB_END);
944
945 if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
946 stroke_id = return_vals[1].data.d_int32;
947
948 gimp_destroy_params (return_vals, nreturn_vals);
949
950 return stroke_id;
951 }
952
953 /**
954 * gimp_vectors_to_selection:
955 * @vectors_ID: The vectors object to render to the selection.
956 * @operation: The desired operation with current selection.
957 * @antialias: Antialias selection.
958 * @feather: Feather selection.
959 * @feather_radius_x: Feather radius x.
960 * @feather_radius_y: Feather radius y.
961 *
962 * Deprecated: Use gimp_image_select_item() instead.
963 *
964 * Returns: TRUE on success.
965 *
966 * Since: 2.4
967 **/
968 gboolean
gimp_vectors_to_selection(gint32 vectors_ID,GimpChannelOps operation,gboolean antialias,gboolean feather,gdouble feather_radius_x,gdouble feather_radius_y)969 gimp_vectors_to_selection (gint32 vectors_ID,
970 GimpChannelOps operation,
971 gboolean antialias,
972 gboolean feather,
973 gdouble feather_radius_x,
974 gdouble feather_radius_y)
975 {
976 GimpParam *return_vals;
977 gint nreturn_vals;
978 gboolean success = TRUE;
979
980 return_vals = gimp_run_procedure ("gimp-vectors-to-selection",
981 &nreturn_vals,
982 GIMP_PDB_VECTORS, vectors_ID,
983 GIMP_PDB_INT32, operation,
984 GIMP_PDB_INT32, antialias,
985 GIMP_PDB_INT32, feather,
986 GIMP_PDB_FLOAT, feather_radius_x,
987 GIMP_PDB_FLOAT, feather_radius_y,
988 GIMP_PDB_END);
989
990 success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
991
992 gimp_destroy_params (return_vals, nreturn_vals);
993
994 return success;
995 }
996
997 /**
998 * gimp_vectors_import_from_file:
999 * @image_ID: The image.
1000 * @filename: The name of the SVG file to import.
1001 * @merge: Merge paths into a single vectors object.
1002 * @scale: Scale the SVG to image dimensions.
1003 * @num_vectors: The number of newly created vectors.
1004 * @vectors_ids: The list of newly created vectors.
1005 *
1006 * Import paths from an SVG file.
1007 *
1008 * This procedure imports paths from an SVG file. SVG elements other
1009 * than paths and basic shapes are ignored.
1010 *
1011 * Returns: TRUE on success.
1012 *
1013 * Since: 2.4
1014 **/
1015 gboolean
gimp_vectors_import_from_file(gint32 image_ID,const gchar * filename,gboolean merge,gboolean scale,gint * num_vectors,gint32 ** vectors_ids)1016 gimp_vectors_import_from_file (gint32 image_ID,
1017 const gchar *filename,
1018 gboolean merge,
1019 gboolean scale,
1020 gint *num_vectors,
1021 gint32 **vectors_ids)
1022 {
1023 GimpParam *return_vals;
1024 gint nreturn_vals;
1025 gboolean success = TRUE;
1026
1027 return_vals = gimp_run_procedure ("gimp-vectors-import-from-file",
1028 &nreturn_vals,
1029 GIMP_PDB_IMAGE, image_ID,
1030 GIMP_PDB_STRING, filename,
1031 GIMP_PDB_INT32, merge,
1032 GIMP_PDB_INT32, scale,
1033 GIMP_PDB_END);
1034
1035 *num_vectors = 0;
1036 *vectors_ids = NULL;
1037
1038 success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
1039
1040 if (success)
1041 {
1042 *num_vectors = return_vals[1].data.d_int32;
1043 *vectors_ids = g_new (gint32, *num_vectors);
1044 memcpy (*vectors_ids,
1045 return_vals[2].data.d_int32array,
1046 *num_vectors * sizeof (gint32));
1047 }
1048
1049 gimp_destroy_params (return_vals, nreturn_vals);
1050
1051 return success;
1052 }
1053
1054 /**
1055 * gimp_vectors_import_from_string:
1056 * @image_ID: The image.
1057 * @string: A string that must be a complete and valid SVG document.
1058 * @length: Number of bytes in string or -1 if the string is NULL terminated.
1059 * @merge: Merge paths into a single vectors object.
1060 * @scale: Scale the SVG to image dimensions.
1061 * @num_vectors: The number of newly created vectors.
1062 * @vectors_ids: The list of newly created vectors.
1063 *
1064 * Import paths from an SVG string.
1065 *
1066 * This procedure works like gimp_vectors_import_from_file() but takes
1067 * a string rather than reading the SVG from a file. This allows you to
1068 * write scripts that generate SVG and feed it to GIMP.
1069 *
1070 * Returns: TRUE on success.
1071 *
1072 * Since: 2.4
1073 **/
1074 gboolean
gimp_vectors_import_from_string(gint32 image_ID,const gchar * string,gint length,gboolean merge,gboolean scale,gint * num_vectors,gint32 ** vectors_ids)1075 gimp_vectors_import_from_string (gint32 image_ID,
1076 const gchar *string,
1077 gint length,
1078 gboolean merge,
1079 gboolean scale,
1080 gint *num_vectors,
1081 gint32 **vectors_ids)
1082 {
1083 GimpParam *return_vals;
1084 gint nreturn_vals;
1085 gboolean success = TRUE;
1086
1087 return_vals = gimp_run_procedure ("gimp-vectors-import-from-string",
1088 &nreturn_vals,
1089 GIMP_PDB_IMAGE, image_ID,
1090 GIMP_PDB_STRING, string,
1091 GIMP_PDB_INT32, length,
1092 GIMP_PDB_INT32, merge,
1093 GIMP_PDB_INT32, scale,
1094 GIMP_PDB_END);
1095
1096 *num_vectors = 0;
1097 *vectors_ids = NULL;
1098
1099 success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
1100
1101 if (success)
1102 {
1103 *num_vectors = return_vals[1].data.d_int32;
1104 *vectors_ids = g_new (gint32, *num_vectors);
1105 memcpy (*vectors_ids,
1106 return_vals[2].data.d_int32array,
1107 *num_vectors * sizeof (gint32));
1108 }
1109
1110 gimp_destroy_params (return_vals, nreturn_vals);
1111
1112 return success;
1113 }
1114
1115 /**
1116 * gimp_vectors_export_to_file:
1117 * @image_ID: The image.
1118 * @filename: The name of the SVG file to create.
1119 * @vectors_ID: The vectors object to be saved, or 0 for all in the image.
1120 *
1121 * save a path as an SVG file.
1122 *
1123 * This procedure creates an SVG file to save a Vectors object, that
1124 * is, a path. The resulting file can be edited using a vector graphics
1125 * application, or later reloaded into GIMP. If you pass 0 as the
1126 * 'vectors' argument, then all paths in the image will be exported.
1127 *
1128 * Returns: TRUE on success.
1129 *
1130 * Since: 2.6
1131 **/
1132 gboolean
gimp_vectors_export_to_file(gint32 image_ID,const gchar * filename,gint32 vectors_ID)1133 gimp_vectors_export_to_file (gint32 image_ID,
1134 const gchar *filename,
1135 gint32 vectors_ID)
1136 {
1137 GimpParam *return_vals;
1138 gint nreturn_vals;
1139 gboolean success = TRUE;
1140
1141 return_vals = gimp_run_procedure ("gimp-vectors-export-to-file",
1142 &nreturn_vals,
1143 GIMP_PDB_IMAGE, image_ID,
1144 GIMP_PDB_STRING, filename,
1145 GIMP_PDB_VECTORS, vectors_ID,
1146 GIMP_PDB_END);
1147
1148 success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
1149
1150 gimp_destroy_params (return_vals, nreturn_vals);
1151
1152 return success;
1153 }
1154
1155 /**
1156 * gimp_vectors_export_to_string:
1157 * @image_ID: The image.
1158 * @vectors_ID: The vectors object to save, or 0 for all in the image.
1159 *
1160 * Save a path as an SVG string.
1161 *
1162 * This procedure works like gimp_vectors_export_to_file() but creates
1163 * a string rather than a file. The contents are a NUL-terminated
1164 * string that holds a complete XML document. If you pass 0 as the
1165 * 'vectors' argument, then all paths in the image will be exported.
1166 *
1167 * Returns: A string whose contents are a complete SVG document.
1168 *
1169 * Since: 2.6
1170 **/
1171 gchar *
gimp_vectors_export_to_string(gint32 image_ID,gint32 vectors_ID)1172 gimp_vectors_export_to_string (gint32 image_ID,
1173 gint32 vectors_ID)
1174 {
1175 GimpParam *return_vals;
1176 gint nreturn_vals;
1177 gchar *string = NULL;
1178
1179 return_vals = gimp_run_procedure ("gimp-vectors-export-to-string",
1180 &nreturn_vals,
1181 GIMP_PDB_IMAGE, image_ID,
1182 GIMP_PDB_VECTORS, vectors_ID,
1183 GIMP_PDB_END);
1184
1185 if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
1186 string = g_strdup (return_vals[1].data.d_string);
1187
1188 gimp_destroy_params (return_vals, nreturn_vals);
1189
1190 return string;
1191 }
1192