summaryrefslogtreecommitdiffstats
path: root/pdb/groups/paths.pdb
blob: 8116bd4dd0a52215e6d9e780fa9807e719960b66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
# 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;