Gimp/pdb/groups/path.pdb
Jehan dc3e815ff0 app, libgimp*, pdb, plug-ins: rename various public API name s/float/double/.
Several types functions were using the wording "float" historically to
mean double-precision, e.g. the float array type (which was in fact a
double array). Or the scanner function gimp_scanner_parse_float() was in
fact returning a double value. What if we wanted someday to actually add
float (usually this naming means in C the single-precision IEEE 754
floating point representation) support? How would we name this?

Now technically it's not entirely wrong (a double is still a floating
point). So I've been wondering if that is because maybe we never planned
to have float and double precision may be good enough for all usage in a
plug-in API (which doesn't have to be as generic so the higher precision
is enough)? But how can we be sure? Also we already had some functions
using the wording double (e.g. gimp_procedure_add_double_argument()), so
let's just go the safe route and use the accurate wording.

The additional change in PDB is internal, but there too, I was also
finding very confusing that we were naming double-precision float as
'float' type. So I took the opportunity to update this. It doesn't
change any signature.

In fact the whole commit doesn't change any type or code logic, only
naming, except for one bug fix in the middle which I encountered while
renaming: in gimp_scanner_parse_deprecated_color(), I discovered a
hidden bug in scanning (color-hsv*) values, which was mistakenly using a
double type for an array of float.
2024-11-02 15:00:03 +01:00

1162 lines
31 KiB
Text

