1
# The GIMP -- an image manipulation program
2
# Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
# "Perlized" from C source by Andy Thomas <alt@gimp.org>
21
$author = $copyright = 'Andy Thomas';
28
$blurb = 'List the paths associated with the passed image.';
31
List the paths associated with the passed image.
36
@inargs = ( &std_image_arg );
37
$inargs[0]->{desc} = 'The ID of the image to list the paths from';
40
{ name => 'path_list', type => 'stringarray',
41
desc => 'List of the paths belonging to this image.',
42
array => { name => 'num_paths',
43
desc => 'The number of paths returned.' },
48
code => 'path_list = gimp_container_get_name_array (gimage->vectors, &num_paths);'
53
$blurb = 'List the points associated with the named path.';
56
List the points associated with the named path.
63
{ name => 'name', type => 'string',
64
desc => 'The name of the path whose points should be listed.' }
66
$inargs[0]->{desc} = 'The ID of the image to list the paths from.';
69
{ name => 'path_type', type => 'int32', init => 1,
70
desc => 'The type of the path. Currently only one type (1 = Bezier)
72
{ name => 'path_closed', type => 'int32', init => 1,
73
desc => 'Return if the path is closed. (0 = path open, 1 = path
75
{ name => 'points_pairs', type => 'floatarray',
76
desc => 'The points in the path represented as 3 floats. The first is
77
the x pos, next is the y pos, last is the type of the pnt.
78
The type field is dependant on the path type. For beziers
79
(type 1 paths) the type can either be (1.0 = BEZIER_ANCHOR,
80
2.0 = BEZIER_CONTROL, 3.0 = BEZIER_MOVE). Note all points
81
are returned in pixel resolution.',
83
array => { name => 'num_path_point_details',
84
desc => 'The number of points returned. Each point is
85
made up of (x, y, pnt_type) of floats.',
86
alias => 'num_point_details', init => 1 } }
90
vars => [ 'GimpVectors *vectors' ],
93
vectors = gimp_image_get_vectors_by_name (gimage, name);
97
GimpVectorsCompatPoint *points;
100
path_type = 1; /* BEZIER (1.2 compat) */
102
points = gimp_vectors_compat_get_points (vectors, &num_points,
105
num_point_details = num_points * 3;
112
points_pairs = g_new0 (gdouble, num_point_details);
114
for (i = 0, curr_point = points_pairs;
116
i++, curr_point += 3)
118
curr_point[0] = points[i].x;
119
curr_point[1] = points[i].y;
120
curr_point[2] = points[i].type;
135
sub path_get_current {
136
$blurb = 'The name of the current path. Error if no paths.';
139
The name of the current path. Error if no paths.
144
@inargs = ( &std_image_arg );
145
$inargs[0]->{desc} = 'The ID of the image to get the current path from.';
148
{ name => 'name', type => 'string',
149
desc => 'The name of the current path.',
154
vars => [ 'GimpVectors *vectors' ],
157
vectors = gimp_image_get_active_vectors (gimage);
160
name = g_strdup (gimp_object_get_name (GIMP_OBJECT (vectors)));
168
sub path_set_current {
169
$blurb = 'Sets the current path associated with the passed image.';
172
Sets a named path as the current path.
179
{ name => 'name', type => 'string',
180
desc => 'The name of the path to make current.' }
182
$inargs[0]->{desc} = 'The ID of the image in which a path will become current.';
185
vars => [ 'GimpVectors *vectors' ],
188
vectors = gimp_image_get_vectors_by_name (gimage, name);
191
gimp_image_set_active_vectors (gimage, vectors);
199
sub path_set_points {
200
$blurb = 'Set the points associated with the named path.';
203
Set the points associated with the named path.
210
{ name => 'name', type => 'string',
211
desc => 'The name of the path to create. If it exists then a unique
212
name will be created - query the list of paths if you want
213
to make sure that the name of the path you create is
214
unique. This will be set as the current path.',
216
{ name => 'ptype', type => 'int32',
217
desc => 'The type of the path. Currently only one type (1 = Bezier)
219
{ name => 'points_pairs', type => 'floatarray',
220
desc => 'The points in the path represented as 3 floats. The first is
221
the x pos, next is the y pos, last is the type of the pnt.
222
The type field is dependant on the path type. For beziers
223
(type 1 paths) the type can either be (1.0 = BEZIER_ANCHOR,
224
2.0 = BEZIER_CONTROL, 3.0= BEZIER_MOVE). Note all points are
225
returned in pixel resolution.',
226
array => { name => 'num_path_points',
227
desc => 'The number of elements in the array, i.e. the number
228
of points in the path * 3. Each point is
229
made up of (x, y, type) of floats. Currently only
230
the creation of bezier curves is allowed. The type
231
parameter must be set to (1) to indicate a BEZIER
232
type curve. Note that for BEZIER curves, points
233
must be given in the following order: ACCACCAC...
234
If the path is not closed the last control
235
point is missed off. Points consist of three
236
control points (control/anchor/control) so for a
237
curve that is not closed there must be at least
238
two points passed (2 x,y pairs). If
239
(num_path_points/3) % 3 = 0 then the path is
240
assumed to be closed and the points are
244
$inargs[0]->{desc} = 'The ID of the image to set the paths in.';
247
vars => [ 'gboolean closed = FALSE' ],
250
if ((num_path_points / 3) % 3 == 0)
252
else if ((num_path_points / 3) % 3 != 2)
257
GimpVectors *vectors;
258
gdouble *curr_point_pair;
259
GimpVectorsCompatPoint *points;
263
n_points = num_path_points / 3;
265
points = g_new0 (GimpVectorsCompatPoint, n_points);
267
for (i = 0, curr_point_pair = points_pairs;
269
i++, curr_point_pair += 3)
271
points[i].x = curr_point_pair[0];
272
points[i].y = curr_point_pair[1];
273
points[i].type = curr_point_pair[2];
276
vectors = gimp_vectors_compat_new (gimage, name, points, n_points,
282
gimp_image_add_vectors (gimage, vectors, 0);
291
sub path_stroke_current {
292
$blurb = 'Stroke the current path in the passed image.';
295
Stroke the current path in the passed image.
300
@inargs = ( &std_image_arg );
301
$inargs[0]->{desc} = 'The ID of the image which contains the path to
305
headers => [ qw("core/gimpstrokedesc.h") ],
308
GimpVectors *vectors = gimp_image_get_active_vectors (gimage);
309
GimpDrawable *drawable = gimp_image_active_drawable (gimage);
311
if (vectors && drawable)
313
GimpStrokeDesc *desc = gimp_stroke_desc_new (gimp, context);
315
g_object_set (desc, "method", GIMP_STROKE_METHOD_PAINT_CORE, NULL);
317
success = gimp_item_stroke (GIMP_ITEM (vectors),
318
drawable, context, desc, TRUE);
320
g_object_unref (desc);
329
sub path_get_point_at_dist {
330
$blurb = 'Get point on a path at a specified distance along the path.';
333
This will return the x,y position of a point at a given distance along the
334
bezier curve. The distance will be obtained by first digitizing the
335
curve internally and then walking along the curve. For a closed curve the
336
start of the path is the first point on the path that was created. This might
337
not be obvious. Note the current path is used.
344
{ name => 'distance', type => 'float',
345
desc => 'The distance along the path.' }
347
$inargs[0]->{desc} = 'The ID of the image the paths belongs to';
350
{ name => 'x_point', type => 'int32',
351
desc => 'The x position of the point.', init => 1 },
352
{ name => 'y_point', type => 'int32',
353
desc => 'The y position of the point.', init => 1 },
354
{ name => 'slope', type => 'float',
355
desc => 'The slope (dy / dx) at the specified point.', init => 1 }
359
vars => [ 'GimpVectors *vectors', 'GimpStroke *stroke',
360
'gdouble distance_along', 'gdouble stroke_length',
361
'gdouble stroke_distance', 'GimpCoords position' ],
364
vectors = gimp_image_get_active_vectors (gimage);
368
distance_along = 0.0;
369
stroke = gimp_vectors_stroke_get_next (vectors, NULL);
371
while (stroke != NULL )
373
stroke_length = gimp_stroke_get_length (stroke, 0.5);
375
if (distance_along + stroke_length < distance)
377
distance_along += stroke_length;
381
stroke_distance = distance - distance_along;
382
stroke_distance = stroke_distance < 0 ? 0: stroke_distance;
384
if (!gimp_stroke_get_point_at_dist (stroke, stroke_distance, 0.5,
393
x_point = ROUND (position.x);
394
y_point = ROUND (position.y);
399
stroke = gimp_vectors_stroke_get_next (vectors, stroke);
411
sub path_get_tattoo {
412
$blurb = 'Returns the tattoo associated with the name path.';
415
This procedure returns the tattoo associated with the specified path. A
416
tattoo is a unique and permanent identifier attached to a path that can
417
be used to uniquely identify a path within an image even between sessions.
424
{ name => 'name', type => 'string',
425
desc => 'The name of the path whose tattoo should be obtained.' }
429
{ name => 'tattoo', type => 'int32',
430
desc => 'The tattoo associated with the named path.', init => 1 }
434
vars => [ 'GimpVectors *vectors' ],
437
vectors = gimp_image_get_vectors_by_name (gimage, name);
440
tattoo = gimp_item_get_tattoo (GIMP_ITEM (vectors));
448
sub path_set_tattoo {
449
$blurb = 'Sets the tattoo associated with the named path.';
452
This procedure sets the tattoo associated with the specified path. A
453
tattoo is a unique and permenant identifier attached to a path that
454
can be used to uniquely identify a path within an image even between
455
sessions. Note that the value passed to this function must have been
456
obtained from a previous call to path_get_tattoo.
463
{ name => 'name', type => 'string',
464
desc => 'the name of the path whose tattoo should be set' },
465
{ name => 'tattovalue', type => 'int32',
466
desc => "The tattoo associated with the name path. Only values
467
returned from 'path_get_tattoo' should be used here",
472
vars => [ 'GimpVectors *vectors' ],
475
vectors = gimp_image_get_vectors_by_name (gimage, name);
478
gimp_item_set_tattoo (GIMP_ITEM (vectors), tattovalue);
487
sub get_path_by_tattoo {
488
$blurb = 'Return the name of the path with the given tattoo.';
491
The procedure returns the name of the path in the specified image
492
which has the passed tattoo. The tattoos are unique within the image
493
and will be preserved across sessions and through renaming of the path.
494
An error is returned if no path with the specified tattoo can be found.
501
{ name => 'tattoo', type => 'int32',
502
desc => 'The tattoo of the required path.' }
506
{ name => 'name', type => 'string', init => 1,
507
desc => 'The name of the path with the specified tattoo.' }
511
vars => [ 'GimpVectors *vectors' ],
514
vectors = gimp_image_get_vectors_by_tattoo (gimage, tattoo);
517
name = g_strdup (gimp_object_get_name (GIMP_OBJECT (vectors)));
526
$blurb = 'Delete the named path associated with the passed image.';
529
Delete the named path.
536
{ name => 'name', type => 'string',
537
desc => 'The name of the path to delete.' }
539
$inargs[0]->{desc} = 'The ID of the image to delete the path from.';
542
vars => [ 'GimpVectors *vectors' ],
545
vectors = gimp_image_get_vectors_by_name (gimage, name);
548
gimp_image_remove_vectors (gimage, vectors);
556
sub path_get_locked {
557
$blurb = 'Returns the locked status associated with the named path.';
560
This procedure returns the lock status associated with the specified
561
path. A path can be "locked" which means that the transformation
562
tool operations will also apply to the path.
569
{ name => 'name', type => 'string',
570
desc => 'The name of the path whose locked status should be
575
{ name => 'lockstatus', type => 'int32',
576
desc => 'The lock status associated with the name path. 0 is
577
returned if the path is not locked. 1 is returned if the
578
path is locked.', init => 1 }
582
vars => [ 'GimpVectors *vectors' ],
585
vectors = gimp_image_get_vectors_by_name (gimage, name);
588
lockstatus = gimp_item_get_linked (GIMP_ITEM (vectors));
596
sub path_set_locked {
597
$blurb = 'Set the locked status associated with the named path.';
600
This procedure sets the lock status associated with the specified path. A
601
path can be "locked" which means that the transformation tool operations
602
will also apply to the path.
609
{ name => 'name', type => 'string',
610
desc => 'the name of the path whose locked status should be set' },
611
{ name => 'lockstatus', type => 'int32',
612
desc => 'The lock status associated with the name path. 0 if the
613
path is not locked. 1 if the path is to be locked',
618
vars => [ 'GimpVectors *vectors' ],
621
vectors = gimp_image_get_vectors_by_name (gimage, name);
624
gimp_item_set_linked (GIMP_ITEM (vectors), lockstatus, TRUE);
632
sub path_to_selection {
633
$blurb = 'Transforms the active path into a selection';
636
This procedure renders the desired path into the current selection.
640
$author = $copyright = 'Joao S. O. Bueno';
645
{ name => 'name', type => 'string',
646
desc => 'The name of the path which should be made into selection.' },
647
{ name => 'op', type => 'enum GimpChannelOps',
648
desc => 'The desired operation with current selection.' },
649
{ name => 'antialias', type => 'boolean',
650
desc => 'Antialias selection.' },
651
{ name => 'feather', type => 'boolean',
652
desc => 'Feather selection.' },
653
{ name => 'feather_radius_x', type => 'float',
654
desc => 'Feather radius x.' },
655
{ name => 'feather_radius_y', type => 'float',
656
desc => 'Feather radius y.' }
660
vars => [ 'GimpVectors *vectors' ],
663
vectors = gimp_image_get_vectors_by_name (gimage, name);
666
gimp_channel_select_vectors (gimp_image_get_mask (gimage),
667
_("Path to Selection"),
682
$blurb = 'Import paths from an SVG file.';
685
This procedure imports paths from an SVG file. This is a temporary solution
686
until the new vectors PDB API is in place. Don't rely on this function
687
being available in future GIMP releases.
690
$author = $copyright = 'Sven Neumann';
695
{ name => 'filename', type => 'string', no_validate => 1,
696
desc => 'The name of the SVG file to import.' },
697
{ name => 'merge', type => 'boolean',
698
desc => 'Merge paths into a single vectors object.' },
699
{ name => 'scale', type => 'boolean',
700
desc => 'Scale the SVG to image dimensions.' }
704
headers => [ qw("vectors/gimpvectors-import.h") ],
705
code => 'success = gimp_vectors_import_file (gimage, filename, merge, scale, -1, NULL);'
709
@headers = qw(<string.h> "core/gimp.h" "core/gimplist.h"
710
"core/gimpchannel-select.h"
711
"vectors/gimpanchor.h" "vectors/gimpbezierstroke.h"
712
"vectors/gimpvectors.h" "vectors/gimpvectors-compat.h"
715
@procs = qw(path_list path_get_current path_set_current path_delete
716
path_get_points path_set_points
717
path_stroke_current path_get_point_at_dist
718
path_get_tattoo path_set_tattoo get_path_by_tattoo
719
path_get_locked path_set_locked path_to_selection
721
%exports = (app => [@procs], lib => [@procs]);