~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/pygimp/pygimp-vectors.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; c-basic-offset: 4 -*-
 
2
    Gimp-Python - allows the writing of Gimp plugins in Python.
 
3
    Copyright (C) 2006  Manish Singh <yosh@gimp.org>
 
4
 
 
5
    This program is free software; you can redistribute it and/or modify
 
6
    it under the terms of the GNU General Public License as published by
 
7
    the Free Software Foundation; either version 2 of the License, or
 
8
    (at your option) any later version.
 
9
 
 
10
    This program is distributed in the hope that it will be useful,
 
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
    GNU General Public License for more details.
 
14
 
 
15
    You should have received a copy of the GNU General Public License
 
16
    along with this program; if not, write to the Free Software
 
17
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
18
    02111-1307, USA.
 
19
 */
 
20
 
 
21
#ifdef HAVE_CONFIG_H
 
22
#  include <config.h>
 
23
#endif
 
24
 
 
25
#include "pygimp.h"
 
26
 
 
27
 
 
28
static PyObject *vectors_bezier_stroke_new(PyGimpVectors *vectors, int stroke);
 
29
 
 
30
 
 
31
typedef struct {
 
32
    PyObject_HEAD
 
33
    gint32 vectors_ID;
 
34
    int stroke;
 
35
} PyGimpVectorsStroke;
 
36
 
 
37
static PyObject *
 
38
vs_get_length(PyGimpVectorsStroke *self, PyObject *args, PyObject *kwargs)
 
39
{
 
40
    double precision;
 
41
    double length;
 
42
 
 
43
    static char *kwlist[] = { "precision", NULL };
 
44
 
 
45
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "d:get_length", kwlist,
 
46
                                     &precision))
 
47
        return NULL;
 
48
 
 
49
    length = gimp_vectors_stroke_get_length(self->vectors_ID, self->stroke,
 
50
                                            precision);
 
51
 
 
52
    return PyFloat_FromDouble(length);
 
53
}
 
54
 
 
55
static PyObject *
 
56
vs_get_point_at_dist(PyGimpVectorsStroke *self, PyObject *args, PyObject *kwargs)
 
57
{
 
58
    double dist, precision;
 
59
    double x, y, slope;
 
60
    gboolean valid;
 
61
    PyObject *ret;
 
62
 
 
63
    static char *kwlist[] = { "dist", "precision", NULL };
 
64
 
 
65
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
66
                                     "dd:get_point_at_dist", kwlist,
 
67
                                     &dist, &precision))
 
68
        return NULL;
 
69
 
 
70
    gimp_vectors_stroke_get_point_at_dist(self->vectors_ID, self->stroke,
 
71
                                          dist, precision,
 
72
                                          &x, &y, &slope, &valid);
 
73
 
 
74
    ret = PyTuple_New(4);
 
75
    if (ret == NULL)
 
76
        return NULL;
 
77
 
 
78
    PyTuple_SetItem(ret, 0, PyFloat_FromDouble(x));
 
79
    PyTuple_SetItem(ret, 1, PyFloat_FromDouble(y));
 
80
    PyTuple_SetItem(ret, 2, PyFloat_FromDouble(slope));
 
81
    PyTuple_SetItem(ret, 3, PyBool_FromLong(valid));
 
82
 
 
83
    return ret;
 
84
}
 
85
 
 
86
static PyObject *
 
87
vs_close(PyGimpVectorsStroke *self)
 
88
{
 
89
    gimp_vectors_stroke_close(self->vectors_ID, self->stroke);
 
90
    Py_INCREF(Py_None);
 
91
    return Py_None;
 
92
}
 
93
 
 
94
 
 
95
static PyObject *
 
96
vs_translate(PyGimpVectorsStroke *self, PyObject *args, PyObject *kwargs)
 
97
{
 
98
    double off_x, off_y;
 
99
 
 
100
    static char *kwlist[] = { "off_x", "off_y", NULL };
 
101
 
 
102
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "dd:translate", kwlist,
 
103
                                     &off_x, &off_y))
 
104
        return NULL;
 
105
 
 
106
    gimp_vectors_stroke_translate(self->vectors_ID, self->stroke, off_x, off_y);
 
107
 
 
108
    Py_INCREF(Py_None);
 
109
    return Py_None;
 
110
}
 
111
 
 
112
static PyObject *
 
113
vs_scale(PyGimpVectorsStroke *self, PyObject *args, PyObject *kwargs)
 
114
{
 
115
    double scale_x, scale_y;
 
116
 
 
117
    static char *kwlist[] = { "scale_x", "scale_y", NULL };
 
118
 
 
119
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "dd:scale", kwlist,
 
120
                                     &scale_x, &scale_y))
 
121
        return NULL;
 
122
 
 
123
    gimp_vectors_stroke_scale(self->vectors_ID, self->stroke, scale_x, scale_y);
 
124
 
 
125
    Py_INCREF(Py_None);
 
126
    return Py_None;
 
127
}
 
128
 
 
129
static PyObject *
 
130
vs_rotate(PyGimpVectorsStroke *self, PyObject *args, PyObject *kwargs)
 
131
{
 
132
    double center_x, center_y, angle;
 
133
 
 
134
    static char *kwlist[] = { "center_x", "center_y", "angle", NULL };
 
135
 
 
136
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ddd:rotate", kwlist,
 
137
                                     &center_x, &center_y, &angle))
 
