[cairo-commit] pycairo/cairo pycairo-surface.c, 1.44, 1.45 cairomodule.c, 1.39, 1.40 cairogtkmodule.c, 1.26, 1.27 pycairo.h, 1.37, 1.38 pycairo-private.h, 1.29, 1.30 pycairo-context.c, 1.56, 1.57

Steve Chaplin commit at pdx.freedesktop.org
Wed Jun 1 05:29:04 PDT 2005


Committed by: stevech1097

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

Modified Files:
	pycairo-surface.c cairomodule.c cairogtkmodule.c pycairo.h 
	pycairo-private.h pycairo-context.c 
Log Message:
SC

Index: pycairo-surface.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-surface.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- pycairo-surface.c	29 May 2005 11:11:48 -0000	1.44
+++ pycairo-surface.c	1 Jun 2005 12:29:02 -0000	1.45
@@ -48,18 +48,24 @@
  * Create a new PycairoSurface from a cairo_surface_t
  * surface - a cairo_surface_t to 'wrap' into a Python object.
  *           it is unreferenced if the PycairoSurface creation fails
+ * type - the type of the object to instantiate; it can be NULL,
+ *        meaning a base cairo.Surface type, or it can be a subclass of
+ *        cairo.Surface.
  * base - the base object used to create the context, or NULL.
  *        it is referenced to keep it alive while the cairo_surface_t is 
  *        being used
  * Return value: New reference or NULL on failure
  */
 PyObject *
-PycairoSurface_FromSurface (cairo_surface_t *surface, PyObject *base)
+PycairoSurface_FromSurface (cairo_surface_t *surface, PyTypeObject *type, 
+			    PyObject *base)
 {
     PyObject *o;
 
     assert (surface != NULL);
-    o = PycairoSurface_Type.tp_alloc (&PycairoSurface_Type, 0);
+    if (type == NULL)
+        type = &PycairoSurface_Type;
+    o = PycairoSurface_Type.tp_alloc (type, 0);
     if (o) {
 	((PycairoSurface *)o)->surface = surface;
 	Py_XINCREF(base);
@@ -111,10 +117,9 @@
     if (!surface)
 	return PyErr_NoMemory();
     /* bug #2765 - "How do we identify surface types?"
-     * determine surface type and use PycairoImageSurface_FromImageSurface() 
-     * etc to create the correct Pycairo object
+     * should pass surface type as arg2
      */
-    return PycairoSurface_FromSurface (surface, NULL);
+    return PycairoSurface_FromSurface (surface, NULL, NULL);
 }
 
 static PyObject *
@@ -226,23 +231,6 @@
 
 /* Class ImageSurface(Surface) -------------------------------------------- */
 
-PyObject *
-PycairoImageSurface_FromImageSurface (cairo_surface_t *surface, PyObject *base)
-{
-    PyObject *o;
-
-    assert (surface != NULL);
-    o = PycairoImageSurface_Type.tp_alloc (&PycairoImageSurface_Type, 0);
-    if (o) {
-	((PycairoImageSurface *)o)->surface = surface;
-	Py_XINCREF(base);
-	((PycairoImageSurface *)o)->base = base;
-    } else {
-	cairo_surface_destroy (surface);
-    }
-    return o;
-}
-
 static PyObject *
 image_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
@@ -325,7 +313,8 @@
 						  array->strides[0]);
     if (!surface)
 	return PyErr_NoMemory();
-    return PycairoImageSurface_FromImageSurface(surface, (PyObject *)array);
+    return PycairoSurface_FromSurface(surface, &PycairoImageSurface_Type, 
+				      (PyObject *)array);
 }
 #endif /* HAVE_NUMPY */
 
@@ -377,7 +366,8 @@
     if (!surface)
 	return PyErr_NoMemory();
 
-    return PycairoImageSurface_FromImageSurface (surface, NULL);
+    return PycairoSurface_FromSurface(surface, &PycairoImageSurface_Type, 
+				      NULL);
     /* FIXME: get surface to hold a reference to buffer */
 }
 #endif
@@ -398,7 +388,8 @@
 			"not be allocated for operation");
 	return NULL;
     }
