[cairo-commit] pycairo/cairo pycairo-private.h, 1.3, 1.4 pycairo-pattern.c, 1.2, 1.3 cairomodule.c, 1.5, 1.6 pycairo-context.c, 1.7, 1.8 pycairo.h, 1.4, 1.5

Steve Chaplin commit at pdx.freedesktop.org
Sun Nov 14 05:04:02 PST 2004


Committed by: stevech1097

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

Modified Files:
	pycairo-private.h pycairo-pattern.c cairomodule.c 
	pycairo-context.c pycairo.h 
Log Message:
SC 14/11/2004

Index: pycairo-private.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-private.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- pycairo-private.h	4 Nov 2004 14:45:35 -0000	1.3
+++ pycairo-private.h	14 Nov 2004 13:04:00 -0000	1.4
@@ -21,8 +21,7 @@
 PyObject *pycairo_matrix_new(cairo_matrix_t *matrix);
 PyObject *pycairo_context_new(cairo_t *ctx);
 PyObject *pycairo_surface_new(cairo_surface_t *surface);
-/*PyObject *pycairo_pattern_new(cairo_pattern_t *pattern); */
-PyObject *pycairo_pattern_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
+PyObject *pycairo_pattern_wrap(cairo_pattern_t *pattern);
 PyObject *pycairo_font_new(cairo_font_t *font);
 
 #endif

Index: pycairo-pattern.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-pattern.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- pycairo-pattern.c	14 Nov 2004 03:22:20 -0000	1.2
+++ pycairo-pattern.c	14 Nov 2004 13:04:00 -0000	1.3
@@ -5,16 +5,41 @@
 #endif
 #include "pycairo-private.h"
 
+
+/* wrap an existing cairo_pattern_t in a PyCairoPattern object */
 PyObject *
-pycairo_pattern_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+pycairo_pattern_wrap(cairo_pattern_t *pattern)
 {
     PyCairoPattern *self;
 
-    self = (PyCairoPattern *)type->tp_alloc(type, 0);
+    self = PyObject_New(PyCairoPattern, &PyCairoPattern_Type);
+    if (self) {
+	cairo_pattern_reference(pattern);
+	self->pattern = pattern;
+    }
+    return (PyObject *)self;
+}
 
-    if (self != NULL) {
+static void
+pycairo_pattern_dealloc(PyCairoPattern *self)
+{
+    if (self->pattern)
+	cairo_pattern_destroy(self->pattern);
+    self->pattern = NULL;
+
+    if (self->ob_type->tp_free)
+	self->ob_type->tp_free((PyObject *)self);
+    else
+	PyObject_Del(self);
+}
+
+static PyObject *
+pycairo_pattern_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+    PyCairoPattern *self = (PyCairoPattern *)type->tp_alloc(type, 0);
+
+    if (self)
       self->pattern = NULL;
-    }
     return (PyObject *)self;
 }
 
@@ -61,26 +86,12 @@
 	return -1;
     }
 
-    cairo_pattern_reference(pattern);
+    /*cairo_pattern_reference(pattern);*/
     self->pattern = pattern;
 
     return 0;
 }
 
-static void
-pycairo_pattern_dealloc(PyCairoPattern *self)
-{
-    if (self->pattern)
-	cairo_pattern_destroy(self->pattern);
-    self->pattern = NULL;
-
-    if (self->ob_type->tp_free)
-	self->ob_type->tp_free((PyObject *)self);
-    else
-	PyObject_Del(self);
-}
-
-
 /* Pattern methods */
 static PyObject *
 pycairo_pattern_add_color_stop(PyCairoPattern *self, PyObject *args)

Index: cairomodule.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/cairomodule.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- cairomodule.c	4 Nov 2004 14:45:35 -0000	1.5
+++ cairomodule.c	14 Nov 2004 13:04:00 -0000	1.6
@@ -37,7 +37,7 @@
 }
 
 static PyObject *
-pycairo_surface_create_for_image(PyObject *self, PyObject *args)
+pycairo_image_surface_create_for_data(PyObject *self, PyObject *args)
 {
     char *data;
     cairo_format_t format;
@@ -77,8 +77,8 @@
 	return NULL;
     }
 