138
        return NULL;
 
139
 
 
140
    gimp_vectors_stroke_rotate(self->vectors_ID, self->stroke, center_x,
 
141
                               center_y, angle);
 
142
 
 
143
    Py_INCREF(Py_None);
 
144
    return Py_None;
 
145
}
 
146
 
 
147
static PyObject *
 
148
vs_flip(PyGimpVectorsStroke *self, PyObject *args, PyObject *kwargs)
 
149
{
 
150
    int    flip_type;
 
151
    double axis;
 
152
 
 
153
    static char *kwlist[] = { "flip_type", "axis", NULL };
 
154
 
 
155
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "id:rotate", kwlist,
 
156
                                     &flip_type, &axis))
 
157
        return NULL;
 
158
 
 
159
    gimp_vectors_stroke_flip(self->vectors_ID, self->stroke, flip_type, axis);
 
160
 
 
161
    Py_INCREF(Py_None);
 
162
    return Py_None;
 
163
}
 
164
 
 
165
static PyObject *
 
166
vs_flip_free(PyGimpVectorsStroke *self, PyObject *args, PyObject *kwargs)
 
167
{
 
168
    double x1,y1,x2,y2;
 
169
 
 
170
    static char *kwlist[] = { "x1", "y1", "x2", "y2", NULL };
 
171
 
 
172
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "dddd:rotate", kwlist,
 
173
                                     &x1, &y1, &x2, &y2))
 
174
        return NULL;
 
175
 
 
176
    gimp_vectors_stroke_flip_free(self->vectors_ID, self->stroke,
 
177
                                  x1, y1, x2, y2);
 
178
    Py_INCREF(Py_None);
 
179
    return Py_None;
 
180
}
 
181
 
 
182
 
 
183
 
 
184
static PyObject *
 
185
vs_interpolate(PyGimpVectorsStroke *self, PyObject *args, PyObject *kwargs)
 
186
{
 
187
    double precision;
 
188
    double *coords;
 
189
    int i, num_coords;
 
190
    gboolean closed;
 
191
    PyObject *ret, *ret_coords;
 
192
 
 
193
    static char *kwlist[] = { "precision", NULL };
 
194
 
 
195
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "d:interpolate", kwlist,
 
196
                                     &precision))
 
197
        return NULL;
 
198
 
 
199
    coords = gimp_vectors_stroke_interpolate(self->vectors_ID, self->stroke,
 
200
                                             precision, &num_coords, &closed);
 
201
 
 
202
    ret = PyTuple_New(2);
 
203
    if (ret == NULL)
 
204
        return NULL;
 
205
 
 
206
    ret_coords = PyList_New(num_coords);
 
207
    if (ret_coords == NULL) {
 
208
        Py_DECREF(ret);
 
209
        return NULL;
 
210
    }
 
211
 
 
212
    for (i = 0; i < num_coords; i++)
 
213
        PyList_SetItem(ret_coords, i, PyFloat_FromDouble(coords[i]));
 
214
 
 
215
    PyTuple_SetItem(ret, 0, ret_coords);
 
216
    PyTuple_SetItem(ret, 1, PyBool_FromLong(closed));
 
217
 
 
218
    return ret;
 
219
}
 
220
 
 
221
static PyMethodDef vs_methods[] = {
 
222
    { "get_length", (PyCFunction)vs_get_length, METH_VARARGS | METH_KEYWORDS },
 
223
    { "get_point_at_dist", (PyCFunction)vs_get_point_at_dist, METH_VARARGS | METH_KEYWORDS },
 
224
    { "close", (PyCFunction)vs_close, METH_NOARGS },
 
225
    { "translate", (PyCFunction)vs_translate, METH_VARARGS | METH_KEYWORDS },
 
226
    { "scale", (PyCFunction)vs_scale, METH_VARARGS | METH_KEYWORDS },
 
227
    { "rotate", (PyCFunction)vs_rotate, METH_VARARGS | METH_KEYWORDS },
 
228
    { "flip", (PyCFunction)vs_flip, METH_VARARGS | METH_KEYWORDS },
 
229
    { "flip_free", (PyCFunction)vs_flip_free, METH_VARARGS | METH_KEYWORDS },
 
230
    { "interpolate", (PyCFunction)vs_interpolate, METH_VARARGS | METH_KEYWORDS },
 
231
    { NULL, NULL, 0 }
 
232
};
 
233
 
 
234
static PyObject *
 
235
vs_get_ID(PyGimpVectorsStroke *self, void *closure)
 
236
{
 
237
    return PyInt_FromLong(self->stroke);
 
238
}
 
239
 
 
240
static PyObject *
 
241
vs_get_vectors_ID(PyGimpVectorsStroke *self, void *closure)
 
242
{
 
243
    return PyInt_FromLong(self->vectors_ID);
 
244
}
 
245
 
 
246
static PyObject *
 
247
vs_get_points(PyGimpVectorsStroke *self, void *closure)
 