-    return PycairoImageSurface_FromImageSurface (surface, NULL);
+    return PycairoSurface_FromSurface (surface, &PycairoImageSurface_Type, 
+				       NULL);
 }
 #endif /* CAIRO_HAS_PNG_FUNCTIONS */
 
@@ -485,21 +476,6 @@
 #ifdef CAIRO_HAS_PDF_SURFACE
 #include <cairo-pdf.h>
 
-PyObject *
-PycairoPDFSurface_FromPDFSurface (cairo_surface_t *surface, PyObject *base)
-{
-    PyObject *o;
-
-    assert (surface != NULL);
-    o = PycairoPDFSurface_Type.tp_alloc (&PycairoPDFSurface_Type, 0);
-    if (o) {
-	((PycairoPDFSurface *)o)->surface = surface;
-	Py_XINCREF(base);
-	((PycairoPDFSurface *)o)->base = base;
-    }
-    return o;
-}
-
 static PyObject *
 pdf_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
@@ -593,21 +569,6 @@
 #ifdef CAIRO_HAS_PS_SURFACE
 #include <cairo-ps.h>
 
-PyObject *
-PycairoPSSurface_FromPSSurface (cairo_surface_t *surface, PyObject *base)
-{
-    PyObject *o;
-
-    assert (surface != NULL);
-    o = PycairoPSSurface_Type.tp_alloc (&PycairoPSSurface_Type, 0);
-    if (o) {
-	((PycairoPSSurface *)o)->surface = surface;
-	Py_XINCREF(base);
-	((PycairoPSSurface *)o)->base = base;
-    }
-    return o;
-}
-
 static PyObject *
 ps_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
@@ -701,21 +662,6 @@
 #if CAIRO_HAS_WIN32_SURFACE
 #include <cairo-win32.h>
 
-PyObject *
-PycairoWin32Surface_FromWin32Surface (cairo_surface_t *surface, PyObject *base)
-{
-    PyObject *o;
-
-    assert (surface != NULL);
-    o = PycairoWin32Surface_Type.tp_alloc (&PycairoWin32Surface_Type, 0);
-    if (o) {
-	((PycairoWin32Surface *)o)->surface = surface;
-	Py_XINCREF(base);
-	((PycairoWin32Surface *)o)->base = base;
-    }
-    return o;
-}
-
 static PyObject *
 win32_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
 {

Index: cairomodule.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/cairomodule.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- cairomodule.c	1 Jun 2005 04:21:19 -0000	1.39
+++ cairomodule.c	1 Jun 2005 12:29:02 -0000	1.40
@@ -105,23 +105,23 @@
     &PycairoPattern_Type,      PycairoPattern_FromPattern,
     &PycairoScaledFont_Type,   PycairoScaledFont_FromScaledFont,
 
-    &PycairoSurface_Type,      PycairoSurface_FromSurface,
-    &PycairoImageSurface_Type, PycairoImageSurface_FromImageSurface,
+    &PycairoImageSurface_Type,
 #ifdef CAIRO_HAS_PDF_SURFACE
-    &PycairoPDFSurface_Type,   PycairoPDFSurface_FromPDFSurface,
+    &PycairoPDFSurface_Type,
 #else
-    0, 0,
+    0,
 #endif
 #ifdef CAIRO_HAS_PS_SURFACE
-    &PycairoPSSurface_Type,    PycairoPSSurface_FromPSSurface,
+    &PycairoPSSurface_Type,
 #else
-    0, 0,
+    0,
 #endif
 #ifdef CAIRO_HAS_WIN32_SURFACE
-    &PycairoWin32Surface_Type, PycairoWin32Surface_FromWin32Surface,
+    &PycairoWin32Surface_Type,
 #else
-    0, 0,
+    0,
 #endif
+                               PycairoSurface_FromSurface,
 
     Pycairo_Check_Status,
 };

Index: cairogtkmodule.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/cairogtkmodule.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- cairogtkmodule.c	27 May 2005 03:02:50 -0000	1.26
+++ cairogtkmodule.c	1 Jun 2005 12:29:02 -0000	1.27
@@ -84,8 +84,8 @@
 	 gdk_pixbuf_get_rowstride(gdk_pixbuf));
     if (!surface)
 	return PyErr_NoMemory();