# 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/>.
sub path_new {
$blurb = 'Creates a new empty path object.';
$help = <<'HELP';
Creates a new empty path object. The path object needs to be added to
the image using gimp_image_insert_path().
HELP
&simon_pdb_misc('2005', '2.4');
@inargs = (
{ name => 'image', type => 'image',
desc => 'The image' },
{ name => 'name', type => 'string',
desc => 'the name of the new path object.' }
);
@outargs = (
{ name => 'path', type => 'path',
desc => 'the current path object, 0 if no path exists
in the image.' }
);
%invoke = (
code => <<'CODE'
{
path = gimp_path_new (image, name);
}
CODE
);
}
sub path_new_from_text_layer {
$blurb = 'Creates a new path object from a text layer.';
$help = <<'HELP';
Creates a new path object from a text layer. The path object needs to
be added to the image using gimp_image_insert_path().
HELP
&marcus_pdb_misc('2008', '2.6');
@inargs = (
{ name => 'image', type => 'image',
desc => 'The image.' },
{ name => 'layer', type => 'layer',
desc => 'The text layer.' }
);
@outargs = (
{ name => 'path', type => 'path',
desc => 'The path of the text layer.' }
);
%invoke = (
code => <<'CODE'
{
if (gimp_pdb_layer_is_text_layer (layer, 0, error))
{
gint x, y;
path = gimp_text_path_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 (path), x, y, FALSE);
}
else
{
success = FALSE;
}
}
CODE
);
}
sub path_copy {
$blurb = 'Copy a path object.';
$help = <<'HELP';
This procedure copies the specified path object and returns the copy.
HELP
barak_pdb_misc('2008', '2.6');
@inargs = (
{ name => 'path', type => 'path',
desc => 'The path object to copy' }
);
@outargs = (
{ name => 'path_copy', type => 'path',
desc => 'The newly copied path object' }
);
%invoke = (
code => <<'CODE'
{
path_copy = GIMP_PATH (gimp_item_duplicate (GIMP_ITEM (path),
G_TYPE_FROM_INSTANCE (path)));
if (! path_copy)
success = FALSE;
}
CODE
);
}
sub path_get_strokes {
$blurb = 'List the strokes associated with the passed path.';
$help = <<'HELP';
Returns an Array with the stroke-IDs associated with the passed path.
HELP
&simon_pdb_misc('2005', '2.4');
@inargs = (
{ name => 'path', type => 'path',
desc => 'The path object' }
);
@outargs = (
{ name => 'stroke_ids', type => 'int32array',
desc => 'List of the strokes belonging to the path.',
array => { name => 'num_strokes',
desc => 'The number of strokes returned.' } }
);
%invoke = (
code => <<"CODE"
{
num_strokes = gimp_path_get_n_strokes (path);
if (num_strokes)
{
GimpStroke *cur_stroke;
gint i = 0;
stroke_ids = g_new (gint32, num_strokes);
for (cur_stroke = gimp_path_stroke_get_next (path, NULL);
cur_stroke;
cur_stroke = gimp_path_stroke_get_next (path, cur_stroke))
{
stroke_ids[i] = gimp_stroke_get_id (cur_stroke);
i++;
}
}
}
CODE
);
}
sub path_stroke_get_length {
$blurb = 'Measure the length of the given stroke.';
$help = 'Measure the length of the given stroke.';
&simon_pdb_misc('2005', '2.4');
@inargs = (
{ name => 'path', type => 'path',
desc => 'The path object' },
{ name => 'stroke_id', type => 'int32',
desc => 'The stroke ID' },
{ name => 'precision', type => '0.0 <= double', default => 0.1,
desc => 'The precision used for approximating straight portions of the stroke' }
);
@outargs = (
{ name => 'length', type => 'double',
desc => 'The length (in pixels) of the given stroke.' }
);
%invoke = (
code => <<"CODE"
{
GimpStroke *stroke = gimp_pdb_get_path_stroke (path, stroke_id, 0, error);
if (stroke)
length = gimp_stroke_get_length (stroke, precision);
else
success = FALSE;
}
CODE
);
}
sub path_stroke_get_point_at_dist {
$blurb = 'Get point at a specified distance along the stroke.';
$help = <<'HELP';
This will return the x,y position of a point at a given distance along the
stroke. The distance will be obtained by first digitizing the
curve internally and then walking along the curve. For a closed stroke the
start of the path is the first point on the path that was created. This might
not be obvious. If the stroke is not long enough, a "valid" flag will be FALSE.
HELP
&simon_pdb_misc('2005', '2.4');
@inargs = (
{ name => 'path', type => 'path',
desc => 'The path object' },
{ name => 'stroke_id', type => 'int32',
desc => 'The stroke ID' },
{ name => 'dist', type => 'double',
desc => 'The given distance.' },
{ name => 'precision', type => 'double',
desc => 'The precision used for the approximation' }
);
@outargs = (
{ name => 'x_point', type => 'double', void_ret => 1,
desc => 'The x position of the point.' },
{ name => 'y_point', type => 'double',
desc => 'The y position of the point.' },
{ name => 'slope', type => 'double',
desc => 'The slope (dy / dx) at the specified point.' },
{ name => 'valid', type => 'boolean',
desc => 'Indicator for the validity of the returned data.' }
);
%invoke = (
code => <<"CODE"
{
GimpStroke *stroke = gimp_pdb_get_path_stroke (path, stroke_id, 0, 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;
}
CODE
);
}
sub path_remove_stroke {
$blurb = 'remove the stroke from a path object.';
$help = <<'HELP';
Remove the stroke from a path object.
HELP
&simon_pdb_misc('2005', '2.4');
@inargs = (
{ name => 'path', type => 'path',
desc => 'The path object' },
{ name => 'stroke_id', type => 'int32',
desc => 'The stroke ID' }
);
%invoke = (
code => <<"CODE"
{
GimpStroke *stroke = gimp_pdb_get_path_stroke (path, stroke_id,
GIMP_PDB_ITEM_CONTENT, error);
if (stroke)
{
if (gimp_item_is_attached (GIMP_ITEM (path)))
gimp_image_undo_push_path_mod (gimp_item_get_image (GIMP_ITEM (path)),
_("Remove path stroke"),
path);
gimp_path_stroke_remove (path, stroke);
}
else
success = FALSE;
}
CODE
);
}
sub path_stroke_close {
$blurb = 'closes the specified stroke.';
$help = <<'HELP';
Closes the specified stroke.
HELP
&simon_pdb_misc('2005', '2.4');
@inargs = (
{ name => 'path', type => 'path',
desc => 'The path object' },
{ name => 'stroke_id', type => 'int32',
desc => 'The stroke ID' }
);
%invoke = (
code => <<"CODE"
{
GimpStroke *stroke = gimp_pdb_get_path_stroke (path, stroke_id,
GIMP_PDB_ITEM_CONTENT, error);
if (stroke)
{
if (gimp_item_is_attached (GIMP_ITEM (path)))
gimp_image_undo_push_path_mod (gimp_item_get_image (GIMP_ITEM (path)),
_("Close path stroke"),
path);
gimp_path_freeze (path);
gimp_stroke_close (stroke);
gimp_path_thaw (path);
}
else
success = FALSE;
}
CODE
);
}
sub path_stroke_reverse {
$blurb = 'reverses the specified stroke.';
$help = <<'HELP';
Reverses the specified stroke.
HELP
&simon_pdb_misc('2020', '3.0');
@inargs = (
{ name => 'path', type => 'path',
desc => 'The path object' },
{ name => 'stroke_id', type => 'int32',
desc => 'The stroke ID' }
);
%invoke = (
code => <<"CODE"
{
GimpStroke *stroke = gimp_pdb_get_path_stroke (path, stroke_id,
GIMP_PDB_ITEM_CONTENT, error);
if (stroke)
{
if (gimp_item_is_attached (GIMP_ITEM (path)))
gimp_image_undo_push_path_mod (gimp_item_get_image (GIMP_ITEM (path)),
_("Reverse path stroke"),
path);
gimp_path_freeze (path);
gimp_stroke_reverse (stroke);
gimp_path_thaw (path);
}
else
success = FALSE;
}
CODE
);
}
sub path_stroke_translate {
$blurb = 'translate the given stroke.';
$help = <<'HELP';
Translate the given stroke.
HELP
&simon_pdb_misc('2005', '2.4');
@inargs = (
{ name => 'path', type => 'path',
desc => 'The path object' },
{ name => 'stroke_id', type => 'int32',
desc => 'The stroke ID' },
{ name => "off_x", type => 'double',
desc => "Offset in x direction" },
{ name => "off_y", type => 'double',
desc => "Offset in y direction" }
);
%invoke = (
code => <<"CODE"
{
GimpStroke *stroke = gimp_pdb_get_path_stroke (path, stroke_id,
GIMP_PDB_ITEM_CONTENT |
GIMP_PDB_ITEM_POSITION,
error);
if (stroke)
{
if (gimp_item_is_attached (GIMP_ITEM (path)))
gimp_image_undo_push_path_mod (gimp_item_get_image (GIMP_ITEM (path)),
_("Translate path stroke"),
path);
gimp_path_freeze (path);
gimp_stroke_translate (stroke, off_x, off_y);
gimp_path_thaw (path);
}
else
success = FALSE;
}
CODE
);
}
sub path_stroke_scale {
$blurb = 'scales the given stroke.';
$help = <<'HELP';
Scale the given stroke.
HELP
&simon_pdb_misc('2005', '2.4');
@inargs = (
{ name => 'path', type => 'path',
desc => 'The path object' },
{ name => 'stroke_id', type => 'int32',
desc => 'The stroke ID' },
{ name => "scale_x", type => 'double',
desc => "Scale factor in x direction" },
{ name => "scale_y", type => 'double',
desc => "Scale factor in y direction" }
);
%invoke = (
code => <<"CODE"
{
GimpStroke *stroke = gimp_pdb_get_path_stroke (path, stroke_id,
GIMP_PDB_ITEM_CONTENT |
GIMP_PDB_ITEM_POSITION,
error);
if (stroke)
{
if (gimp_item_is_attached (GIMP_ITEM (path)))
gimp_image_undo_push_path_mod (gimp_item_get_image (GIMP_ITEM (path)),
_("Scale path stroke"),
path);
gimp_path_freeze (path);
gimp_stroke_scale (stroke, scale_x, scale_y);
gimp_path_thaw (path);
}
else
success = FALSE;
}
CODE
);
}
sub path_stroke_rotate {
$blurb = 'rotates the given stroke.';
$help = <<'HELP';
Rotates the given stroke around given center by angle (in degrees).
HELP
&joao_pdb_misc('2006', '2.4');
@inargs = (
{ name => 'path', type => 'path',
desc => 'The path object' },
{ name => 'stroke_id', type => 'int32',
desc => 'The stroke ID' },
{ name => "center_x", type => 'double',
desc => "X coordinate of the rotation center" },
{ name => "center_y", type => 'double',
desc => "Y coordinate of the rotation center" },
{ name => "angle", type => 'double',
desc => "angle to rotate about" }
);
%invoke = (
code => <<"CODE"
{
GimpStroke *stroke = gimp_pdb_get_path_stroke (path, stroke_id,
GIMP_PDB_ITEM_CONTENT |
GIMP_PDB_ITEM_POSITION,
error);
if (stroke)
{
if (gimp_item_is_attached (GIMP_ITEM (path)))
gimp_image_undo_push_path_mod (gimp_item_get_image (GIMP_ITEM (path)),
_("Rotate path stroke"),
path);
gimp_path_freeze (path);
gimp_stroke_rotate (stroke, center_x, center_y, angle);
gimp_path_thaw (path);
}
else
success = FALSE;
}
CODE
);
}
sub path_stroke_flip {
$blurb = 'flips the given stroke.';
$help = <<'HELP';
Rotates the given stroke around given center by angle (in degrees).
HELP
&joao_pdb_misc('2006', '2.4');
@inargs = (
{ name => 'path', type => 'path',
desc => 'The path object' },
{ name => 'stroke_id', type => 'int32',
desc => 'The stroke ID' },
{ name => "flip_type",
type => 'enum GimpOrientationType (no GIMP_ORIENTATION_UNKNOWN)',
desc => "Flip orientation, either vertical or horizontal" },
{ name => "axis", type => 'double',
desc => "axis coordinate about which to flip, in pixels" }
);
%invoke = (
code => <<"CODE"
{
GimpStroke *stroke = gimp_pdb_get_path_stroke (path, stroke_id,
GIMP_PDB_ITEM_CONTENT |
GIMP_PDB_ITEM_POSITION,
error);
if (stroke)
{
if (gimp_item_is_attached (GIMP_ITEM (path)))
gimp_image_undo_push_path_mod (gimp_item_get_image (GIMP_ITEM (path)),
_("Flip path stroke"),
path);
gimp_path_freeze (path);
gimp_stroke_flip (stroke, flip_type, axis);
gimp_path_thaw (path);
}
else
success = FALSE;
}
CODE
);
}
sub path_stroke_flip_free {
$blurb = 'flips the given stroke about an arbitrary axis.';
$help = <<'HELP';
Flips the given stroke about an arbitrary axis. Axis is defined by two coordinates
in the image (in pixels), through which the flipping axis passes.
HELP
&joao_pdb_misc('2006', '2.4');
@inargs = (
{ name => 'path', type => 'path',
desc => 'The path object' },
{ name => 'stroke_id', type => 'int32',
desc => 'The stroke ID' },
{ name => "x1", type => 'double',
desc => "X coordinate of the first point of the flipping axis" },
{ name => "y1", type => 'double',
desc => "Y coordinate of the first point of the flipping axis" },
{ name => "x2", type => 'double',
desc => "X coordinate of the second point of the flipping axis" },
{ name => "y2", type => 'double',
desc => "Y coordinate of the second point of the flipping axis" },
);
%invoke = (
code => <<"CODE"
{
GimpStroke *stroke = gimp_pdb_get_path_stroke (path, stroke_id,
GIMP_PDB_ITEM_CONTENT |
GIMP_PDB_ITEM_POSITION,
error);
if (stroke)
{
if (gimp_item_is_attached (GIMP_ITEM (path)))
gimp_image_undo_push_path_mod (gimp_item_get_image (GIMP_ITEM (path)),
_("Flip path stroke"),
path);
gimp_path_freeze (path);
gimp_stroke_flip_free (stroke, x1, y1, x2, y2);
gimp_path_thaw (path);
}
else
success = FALSE;
}
CODE
);
}
sub path_stroke_get_points {
$blurb = 'returns the control points of a stroke.';
$help = <<'HELP';
returns the control points of a stroke. The interpretation of the coordinates
returned depends on the type of the stroke. For Gimp 2.4 this is always a
bezier stroke, where the coordinates are the control points.
HELP
&simon_pdb_misc('2006', '2.4');
@inargs = (
{ name => 'path', type => 'path',
desc => 'The path object' },
{ name => 'stroke_id', type => 'int32',
desc => 'The stroke ID' }
);
@outargs = (
{ name => 'type', type => 'enum GimpPathStrokeType',
desc => 'type of the stroke (always GIMP_PATH_STROKE_TYPE_BEZIER for now).' },
{ name => 'controlpoints', type => 'doublearray',
desc => 'List of the control points for the stroke (x0, y0, x1, y1, ...).',
array => { name => 'num_points',
desc => 'The number of floats returned.' } },
{ name => 'closed', type => 'boolean',
desc => 'Whether the stroke is closed or not.' }
);
%invoke = (
code => <<"CODE"
{
GimpStroke *stroke = gimp_pdb_get_path_stroke (path, stroke_id, 0, 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_PATH_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;
}
CODE
);
}
sub path_stroke_interpolate {
$blurb = 'returns polygonal approximation of the stroke.';
$help = <<'HELP';
returns polygonal approximation of the stroke.
HELP
&simon_pdb_misc('2005', '2.4');
@inargs = (
{ name => 'path', type => 'path',
desc => 'The path object' },
{ name => 'stroke_id', type => 'int32',
desc => 'The stroke ID' },
{ name => 'precision', type => 'double',
desc => 'The precision used for the approximation' }
);
@outargs = (
{ name => 'coords', type => 'doublearray',
desc => 'List of the coords along the path (x0, y0, x1, y1, ...).',
array => { name => 'num_coords',
desc => 'The number of floats returned.' } },
{ name => 'closed', type => 'boolean',
desc => 'Whether the stroke is closed or not.' }
);
%invoke = (
code => <<"CODE"
{
GimpStroke *stroke = gimp_pdb_get_path_stroke (path, stroke_id, 0, 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;
}
CODE
);
}
sub path_stroke_new_from_points {
$blurb = 'Adds a stroke of a given type to the path object.';
$help = <<'HELP';
Adds a stroke of a given type to the path object. The coordinates of the
control points can be specified.
For now only strokes of the type GIMP_PATH_STROKE_TYPE_BEZIER are supported.
The control points are specified as a pair of double values for the x- and
y-coordinate.
The Bezier stroke type needs a multiple of three control points. Each Bezier
segment endpoint (anchor, A) has two additional control points (C) associated.
They are specified in the order CACCACCAC...
HELP
&simon_pdb_misc('2006', '2.4');
@inargs = (
{ name => 'path', type => 'path',
desc => 'The path object' },
{ name => 'type', type => 'enum GimpPathStrokeType',
desc => 'type of the stroke (always GIMP_PATH_STROKE_TYPE_BEZIER for now).' },
{ name => 'controlpoints', type => 'doublearray',
desc => 'List of the x- and y-coordinates of the control points.',
array => { name => 'num_points',
desc => 'The number of elements in the array, i.e. the
number of controlpoints in the stroke * 2
(x- and y-coordinate).' } },
{ name => 'closed', type => 'boolean',
desc => 'Whether the stroke is to be closed or not.' }
);
@outargs = (
{ name => 'stroke_id', type => 'int32',
desc => 'The stroke ID of the newly created stroke.' }
);
%invoke = (
code => <<"CODE"
{
GimpStroke *stroke;
GimpCoords *coords;
GimpCoords default_coords = GIMP_COORDS_DEFAULT_VALUES;
gint i;
success = FALSE;
if (type == GIMP_PATH_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 (path)))
gimp_image_undo_push_path_mod (gimp_item_get_image (GIMP_ITEM (path)),
_("Add path stroke"),
path);
gimp_path_stroke_add (path, stroke);
g_object_unref (stroke);
stroke_id = gimp_stroke_get_id (stroke);
success = TRUE;
}
g_free (coords);
}
}
CODE
);
}
sub path_bezier_stroke_new_moveto {
$blurb = 'Adds a bezier stroke with a single moveto to the path object.';
$help = <<'HELP';
Adds a bezier stroke with a single moveto to the path object.
HELP
&simon_pdb_misc('2005', '2.4');
@inargs = (
{ name => 'path', type => 'path',
desc => 'The path object' },
{ name => 'x0', type => 'double',
desc => 'The x-coordinate of the moveto' },
{ name => 'y0', type => 'double',
desc => 'The y-coordinate of the moveto' }
);
@outargs = (
{ name => 'stroke_id', type => 'int32',
desc => 'The resulting stroke' }
);
%invoke = (
code => <<"CODE"
{
if (gimp_pdb_item_is_modifiable (GIMP_ITEM (path),
GIMP_PDB_ITEM_CONTENT, error) &&
gimp_pdb_item_is_not_group (GIMP_ITEM (path), 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 (path)))
gimp_image_undo_push_path_mod (gimp_item_get_image (GIMP_ITEM (path)),
_("Add path stroke"),
path);
gimp_path_stroke_add (path, stroke);
g_object_unref (stroke);
stroke_id = gimp_stroke_get_id (stroke);
}
else
success = FALSE;
}
CODE
);
}
sub path_bezier_stroke_lineto {
$blurb = 'Extends a bezier stroke with a lineto.';
$help = <<'HELP';
Extends a bezier stroke with a lineto.
HELP
&simon_pdb_misc('2005', '2.4');
@inargs = (
{ name => 'path', type => 'path',
desc => 'The path object' },
{ name => 'stroke_id', type => 'int32',
desc => 'The stroke ID' },
{ name => 'x0', type => 'double',
desc => 'The x-coordinate of the lineto' },
{ name => 'y0', type => 'double',
desc => 'The y-coordinate of the lineto' }
);
%invoke = (
code => <<"CODE"
{
GimpStroke *stroke = gimp_pdb_get_path_stroke (path, stroke_id,
GIMP_PDB_ITEM_CONTENT, error);
if (stroke)
{
GimpCoords coord0 = GIMP_COORDS_DEFAULT_VALUES;
coord0.x = x0;
coord0.y = y0;
if (gimp_item_is_attached (GIMP_ITEM (path)))
gimp_image_undo_push_path_mod (gimp_item_get_image (GIMP_ITEM (path)),
_("Extend path stroke"),
path);
gimp_path_freeze (path);
gimp_bezier_stroke_lineto (stroke, &coord0);
gimp_path_thaw (path);
}
else
success = FALSE;
}
CODE
);
}
sub path_bezier_stroke_conicto {
$blurb = 'Extends a bezier stroke with a conic bezier spline.';
$help = <<'HELP';
Extends a bezier stroke with a conic bezier spline. Actually a
cubic bezier spline gets added that realizes the shape of a conic
bezier spline.
HELP
&simon_pdb_misc('2005', '2.4');
@inargs = (
{ name => 'path', type => 'path',
desc => 'The path object' },
{ name => 'stroke_id', type => 'int32',
desc => 'The stroke ID' },
{ name => 'x0', type => 'double',
desc => 'The x-coordinate of the control point' },
{ name => 'y0', type => 'double',
desc => 'The y-coordinate of the control point' },
{ name => 'x1', type => 'double',
desc => 'The x-coordinate of the end point' },
{ name => 'y1', type => 'double',
desc => 'The y-coordinate of the end point' }
);
%invoke = (
code => <<"CODE"
{
GimpStroke *stroke = gimp_pdb_get_path_stroke (path, stroke_id,
GIMP_PDB_ITEM_CONTENT, 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 (path)))
gimp_image_undo_push_path_mod (gimp_item_get_image (GIMP_ITEM (path)),
_("Extend path stroke"),
path);
gimp_path_freeze (path);
gimp_bezier_stroke_conicto (stroke, &coord0, &coord1);
gimp_path_thaw (path);
}
else
success = FALSE;
}
CODE
);
}
sub path_bezier_stroke_cubicto {
$blurb = 'Extends a bezier stroke with a cubic bezier spline.';
$help = <<'HELP';
Extends a bezier stroke with a cubic bezier spline.
HELP
&simon_pdb_misc('2005', '2.4');
@inargs = (
{ name => 'path', type => 'path',
desc => 'The path object' },
{ name => 'stroke_id', type => 'int32',
desc => 'The stroke ID' },
{ name => 'x0', type => 'double',
desc => 'The x-coordinate of the first control point' },
{ name => 'y0', type => 'double',
desc => 'The y-coordinate of the first control point' },
{ name => 'x1', type => 'double',
desc => 'The x-coordinate of the second control point' },
{ name => 'y1', type => 'double',
desc => 'The y-coordinate of the second control point' },
{ name => 'x2', type => 'double',
desc => 'The x-coordinate of the end point' },
{ name => 'y2', type => 'double',
desc => 'The y-coordinate of the end point' }
);
%invoke = (
code => <<"CODE"
{
GimpStroke *stroke = gimp_pdb_get_path_stroke (path, stroke_id,
GIMP_PDB_ITEM_CONTENT, 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 (path)))
gimp_image_undo_push_path_mod (gimp_item_get_image (GIMP_ITEM (path)),
_("Extend path stroke"),
path);
gimp_path_freeze (path);
gimp_bezier_stroke_cubicto (stroke, &coord0, &coord1, &coord2);
gimp_path_thaw (path);
}
else
success = FALSE;
}
CODE
);
}
sub path_bezier_stroke_new_ellipse {
$blurb = 'Adds a bezier stroke describing an ellipse the path object.';
$help = <<'HELP';
Adds a bezier stroke describing an ellipse on the path object.
HELP
&simon_pdb_misc('2005', '2.4');
@inargs = (
{ name => 'path', type => 'path',
desc => 'The path object' },
{ name => 'x0', type => 'double',
desc => 'The x-coordinate of the center' },
{ name => 'y0', type => 'double',
desc => 'The y-coordinate of the center' },
{ name => 'radius_x', type => 'double',
desc => 'The radius in x direction' },
{ name => 'radius_y', type => 'double',
desc => 'The radius in y direction' },
{ name => 'angle', type => 'double',
desc => 'The angle the x-axis of the ellipse
(radians, counterclockwise)' }
);
@outargs = (
{ name => 'stroke_id', type => 'int32',
desc => 'The resulting stroke' }
);
%invoke = (
code => <<"CODE"
{
if (gimp_pdb_item_is_modifiable (GIMP_ITEM (path),
GIMP_PDB_ITEM_CONTENT, error) &&
gimp_pdb_item_is_not_group (GIMP_ITEM (path), 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 (path)))
gimp_image_undo_push_path_mod (gimp_item_get_image (GIMP_ITEM (path)),
_("Add path stroke"),
path);
gimp_path_stroke_add (path, stroke);
g_object_unref (stroke);
stroke_id = gimp_stroke_get_id (stroke);
}
else
success = FALSE;
}
CODE
);
}
@headers = qw(<string.h>
"core/gimplist.h"
"core/gimpimage.h"
"core/gimpimage-undo-push.h"
"text/gimptext-path.h"
"text/gimptextlayer.h"
"vectors/gimpanchor.h"
"vectors/gimpstroke-new.h"
"vectors/gimpbezierstroke.h"
"vectors/gimppath.h"
"gimppdb-utils.h"
"gimp-intl.h");
@procs = qw(path_new
path_new_from_text_layer
path_copy
path_get_strokes
path_stroke_get_length
path_stroke_get_point_at_dist
path_remove_stroke
path_stroke_close
path_stroke_reverse
path_stroke_translate
path_stroke_scale
path_stroke_rotate
path_stroke_flip
path_stroke_flip_free
path_stroke_get_points
path_stroke_new_from_points
path_stroke_interpolate
path_bezier_stroke_new_moveto
path_bezier_stroke_lineto
path_bezier_stroke_conicto
path_bezier_stroke_cubicto
path_bezier_stroke_new_ellipse);
%exports = (app => [@procs], lib => [@procs]);
$desc = 'Path';
$doc_title = 'gimppath';
$doc_short_desc = 'Functions for querying and manipulating path.';
$doc_long_desc = 'Functions for querying and manipulating path.';
1;