mirror of https://github.com/GNOME/gimp.git
bezier_stroke_new_moveto and bezier_stroke_new_ellipse are now class
2006-11-24 Manish Singh <yosh@gimp.org> * plug-ins/pygimp/pygimp-vectors.c: bezier_stroke_new_moveto and bezier_stroke_new_ellipse are now class methods of VectorsBezierStroke. * plug-ins/pygimp/gimpmodule.c: vectors import now has better error handling and cleanup. Also stick VectorsBezierStroke in the gimp namespace so the class is available for constructing.
This commit is contained in:
parent
e7e347fb80
commit
67556fd196
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
2006-11-24 Manish Singh <yosh@gimp.org>
|
||||
|
||||
* plug-ins/pygimp/pygimp-vectors.c: bezier_stroke_new_moveto and
|
||||
bezier_stroke_new_ellipse are now class methods of
|
||||
VectorsBezierStroke.
|
||||
|
||||
* plug-ins/pygimp/gimpmodule.c: vectors import now has better
|
||||
error handling and cleanup. Also stick VectorsBezierStroke in
|
||||
the gimp namespace so the class is available for constructing.
|
||||
|
||||
2006-11-24 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* configure.in: bumped version to 2.3.14.
|
||||
|
|
|
@ -1489,6 +1489,7 @@ pygimp_vectors_import_from_file(PyObject *self, PyObject *args, PyObject *kwargs
|
|||
PyObject *py_file;
|
||||
gboolean merge = FALSE, scale = FALSE;
|
||||
int *vectors, num_vectors;
|
||||
gboolean success;
|
||||
|
||||
static char *kwlist[] = { "image", "svg_file", "merge", "scale", NULL };
|
||||
|
||||
|
@ -1499,14 +1500,31 @@ pygimp_vectors_import_from_file(PyObject *self, PyObject *args, PyObject *kwargs
|
|||
return NULL;
|
||||
|
||||
if (PyString_Check(py_file)) {
|
||||
gimp_vectors_import_from_file(img->ID,
|
||||
PyString_AsString(py_file),
|
||||
merge, scale,
|
||||
&num_vectors, &vectors);
|
||||
success = gimp_vectors_import_from_file(img->ID,
|
||||
PyString_AsString(py_file),
|
||||
merge, scale,
|
||||
&num_vectors, &vectors);
|
||||
} else {
|
||||
PyObject *chunk_size = PyInt_FromLong(16 * 1024);
|
||||
PyObject *buffer = PyString_FromString("");
|
||||
PyObject *read_method = PyString_FromString("read");
|
||||
PyObject *chunk_size, *buffer, *read_method;
|
||||
|
||||
chunk_size = PyInt_FromLong(16 * 1024);
|
||||
if (chunk_size == NULL)
|
||||
return NULL;
|
||||
|
||||
buffer = PyString_FromString("");
|
||||
if (buffer == NULL) {
|
||||
Py_DECREF(chunk_size);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
read_method = PyString_FromString("read");
|
||||
if (read_method == NULL || !PyCallable_Check(read_method)) {
|
||||
Py_XDECREF(read_method);
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"svg_file must be an object that has a \"read\" "
|
||||
"method, or a filename (str)");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
PyObject *chunk;
|
||||
|
@ -1522,27 +1540,34 @@ pygimp_vectors_import_from_file(PyObject *self, PyObject *args, PyObject *kwargs
|
|||
}
|
||||
|
||||
if (PyString_GET_SIZE(chunk) != 0) {
|
||||
PyObject *newbuffer;
|
||||
PyString_ConcatAndDel(&newbuffer, chunk);
|
||||
Py_DECREF(buffer);
|
||||
buffer = newbuffer;
|
||||
PyString_ConcatAndDel(&buffer, chunk);
|
||||
if (buffer == NULL) {
|
||||
Py_DECREF(chunk_size);
|
||||
Py_DECREF(read_method);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
Py_DECREF(chunk);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
gimp_vectors_import_from_string(img->ID,
|
||||
PyString_AsString(buffer),
|
||||
PyString_Size(buffer),
|
||||
merge, scale,
|
||||
&num_vectors, &vectors);
|
||||
success = gimp_vectors_import_from_string(img->ID,
|
||||
PyString_AsString(buffer),
|
||||
PyString_Size(buffer),
|
||||
merge, scale,
|
||||
&num_vectors, &vectors);
|
||||
|
||||
Py_DECREF(chunk_size);
|
||||
Py_DECREF(buffer);
|
||||
Py_DECREF(read_method);
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
PyErr_SetString(pygimp_error, "Vectors import failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return vectors_to_objects(num_vectors, vectors);
|
||||
}
|
||||
|
||||
|
@ -1554,6 +1579,7 @@ pygimp_vectors_import_from_string(PyObject *self, PyObject *args, PyObject *kwar
|
|||
int length;
|
||||
gboolean merge = FALSE, scale = FALSE;
|
||||
int *vectors, num_vectors;
|
||||
gboolean success;
|
||||
|
||||
static char *kwlist[] = { "image", "svg_string", "merge", "scale", NULL };
|
||||
|
||||
|
@ -1564,9 +1590,14 @@ pygimp_vectors_import_from_string(PyObject *self, PyObject *args, PyObject *kwar
|
|||
&merge, &scale))
|
||||
return NULL;
|
||||
|
||||
gimp_vectors_import_from_string(img->ID, svg_string, length,
|
||||
merge, scale,
|
||||
&num_vectors, &vectors);
|
||||
success = gimp_vectors_import_from_string(img->ID, svg_string, length,
|
||||
merge, scale,
|
||||
&num_vectors, &vectors);
|
||||
|
||||
if (!success) {
|
||||
PyErr_SetString(pygimp_error, "Vectors import failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return vectors_to_objects(num_vectors, vectors);
|
||||
}
|
||||
|
@ -1841,6 +1872,7 @@ initgimp(void)
|
|||
PyDict_SetItemString(d, "Tile", (PyObject *)&PyGimpTile_Type);
|
||||
PyDict_SetItemString(d, "PixelRgn", (PyObject *)&PyGimpPixelRgn_Type);
|
||||
PyDict_SetItemString(d, "Parasite", (PyObject *)&PyGimpParasite_Type);
|
||||
PyDict_SetItemString(d, "VectorsBezierStroke", (PyObject *)&PyGimpVectorsBezierStroke_Type);
|
||||
PyDict_SetItemString(d, "Vectors", (PyObject *)&PyGimpVectors_Type);
|
||||
|
||||
/* for other modules */
|
||||
|
|
|
@ -25,6 +25,9 @@
|
|||
#include "pygimp.h"
|
||||
|
||||
|
||||
static PyObject *vectors_bezier_stroke_new(PyGimpVectors *vectors, int stroke);
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
gint32 vectors_ID;
|
||||
|
@ -356,6 +359,48 @@ PyTypeObject PyGimpVectorsStroke_Type = {
|
|||
};
|
||||
|
||||
|
||||
static PyObject *
|
||||
vbs_new_moveto(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
PyGimpVectors *vectors;
|
||||
double x0, y0;
|
||||
int stroke;
|
||||
|
||||
static char *kwlist[] = { "vectors", "x0", "y0", NULL };
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
|
||||
"O!dd:new_moveto", kwlist,
|
||||
&PyGimpVectors_Type, &vectors,
|
||||
&x0, &y0))
|
||||
return NULL;
|
||||
|
||||
stroke = gimp_vectors_bezier_stroke_new_moveto(vectors->ID, x0, y0);
|
||||
|
||||
return vectors_bezier_stroke_new(vectors, stroke);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
vbs_new_ellipse(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
PyGimpVectors *vectors;
|
||||
double x0, y0, radius_x, radius_y, angle;
|
||||
int stroke;
|
||||
|
||||
static char *kwlist[] = { "vectors", "x0", "y0", "radius_x", "radius_y",
|
||||
"angle", NULL };
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
|
||||
"O!ddddd:new_ellipse", kwlist,
|
||||
&PyGimpVectors_Type, &vectors,
|
||||
&x0, &y0, &radius_x, &radius_y, &angle))
|
||||
return NULL;
|
||||
|
||||
stroke = gimp_vectors_bezier_stroke_new_ellipse(vectors->ID, x0, y0,
|
||||
radius_x, radius_y, angle);
|
||||
|
||||
return vectors_bezier_stroke_new(vectors, stroke);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
vbs_lineto(PyGimpVectorsStroke *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
|
@ -413,6 +458,8 @@ vbs_cubicto(PyGimpVectorsStroke *self, PyObject *args, PyObject *kwargs)
|
|||
}
|
||||
|
||||
static PyMethodDef vbs_methods[] = {
|
||||
{ "new_moveto", (PyCFunction)vbs_new_moveto, METH_VARARGS | METH_KEYWORDS | METH_CLASS },
|
||||
{ "new_ellipse", (PyCFunction)vbs_new_ellipse, METH_VARARGS | METH_KEYWORDS | METH_CLASS },
|
||||
{ "lineto", (PyCFunction)vbs_lineto, METH_VARARGS | METH_KEYWORDS },
|
||||
{ "conicto", (PyCFunction)vbs_conicto, METH_VARARGS | METH_KEYWORDS },
|
||||
{ "cubicto", (PyCFunction)vbs_cubicto, METH_VARARGS | METH_KEYWORDS },
|
||||
|
@ -445,7 +492,7 @@ vbs_init(PyGimpVectorsStroke *self, PyObject *args, PyObject *kwargs)
|
|||
static char *kwlist[] = { "vectors", "controlpoints", "closed", NULL };
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
|
||||
"O!O|i:gimp.Vectors.__init__",
|
||||
"O!O|i:gimp.VectorsBezierStroke.__init__",
|
||||
kwlist,
|
||||
&PyGimpVectors_Type, &vectors,
|
||||
&py_controlpoints, &closed));
|
||||
|
@ -562,43 +609,6 @@ vectors_remove_stroke(PyGimpVectors *self, PyObject *args, PyObject *kwargs)
|
|||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
vectors_bezier_stroke_new_moveto(PyGimpVectors *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
double x0, y0;
|
||||
int stroke;
|
||||
|
||||
static char *kwlist[] = { "x0", "y0", NULL };
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
|
||||
"dd:bezier_stroke_new_moveto", kwlist,
|
||||
&x0, &y0))
|
||||
return NULL;
|
||||
|
||||
stroke = gimp_vectors_bezier_stroke_new_moveto(self->ID, x0, y0);
|
||||
|
||||
return vectors_bezier_stroke_new(self, stroke);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
vectors_bezier_stroke_new_ellipse(PyGimpVectors *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
double x0, y0, radius_x, radius_y, angle;
|
||||
int stroke;
|
||||
|
||||
static char *kwlist[] = { "x0", "y0", "radius_x", "radius_y", "angle", NULL };
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
|
||||
"ddddd:bezier_stroke_new_ellipse", kwlist,
|
||||
&x0, &y0, &radius_x, &radius_y, &angle))
|
||||
return NULL;
|
||||
|
||||
stroke = gimp_vectors_bezier_stroke_new_ellipse(self->ID, x0, y0,
|
||||
radius_x, radius_y, angle);
|
||||
|
||||
return vectors_bezier_stroke_new(self, stroke);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
vectors_to_selection(PyGimpVectors *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
|
@ -702,12 +712,6 @@ static PyMethodDef vectors_methods[] = {
|
|||
{ "remove_stroke",
|
||||
(PyCFunction)vectors_remove_stroke,
|
||||
METH_VARARGS | METH_KEYWORDS },
|
||||
{ "bezier_stroke_new_moveto",
|
||||
(PyCFunction)vectors_bezier_stroke_new_moveto,
|
||||
METH_VARARGS | METH_KEYWORDS },
|
||||
{ "bezier_stroke_new_ellipse",
|
||||
(PyCFunction)vectors_bezier_stroke_new_ellipse,
|
||||
METH_VARARGS | METH_KEYWORDS },
|
||||
{ "to_selection",
|
||||
(PyCFunction)vectors_to_selection,
|
||||
METH_VARARGS | METH_KEYWORDS },
|
||||
|
|
Loading…
Reference in New Issue