-    surface = cairo_surface_create_for_image(data, format,
-					     width, height, stride);
+    surface = cairo_image_surface_create_for_data(data, format,
+						  width, height, stride);
     if (!surface)
 	return PyErr_NoMemory();
     /* should get surface to hold reference to buffer ... */
@@ -86,9 +86,85 @@
     return pycairo_surface_new(surface);
 }
 
+#ifdef CAIRO_HAS_PS_SURFACE
+static PyObject *
+pycairo_ps_surface_create(PyObject *self, PyObject *args)
+{
+    PyObject *file_object;
+    int width_inches, height_inches, x_pixels_per_inch, y_pixels_per_inch;
+    cairo_surface_t *surface;
+
+    if (!PyArg_ParseTuple(args, "O!iiii:ps_surface_create",
+			  &PyFile_Type, &file_object, &width_inches, &height_inches, &x_pixels_per_inch, &y_pixels_per_inch))
+	return NULL;
+    if (width_inches <= 0) {
+	PyErr_SetString(PyExc_ValueError, "width_inches must be positive");
+	return NULL;
+    }
+    if (height_inches <= 0) {
+	PyErr_SetString(PyExc_ValueError, "height_inches must be positive");
+	return NULL;
+    }
+    if (x_pixels_per_inch <= 0) {
+	PyErr_SetString(PyExc_ValueError, "x_pixels_per_inch must be positive");
+	return NULL;
+    }
+    if (y_pixels_per_inch <= 0) {
+	PyErr_SetString(PyExc_ValueError, "y_pixels_per_inch must be positive");
+	return NULL;
+    }
+    surface = cairo_ps_surface_create(PyFile_AsFile(file_object), width_inches, height_inches, x_pixels_per_inch, y_pixels_per_inch);
+    if (!surface)
+	return PyErr_NoMemory();
+
+    return pycairo_surface_new(surface);
+}
+#endif /* CAIRO_HAS_PS_SURFACE */
+
+#ifdef CAIRO_HAS_PNG_SURFACE
+static PyObject *
+pycairo_png_surface_create(PyObject *self, PyObject *args)
+{
+    PyObject *file_object;
+    cairo_format_t format;
+    int width, height;
+    cairo_surface_t *surface;
+
+    if (!PyArg_ParseTuple(args, "O!iii:png_surface_create",
+			  &PyFile_Type, &file_object, &format, &width, &height))
+	return NULL;
+
+    if (width <= 0) {
+	PyErr_SetString(PyExc_ValueError, "width must be positive");
+	return NULL;
+    }
+    if (height <= 0) {
+	PyErr_SetString(PyExc_ValueError, "height must be positive");
+	return NULL;
+    }
+
+    surface = cairo_png_surface_create(PyFile_AsFile(file_object), format, width, height);
+    if (!surface)
+	return PyErr_NoMemory();
+
+    return pycairo_surface_new(surface);
+}
+#endif /* CAIRO_HAS_PNG_SURFACE */
+
+
 static PyMethodDef cairo_functions[] = {
-    { "surface_create_for_image",
-      (PyCFunction)pycairo_surface_create_for_image, METH_VARARGS },
+    /* this is the old function name, should use image_surface_create_for_data */
+    { "surface_create_for_image", (PyCFunction)pycairo_image_surface_create_for_data, METH_VARARGS, "this is the old function name, should use image_surface_create_for_data" },
+    { "image_surface_create_for_data", (PyCFunction)pycairo_image_surface_create_for_data, METH_VARARGS, "" },
+
+#ifdef CAIRO_HAS_PS_SURFACE
+    { "ps_surface_create", (PyCFunction)pycairo_ps_surface_create, METH_VARARGS, "" },
+#endif
+
+#ifdef CAIRO_HAS_PNG_SURFACE
+    { "png_surface_create", (PyCFunction)pycairo_png_surface_create, METH_VARARGS, "" },
+#endif
+
     { NULL, NULL, 0 }
 };
 
