22
33#include < cstring>
44
5+
6+ // font stuff from paint
7+
8+ static char agg_font__doc__[] =
9+ " Font(filename, size = 12, rotate = 0)\n "
10+ " \n "
11+ " Load the named font and return the font object" ;
12+
13+ static PyObject *agg_font (PyObject *module , PyObject *args)
14+ {
15+ return font_new (args);
16+ }
17+
18+
19+
520// image renderers that also have to deal with points (72/inch) make
621// an assumption about how many pixels represent 1 inch. GD and paint
722// use 96. What's good for the goose ...
@@ -279,7 +294,6 @@ _gc_get_linewidth(PyObject *gc) {
279294
280295extern " C" staticforward PyTypeObject RendererAgg_Type;
281296
282-
283297#define RendererAggObject_Check (v ) ((v)->ob_type == &RendererAgg_Type)
284298
285299static RendererAggObject *
@@ -597,6 +611,48 @@ RendererAgg_draw_lines(RendererAggObject *renderer, PyObject* args) {
597611}
598612
599613
614+
615+ static char RendererAgg_rgb__doc__[] =
616+ " rgb(r, g, b)\n "
617+ " \n "
618+ " Create an rgba color value with a = 0xff." ;
619+
620+ static PyObject *RendererAgg_rgb (PyObject *self, PyObject *args)
621+ {
622+ int r, g, b;
623+
624+ if (!PyArg_ParseTuple (args, " iii" , &r, &g, &b))
625+ return NULL ;
626+
627+ return (PyObject*)PyInt_FromLong ((r << 24 ) + (g << 16 ) + (b << 8 ) + 0xff );
628+ }
629+
630+ static char RendererAgg_rgba__doc__[] =
631+ " rgba(r, g, b, a)\n "
632+ " \n "
633+ " Create an rgba color value." ;
634+
635+ static PyObject *RendererAgg_rgba (PyObject *self, PyObject *args)
636+ {
637+ int r, g, b, a;
638+
639+ if (!PyArg_ParseTuple (args, " iiii" , &r, &g, &b, &a))
640+ return NULL ;
641+
642+ return (PyObject*)PyInt_FromLong ((r << 24 ) + (g << 16 ) + (b << 8 ) + a);
643+ }
644+
645+ char RendererAgg_draw_text__doc__[] =
646+ " draw_text(font, x, y, textcolor, text)\n "
647+ " \n "
648+ " Render the text in the supplied font at the specified location" ;
649+
650+ PyObject *
651+ RendererAgg_draw_text (RendererAggObject *renderer, PyObject* args) {
652+
653+ return font_draw_text (renderer, args);
654+ }
655+
600656static PyObject *
601657RendererAgg_write_rgba (RendererAggObject *renderer, PyObject* args) {
602658 // printf("save buffer called\n");
@@ -702,11 +758,15 @@ RendererAgg_write_png(RendererAggObject *renderer, PyObject *args)
702758// must be defined before getattr
703759static PyMethodDef RendererAgg_methods[] = {
704760
705- {" draw_ellipse" , (PyCFunction)RendererAgg_draw_ellipse, METH_VARARGS},
706- {" draw_rectangle" , (PyCFunction)RendererAgg_draw_rectangle, METH_VARARGS},
707- {" draw_lines" , (PyCFunction)RendererAgg_draw_lines, METH_VARARGS},
708- {" write_rgba" , (PyCFunction)RendererAgg_write_rgba, METH_VARARGS},
709- {" write_png" , (PyCFunction)RendererAgg_write_png, METH_VARARGS},
761+ { " draw_ellipse" , (PyCFunction)RendererAgg_draw_ellipse, METH_VARARGS},
762+ { " draw_rectangle" , (PyCFunction)RendererAgg_draw_rectangle, METH_VARARGS},
763+ { " draw_lines" , (PyCFunction)RendererAgg_draw_lines, METH_VARARGS},
764+ { " draw_text" , (PyCFunction)RendererAgg_draw_text, METH_VARARGS, RendererAgg_draw_text__doc__},
765+ { " write_rgba" , (PyCFunction)RendererAgg_write_rgba, METH_VARARGS},
766+ { " write_png" , (PyCFunction)RendererAgg_write_png, METH_VARARGS},
767+ { " rgb" , (PyCFunction)RendererAgg_rgb, METH_VARARGS, RendererAgg_rgb__doc__ },
768+ { " rgba" , (PyCFunction)RendererAgg_rgba, METH_VARARGS, RendererAgg_rgba__doc__ },
769+
710770 {NULL , NULL } /* sentinel */
711771};
712772
@@ -805,6 +865,7 @@ static PyTypeObject RendererAgg_Type = {
805865
806866static PyMethodDef _backend_agg_methods[] = {
807867 {" RendererAgg" , _backend_agg_new_renderer, METH_VARARGS},
868+ { " Font" , (PyCFunction)agg_font, METH_VARARGS, agg_font__doc__ },
808869 {NULL , NULL } /* sentinel */
809870};
810871
@@ -818,6 +879,7 @@ DL_EXPORT(void)
818879 /* Initialize the type of the new type object here; doing it here
819880 * is required for portability to Windows without requiring C++. */
820881 RendererAgg_Type.ob_type = &PyType_Type;
882+ Font_Type.ob_type = &PyType_Type;
821883
822884 /* Create the module and add the functions */
823885 module = Py_InitModule (" _backend_agg" , _backend_agg_methods);
0 commit comments