248
{
 
249
    double *controlpoints;
 
250
    int i, num_points;
 
251
    gboolean closed;
 
252
    PyObject *ret, *ret_points;
 
253
 
 
254
    gimp_vectors_stroke_get_points(self->vectors_ID, self->stroke,
 
255
                                   &num_points, &controlpoints, &closed);
 
256
 
 
257
    ret = PyTuple_New(2);
 
258
    if (ret == NULL)
 
259
        return NULL;
 
260
 
 
261
    ret_points = PyList_New(num_points);
 
262
    if (ret_points == NULL) {
 
263
        Py_DECREF(ret);
 
264
        return NULL;
 
265
    }
 
266
 
 
267
    for (i = 0; i < num_points; i++)
 
268
        PyList_SetItem(ret_points, i, PyFloat_FromDouble(controlpoints[i]));
 
269
 
 
270
    PyTuple_SetItem(ret, 0, ret_points);
 
271
    PyTuple_SetItem(ret, 1, PyBool_FromLong(closed));
 
272
 
 
273
    return ret;
 
274
}
 
275
 
 
276
static PyGetSetDef vs_getsets[] = {
 
277
    { "ID", (getter)vs_get_ID, (setter)0 },
 
278
    { "vectors_ID", (getter)vs_get_vectors_ID, (setter)0 },
 
279
    { "points", (getter)vs_get_points, (setter)0 },
 
280
    { NULL, (getter)0, (setter)0 }
 
281
};
 
282
 
 
283
static void
 
284
vs_dealloc(PyGimpVectorsStroke *self)
 
285
{
 
286
    PyObject_DEL(self);
 
287
}
 
288
 
 
289
static PyObject *
 
290
vs_repr(PyGimpVectorsStroke *self)
 
291
{
 
292
    PyObject *s;
 
293
    char *name;
 
294
 
 
295
    name = gimp_vectors_get_name(self->vectors_ID);
 
296
    s = PyString_FromFormat("<gimp.VectorsStroke %d of gimp.Vectors '%s'>",
 
297
                            self->stroke, name ? name : "(null)");
 
298
    g_free(name);
 
299
 
 
300
    return s;
 
301
}
 
302
 
 
303
static int
 
304
vs_cmp(PyGimpVectorsStroke *self, PyGimpVectorsStroke *other)
 
305
{
 
306
    if (self->vectors_ID == other->vectors_ID) {
 
307
        if (self->stroke == other->stroke)
 
308
            return 0;
 
309
        if (self->stroke > other->stroke)
 
310
            return -1;
 
311
        return 1;
 
312
    }
 
313
    if (self->vectors_ID > other->vectors_ID)
 
314
        return -1;
 
315
    return 1;
 
316
}
 
317
 
 
318
PyTypeObject PyGimpVectorsStroke_Type = {
 
319
    PyObject_HEAD_INIT(NULL)
 
320
    0,                                  /* ob_size */
 
321
    "gimp.VectorsStroke",               /* tp_name */
 
322
    sizeof(PyGimpVectorsStroke),        /* tp_basicsize */
 
323
    0,                                  /* tp_itemsize */
 
324
    /* methods */
 
325
    (destructor)vs_dealloc,             /* tp_dealloc */
 
326
    (printfunc)0,                       /* tp_print */
 
327
    (getattrfunc)0,                     /* tp_getattr */
 
328
    (setattrfunc)0,                     /* tp_setattr */
 
329
    (cmpfunc)vs_cmp,                    /* tp_compare */
 
330
    (reprfunc)vs_repr,                  /* tp_repr */
 
331
    0,                                  /* tp_as_number */
 
332
    0,                                  /* tp_as_sequence */
 
333
    0,                                  /* tp_as_mapping */
 
334
    (hashfunc)0,                        /* tp_hash */
 
335
    (ternaryfunc)0,                     /* tp_call */
 
336
    (reprfunc)0,                        /* tp_str */
 
337
    (getattrofunc)0,                    /* tp_getattro */
 
338
    (setattrofunc)0,                    /* tp_setattro */
 
339
    0,                                  /* tp_as_buffer */
 
340
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
 
341
    NULL, /* Documentation string */
 
342
    (traverseproc)0,                    /* tp_traverse */
 
343
    (inquiry)0,                         /* tp_clear */
 
344
    (richcmpfunc)0,                     /* tp_richcompare */
 
345
    0,                                  /* tp_weaklistoffset */
 
346
    (getiterfunc)0,                     /* tp_iter */
 
347
    (iternextfunc)0,                    /* tp_iternext */
 
348
    vs_methods,                         /* tp_methods */
 
349
    0,                                  /* tp_members */
 
350
    vs_getsets,                         /* tp_getset */
 
351
    (PyTypeObject *)0,                  /* tp_base */
 
352
    (PyObject *)0,                      /* tp_dict */
 
353
    0,                                  /* tp_descr_get */
 
354
    0,                                  /* tp_descr_set */
 
355
    0,                                  /* tp_dictoffset */
 
356
    (initproc)0,                        /* tp_init */
 
357
    (allocfunc)0,                       /* tp_alloc */
 
358
    (newfunc)0,                         /* tp_new */
 
359
};
 
360
 
 
361
 
 
362
static PyObject *
 
363
vbs_new_moveto(PyTypeObject *type, PyObject *args, PyObject *kwargs)
 
364
{
 
365
    PyGimpVectors *vectors;
 
366
    double x0, y0;
 
367
    int stroke;
 
368
 
 
369
    static char *kwlist[] = { "vectors", "x0", "y0", NULL };
 
370
 
 
371
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
372
                                     "O!dd:new_moveto", kwlist,
 
373
                                     &PyGimpVectors_Type, &vectors,
 
374
                                     &x0, &y0))
 
