[cairo-commit] pycairo/cairo pycairo-context.c,1.8,1.9

Steve Chaplin commit at pdx.freedesktop.org
Mon Nov 15 02:06:37 PST 2004


Committed by: stevech1097

Update of /cvs/cairo/pycairo/cairo
In directory gabe:/tmp/cvs-serv9293/cairo

Modified Files:
	pycairo-context.c 
Log Message:
SC 15/11/2004

Index: pycairo-context.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-context.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- pycairo-context.c	14 Nov 2004 13:04:00 -0000	1.8
+++ pycairo-context.c	15 Nov 2004 10:06:34 -0000	1.9
@@ -912,83 +912,6 @@
     return Py_None;
 }
 
-static PyMethodDef pycairo_methods[] = {
-    { "copy", (PyCFunction)pycairo_copy, METH_VARARGS },
-    { "save", (PyCFunction)pycairo_save, METH_NOARGS },
-    { "restore", (PyCFunction)pycairo_restore, METH_NOARGS },
-    { "set_target_surface", (PyCFunction)pycairo_set_target_surface,
-      METH_VARARGS },
-#ifdef CAIRO_HAS_PS_SURFACE
-    { "set_target_ps", (PyCFunction)pycairo_set_target_ps,
-      METH_VARARGS},
-#endif
-#ifdef CAIRO_HAS_PNG_SURFACE
-    { "set_target_png", (PyCFunction)pycairo_set_target_png,
-      METH_VARARGS },
-#endif
-    { "set_operator", (PyCFunction)pycairo_set_operator, METH_VARARGS },
-    { "set_rgb_color", (PyCFunction)pycairo_set_rgb_color, METH_VARARGS },
-    { "set_alpha", (PyCFunction)pycairo_set_alpha, METH_VARARGS },
-    { "set_pattern", (PyCFunction)pycairo_set_pattern, METH_VARARGS },
-    { "set_tolerance", (PyCFunction)pycairo_set_tolerance, METH_VARARGS },
-    { "set_fill_rule", (PyCFunction)pycairo_set_fill_rule, METH_VARARGS },
-    { "set_line_width", (PyCFunction)pycairo_set_line_width, METH_VARARGS },
-    { "set_line_cap", (PyCFunction)pycairo_set_line_cap, METH_VARARGS },
-    { "set_line_join", (PyCFunction)pycairo_set_line_join, METH_VARARGS },
-    { "set_dash", (PyCFunction)pycairo_set_dash, METH_VARARGS },
-    { "set_miter_limit", (PyCFunction)pycairo_set_miter_limit, METH_VARARGS },
-    { "translate", (PyCFunction)pycairo_translate, METH_VARARGS },
-    { "scale", (PyCFunction)pycairo_scale, METH_VARARGS },
-    { "rotate", (PyCFunction)pycairo_rotate, METH_VARARGS },
-    { "concat_matrix", (PyCFunction)pycairo_concat_matrix, METH_VARARGS },
-    { "set_matrix", (PyCFunction)pycairo_set_matrix, METH_VARARGS },
-    { "default_matrix", (PyCFunction)pycairo_default_matrix, METH_NOARGS },
-    { "identity_matrix", (PyCFunction)pycairo_identity_matrix, METH_NOARGS },
-    { "transform_point", (PyCFunction)pycairo_transform_point, METH_VARARGS },
-    { "transform_distance", (PyCFunction)pycairo_transform_distance,
-      METH_VARARGS },
-    { "inverse_transform_point", (PyCFunction)pycairo_inverse_transform_point,
-      METH_VARARGS },
-    { "inverse_transform_distance",
-      (PyCFunction)pycairo_inverse_transform_distance, METH_VARARGS },
-    { "new_path", (PyCFunction)pycairo_new_path, METH_NOARGS },
-    { "move_to", (PyCFunction)pycairo_move_to, METH_VARARGS },
-    { "line_to", (PyCFunction)pycairo_line_to, METH_VARARGS },
-    { "curve_to", (PyCFunction)pycairo_curve_to, METH_VARARGS },
-    { "arc", (PyCFunction)pycairo_arc, METH_VARARGS },
-    { "arc_negative", (PyCFunction)pycairo_arc_negative, METH_VARARGS },
-    { "rel_move_to", (PyCFunction)pycairo_rel_move_to, METH_VARARGS },
-    { "rel_line_to", (PyCFunction)pycairo_rel_line_to, METH_VARARGS },
-    { "rel_curve_to", (PyCFunction)pycairo_rel_curve_to, METH_VARARGS },
-    { "rectangle", (PyCFunction)pycairo_rectangle, METH_VARARGS },
-    { "close_path", (PyCFunction)pycairo_close_path, METH_NOARGS },
-    { "stroke", (PyCFunction)pycairo_stroke, METH_NOARGS },
-    { "fill", (PyCFunction)pycairo_fill, METH_NOARGS },
-    { "copy_page", (PyCFunction)pycairo_copy_page, METH_NOARGS },
-    { "show_page", (PyCFunction)pycairo_show_page, METH_NOARGS },
-    { "in_stroke", (PyCFunction)pycairo_in_stroke, METH_VARARGS },
-    { "in_fill", (PyCFunction)pycairo_in_fill, METH_VARARGS },
-    { "stroke_extents", (PyCFunction)pycairo_stroke_extents, METH_VARARGS },
-    { "fill_extents", (PyCFunction)pycairo_fill_extents, METH_VARARGS },
-    { "init_clip", (PyCFunction)pycairo_init_clip, METH_NOARGS },
-    { "clip", (PyCFunction)pycairo_clip, METH_NOARGS },
-    { "select_font", (PyCFunction)pycairo_select_font, METH_VARARGS },
-    { "scale_font", (PyCFunction)pycairo_scale_font, METH_VARARGS },
-    { "transform_font", (PyCFunction)pycairo_transform_font, METH_VARARGS },
-    { "show_text", (PyCFunction)pycairo_show_text, METH_VARARGS },
-    /* TODO: { "show_glyphs", (PyCFunction)pycairo_show_glyphs, METH_NOARGS }, */
-    /* TODO: { "current_font_extents", (PyCFunction)pycairo_current_font_extents, METH_NOARGS }, */
-    { "set_font", (PyCFunction)pycairo_set_font, METH_VARARGS },
-    { "text_extents", (PyCFunction)pycairo_text_extents, METH_VARARGS },
-    { "show_surface", (PyCFunction)pycairo_show_surface, METH_VARARGS },
-    /* TODO: { "glyph_extents", (PyCFunction)pycairo_glyph_extents, METH_NOARGS }, */
-    { "text_path", (PyCFunction)pycairo_text_path, METH_VARARGS },
-    /* TODO: { "glyph_path", (PyCFunction)pycairo_glyph_path, METH_VARARGS }, */
-    /*{ "current_path", (PyCFunction)pycairo_current_path, METH_VARARGS },*/
-    /*{ "current_path_flat", (PyCFunction)pycairo_current_path_flat, METH_VARARGS },*/
-    { NULL, NULL, 0 }
-};
-
 static PyObject *
 pycairo_current_font(PyCairoContext *self)
 {
@@ -1108,6 +1031,202 @@
     return Py_None;
 }
 
