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
|
/*
* THIS IS WORK IN PROGRESS.
*
* The Python Imaging Library.
* $Id: //modules/pil/outline.c#4 $
*
* "arrow" outline stuff. the contents of this module
* will be merged with the path module and the rest of
* the arrow graphics package, but not before PIL 1.1.
* use at your own risk.
*
* history:
* 99-01-10 fl Added to PIL (experimental)
*
* Copyright (c) Secret Labs AB 1999.
* Copyright (c) Fredrik Lundh 1999.
*
* See the README file for information on usage and redistribution.
*/
#include "Python.h"
#if PY_VERSION_HEX < 0x01060000
#define PyObject_DEL(op) PyMem_DEL((op))
#endif
#include "Imaging.h"
/* -------------------------------------------------------------------- */
/* Class */
typedef struct {
PyObject_HEAD
ImagingOutline outline;
} OutlineObject;
staticforward PyTypeObject OutlineType;
#define PyOutline_Check(op) ((op)->ob_type == &OutlineType)
static OutlineObject*
_outline_new(void)
{
OutlineObject *self;
self = PyObject_NEW(OutlineObject, &OutlineType);
if (self == NULL)
return NULL;
self->outline = ImagingOutlineNew();
return self;
}
static void
_outline_dealloc(OutlineObject* self)
{
ImagingOutlineDelete(self->outline);
PyObject_DEL(self);
}
ImagingOutline
PyOutline_AsOutline(PyObject* outline)
{
if (PyOutline_Check(outline))
return ((OutlineObject*) outline)->outline;
return NULL;
}
/* -------------------------------------------------------------------- */
/* Factories */
PyObject*
PyOutline_Create(PyObject* self, PyObject* args)
{
if (!PyArg_ParseTuple(args, ":outline"))
return NULL;
return (PyObject*) _outline_new();
}
/* -------------------------------------------------------------------- */
/* Methods */
static PyObject*
_outline_move(OutlineObject* self, PyObject* args)
{
float x0, y0;
if (!PyArg_ParseTuple(args, "ff", &x0, &y0))
return NULL;
ImagingOutlineMove(self->outline, x0, y0);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject*
_outline_line(OutlineObject* self, PyObject* args)
{
float x1, y1;
if (!PyArg_ParseTuple(args, "ff", &x1, &y1))
return NULL;
ImagingOutlineLine(self->outline, x1, y1);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject*
_outline_curve(OutlineObject* self, PyObject* args)
{
float x1, y1, x2, y2, x3, y3;
if (!PyArg_ParseTuple(args, "ffffff", &x1, &y1, &x2, &y2, &x3, &y3))
return NULL;
ImagingOutlineCurve(self->outline, x1, y1, x2, y2, x3, y3);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject*
_outline_close(OutlineObject* self, PyObject* args)
{
if (!PyArg_ParseTuple(args, ":close"))
return NULL;
ImagingOutlineClose(self->outline);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject*
_outline_transform(OutlineObject* self, PyObject* args)
{
double a[6];
if (!PyArg_ParseTuple(args, "(dddddd)", a+0, a+1, a+2, a+3, a+4, a+5))
return NULL;
ImagingOutlineTransform(self->outline, a);
Py_INCREF(Py_None);
return Py_None;
}
static struct PyMethodDef _outline_methods[] = {
{"line", (PyCFunction)_outline_line, 1},
{"curve", (PyCFunction)_outline_curve, 1},
{"move", (PyCFunction)_outline_move, 1},
{"close", (PyCFunction)_outline_close, 1},
{"transform", (PyCFunction)_outline_transform, 1},
{NULL, NULL} /* sentinel */
};
static PyObject*
_outline_getattr(OutlineObject* self, char* name)
{
return Py_FindMethod(_outline_methods, (PyObject*) self, name);
}
statichere PyTypeObject OutlineType = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"Outline", /*tp_name*/
sizeof(OutlineObject), /*tp_size*/
0, /*tp_itemsize*/
/* methods */
(destructor)_outline_dealloc, /*tp_dealloc*/
0, /*tp_print*/
(getattrfunc)_outline_getattr, /*tp_getattr*/
0 /*tp_setattr*/
};
|