375
        return NULL;
 
376
 
 
377
    stroke = gimp_vectors_bezier_stroke_new_moveto(vectors->ID, x0, y0);
 
378
 
 
379
    return vectors_bezier_stroke_new(vectors, stroke);
 
380
}
 
381
 
 
382
static PyObject *
 
383
vbs_new_ellipse(PyTypeObject *type, PyObject *args, PyObject *kwargs)
 
384
{
 
385
    PyGimpVectors *vectors;
 
386
    double x0, y0, radius_x, radius_y, angle;
 
387
    int stroke;
 
388
 
 
389
    static char *kwlist[] = { "vectors", "x0", "y0", "radius_x", "radius_y",
 
390
                              "angle", NULL };
 
391
 
 
392
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
393
                                     "O!ddddd:new_ellipse", kwlist,
 
394
                                     &PyGimpVectors_Type, &vectors,
 
395
                                     &x0, &y0, &radius_x, &radius_y, &angle))
 
396
        return NULL;
 
397
 
 
398
    stroke = gimp_vectors_bezier_stroke_new_ellipse(vectors->ID, x0, y0,
 
399
                                                    radius_x, radius_y, angle);
 
400
 
 
401
    return vectors_bezier_stroke_new(vectors, stroke);
 
402
}
 
403
 
 
404
static PyObject *
 
405
vbs_lineto(PyGimpVectorsStroke *self, PyObject *args, PyObject *kwargs)
 
406
{
 
407
    double x0, y0;
 
408
 
 
409
    static char *kwlist[] = { "x0", "y0", NULL };
 
410
 
 
411
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
412
                                     "dd:lineto", kwlist,
 
413
                                     &x0, &y0))
 
414
        return NULL;
 
415
 
 
416
    gimp_vectors_bezier_stroke_lineto(self->vectors_ID, self->stroke, x0, y0);
 
417
 
 
418
    Py_INCREF(Py_None);
 
419
    return Py_None;
 
420
}
 
421
 
 
422
static PyObject *
 
423
vbs_conicto(PyGimpVectorsStroke *self, PyObject *args, PyObject *kwargs)
 
424
{
 
425
    double x0, y0, x1, y1;
 
426
 
 
427
    static char *kwlist[] = { "x0", "y0", "x1", "y1", NULL };
 
428
 
 
429
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
430
                                     "dddd:conicto", kwlist,
 
431
                                     &x0, &y0, &x1, &y1))
 
432
        return NULL;
 
433
 
 
434
    gimp_vectors_bezier_stroke_conicto(self->vectors_ID, self->stroke,
 
435
                                       x0, y0, x1, y1);
 
436
 
 
437
    Py_INCREF(Py_None);
 
438
    return Py_None;
 
439
}
 
440
 
 
441
static PyObject *
 
442
vbs_cubicto(PyGimpVectorsStroke *self, PyObject *args, PyObject *kwargs)
 
443
{
 
444
    double x0, y0, x1, y1, x2, y2;
 
445
 
 
446
    static char *kwlist[] = { "x0", "y0", "x1", "y1", "x2", "y2", NULL };
 
447
 
 
448
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
449
                                     "dddddd:conicto", kwlist,
 
450
                                     &x0, &y0, &x1, &y1, &x2, &y2))
 
451
        return NULL;
 
452
 
 
453
    gimp_vectors_bezier_stroke_cubicto(self->vectors_ID, self->stroke,
 
454
                                       x0, y0, x1, y1, x2, y2);
 
455
 
 
456
    Py_INCREF(Py_None);
 
457
    return Py_None;
 
458
}
 
459
 
 
460
static PyMethodDef vbs_methods[] = {
 
461
    { "new_moveto", (PyCFunction)vbs_new_moveto, METH_VARARGS | METH_KEYWORDS | METH_CLASS },
 
462
    { "new_ellipse", (PyCFunction)vbs_new_ellipse, METH_VARARGS | METH_KEYWORDS | METH_CLASS },
 
463
    { "lineto", (PyCFunction)vbs_lineto, METH_VARARGS | METH_KEYWORDS },
 
464
    { "conicto", (PyCFunction)vbs_conicto, METH_VARARGS | METH_KEYWORDS },
 
465
    { "cubicto", (PyCFunction)vbs_cubicto, METH_VARARGS | METH_KEYWORDS },
 
466
    { NULL, NULL, 0 }
 
467
};
 
468
 
 
469
static PyObject *
 
470
vbs_repr(PyGimpVectorsStroke *self)
 
471
{
 
472
    PyObject *s;
 
473
    char *name;
 
474
 
 
475
    name = gimp_vectors_get_name(self->vectors_ID);
 
476
    s = PyString_FromFormat("<gimp.VectorsBezierStroke %d of gimp.Vectors '%s'>",
 
477
                            self->stroke, name ? name : "(null)");
 
478
    g_free(name);
 
479
 
 
480
    return s;
 
481
}
 
482
 
 
483
static int
 
484
vbs_init(PyGimpVectorsStroke *self, PyObject *args, PyObject *kwargs)
 