@@ -102,6 +178,8 @@
     pycairo_font_new,
     &PyCairoContext_Type,
     pycairo_context_new,
+    &PyCairoPattern_Type,
+    pycairo_pattern_wrap,
 };
 
 DL_EXPORT(void)
@@ -173,6 +251,7 @@
     CONSTANT(FILTER_BEST);
     CONSTANT(FILTER_NEAREST);
     CONSTANT(FILTER_BILINEAR);
+    CONSTANT(FILTER_GAUSSIAN);
 
     CONSTANT(FONT_WEIGHT_NORMAL);
     CONSTANT(FONT_WEIGHT_BOLD);
@@ -180,6 +259,10 @@
     CONSTANT(FONT_SLANT_NORMAL);
     CONSTANT(FONT_SLANT_ITALIC);
     CONSTANT(FONT_SLANT_OBLIQUE);
+
+    CONSTANT(EXTEND_NONE);
+    CONSTANT(EXTEND_REPEAT);
+    CONSTANT(EXTEND_REFLECT);
 #undef CONSTANT
 
 }

Index: pycairo-context.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-context.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- pycairo-context.c	4 Nov 2004 14:45:35 -0000	1.7
+++ pycairo-context.c	14 Nov 2004 13:04:00 -0000	1.8
@@ -111,6 +111,7 @@
 cairo_set_target_image();
 #endif
 
+#ifdef CAIRO_HAS_PS_SURFACE
 static PyObject *
 pycairo_set_target_ps(PyCairoContext *self, PyObject *args)
 {
@@ -120,12 +121,12 @@
 
     if (!PyArg_ParseTuple(args, "O!dddd:Context.set_target_ps",
 			  &PyFile_Type, &file_object,
-			  &width_inches, &height_inches, 
+			  &width_inches, &height_inches,
 			  &x_pixels_per_inch, &y_pixels_per_inch))
 	return NULL;
 
     cairo_set_target_ps(self->ctx, PyFile_AsFile(file_object),
-			width_inches, height_inches, 
+			width_inches, height_inches,
 			x_pixels_per_inch, y_pixels_per_inch);
     if (pycairo_check_status(cairo_status(self->ctx)))
 	return NULL;
@@ -133,7 +134,9 @@
     Py_INCREF(Py_None);
     return Py_None;
 }
+#endif  /* CAIRO_HAS_PS_SURFACE */
 
