forked from openkylin/gimp
637 lines
17 KiB
Plaintext
637 lines
17 KiB
Plaintext
# GIMP - The GNU Image Manipulation Program
|
|
# Copyright (C) 1995 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 <https://www.gnu.org/licenses/>.
|
|
|
|
# "Perlized" from C source by Andy Thomas <alt@gimp.org>
|
|
|
|
sub path_list {
|
|
&std_pdb_deprecated('gimp-image-get-vectors');
|
|
|
|
@inargs = (
|
|
{ name => 'image', type => 'image',
|
|
desc => 'The image to list the paths from' }
|
|
);
|
|
|
|
@outargs = (
|
|
{ name => 'path_list', type => 'stringarray',
|
|
desc => 'List of the paths belonging to this image',
|
|
array => { name => 'num_paths',
|
|
desc => 'The number of paths returned.' } }
|
|
);
|
|
|
|
%invoke = (
|
|
code => <<'CODE'
|
|
{
|
|
path_list = gimp_container_get_name_array (gimp_image_get_vectors (image),
|
|
&num_paths);
|
|
}
|
|
CODE
|
|
);
|
|
}
|
|
|
|
sub path_get_points {
|
|
&std_pdb_deprecated('gimp-vectors-stroke-get-points');
|
|
|
|
@inargs = (
|
|
{ name => 'image', type => 'image',
|
|
desc => 'The image to list the paths from' },
|
|
{ name => 'name', type => 'string',
|
|
desc => 'The name of the path whose points should be listed.' }
|
|
);
|
|
|
|
@outargs = (
|
|
{ name => 'path_type', type => 'int32',
|
|
desc => 'The type of the path. Currently only one type (1 = Bezier)
|
|
is supported' },
|
|
{ name => 'path_closed', type => 'int32',
|
|
desc => 'Return if the path is closed. (0 = path open, 1 = path
|
|
closed)' },
|
|
{ name => 'points_pairs', type => 'floatarray',
|
|
desc => 'The points in the path represented as 3 floats. The first is
|
|
the x pos, next is the y pos, last is the type of the pnt.
|
|
The type field is dependent on the path type. For beziers
|
|
(type 1 paths) the type can either be (1.0 = BEZIER_ANCHOR,
|
|
2.0 = BEZIER_CONTROL, 3.0 = BEZIER_MOVE). Note all points
|
|
are returned in pixel resolution.',
|
|
array => { name => 'num_path_point_details',
|
|
desc => 'The number of points returned. Each point is
|
|
made up of (x, y, pnt_type) of floats.' } }
|
|
);
|
|
|
|
%invoke = (
|
|
code => <<'CODE'
|
|
{
|
|
GimpVectors *vectors = gimp_image_get_vectors_by_name (image, name);
|
|
|
|
if (vectors)
|
|
{
|
|
GimpVectorsCompatPoint *points;
|
|
gint num_points;
|
|
|
|
path_type = 1; /* BEZIER (1.2 compat) */
|
|
|
|
points = gimp_vectors_compat_get_points (vectors, &num_points,
|
|
&path_closed);
|
|
|
|
num_path_point_details = num_points * 3;
|
|
|
|
if (points)
|
|
{
|
|
gdouble *curr_point;
|
|
gint i;
|
|
|
|
points_pairs = g_new0 (gdouble, num_path_point_details);
|
|
|
|
for (i = 0, curr_point = points_pairs;
|
|
i < num_points;
|
|
i++, curr_point += 3)
|
|
{
|
|
curr_point[0] = points[i].x;
|
|
curr_point[1] = points[i].y;
|
|
curr_point[2] = points[i].type;
|
|
}
|
|
|
|
g_free (points);
|
|
}
|
|
else
|
|
success = FALSE;
|
|
}
|
|
else
|
|
success = FALSE;
|
|
}
|
|
CODE
|
|
);
|
|
}
|
|
|
|
sub path_get_current {
|
|
&std_pdb_deprecated('gimp-image-get-active-vectors');
|
|
|
|
@inargs = (
|
|
{ name => 'image', type => 'image',
|
|
desc => 'The image to get the current path from' },
|
|
);
|
|
|
|
@outargs = (
|
|
{ name => 'name', type => 'string',
|
|
desc => 'The name of the current path.' }
|
|
);
|
|
|
|
%invoke = (
|
|
code => <<'CODE'
|
|
{
|
|
GimpVectors *vectors = gimp_image_get_active_vectors (image);
|
|
|
|
if (vectors)
|
|
name = g_strdup (gimp_object_get_name (vectors));
|
|
else
|
|
success = FALSE;
|
|
}
|
|
CODE
|
|
);
|
|
}
|
|
|
|
sub path_set_current {
|
|
&std_pdb_deprecated('gimp-image-set-active-vectors');
|
|
|
|
@inargs = (
|
|
{ name => 'image', type => 'image',
|
|
desc => 'The image in which a path will become current' },
|
|
{ name => 'name', type => 'string',
|
|
desc => 'The name of the path to make current.' }
|
|
);
|
|
|
|
%invoke = (
|
|
code => <<'CODE'
|
|
{
|
|
GimpVectors *vectors = gimp_image_get_vectors_by_name (image, name);
|
|
|
|
if (vectors)
|
|
gimp_image_set_active_vectors (image, vectors);
|
|
else
|
|
success = FALSE;
|
|
}
|
|
CODE
|
|
);
|
|
}
|
|
|
|
sub path_set_points {
|
|
&std_pdb_deprecated('gimp-vectors-stroke-new-from-points');
|
|
|
|
@inargs = (
|
|
{ name => 'image', type => 'image',
|
|
desc => 'The image to set the paths in' },
|
|
{ name => 'name', type => 'string',
|
|
desc => 'The name of the path to create. If it exists then a unique
|
|
name will be created - query the list of paths if you want
|
|
to make sure that the name of the path you create is
|
|
unique. This will be set as the current path.' },
|
|
{ name => 'ptype', type => 'int32', dead => 1,
|
|
desc => 'The type of the path. Currently only one type (1 = Bezier)
|
|
is supported.' },
|
|
{ name => 'points_pairs', type => 'floatarray',
|
|
desc => 'The points in the path represented as 3 floats. The first is
|
|
the x pos, next is the y pos, last is the type of the pnt.
|
|
The type field is dependent on the path type. For beziers
|
|
(type 1 paths) the type can either be (1.0 = BEZIER_ANCHOR,
|
|
2.0 = BEZIER_CONTROL, 3.0= BEZIER_MOVE). Note all points are
|
|
returned in pixel resolution.',
|
|
array => { name => 'num_path_points',
|
|
desc => 'The number of elements in the array, i.e. the number
|
|
of points in the path * 3. Each point is
|
|
made up of (x, y, type) of floats. Currently only
|
|
the creation of bezier curves is allowed. The type
|
|
parameter must be set to (1) to indicate a BEZIER
|
|
type curve. Note that for BEZIER curves, points
|
|
must be given in the following order: ACCACCAC...
|
|
If the path is not closed the last control
|
|
point is missed off. Points consist of three
|
|
control points (control/anchor/control) so for a
|
|
curve that is not closed there must be at least
|
|
two points passed (2 x,y pairs). If
|
|
(num_path_points/3) % 3 = 0 then the path is
|
|
assumed to be closed and the points are
|
|
ACCACCACCACC.' } }
|
|
);
|
|
|
|
%invoke = (
|
|
code => <<'CODE'
|
|
{
|
|
gboolean closed = FALSE;
|
|
|
|
if ((num_path_points / 3) % 3 == 0)
|
|
closed = TRUE;
|
|
else if ((num_path_points / 3) % 3 != 2)
|
|
success = FALSE;
|
|
|
|
if (success)
|
|
{
|
|
GimpVectors *vectors;
|
|
const gdouble *curr_point_pair;
|
|
GimpVectorsCompatPoint *points;
|
|
gint n_points;
|
|
gint i;
|
|
|
|
n_points = num_path_points / 3;
|
|
|
|
points = g_new0 (GimpVectorsCompatPoint, n_points);
|
|
|
|
for (i = 0, curr_point_pair = points_pairs;
|
|
i < n_points;
|
|
i++, curr_point_pair += 3)
|
|
{
|
|
points[i].x = curr_point_pair[0];
|
|
points[i].y = curr_point_pair[1];
|
|
points[i].type = curr_point_pair[2];
|
|
}
|
|
|
|
vectors = gimp_vectors_compat_new (image, name, points, n_points,
|
|
closed);
|
|
|
|
g_free (points);
|
|
|
|
if (vectors)
|
|
success = gimp_image_add_vectors (image, vectors, NULL, 0, TRUE);
|
|
else
|
|
success = FALSE;
|
|
}
|
|
}
|
|
CODE
|
|
);
|
|
}
|
|
|
|
sub path_stroke_current {
|
|
&std_pdb_deprecated('gimp-edit-stroke-vectors');
|
|
|
|
@inargs = (
|
|
{ name => 'image', type => 'image',
|
|
desc => 'The image which contains the path to stroke' },
|
|
);
|
|
|
|
%invoke = (
|
|
headers => [ qw("core/gimpstrokeoptions.h") ],
|
|
code => <<'CODE'
|
|
{
|
|
GimpVectors *vectors = gimp_image_get_active_vectors (image);
|
|
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
|
|
|
|
if (vectors && drawable &&
|
|
gimp_pdb_item_is_modifiable (GIMP_ITEM (drawable),
|
|
GIMP_PDB_ITEM_CONTENT, error) &&
|
|
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
|
|
{
|
|
GimpStrokeOptions *options;
|
|
GimpPaintOptions *paint_options;
|
|
|
|
options = gimp_stroke_options_new (gimp, context, TRUE);
|
|
g_object_set (options,
|
|
"method", GIMP_STROKE_PAINT_METHOD,
|
|
NULL);
|
|
|
|
paint_options =
|
|
gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context), NULL);
|
|
paint_options = gimp_config_duplicate (GIMP_CONFIG (paint_options));
|
|
|
|
success = gimp_item_stroke (GIMP_ITEM (vectors),
|
|
drawable, context, options, paint_options,
|
|
TRUE, progress, error);
|
|
|
|
g_object_unref (options);
|
|
g_object_unref (paint_options);
|
|
}
|
|
else
|
|
success = FALSE;
|
|
}
|
|
CODE
|
|
);
|
|
}
|
|
|
|
sub path_get_point_at_dist {
|
|
&std_pdb_deprecated('gimp-vectors-stroke-get-point-at-dist');
|
|
|
|
@inargs = (
|
|
{ name => 'image', type => 'image',
|
|
desc => 'The image the paths belongs to' },
|
|
{ name => 'distance', type => 'float',
|
|
desc => 'The distance along the path.' }
|
|
);
|
|
|
|
@outargs = (
|
|
{ name => 'x_point', type => 'int32',
|
|
desc => 'The x position of the point.' },
|
|
{ name => 'y_point', type => 'int32',
|
|
desc => 'The y position of the point.' },
|
|
{ name => 'slope', type => 'float',
|
|
desc => 'The slope (dy / dx) at the specified point.' }
|
|
);
|
|
|
|
%invoke = (
|
|
code => <<'CODE'
|
|
{
|
|
GimpVectors *vectors;
|
|
GimpStroke *stroke;
|
|
gdouble distance_along;
|
|
gdouble stroke_length;
|
|
gdouble stroke_distance;
|
|
GimpCoords position;
|
|
|
|
vectors = gimp_image_get_active_vectors (image);
|
|
|
|
if (vectors)
|
|
{
|
|
distance_along = 0.0;
|
|
stroke = gimp_vectors_stroke_get_next (vectors, NULL);
|
|
|
|
while (stroke != NULL )
|
|
{
|
|
stroke_length = gimp_stroke_get_length (stroke, 0.5);
|
|
|
|
if (distance_along + stroke_length < distance)
|
|
{
|
|
distance_along += stroke_length;
|
|
}
|
|
else
|
|
{
|
|
stroke_distance = distance - distance_along;
|
|
stroke_distance = stroke_distance < 0 ? 0: stroke_distance;
|
|
|
|
if (!gimp_stroke_get_point_at_dist (stroke, stroke_distance, 0.5,
|
|
&position, &slope))
|
|
{
|
|
success = FALSE;
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
success = TRUE;
|
|
x_point = ROUND (position.x);
|
|
y_point = ROUND (position.y);
|
|
break;
|
|
}
|
|
}
|
|
|
|
stroke = gimp_vectors_stroke_get_next (vectors, stroke);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
success = FALSE;
|
|
}
|
|
}
|
|
CODE
|
|
);
|
|
}
|
|
|
|
sub path_get_tattoo {
|
|
&std_pdb_deprecated('gimp-vectors-get-tattoo');
|
|
|
|
@inargs = (
|
|
{ name => 'image', type => 'image',
|
|
desc => 'The image' },
|
|
{ name => 'name', type => 'string',
|
|
desc => 'The name of the path whose tattoo should be obtained.' }
|
|
);
|
|
|
|
@outargs = (
|
|
{ name => 'tattoo', type => 'int32',
|
|
desc => 'The tattoo associated with the named path.' }
|
|
);
|
|
|
|
%invoke = (
|
|
code => <<'CODE'
|
|
{
|
|
GimpVectors *vectors = gimp_image_get_vectors_by_name (image, name);
|
|
|
|
if (vectors)
|
|
tattoo = gimp_item_get_tattoo (GIMP_ITEM (vectors));
|
|
else
|
|
success = FALSE;
|
|
}
|
|
CODE
|
|
);
|
|
}
|
|
|
|
sub path_set_tattoo {
|
|
&std_pdb_deprecated('gimp-vectors-set-tattoo');
|
|
|
|
@inargs = (
|
|
{ name => 'image', type => 'image',
|
|
desc => 'The image' },
|
|
{ name => 'name', type => 'string',
|
|
desc => 'the name of the path whose tattoo should be set' },
|
|
{ name => 'tattovalue', type => 'int32',
|
|
desc => "The tattoo associated with the name path. Only values
|
|
returned from 'path_get_tattoo' should be used here" }
|
|
);
|
|
|
|
%invoke = (
|
|
code => <<'CODE'
|
|
{
|
|
GimpVectors *vectors = gimp_image_get_vectors_by_name (image, name);
|
|
|
|
if (vectors)
|
|
gimp_item_set_tattoo (GIMP_ITEM (vectors), tattovalue);
|
|
else
|
|
success = FALSE;
|
|
}
|
|
CODE
|
|
);
|
|
}
|
|
|
|
sub get_path_by_tattoo {
|
|
&std_pdb_deprecated('gimp-image-get-vectors-by-tattoo');
|
|
|
|
@inargs = (
|
|
{ name => 'image', type => 'image',
|
|
desc => 'The image' },
|
|
{ name => 'tattoo', type => 'int32',
|
|
desc => 'The tattoo of the required path.' }
|
|
);
|
|
|
|
@outargs = (
|
|
{ name => 'name', type => 'string',
|
|
desc => 'The name of the path with the specified tattoo.' }
|
|
);
|
|
|
|
%invoke = (
|
|
code => <<'CODE'
|
|
{
|
|
GimpVectors *vectors = gimp_image_get_vectors_by_tattoo (image, tattoo);
|
|
|
|
if (vectors)
|
|
name = g_strdup (gimp_object_get_name (vectors));
|
|
else
|
|
success = FALSE;
|
|
}
|
|
CODE
|
|
);
|
|
}
|
|
|
|
sub path_delete {
|
|
&std_pdb_deprecated('gimp-image-remove-vectors');
|
|
|
|
@inargs = (
|
|
{ name => 'image', type => 'image',
|
|
desc => 'The image to delete the path from' },
|
|
{ name => 'name', type => 'string',
|
|
desc => 'The name of the path to delete.' }
|
|
);
|
|
|
|
%invoke = (
|
|
code => <<'CODE'
|
|
{
|
|
GimpVectors *vectors = gimp_image_get_vectors_by_name (image, name);
|
|
|
|
if (vectors)
|
|
gimp_image_remove_vectors (image, vectors, TRUE, NULL);
|
|
else
|
|
success = FALSE;
|
|
}
|
|
CODE
|
|
);
|
|
}
|
|
|
|
sub path_get_locked {
|
|
&std_pdb_deprecated('gimp-vectors-get-linked');
|
|
|
|
@inargs = (
|
|
{ name => 'image', type => 'image',
|
|
desc => 'The image' },
|
|
{ name => 'name', type => 'string',
|
|
desc => 'The name of the path whose locked status should be
|
|
obtained.' }
|
|
);
|
|
|
|
@outargs = (
|
|
{ name => 'locked', type => 'boolean',
|
|
desc => 'TRUE if the path is locked, FALSE otherwise' }
|
|
);
|
|
|
|
%invoke = (
|
|
code => <<'CODE'
|
|
{
|
|
GimpVectors *vectors = gimp_image_get_vectors_by_name (image, name);
|
|
|
|
if (vectors)
|
|
locked = gimp_item_get_linked (GIMP_ITEM (vectors));
|
|
else
|
|
success = FALSE;
|
|
}
|
|
CODE
|
|
);
|
|
}
|
|
|
|
sub path_set_locked {
|
|
&std_pdb_deprecated('gimp-vectors-set-linked');
|
|
|
|
@inargs = (
|
|
{ name => 'image', type => 'image',
|
|
desc => 'The image' },
|
|
{ name => 'name', type => 'string',
|
|
desc => 'the name of the path whose locked status should be set' },
|
|
{ name => 'locked', type => 'boolean',
|
|
desc => 'Whether the path is locked' }
|
|
);
|
|
|
|
%invoke = (
|
|
code => <<'CODE'
|
|
{
|
|
GimpVectors *vectors = gimp_image_get_vectors_by_name (image, name);
|
|
|
|
if (vectors)
|
|
gimp_item_set_linked (GIMP_ITEM (vectors), locked, TRUE);
|
|
else
|
|
success = FALSE;
|
|
}
|
|
CODE
|
|
);
|
|
}
|
|
|
|
sub path_to_selection {
|
|
&std_pdb_deprecated('gimp-vectors-to-selection');
|
|
|
|
@inargs = (
|
|
{ name => 'image', type => 'image',
|
|
desc => 'The image' },
|
|
{ name => 'name', type => 'string',
|
|
desc => 'The name of the path which should be made into selection.' },
|
|
{ name => 'op', type => 'enum GimpChannelOps',
|
|
desc => 'The desired operation with current selection' },
|
|
{ name => 'antialias', type => 'boolean',
|
|
desc => 'Antialias selection.' },
|
|
{ name => 'feather', type => 'boolean',
|
|
desc => 'Feather selection.' },
|
|
{ name => 'feather_radius_x', type => 'float',
|
|
desc => 'Feather radius x.' },
|
|
{ name => 'feather_radius_y', type => 'float',
|
|
desc => 'Feather radius y.' }
|
|
);
|
|
|
|
%invoke = (
|
|
code => <<'CODE'
|
|
{
|
|
GimpVectors *vectors = gimp_image_get_vectors_by_name (image, name);
|
|
|
|
if (vectors)
|
|
gimp_item_to_selection (GIMP_ITEM (vectors),
|
|
op,
|
|
antialias,
|
|
feather,
|
|
feather_radius_x,
|
|
feather_radius_y);
|
|
else
|
|
success = FALSE;
|
|
}
|
|
CODE
|
|
);
|
|
}
|
|
|
|
sub path_import {
|
|
&std_pdb_deprecated('gimp-vectors-import-from-file');
|
|
|
|
@inargs = (
|
|
{ name => 'image', type => 'image',
|
|
desc => 'The image' },
|
|
{ name => 'filename', type => 'string', allow_non_utf8 => 1,
|
|
desc => 'The name of the SVG file to import.' },
|
|
{ name => 'merge', type => 'boolean',
|
|
desc => 'Merge paths into a single vectors object.' },
|
|
{ name => 'scale', type => 'boolean',
|
|
desc => 'Scale the SVG to image dimensions.' }
|
|
);
|
|
|
|
%invoke = (
|
|
headers => [ qw("vectors/gimpvectors-import.h") ],
|
|
code => <<'CODE'
|
|
{
|
|
GFile *file = g_file_new_for_path (filename);
|
|
|
|
success = gimp_vectors_import_file (image, file,
|
|
merge, scale, NULL, -1, NULL, NULL);
|
|
|
|
g_object_unref (file);
|
|
}
|
|
CODE
|
|
);
|
|
}
|
|
|
|
|
|
@headers = qw(<string.h>
|
|
"libgimpconfig/gimpconfig.h"
|
|
"libgimpmath/gimpmath.h"
|
|
"core/gimplist.h"
|
|
"vectors/gimpanchor.h"
|
|
"vectors/gimpbezierstroke.h"
|
|
"vectors/gimpvectors.h"
|
|
"vectors/gimpvectors-compat.h"
|
|
"gimppdb-utils.h"
|
|
"gimppdbcontext.h"
|
|
"gimp-intl.h");
|
|
|
|
@procs = qw(path_list path_get_current path_set_current path_delete
|
|
path_get_points path_set_points
|
|
path_stroke_current path_get_point_at_dist
|
|
path_get_tattoo path_set_tattoo get_path_by_tattoo
|
|
path_get_locked path_set_locked
|
|
path_to_selection path_import);
|
|
|
|
%exports = (app => [@procs], lib => [@procs]);
|
|
|
|
$desc = 'Paths';
|
|
$doc_title = 'gimppaths';
|
|
$doc_short_desc = 'Deprecated operations related to paths.';
|
|
$doc_long_desc = 'Deprecated operations related to paths.';
|
|
|
|
1;
|