485
{
 
486
    PyGimpVectors *vectors;
 
487
    double *controlpoints;
 
488
    gboolean closed = FALSE;
 
489
    PyObject *py_controlpoints, *item;
 
490
    int i, num_points;
 
491
 
 
492
    static char *kwlist[] = { "vectors", "controlpoints", "closed", NULL };
 
493
 
 
494
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
495
                                     "O!O|i:gimp.VectorsBezierStroke.__init__",
 
496
                                     kwlist,
 
497
                                     &PyGimpVectors_Type, &vectors,
 
498
                                     &py_controlpoints, &closed));
 
499
        return -1;
 
500
 
 
501
    if (!PySequence_Check(py_controlpoints)) {
 
502
        PyErr_SetString(PyExc_TypeError,
 
503
                        "controlpoints must be a sequence");
 
504
        return -1;
 
505
    }
 
506
 
 
507
    num_points = PySequence_Length(py_controlpoints);
 
508
    controlpoints = g_new(gdouble, num_points);
 
509
 
 
510
    for (i = 0; i < num_points; i++) {
 
511
        item = PySequence_GetItem(py_controlpoints, i);
 
512
 
 
513
        if (!PyFloat_Check(item)) {
 
514
            PyErr_SetString(PyExc_TypeError,
 
515
                            "controlpoints must be a sequence of floats");
 
516
            g_free(controlpoints);
 
517
            return -1;
 
518
        }
 
519
 
 
520
        controlpoints[i] = PyFloat_AsDouble(item);
 
521
    }
 
522
 
 
523
    self->vectors_ID = vectors->ID;
 
524
    self->stroke =
 
525
        gimp_vectors_stroke_new_from_points(self->vectors_ID,
 
526
                                            GIMP_VECTORS_STROKE_TYPE_BEZIER,
 
527
                                            num_points, controlpoints, closed);
 
528
 
 
529
    g_free(controlpoints);
 
530
 
 
531
    return 0;
 
532
}
 
533
 
 
534
PyTypeObject PyGimpVectorsBezierStroke_Type = {
 
535
    PyObject_HEAD_INIT(NULL)
 
536
    0,                                  /* ob_size */
 
537
    "gimp.VectorsBezierStroke",         /* tp_name */
 
538
    sizeof(PyGimpVectorsStroke),        /* tp_basicsize */
 
539
    0,                                  /* tp_itemsize */
 
540
    /* methods */
 
541
    (destructor)vs_dealloc,             /* tp_dealloc */
 
542
    (printfunc)0,                       /* tp_print */
 
543
    (getattrfunc)0,                     /* tp_getattr */
 
544
    (setattrfunc)0,                     /* tp_setattr */
 
545
    (cmpfunc)vs_cmp,                    /* tp_compare */
 
546
    (reprfunc)vbs_repr,                 /* tp_repr */
 
547
    0,                                  /* tp_as_number */
 
548
    0,                                  /* tp_as_sequence */
 
549
    0,                                  /* tp_as_mapping */
 
550
    (hashfunc)0,                        /* tp_hash */
 
551
    (ternaryfunc)0,                     /* tp_call */
 
552
    (reprfunc)0,                        /* tp_str */
 
553
    (getattrofunc)0,                    /* tp_getattro */
 
554
    (setattrofunc)0,                    /* tp_setattro */
 
555
    0,                                  /* tp_as_buffer */
 
556
    Py_TPFLAGS_DEFAULT,                 /* tp_flags */
 
557
    NULL, /* Documentation string */
 
558
    (traverseproc)0,                    /* tp_traverse */
 
559
    (inquiry)0,                         /* tp_clear */
 
560
    (richcmpfunc)0,                     /* tp_richcompare */
 
561
    0,                                  /* tp_weaklistoffset */
 
562
    (getiterfunc)0,                     /* tp_iter */
 
563
    (iternextfunc)0,                    /* tp_iternext */
 
564
    vbs_methods,                        /* tp_methods */
 
565
    0,                                  /* tp_members */
 
566
    0,                                  /* tp_getset */
 
567
    &PyGimpVectorsStroke_Type,          /* tp_base */
 
568
    (PyObject *)0,                      /* tp_dict */
 
569
    0,                                  /* tp_descr_get */
 
570
    0,                                  /* tp_descr_set */
 
571
    0,                                  /* tp_dictoffset */
 
572
    (initproc)vbs_init,                 /* tp_init */
 
573
    (allocfunc)0,                       /* tp_alloc */
 
574
    (newfunc)0,                         /* tp_new */
 
575
};
 
576
 
 
577
static PyObject *
 
578
vectors_bezier_stroke_new(PyGimpVectors *vectors, int stroke)
 
579
{
 
580
    PyGimpVectorsStroke *self;
 
581
 
 
582
    self = PyObject_NEW(PyGimpVectorsStroke, &PyGimpVectorsBezierStroke_Type);
 
583
 
 
584
    if (self == NULL)
 
585
        return NULL;
 
586
 
 
587
    self->vectors_ID = vectors->ID;
 
588
    self->stroke = stroke;
 
589
 
 
590
    return (PyObject *)self;
 
591
}
 
592
 
 
593
 
 
594
static PyObject *
 
595
vectors_remove_stroke(PyGimpVectors *self, PyObject *args, PyObject *kwargs)
 