-    return PycairoImageSurface_FromImageSurface (surface, 
-						 (PyObject *)py_pixbuf);
+    return PycairoSurface_FromSurface (surface, &PycairoImageSurface_Type,
+				       (PyObject *)py_pixbuf);
 }
 
 #ifndef HAVE_GTK28
@@ -144,7 +144,7 @@
 	PyErr_SetString(PyExc_RuntimeError, "could not create context");
 	return NULL;
     }
-    return PycairoContext_FromContext (cr, (PyObject *)py_drawable);
+    return PycairoContext_FromContext (cr, NULL, (PyObject *)py_drawable);
 }
 
 static PyMethodDef cairogtk_functions[] = {

Index: pycairo.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo.h,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- pycairo.h	30 May 2005 04:27:01 -0000	1.37
+++ pycairo.h	1 Jun 2005 12:29:02 -0000	1.38
@@ -82,7 +82,8 @@
 typedef struct {
     /* (type object, constructor) pairs */
     PyTypeObject *Context_Type;
-    PyObject *(*Context_FromContext)(cairo_t *ctx, PyObject *base);
+    PyObject *(*Context_FromContext)(cairo_t *ctx, PyTypeObject *type,
+				     PyObject *base);
     PyTypeObject *FontFace_Type;
     PyObject *(*FontFace_FromFontFace)(cairo_font_face_t *font_face);
     PyTypeObject *Matrix_Type;
@@ -94,20 +95,12 @@
     PyTypeObject *ScaledFont_Type;
     PyObject *(*ScaledFont_FromScaledFont)(cairo_scaled_font_t *scaled_font);
 
-    PyTypeObject *Surface_Type;
-    PyObject *(*Surface_FromSurface)(cairo_surface_t *surface, PyObject *base);
     PyTypeObject *ImageSurface_Type;
-    PyObject *(*ImageSurface_FromImageSurface)(cairo_surface_t *surface, 
-					       PyObject *base);
     PyTypeObject *PDFSurface_Type;
-    PyObject *(*PDFSurface_FromPDFSurface)(cairo_surface_t *surface, 
-					   PyObject *base);
     PyTypeObject *PSSurface_Type;
-    PyObject *(*PSSurface_FromPSSurface)(cairo_surface_t *surface, 
-					 PyObject *base);
     PyTypeObject *Win32Surface_Type;
-    PyObject *(*Win32Surface_FromWin32Surface)(cairo_surface_t *surface, 
-					       PyObject *base);
+    PyObject *(*Surface_FromSurface)(cairo_surface_t *surface, 
+				     PyTypeObject *type, PyObject *base);
 
     /* misc functions */
     int (*Check_Status)(cairo_status_t status);
@@ -131,29 +124,22 @@
 #define PycairoScaledFont_FromScaledFont \
         (Pycairo_CAPI->ScaledFont_FromScaledFont)
 
-#define PycairoSurface_Type         *(Pycairo_CAPI->Surface_Type)
-#define PycairoSurface_FromSurface   (Pycairo_CAPI->Surface_FromSurface)
 #define PycairoImageSurface_Type    *(Pycairo_CAPI->ImageSurface_Type)
-#define PycairoImageSurface_FromImageSurface \
-        (Pycairo_CAPI->ImageSurface_FromImageSurface)
 
 #if CAIRO_HAS_PDF_SURFACE
 #define PycairoPDFSurface_Type      *(Pycairo_CAPI->PDFSurface_Type)
-#define PycairoPDFSurface_FromPDFSurface \
-        (Pycairo_CAPI->PDFSurface_FromPDFSurface)
 #endif
 
 #if CAIRO_HAS_PS_SURFACE
 #define PycairoPSSurface_Type       *(Pycairo_CAPI->PSSurface_Type)
-#define PycairoPSSurface_FromPSSurface (Pycairo_CAPI->PSSurface_FromPSSurface)
 #endif
 
 #if CAIRO_HAS_WIN32_SURFACE
 #define PycairoWin32Surface_Type    *(Pycairo_CAPI->Win32Surface_Type)
-#define PycairoWin32Surface_FromPSSurface \
-        (Pycairo_CAPI->Win32Surface_FromWin32Surface)
 #endif
 
+#define PycairoSurface_FromSurface   (Pycairo_CAPI->Surface_FromSurface)
+
 #define Pycairo_Check_Status         (Pycairo_CAPI->Check_Status)
 
 

Index: pycairo-private.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-private.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- pycairo-private.h	30 May 2005 04:27:01 -0000	1.29
+++ pycairo-private.h	1 Jun 2005 12:29:02 -0000	1.30
@@ -44,7 +44,8 @@
 extern PyObject *CairoError;
 
 extern PyTypeObject PycairoContext_Type;
-PyObject *PycairoContext_FromContext (cairo_t *ctx, PyObject *base);
+PyObject *PycairoContext_FromContext (cairo_t *ctx, PyTypeObject *type,
+				      PyObject *base);
 
 extern PyTypeObject PycairoFontFace_Type;
 PyObject *PycairoFontFace_FromFontFace (cairo_font_face_t *font_face);
@@ -62,31 +63,24 @@
 PyObject *PycairoScaledFont_FromScaledFont (cairo_scaled_font_t *scaled_font);
 
 extern PyTypeObject PycairoSurface_Type;
-PyObject *PycairoSurface_FromSurface (cairo_surface_t *surface, 
-				      PyObject *base);
-
 extern PyTypeObject PycairoImageSurface_Type;
-PyObject *PycairoImageSurface_FromImageSurface (cairo_surface_t *surface, 
-						PyObject *base);
 
 #if CAIRO_HAS_PDF_SURFACE
 extern PyTypeObject PycairoPDFSurface_Type;
-PyObject *PycairoPDFSurface_FromPDFSurface (cairo_surface_t *surface, 
-					    PyObject *base);
 #endif
 
 #if CAIRO_HAS_PS_SURFACE
 extern PyTypeObject PycairoPSSurface_Type;
-PyObject *PycairoPSSurface_FromPSSurface (cairo_surface_t *surface, 
-					  PyObject *base);
 #endif
 
 #if CAIRO_HAS_WIN32_SURFACE
 extern PyTypeObject PycairoWin32Surface_Type;
-PyObject *PycairoWin32Surface_FromWin32Surface (cairo_surface_t *surface, 
-						PyObject *base);
 #endif
 
+PyObject *PycairoSurface_FromSurface (cairo_surface_t *surface,  
+				      PyTypeObject *type,
+				      PyObject *base);
+
 int Pycairo_Check_Status (cairo_status_t status);
 
 /* useful macros from Python 2.4 */

Index: pycairo-context.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-context.c,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- pycairo-context.c	25 May 2005 11:07:13 -0000	1.56
+++ pycairo-context.c	1 Jun 2005 12:29:02 -0000	1.57
@@ -39,17 +39,22 @@
  * Create a new PycairoContext from a cairo_t
  * ctx  - a cairo_t to 'wrap' into a Python object.
  *        it is unreferenced if the PycairoContext creation fails
+ * type - the type of the object to instantiate; it can be NULL,
+ *        meaning a base cairo.Context type, or it can be a subclass of
+ *        cairo.Context.
  * base - the base object used to create the context, or NULL.
  *        it is referenced to keep it alive while the cairo_t is being used
  * Return value: New reference or NULL on failure
  */
 PyObject *
-PycairoContext_FromContext(cairo_t *ctx, PyObject *base)
+PycairoContext_FromContext(cairo_t *ctx, PyTypeObject *type, PyObject *base)
 {
     PyObject *o;
 
     assert (ctx != NULL);
-    o = PycairoContext_Type.tp_alloc (&PycairoContext_Type, 0);
+    if (type == NULL)
+        type = &PycairoContext_Type;
+    o = PycairoContext_Type.tp_alloc (type, 0);
     if (o) {
 	((PycairoContext *)o)->ctx = ctx;
 	Py_XINCREF(base);
@@ -381,7 +386,10 @@
 	return NULL;
     }
     cairo_surface_reference (surface);
-    return PycairoSurface_FromSurface (surface, NULL);
+    /* bug #2765 - "How do we identify surface types?"
+     * should pass surface type as arg2
+     */
+    return PycairoSurface_FromSurface (surface, NULL, NULL);
 }
 
 static PyObject *




More information about the cairo-commit mailing list