+#ifdef CAIRO_HAS_PNG_SURFACE
 static PyObject *
 pycairo_set_target_png(PyCairoContext *self, PyObject *args)
 {
@@ -141,12 +144,12 @@
     cairo_format_t format;
     int width, height;
 
-    if (!PyArg_ParseTuple(args, "O!iii:Context.set_target_png", 
-			  &PyFile_Type, &file_object, &format, &width, 
+    if (!PyArg_ParseTuple(args, "O!iii:Context.set_target_png",
+			  &PyFile_Type, &file_object, &format, &width,
 			  &height))
 	return NULL;
 
-    cairo_set_target_png(self->ctx, PyFile_AsFile(file_object), format, 
+    cairo_set_target_png(self->ctx, PyFile_AsFile(file_object), format,
 			 width, height);
     if (pycairo_check_status(cairo_status(self->ctx)))
 	return NULL;
@@ -154,6 +157,7 @@
     Py_INCREF(Py_None);
     return Py_None;
 }
+#endif /* CAIRO_HAS_PNG_SURFACE */
 
 static PyObject *
 pycairo_set_operator(PyCairoContext *self, PyObject *args)
@@ -171,6 +175,91 @@
 }
 
 static PyObject *
+pycairo_in_stroke(PyCairoContext *self, PyObject *args)
+{
+    double x, y;
+    PyObject *result;
+
+    if (!PyArg_ParseTuple(args, "dd:Context.in_stroke", &x, &y))
+	return NULL;
+
+    result = cairo_in_stroke(self->ctx, x, y) ? Py_True : Py_False;
+    if (pycairo_check_status(cairo_status(self->ctx)))
+	return NULL;
+    Py_INCREF(result);
+    return result;
+}
+
+static PyObject *
+pycairo_in_fill(PyCairoContext *self, PyObject *args)
+{
+    double x, y;
+    PyObject *result;
+
+    if (!PyArg_ParseTuple(args, "dd:Context.in_fill", &x, &y))
+	return NULL;
+
+    result = cairo_in_fill(self->ctx, x, y) ? Py_True : Py_False;
+    if (pycairo_check_status(cairo_status(self->ctx)))
+	return NULL;
+    Py_INCREF(result);
+    return result;
+}
+
+
+static PyObject *
+pycairo_stroke_extents(PyCairoContext *self, PyObject *args)
+{
+    double x1, y1, x2, y2;
+    if (!PyArg_ParseTuple(args, "dddd:Context.stroke_extents", 
+			  &x1, &y1, &x2, &y2))
+	return NULL;
+
+    cairo_stroke_extents(self->ctx, &x1, &y1, &x2, &y2);
+    if (pycairo_check_status(cairo_status(self->ctx)))
+	return NULL;
+    return Py_BuildValue("(dddd)", x1, y1, x2, y2);
+}
+
+static PyObject *
+pycairo_fill_extents(PyCairoContext *self, PyObject *args)
+{
+    double x1, y1, x2, y2;
+    if (!PyArg_ParseTuple(args, "dddd:Context.fill_extents", 
+			  &x1, &y1, &x2, &y2))
+
+    cairo_fill_extents(self->ctx, &x1, &y1, &x2, &y2);
+    if (pycairo_check_status(cairo_status(self->ctx)))
+	return NULL;
+    return Py_BuildValue("(dddd)", x1, y1, x2, y2);
+}
+
+static PyObject *
+pycairo_init_clip(PyCairoContext *self)
+{
+    cairo_init_clip(self->ctx);
+    if (pycairo_check_status(cairo_status(self->ctx)))
+	return NULL;
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
+static PyObject *
+pycairo_text_path(PyCairoContext *self, PyObject *args)
+{
+    const unsigned char *utf8;
+
+    if (!PyArg_ParseTuple(args, "s:Context.text_path", &utf8))
+	return NULL;
+
+    cairo_text_path(self->ctx, utf8);
+    if (pycairo_check_status(cairo_status(self->ctx)))
+	return NULL;
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
+static PyObject *
 pycairo_set_rgb_color(PyCairoContext *self, PyObject *args)
 {
     double red, green, blue;
@@ -829,10 +918,14 @@
     { "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 },
@@ -873,14 +966,26 @@
     { "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 }
 };
 
@@ -990,6 +1095,20 @@
     return pycairo_surface_new(surface);
 }
 
+static PyObject *
+pycairo_current_pattern(PyCairoContext *self)
+{
+    cairo_pattern_t *pattern;
+
+    pattern = cairo_current_pattern(self->ctx);
+    if (pattern)
+	return pycairo_pattern_wrap(pattern);
+
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
+
 static PyGetSetDef pycairo_getsets[] = {
     { "font", (getter)pycairo_current_font, (setter)0 },
     { "operator", (getter)pycairo_current_operator, (setter)0 },
@@ -1004,6 +1123,7 @@
     { "miter_limit", (getter)pycairo_current_miter_limit, (setter)0 },
     { "matrix", (getter)pycairo_current_matrix, (setter)0 },
     { "target_surface", (getter)pycairo_current_target_surface, (setter)0 },
+    { "pattern", (getter)pycairo_current_pattern, (setter)0 },
     { NULL, (getter)0, (setter)0 }
 };
 

Index: pycairo.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- pycairo.h	4 Nov 2004 14:45:35 -0000	1.4
+++ pycairo.h	14 Nov 2004 13:04:00 -0000	1.5
@@ -41,6 +41,8 @@
     PyObject *(* font_new)(cairo_font_t *font);
     PyTypeObject *context_type;
     PyObject *(* context_new)(cairo_t *ctx);
+    PyTypeObject *pattern_type;
+    PyObject *(* pattern_wrap)(cairo_pattern_t *pattern);
 };
 
 #ifndef _INSIDE_PYCAIRO_




More information about the cairo-commit mailing list