596
{
 
597
    int stroke;
 
598
 
 
599
    static char *kwlist[] = { "stroke", NULL };
 
600
 
 
601
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:remove_stroke", kwlist,
 
602
                                     &stroke))
 
603
        return NULL;
 
604
 
 
605
 
 
606
    gimp_vectors_remove_stroke(self->ID, stroke);
 
607
 
 
608
    Py_INCREF(Py_None);
 
609
    return Py_None;
 
610
}
 
611
 
 
612
static PyObject *
 
613
vectors_to_selection(PyGimpVectors *self, PyObject *args, PyObject *kwargs)
 
614
{
 
615
    GimpChannelOps operation = GIMP_CHANNEL_OP_REPLACE;
 
616
    gboolean antialias = TRUE, feather = FALSE;
 
617
    double feather_radius_x = 0.0, feather_radius_y = 0.0;
 
618
 
 
619
    static char *kwlist[] = { "operation", "antialias", "feather",
 
620
                              "feather_radius_x", "feather_radius_y", NULL };
 
621
 
 
622
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
623
                                     "|iiidd:to_selection", kwlist,
 
624
                                     &operation, &antialias, &feather,
 
625
                                     &feather_radius_x, &feather_radius_y))
 
626
        return NULL;
 
627
 
 
628
    gimp_vectors_to_selection(self->ID, operation, antialias, feather,
 
629
                              feather_radius_x, feather_radius_y);
 
630
 
 
631
    Py_INCREF(Py_None);
 
632
    return Py_None;
 
633
}
 
634
 
 
635
static PyObject *
 
636
vectors_parasite_find(PyGimpVectors *self, PyObject *args)
 
637
{
 
638
    char *name;
 
639
 
 
640
    if (!PyArg_ParseTuple(args, "s:parasite_find", &name))
 
641
        return NULL;
 
642
 
 
643
    return pygimp_parasite_new(gimp_vectors_parasite_find(self->ID, name));
 
644
}
 
645
 
 
646
static PyObject *
 
647
vectors_parasite_attach(PyGimpVectors *self, PyObject *args)
 
648
{
 
649
    PyGimpParasite *parasite;
 
650
 
 
651
    if (!PyArg_ParseTuple(args, "O!:parasite_attach", &PyGimpParasite_Type,
 
652
                          &parasite))
 
653
        return NULL;
 
654
 
 
655
    if (!gimp_vectors_parasite_attach(self->ID, parasite->para)) {
 
656
        PyErr_Format(pygimp_error,
 
657
                     "could not attach parasite '%s' to vectors (ID %d)",
 
658
                     parasite->para->name, self->ID);
 
659
        return NULL;
 
660
    }
 
661
 
 
662
    Py_INCREF(Py_None);
 
663
    return Py_None;
 
664
}
 
665
 
 
666
static PyObject *
 
667
vectors_parasite_detach(PyGimpVectors *self, PyObject *args)
 
668
{
 
669
    char *name;
 
670
 
 
671
    if (!PyArg_ParseTuple(args, "s:parasite_detach", &name))
 
672
        return NULL;
 
673
 
 
674
    if (!gimp_vectors_parasite_detach(self->ID, name)) {
 
675
        PyErr_Format(pygimp_error,
 
676
                     "could not detach parasite '%s' from vectors (ID %d)",
 
677
                     name, self->ID);
 
678
        return NULL;
 
679
    }
 
680
 
 
681
    Py_INCREF(Py_None);
 
682
    return Py_None;
 
683
}
 
684
 
 
685
static PyObject *
 
686
vectors_parasite_list(PyGimpVectors *self)
 
687
{
 
688
    gint num_parasites;
 
689
    gchar **parasites;
 
690
 
 
691
    if (gimp_vectors_parasite_list(self->ID, &num_parasites, &parasites)) {
 
692
        PyObject *ret;
 
693
        gint i;
 
694
 
 
695
        ret = PyTuple_New(num_parasites);
 
696
 
 
697
        for (i = 0; i < num_parasites; i++) {
 
698
            PyTuple_SetItem(ret, i, PyString_FromString(parasites[i]));
 
699
            g_free(parasites[i]);
 
700
        }
 
701
 
 
702
        g_free(parasites);
 
703
        return ret;
 
704
    }
 
705
 
 
706
    PyErr_Format(pygimp_error, "could not list parasites on vectors (ID %d)",
 
707
                 self->ID);
 
708
    return NULL;
 
709
}
 
710
 
 
711
static PyMethodDef vectors_methods[] = {
 
712
    { "remove_stroke",
 
713
      (PyCFunction)vectors_remove_stroke,
 
714
      METH_VARARGS | METH_KEYWORDS },
 
715
    { "to_selection",
 
716
      (PyCFunction)vectors_to_selection,
 
717
      METH_VARARGS | METH_KEYWORDS },
 
718
    { "parasite_find",
 
719
      (PyCFunction)vectors_parasite_find,
 
720
      METH_VARARGS },
 
721
    { "parasite_attach",
 
722
      (PyCFunction)vectors_parasite_attach,
 
723
      METH_VARARGS },
 
724
    { "parasite_detach",
 
725
      (PyCFunction)vectors_parasite_detach,
 
726
      METH_VARARGS },
 
727
    { "parasite_list",
 
728
      (PyCFunction)vectors_parasite_list,
 
729
      METH_NOARGS },
 
730
    { NULL, NULL, 0 }
 
731
};
 
