summaryrefslogtreecommitdiff
path: root/src/pycairo-surface.c
diff options
context:
space:
mode:
authorSteve Chaplin <stevech1097@yahoo.com.au>2009-08-24 20:09:32 +0800
committerSteve Chaplin <stevech1097@yahoo.com.au>2009-08-24 20:09:32 +0800
commit9d9ad8f01001df91a131cc811cf733409c813829 (patch)
treeed01875df19be67cbf760da53009d1cc9ddb2f63 /src/pycairo-surface.c
parenta0b47905e765aeeda6220c2dece4d959b7b25a5f (diff)
downloadpy2cairo-9d9ad8f01001df91a131cc811cf733409c813829.tar.gz
allow None as filename arg to PDF/PS/SVGSurface
Diffstat (limited to 'src/pycairo-surface.c')
-rw-r--r--src/pycairo-surface.c52
1 files changed, 41 insertions, 11 deletions
diff --git a/src/pycairo-surface.c b/src/pycairo-surface.c
index 65af7f5..b4a4a2d 100644
--- a/src/pycairo-surface.c
+++ b/src/pycairo-surface.c
@@ -706,7 +706,13 @@ pdf_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
&file, &width_in_points, &height_in_points))
return NULL;
- if (PyObject_TypeCheck (file, &PyBaseString_Type)) {
+ if (file == Py_None) {
+ Py_BEGIN_ALLOW_THREADS
+ sfc = cairo_pdf_surface_create (NULL,
+ width_in_points, height_in_points);
+ Py_END_ALLOW_THREADS
+ return PycairoSurface_FromSurface (sfc, NULL);
+ }else if (PyObject_TypeCheck (file, &PyBaseString_Type)) {
/* string (filename) argument */
Py_BEGIN_ALLOW_THREADS
sfc = cairo_pdf_surface_create (PyString_AsString(file),
@@ -719,8 +725,12 @@ pdf_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
if (writer == NULL || !PyCallable_Check (writer)) {
Py_XDECREF(writer);
PyErr_SetString(PyExc_TypeError,
-"PDFSurface argument 1 must be a filename (str), file object, or an object "
-"that has a \"write\" method (like StringIO)");
+"PDFSurface argument 1 must be\n"
+" None, or\n"
+" a filename (str), or\n"
+" a file object, or\n"
+" an object that has a \"write\" method (like StringIO)."
+ );
return NULL;
}
Py_DECREF(writer);
@@ -812,11 +822,17 @@ ps_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
&file, &width_in_points, &height_in_points))
return NULL;
- if (PyObject_TypeCheck (file, &PyBaseString_Type)) {
+ if (file == Py_None) {
+ Py_BEGIN_ALLOW_THREADS
+ sfc = cairo_ps_surface_create (NULL,
+ width_in_points, height_in_points);
+ Py_END_ALLOW_THREADS
+ return PycairoSurface_FromSurface (sfc, NULL);
+ }else if (PyObject_TypeCheck (file, &PyBaseString_Type)) {
/* string (filename) argument */
Py_BEGIN_ALLOW_THREADS
sfc = cairo_ps_surface_create (PyString_AsString(file),
- width_in_points, height_in_points);
+ width_in_points, height_in_points);
Py_END_ALLOW_THREADS
return PycairoSurface_FromSurface (sfc, NULL);
}
@@ -825,8 +841,12 @@ ps_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
if (writer == NULL || !PyCallable_Check (writer)) {
Py_XDECREF(writer);
PyErr_SetString(PyExc_TypeError,
-"PSSurface argument 1 must be a filename (str), file object, or an object "
-"that has a \"write\" method (like StringIO)");
+"PSSurface argument 1 must be\n"
+" None, or\n"
+" a filename (str), or\n"
+" a file object, or\n"
+" an object that has a \"write\" method (like StringIO)."
+ );
return NULL;
}
Py_DECREF(writer);
@@ -1004,11 +1024,17 @@ svg_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
&file, &width_in_points, &height_in_points))
return NULL;
- if (PyObject_TypeCheck (file, &PyBaseString_Type)) {
+ if (file == Py_None) {
+ Py_BEGIN_ALLOW_THREADS
+ sfc = cairo_svg_surface_create (NULL,
+ width_in_points, height_in_points);
+ Py_END_ALLOW_THREADS
+ return PycairoSurface_FromSurface (sfc, NULL);
+ }else if (PyObject_TypeCheck (file, &PyBaseString_Type)) {
/* string (filename) argument */
Py_BEGIN_ALLOW_THREADS
sfc = cairo_svg_surface_create (PyString_AsString(file),
- width_in_points, height_in_points);
+ width_in_points, height_in_points);
Py_END_ALLOW_THREADS
return PycairoSurface_FromSurface (sfc, NULL);
}
@@ -1017,8 +1043,12 @@ svg_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
if (writer == NULL || !PyCallable_Check (writer)) {
Py_XDECREF(writer);
PyErr_SetString(PyExc_TypeError,
-"SVGSurface argument 1 must be a filename (str), file object, or an object "
-"that has a \"write\" method (like StringIO)");
+"SVGSurface argument 1 must be\n"
+" None, or\n"
+" a filename (str), or\n"
+" a file object, or\n"
+" an object that has a \"write\" method (like StringIO)."
+ );
return NULL;
}
Py_DECREF(writer);