[cairo-commit] pycairo/cairo pycairo-surface.c, 1.63,
1.64 pycairo-context.c, 1.68, 1.69 pycairo-private.h, 1.35,
1.36 pycairo.h, 1.45, 1.46 pycairo-pattern.c, 1.30, 1.31
Steve Chaplin
commit at pdx.freedesktop.org
Mon Apr 24 19:46:01 PDT 2006
Committed by: stevech1097
Update of /cvs/cairo/pycairo/cairo
In directory kemper:/tmp/cvs-serv20170/cairo
Modified Files:
pycairo-surface.c pycairo-context.c pycairo-private.h
pycairo.h pycairo-pattern.c
Log Message:
'SC'
Index: pycairo-surface.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-surface.c,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -d -r1.63 -r1.64
--- pycairo-surface.c 17 Jan 2006 12:00:08 -0000 1.63
+++ pycairo-surface.c 25 Apr 2006 02:45:59 -0000 1.64
@@ -50,18 +50,15 @@
* surface - a cairo_surface_t to 'wrap' into a Python object.
* it is unreferenced if the PycairoSurface creation fails, or if
the cairo_surface_t has an error status
- * 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, PyTypeObject *type,
- PyObject *base)
+PycairoSurface_FromSurface (cairo_surface_t *surface, PyObject *base)
{
+ PyTypeObject *type;
PyObject *o;
assert (surface != NULL);
@@ -71,15 +68,41 @@
return NULL;
}
- if (type == NULL)
- type = &PycairoSurface_Type;
- o = PycairoSurface_Type.tp_alloc (type, 0);
- if (o) {
+ switch (cairo_surface_get_type (surface)) {
+ case CAIRO_SURFACE_TYPE_IMAGE:
+ type = &PycairoImageSurface_Type;
+ break;
+#if CAIRO_HAS_PDF_SURFACE
+ case CAIRO_SURFACE_TYPE_PDF:
+ type = &PycairoPDFSurface_Type;
+ break;
+#endif
+#if CAIRO_HAS_PS_SURFACE
+ case CAIRO_SURFACE_TYPE_PS:
+ type = &PycairoPSSurface_Type;
+ break;
+#endif
+#if CAIRO_HAS_WIN32_SURFACE
+ case CAIRO_SURFACE_TYPE_WIN32:
+ type = &PycairoWin32Surface_Type;
+ break;
+#endif
+#if CAIRO_HAS_SVG_SURFACE
+ case CAIRO_SURFACE_TYPE_SVG:
+ type = &PycairoSVGSurface_Type;
+ break;
+#endif
+ default:
+ ASSERT_NOT_REACHED;
+ }
+
+ o = type->tp_alloc (type, 0);
+ if (o == NULL) {
+ cairo_surface_destroy (surface);
+ } else {
((PycairoSurface *)o)->surface = surface;
Py_XINCREF(base);
((PycairoSurface *)o)->base = base;
- } else {
- cairo_surface_destroy (surface);
}
return o;
}
@@ -123,10 +146,7 @@
surface = cairo_surface_create_similar (o->surface, content,
width, height);
- /* bug #2765 - "How do we identify surface types?"
- * should pass surface type as arg2
- */
- return PycairoSurface_FromSurface (surface, NULL, NULL);
+ return PycairoSurface_FromSurface (surface, NULL);
}
static PyObject *
@@ -411,8 +431,7 @@
array->dimensions[1],
array->dimensions[0],
array->strides[0]);
- return PycairoSurface_FromSurface(surface, &PycairoImageSurface_Type,
- (PyObject *)array);
+ return PycairoSurface_FromSurface(surface, (PyObject *)array);
}
#endif /* HAVE_NUMPY */
@@ -462,7 +481,7 @@
}
surface = cairo_image_surface_create_for_data (buffer, format, width,
height, stride);
- return PycairoSurface_FromSurface(surface, &PycairoImageSurface_Type, obj);
+ return PycairoSurface_FromSurface(surface, obj);
}
@@ -534,8 +553,7 @@
if (PyObject_TypeCheck (file, &PyBaseString_Type))
fclose (fp);
- return PycairoSurface_FromSurface (surface, &PycairoImageSurface_Type,
- NULL);
+ return PycairoSurface_FromSurface (surface, NULL);
}
#endif /* CAIRO_HAS_PNG_FUNCTIONS */
Index: pycairo-context.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-context.c,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -d -r1.68 -r1.69
--- pycairo-context.c 4 Mar 2006 10:36:14 -0000 1.68
+++ pycairo-context.c 25 Apr 2006 02:45:59 -0000 1.69
@@ -408,10 +408,7 @@
{
cairo_surface_t *surface = cairo_get_target (o->ctx);
cairo_surface_reference (surface);
- /* bug #2765 - "How do we identify surface types?"
- * should pass surface type as arg2
- */
- return PycairoSurface_FromSurface (surface, NULL, NULL);
+ return PycairoSurface_FromSurface (surface, NULL);
}
static PyObject *
Index: pycairo-private.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-private.h,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- pycairo-private.h 4 Mar 2006 10:36:14 -0000 1.35
+++ pycairo-private.h 25 Apr 2006 02:45:59 -0000 1.36
@@ -89,7 +89,6 @@
#endif
PyObject *PycairoSurface_FromSurface (cairo_surface_t *surface,
- PyTypeObject *type,
PyObject *base);
int Pycairo_Check_Status (cairo_status_t status);
@@ -109,4 +108,10 @@
} while (0)
#endif /* PY_MAJOR_VERSION */
+#define ASSERT_NOT_REACHED \
+do { \
+ static const int NOT_REACHED = 0; \
+ assert (NOT_REACHED); \
+} while (0)
+
#endif /* _PYCAIRO_PRIVATE_H_ */
Index: pycairo.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo.h,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- pycairo.h 4 Mar 2006 10:36:14 -0000 1.45
+++ pycairo.h 25 Apr 2006 02:45:59 -0000 1.46
@@ -127,7 +127,7 @@
PyTypeObject *SVGSurface_Type;
PyTypeObject *Win32Surface_Type;
PyObject *(*Surface_FromSurface)(cairo_surface_t *surface,
- PyTypeObject *type, PyObject *base);
+ PyObject *base);
/* misc functions */
int (*Check_Status)(cairo_status_t status);
Index: pycairo-pattern.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-pattern.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- pycairo-pattern.c 4 Mar 2006 10:36:14 -0000 1.30
+++ pycairo-pattern.c 25 Apr 2006 02:45:59 -0000 1.31
@@ -72,6 +72,8 @@
case CAIRO_PATTERN_TYPE_RADIAL:
type = &PycairoRadialGradient_Type;
break;
+ default:
+ ASSERT_NOT_REACHED;
}
o = type->tp_alloc(type, 0);
More information about the cairo-commit
mailing list