732
 
 
733
static PyObject *
 
734
vectors_get_image(PyGimpVectors *self, void *closure)
 
735
{
 
736
    return pygimp_image_new(gimp_vectors_get_image(self->ID));
 
737
}
 
738
 
 
739
static PyObject *
 
740
vectors_get_ID(PyGimpVectors *self, void *closure)
 
741
{
 
742
    return PyInt_FromLong(self->ID);
 
743
}
 
744
 
 
745
static PyObject *
 
746
vectors_get_name(PyGimpVectors *self, void *closure)
 
747
{
 
748
    return PyString_FromString(gimp_vectors_get_name(self->ID));
 
749
}
 
750
 
 
751
static int
 
752
vectors_set_name(PyGimpVectors *self, PyObject *value, void *closure)
 
753
{
 
754
    if (value == NULL) {
 
755
        PyErr_SetString(PyExc_TypeError, "cannot delete name");
 
756
        return -1;
 
757
    }
 
758
 
 
759
    if (!PyString_Check(value) && !PyUnicode_Check(value)) {
 
760
        PyErr_SetString(PyExc_TypeError, "type mismatch");
 
761
        return -1;
 
762
    }
 
763
 
 
764
    gimp_vectors_set_name(self->ID, PyString_AsString(value));
 
765
 
 
766
    return 0;
 
767
}
 
768
 
 
769
static PyObject *
 
770
vectors_get_visible(PyGimpVectors *self, void *closure)
 
771
{
 
772
    return PyBool_FromLong(gimp_vectors_get_visible(self->ID));
 
773
}
 
774
 
 
775
static int
 
776
vectors_set_visible(PyGimpVectors *self, PyObject *value, void *closure)
 
777
{
 
778
    if (value == NULL) {
 
779
        PyErr_SetString(PyExc_TypeError, "cannot delete visible");
 
780
        return -1;
 
781
    }
 
782
 
 
783
    if (!PyInt_Check(value)) {
 
784
        PyErr_SetString(PyExc_TypeError, "type mismatch");
 
785
        return -1;
 
786
    }
 
787
 
 
788
    gimp_vectors_set_visible(self->ID, PyInt_AsLong(value));
 
789
 
 
790
    return 0;
 
791
}
 
792
 
 
793
static PyObject *
 
794
vectors_get_linked(PyGimpVectors *self, void *closure)
 
795
{
 
796
    return PyBool_FromLong(gimp_vectors_get_linked(self->ID));
 
797
}
 
798
 
 
799
static int
 
800
vectors_set_linked(PyGimpVectors *self, PyObject *value, void *closure)
 
801
{
 
802
    if (value == NULL) {
 
803
        PyErr_SetString(PyExc_TypeError, "cannot delete linked");
 
804
        return -1;
 
805
    }
 
806
 
 
807
    if (!PyInt_Check(value)) {
 
808
        PyErr_SetString(PyExc_TypeError, "type mismatch");
 
809
        return -1;
 
810
    }
 
811
 
 
812
    gimp_vectors_set_linked(self->ID, PyInt_AsLong(value));
 
813
 
 
814
    return 0;
 
815
}
 
816
 
 
817
static PyObject *
 
818
vectors_get_tattoo(PyGimpVectors *self, void *closure)
 
819
{
 
820
    return PyInt_FromLong(gimp_vectors_get_tattoo(self->ID));
 
821
}
 
822
 
 
823
static int
 
824
vectors_set_tattoo(PyGimpVectors *self, PyObject *value, void *closure)
 
825
{
 
826
    if (value == NULL) {
 
827
        PyErr_SetString(PyExc_TypeError, "cannot delete tattoo");
 
828
        return -1;
 
829
    }
 
830
 
 
831
    if (!PyInt_Check(value)) {
 
832
        PyErr_SetString(PyExc_TypeError, "type mismatch");
 
833
        return -1;
 
834
    }
 
835
 
 
836
    gimp_vectors_set_tattoo(self->ID, PyInt_AsLong(value));
 
837
 
 
838
    return 0;
 
839
}
 
840
 
 
841
static PyObject *
 
842
vectors_get_strokes(PyGimpVectors *self, void *closure)
 
843
{
 
844
    int *strokes;
 
845
    int i, num_strokes;
 
846
    PyObject *ret;
 
847
 
 
848
    strokes = gimp_vectors_get_strokes(self->ID, &num_strokes);
 
849
 
 
850
    ret = PyList_New(num_strokes);
 
851
    if (ret == NULL)
 
852
        return NULL;
 
853
 
 
854
    for (i = 0; i < num_strokes; i++)
 
855
        PyList_SetItem(ret, i, vectors_bezier_stroke_new(self, strokes[i]));
 
856
 
 
857
    g_free(strokes);
 
858
 
 
859
    return ret;
 
860
}
 
861
 
 
862
static PyGetSetDef vectors_getsets[] = {
 
863
    { "ID", (getter)vectors_get_ID, (setter)0 },
 
864
    { "image", (getter)vectors_get_image, (setter)0 },
 
865
    { "name", (getter)vectors_get_name, (setter)vectors_set_name },
 
866
    { "visible", (getter)vectors_get_visible, (setter)vectors_set_visible },
 
867
    { "linked", (getter)vectors_get_linked, (setter)vectors_set_linked },
 
868
    { "tattoo", (getter)vectors_get_tattoo, (setter)vectors_set_tattoo },
 
869
    { "strokes", (getter)vectors_get_strokes, (setter)0 },
 
870
    { NULL, (getter)0, (setter)0 }
 
871
};
 
