outline.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * THIS IS WORK IN PROGRESS.
  3. *
  4. * The Python Imaging Library.
  5. *
  6. * "arrow" outline stuff. the contents of this module
  7. * will be merged with the path module and the rest of
  8. * the arrow graphics package, but not before PIL 1.1.
  9. * use at your own risk.
  10. *
  11. * history:
  12. * 99-01-10 fl Added to PIL (experimental)
  13. *
  14. * Copyright (c) Secret Labs AB 1999.
  15. * Copyright (c) Fredrik Lundh 1999.
  16. *
  17. * See the README file for information on usage and redistribution.
  18. */
  19. #include "Python.h"
  20. #include "Imaging.h"
  21. /* -------------------------------------------------------------------- */
  22. /* Class */
  23. typedef struct {
  24. PyObject_HEAD
  25. ImagingOutline outline;
  26. } OutlineObject;
  27. static PyTypeObject OutlineType;
  28. #define PyOutline_Check(op) (Py_TYPE(op) == &OutlineType)
  29. static OutlineObject*
  30. _outline_new(void)
  31. {
  32. OutlineObject *self;
  33. if (PyType_Ready(&OutlineType) < 0)
  34. return NULL;
  35. self = PyObject_New(OutlineObject, &OutlineType);
  36. if (self == NULL)
  37. return NULL;
  38. self->outline = ImagingOutlineNew();
  39. return self;
  40. }
  41. static void
  42. _outline_dealloc(OutlineObject* self)
  43. {
  44. ImagingOutlineDelete(self->outline);
  45. PyObject_Del(self);
  46. }
  47. ImagingOutline
  48. PyOutline_AsOutline(PyObject* outline)
  49. {
  50. if (PyOutline_Check(outline))
  51. return ((OutlineObject*) outline)->outline;
  52. return NULL;
  53. }
  54. /* -------------------------------------------------------------------- */
  55. /* Factories */
  56. PyObject*
  57. PyOutline_Create(PyObject* self, PyObject* args)
  58. {
  59. if (!PyArg_ParseTuple(args, ":outline"))
  60. return NULL;
  61. return (PyObject*) _outline_new();
  62. }
  63. /* -------------------------------------------------------------------- */
  64. /* Methods */
  65. static PyObject*
  66. _outline_move(OutlineObject* self, PyObject* args)
  67. {
  68. float x0, y0;
  69. if (!PyArg_ParseTuple(args, "ff", &x0, &y0))
  70. return NULL;
  71. ImagingOutlineMove(self->outline, x0, y0);
  72. Py_INCREF(Py_None);
  73. return Py_None;
  74. }
  75. static PyObject*
  76. _outline_line(OutlineObject* self, PyObject* args)
  77. {
  78. float x1, y1;
  79. if (!PyArg_ParseTuple(args, "ff", &x1, &y1))
  80. return NULL;
  81. ImagingOutlineLine(self->outline, x1, y1);
  82. Py_INCREF(Py_None);
  83. return Py_None;
  84. }
  85. static PyObject*
  86. _outline_curve(OutlineObject* self, PyObject* args)
  87. {
  88. float x1, y1, x2, y2, x3, y3;
  89. if (!PyArg_ParseTuple(args, "ffffff", &x1, &y1, &x2, &y2, &x3, &y3))
  90. return NULL;
  91. ImagingOutlineCurve(self->outline, x1, y1, x2, y2, x3, y3);
  92. Py_INCREF(Py_None);
  93. return Py_None;
  94. }
  95. static PyObject*
  96. _outline_close(OutlineObject* self, PyObject* args)
  97. {
  98. if (!PyArg_ParseTuple(args, ":close"))
  99. return NULL;
  100. ImagingOutlineClose(self->outline);
  101. Py_INCREF(Py_None);
  102. return Py_None;
  103. }
  104. static PyObject*
  105. _outline_transform(OutlineObject* self, PyObject* args)
  106. {
  107. double a[6];
  108. if (!PyArg_ParseTuple(args, "(dddddd)", a+0, a+1, a+2, a+3, a+4, a+5))
  109. return NULL;
  110. ImagingOutlineTransform(self->outline, a);
  111. Py_INCREF(Py_None);
  112. return Py_None;
  113. }
  114. static struct PyMethodDef _outline_methods[] = {
  115. {"line", (PyCFunction)_outline_line, 1},
  116. {"curve", (PyCFunction)_outline_curve, 1},
  117. {"move", (PyCFunction)_outline_move, 1},
  118. {"close", (PyCFunction)_outline_close, 1},
  119. {"transform", (PyCFunction)_outline_transform, 1},
  120. {NULL, NULL} /* sentinel */
  121. };
  122. static PyTypeObject OutlineType = {
  123. PyVarObject_HEAD_INIT(NULL, 0)
  124. "Outline", /*tp_name*/
  125. sizeof(OutlineObject), /*tp_size*/
  126. 0, /*tp_itemsize*/
  127. /* methods */
  128. (destructor)_outline_dealloc, /*tp_dealloc*/
  129. 0, /*tp_print*/
  130. 0, /*tp_getattr*/
  131. 0, /*tp_setattr*/
  132. 0, /*tp_compare*/
  133. 0, /*tp_repr*/
  134. 0, /*tp_as_number */
  135. 0, /*tp_as_sequence */
  136. 0, /*tp_as_mapping */
  137. 0, /*tp_hash*/
  138. 0, /*tp_call*/
  139. 0, /*tp_str*/
  140. 0, /*tp_getattro*/
  141. 0, /*tp_setattro*/
  142. 0, /*tp_as_buffer*/
  143. Py_TPFLAGS_DEFAULT, /*tp_flags*/
  144. 0, /*tp_doc*/
  145. 0, /*tp_traverse*/
  146. 0, /*tp_clear*/
  147. 0, /*tp_richcompare*/
  148. 0, /*tp_weaklistoffset*/
  149. 0, /*tp_iter*/
  150. 0, /*tp_iternext*/
  151. _outline_methods, /*tp_methods*/
  152. 0, /*tp_members*/
  153. 0, /*tp_getset*/
  154. };