+/* struct and wrappers for cairo_current_path() */ 
+typedef struct {
+	PyObject* move_to;
+	PyObject* line_to;
+	PyObject* curve_to;
+	PyObject* close_path;
+} py_path_callbacks;
+
+static void 
+py_wrapper_move_to(void *closure, double x, double y)
+{
+    if(!PyErr_Occurred()) {
+	py_path_callbacks *callbacks = (py_path_callbacks *)closure;
+	PyObject *arglist, *result = NULL;
+	arglist = Py_BuildValue("(dd)", x, y);
+	result = PyEval_CallObject(callbacks->move_to, arglist);
+	Py_DECREF(arglist);
+	Py_XDECREF(result);
+    }
+}
+
+static void 
+py_wrapper_line_to(void *closure, double x, double y)
+{
+    if(!PyErr_Occurred()) {
+	py_path_callbacks *callbacks = (py_path_callbacks *)closure;
+	PyObject *arglist, *result = NULL;
+	arglist = Py_BuildValue("(dd)", x, y);
+	result = PyEval_CallObject(callbacks->line_to, arglist);
+	Py_DECREF(arglist);
+	Py_XDECREF(result);
+    }
+}
+
+static void 
+py_wrapper_curve_to(void *closure, double x1, double y1, double x2, double y2, double x3, double y3)
+{
+    if(!PyErr_Occurred()) {
+	py_path_callbacks *callbacks = (py_path_callbacks *)closure;
+	PyObject *arglist, *result = NULL;
+	arglist = Py_BuildValue("(dddddd)", x1, y1, x2, y2, x3, y3);
+	result = PyEval_CallObject(callbacks->curve_to, arglist);
+	Py_DECREF(arglist);
+	Py_XDECREF(result);
+    }
+}
+
+static void 
+py_wrapper_close_path(void *closure)
+{
+    if(!PyErr_Occurred()) {
+	py_path_callbacks *callbacks = (py_path_callbacks *)closure;
+	PyObject *arglist, *result = NULL;
+    	arglist = Py_BuildValue("()");
+	result = PyEval_CallObject(callbacks->close_path, arglist);
+	Py_DECREF(arglist);
+	Py_XDECREF(result);
+    }
+}
+
+static PyObject *
+pycairo_current_path(PyCairoContext *self, PyObject *args)
+{
+    py_path_callbacks callbacks;
+
+    if(!PyArg_ParseTuple(args, "OOOO:Context.current_path_flat",
+			  &callbacks.move_to, &callbacks.line_to, &callbacks.curve_to, &callbacks.close_path))
+	return NULL;
+
+    if(!PyCallable_Check(callbacks.move_to)) {
+	PyErr_SetString(PyExc_TypeError, "move_to must be callable");
+	return NULL;
+    }
+    if(!PyCallable_Check(callbacks.line_to)) {
+	PyErr_SetString(PyExc_TypeError, "line_to must be callable");
+	return NULL;
+    }
+    if(!PyCallable_Check(callbacks.curve_to)) {
+	PyErr_SetString(PyExc_TypeError, "curve_to must be callable");
+	return NULL;
+    }
+    if(!PyCallable_Check(callbacks.close_path)) {
+	PyErr_SetString(PyExc_TypeError, "close_path must be callable");
+	return NULL;
+    }
+
+    cairo_current_path(self->ctx, py_wrapper_move_to, py_wrapper_line_to, py_wrapper_curve_to, py_wrapper_close_path, &callbacks);
+    if(PyErr_Occurred() || pycairo_check_status(cairo_status(self->ctx)))
+	return NULL;
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
+static PyObject *
+pycairo_current_path_flat(PyCairoContext *self, PyObject *args)
+{
+    py_path_callbacks callbacks;
+
+    if(!PyArg_ParseTuple(args, "OOO:Context.current_path_flat",
+			  &callbacks.move_to, &callbacks.line_to, &callbacks.close_path))
+	return NULL;
+
+    if(!PyCallable_Check(callbacks.move_to)) {
+	PyErr_SetString(PyExc_TypeError, "move_to must be callable");
+	return NULL;
+    }
+    if(!PyCallable_Check(callbacks.line_to)) {
+	PyErr_SetString(PyExc_TypeError, "line_to must be callable");
+	return NULL;
+    }
+    if(!PyCallable_Check(callbacks.close_path)) {
+	PyErr_SetString(PyExc_TypeError, "close_path must be callable");
+	return NULL;
+    }
+
+    cairo_current_path_flat(self->ctx, py_wrapper_move_to, py_wrapper_line_to, py_wrapper_close_path, &callbacks);
+    if(PyErr_Occurred() || pycairo_check_status(cairo_status(self->ctx)))
+	return NULL;
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
+static PyMethodDef pycairo_methods[] = {
+    { "copy", (PyCFunction)pycairo_copy, METH_VARARGS },
+    { "save", (PyCFunction)pycairo_save, METH_NOARGS },
+    { "restore", (PyCFunction)pycairo_restore, METH_NOARGS },
+    { "set_target_surface", (PyCFunction)pycairo_set_target_surface,
+      METH_VARARGS },
+#ifdef CAIRO_HAS_PS_SURFACE
+    { "set_target_ps", (PyCFunction)pycairo_set_target_ps, METH_VARARGS},
+#endif
+#ifdef CAIRO_HAS_PNG_SURFACE
+    { "set_target_png", (PyCFunction)pycairo_set_target_png, METH_VARARGS },
+#endif
+    { "set_operator", (PyCFunction)pycairo_set_operator, METH_VARARGS },
+    { "set_rgb_color", (PyCFunction)pycairo_set_rgb_color, METH_VARARGS },
+    { "set_alpha", (PyCFunction)pycairo_set_alpha, METH_VARARGS },
+    { "set_pattern", (PyCFunction)pycairo_set_pattern, METH_VARARGS },
+    { "set_tolerance", (PyCFunction)pycairo_set_tolerance, METH_VARARGS },
+    { "set_fill_rule", (PyCFunction)pycairo_set_fill_rule, METH_VARARGS },
+    { "set_line_width", (PyCFunction)pycairo_set_line_width, METH_VARARGS },
+    { "set_line_cap", (PyCFunction)pycairo_set_line_cap, METH_VARARGS },
+    { "set_line_join", (PyCFunction)pycairo_set_line_join, METH_VARARGS },
+    { "set_dash", (PyCFunction)pycairo_set_dash, METH_VARARGS },
+    { "set_miter_limit", (PyCFunction)pycairo_set_miter_limit, METH_VARARGS },
+    { "translate", (PyCFunction)pycairo_translate, METH_VARARGS },
+    { "scale", (PyCFunction)pycairo_scale, METH_VARARGS },
+    { "rotate", (PyCFunction)pycairo_rotate, METH_VARARGS },
+    { "concat_matrix", (PyCFunction)pycairo_concat_matrix, METH_VARARGS },
+    { "set_matrix", (PyCFunction)pycairo_set_matrix, METH_VARARGS },
+    { "default_matrix", (PyCFunction)pycairo_default_matrix, METH_NOARGS },
+    { "identity_matrix", (PyCFunction)pycairo_identity_matrix, METH_NOARGS },
+    { "transform_point", (PyCFunction)pycairo_transform_point, METH_VARARGS },
+    { "transform_distance", (PyCFunction)pycairo_transform_distance,
+      METH_VARARGS },
+    { "inverse_transform_point", (PyCFunction)pycairo_inverse_transform_point,
+      METH_VARARGS },
+    { "inverse_transform_distance",
+      (PyCFunction)pycairo_inverse_transform_distance, METH_VARARGS },
+    { "new_path", (PyCFunction)pycairo_new_path, METH_NOARGS },
+    { "move_to", (PyCFunction)pycairo_move_to, METH_VARARGS },
+    { "line_to", (PyCFunction)pycairo_line_to, METH_VARARGS },
+    { "curve_to", (PyCFunction)pycairo_curve_to, METH_VARARGS },
+    { "arc", (PyCFunction)pycairo_arc, METH_VARARGS },
+    { "arc_negative", (PyCFunction)pycairo_arc_negative, METH_VARARGS },
+    { "rel_move_to", (PyCFunction)pycairo_rel_move_to, METH_VARARGS },
+    { "rel_line_to", (PyCFunction)pycairo_rel_line_to, METH_VARARGS },
+    { "rel_curve_to", (PyCFunction)pycairo_rel_curve_to, METH_VARARGS },
+    { "rectangle", (PyCFunction)pycairo_rectangle, METH_VARARGS },
+    { "close_path", (PyCFunction)pycairo_close_path, METH_NOARGS },
+    { "stroke", (PyCFunction)pycairo_stroke, METH_NOARGS },
+    { "fill", (PyCFunction)pycairo_fill, METH_NOARGS },
+    { "copy_page", (PyCFunction)pycairo_copy_page, METH_NOARGS },
+    { "show_page", (PyCFunction)pycairo_show_page, METH_NOARGS },
+    { "in_stroke", (PyCFunction)pycairo_in_stroke, METH_VARARGS },
+    { "in_fill", (PyCFunction)pycairo_in_fill, METH_VARARGS },
+    { "stroke_extents", (PyCFunction)pycairo_stroke_extents, METH_VARARGS },
+    { "fill_extents", (PyCFunction)pycairo_fill_extents, METH_VARARGS },
+    { "init_clip", (PyCFunction)pycairo_init_clip, METH_NOARGS },
+    { "clip", (PyCFunction)pycairo_clip, METH_NOARGS },
+    { "select_font", (PyCFunction)pycairo_select_font, METH_VARARGS },
+    { "scale_font", (PyCFunction)pycairo_scale_font, METH_VARARGS },
+    { "transform_font", (PyCFunction)pycairo_transform_font, METH_VARARGS },
+    { "show_text", (PyCFunction)pycairo_show_text, METH_VARARGS },
+    /* TODO: { "show_glyphs", (PyCFunction)pycairo_show_glyphs, METH_NOARGS }, */
+    /* TODO: { "current_font_extents", (PyCFunction)pycairo_current_font_extents, METH_NOARGS }, */
+    { "set_font", (PyCFunction)pycairo_set_font, METH_VARARGS },
+    { "text_extents", (PyCFunction)pycairo_text_extents, METH_VARARGS },
+    { "show_surface", (PyCFunction)pycairo_show_surface, METH_VARARGS },
+    /* TODO: { "glyph_extents", (PyCFunction)pycairo_glyph_extents, METH_NOARGS }, */
+    { "text_path", (PyCFunction)pycairo_text_path, METH_VARARGS },
+    /* TODO: { "glyph_path", (PyCFunction)pycairo_glyph_path, METH_VARARGS }, */
+    { "current_path", (PyCFunction)pycairo_current_path, METH_VARARGS },
+    { "current_path_flat", (PyCFunction)pycairo_current_path_flat, METH_VARARGS },
+    { NULL, NULL, 0 }
+};
 
 static PyGetSetDef pycairo_getsets[] = {
     { "font", (getter)pycairo_current_font, (setter)0 },
@@ -1149,8 +1268,8 @@
     (getattrofunc)0,                    /* tp_getattro */
     (setattrofunc)0,                    /* tp_setattro */
     0,                                  /* tp_as_buffer */
-    Py_TPFLAGS_DEFAULT,                 /* tp_flags */
-    NULL, /* Documentation string */
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+    NULL,                               /* tp_doc */
     (traverseproc)0,                    /* tp_traverse */
     (inquiry)0,                         /* tp_clear */
     (richcmpfunc)0,                     /* tp_richcompare */




More information about the cairo-commit mailing list