872
 
 
873
static void
 
874
vectors_dealloc(PyGimpVectors *self)
 
875
{
 
876
    PyObject_DEL(self);
 
877
}
 
878
 
 
879
static PyObject *
 
880
vectors_repr(PyGimpVectors *self)
 
881
{
 
882
    PyObject *s;
 
883
    char *name;
 
884
 
 
885
    name = gimp_vectors_get_name(self->ID);
 
886
    s = PyString_FromFormat("<gimp.Vectors '%s'>", name ? name : "(null)");
 
887
    g_free(name);
 
888
 
 
889
    return s;
 
890
}
 
891
 
 
892
static int
 
893
vectors_cmp(PyGimpVectors *self, PyGimpVectors *other)
 
894
{
 
895
    if (self->ID == other->ID)
 
896
        return 0;
 
897
    if (self->ID > other->ID)
 
898
        return -1;
 
899
    return 1;
 
900
}
 
901
 
 
902
static int
 
903
vectors_init(PyGimpVectors *self, PyObject *args, PyObject *kwargs)
 
904
{
 
905
    PyGimpImage *img;
 
906
    char *name;
 
907
 
 
908
    static char *kwlist[] = { "image", "name", NULL };
 
909
 
 
910
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
911
                                     "O!s:gimp.Vectors.__init__",
 
912
                                     kwlist,
 
913
                                     &PyGimpImage_Type, &img, &name))
 
914
        return -1;
 
915
 
 
916
    self->ID = gimp_vectors_new(img->ID, name);
 
917
 
 
918
    if (self->ID < 0) {
 
919
        PyErr_Format(pygimp_error,
 
920
                     "could not create vectors '%s' on image (ID %d)",
 
921
                     name, img->ID);
 
922
        return -1;
 
923
    }
 
924
 
 
925
    return 0;
 
926
}
 
927
 
 
928
PyTypeObject PyGimpVectors_Type = {
 
929
    PyObject_HEAD_INIT(NULL)
 
930
    0,                                  /* ob_size */
 
931
    "gimp.Vectors",                     /* tp_name */
 
932
    sizeof(PyGimpVectors),              /* tp_basicsize */
 
933
    0,                                  /* tp_itemsize */
 
934
    /* methods */
 
935
    (destructor)vectors_dealloc,        /* tp_dealloc */
 
936
    (printfunc)0,                       /* tp_print */
 
937
    (getattrfunc)0,                     /* tp_getattr */
 
938
    (setattrfunc)0,                     /* tp_setattr */
 
939
    (cmpfunc)vectors_cmp,               /* tp_compare */
 
940
    (reprfunc)vectors_repr,             /* tp_repr */
 
941
    0,                                  /* tp_as_number */
 
942
    0,                                  /* tp_as_sequence */
 
943
    0,                                  /* tp_as_mapping */
 
944
    (hashfunc)0,                        /* tp_hash */
 
945
    (ternaryfunc)0,                     /* tp_call */
 
946
    (reprfunc)0,                        /* tp_str */
 
947
    (getattrofunc)0,                    /* tp_getattro */
 
948
    (setattrofunc)0,                    /* tp_setattro */
 
949
    0,                                  /* tp_as_buffer */
 
950
    Py_TPFLAGS_DEFAULT,                 /* tp_flags */
 
951
    NULL, /* Documentation string */
 
952
    (traverseproc)0,                    /* tp_traverse */
 
953
    (inquiry)0,                         /* tp_clear */
 
954
    (richcmpfunc)0,                     /* tp_richcompare */
 
955
    0,                                  /* tp_weaklistoffset */
 
956
    (getiterfunc)0,                     /* tp_iter */
 
957
    (iternextfunc)0,                    /* tp_iternext */
 
958
    vectors_methods,                    /* tp_methods */
 
959
    0,                                  /* tp_members */
 
960
    vectors_getsets,                    /* tp_getset */
 
961
    (PyTypeObject *)0,                  /* tp_base */
 
962
    (PyObject *)0,                      /* tp_dict */
 
963
    0,                                  /* tp_descr_get */
 
964
    0,                                  /* tp_descr_set */
 
965
    0,                                  /* tp_dictoffset */
 
966
    (initproc)vectors_init,             /* tp_init */
 
967
    (allocfunc)0,                       /* tp_alloc */
 
968
    (newfunc)0,                         /* tp_new */
 
969
};
 
970
 
 
971
PyObject *
 
972
pygimp_vectors_new(gint32 ID)
 
973
{
 
974
    PyGimpVectors *self;
 
975
 
 
976
    if (ID == -1) {
 
977
        Py_INCREF(Py_None);
 
978
        return Py_None;
 
979
    }
 
980
 
 
981
    self = PyObject_NEW(PyGimpVectors, &PyGimpVectors_Type);
 
982
 
 
983
    if (self == NULL)
 
984
        return NULL;
 
985
 
 
986
    self->ID = ID;
 
987
 
 
988
    return (PyObject *)self;
 
989
}