diff --git a/src/cairomodule.c b/src/cairomodule.c index a83ba49..68b2a9b 100644 --- a/src/cairomodule.c +++ b/src/cairomodule.c @@ -129,8 +129,10 @@ static Pycairo_CAPI_t CAPI = { #endif #ifdef CAIRO_HAS_WIN32_SURFACE &PycairoWin32Surface_Type, + &PycairoWin32PrintingSurface_Type, #else 0, + 0, #endif #ifdef CAIRO_HAS_XCB_SURFACE &PycairoXCBSurface_Type, @@ -221,6 +223,8 @@ init_cairo(void) #ifdef CAIRO_HAS_WIN32_SURFACE if (PyType_Ready(&PycairoWin32Surface_Type) < 0) return; + if (PyType_Ready(&PycairoWin32PrintingSurface_Type) < 0) + return; #endif #ifdef CAIRO_HAS_XCB_SURFACE if (PyType_Ready(&PycairoXCBSurface_Type) < 0) @@ -303,6 +307,9 @@ init_cairo(void) Py_INCREF(&PycairoWin32Surface_Type); PyModule_AddObject(m, "Win32Surface", (PyObject *)&PycairoWin32Surface_Type); + Py_INCREF(&PycairoWin32PrintingSurface_Type); + PyModule_AddObject(m, "Win32PrintingSurface", + (PyObject *)&PycairoWin32PrintingSurface_Type); #endif #ifdef CAIRO_HAS_XCB_SURFACE diff --git a/src/private.h b/src/private.h index 4bbf4fd..7a25417 100644 --- a/src/private.h +++ b/src/private.h @@ -92,6 +92,7 @@ extern PyTypeObject PycairoSVGSurface_Type; #if CAIRO_HAS_WIN32_SURFACE extern PyTypeObject PycairoWin32Surface_Type; +extern PyTypeObject PycairoWin32PrintingSurface_Type; #endif #if CAIRO_HAS_XCB_SURFACE diff --git a/src/pycairo.h b/src/pycairo.h index f9cfacf..da88cbf 100644 --- a/src/pycairo.h +++ b/src/pycairo.h @@ -92,6 +92,7 @@ typedef struct { #define PycairoPSSurface PycairoSurface #define PycairoSVGSurface PycairoSurface #define PycairoWin32Surface PycairoSurface +#define PycairoWin32PrintingSurface PycairoSurface #define PycairoXCBSurface PycairoSurface #define PycairoXlibSurface PycairoSurface @@ -132,6 +133,7 @@ typedef struct { PyTypeObject *PSSurface_Type; PyTypeObject *SVGSurface_Type; PyTypeObject *Win32Surface_Type; + PyTypeObject *Win32PrintingSurface_Type; PyTypeObject *XCBSurface_Type; PyTypeObject *XlibSurface_Type; PyObject *(*Surface_FromSurface)(cairo_surface_t *surface, PyObject *base); @@ -186,6 +188,8 @@ typedef struct { #if CAIRO_HAS_WIN32_SURFACE #define PycairoWin32Surface_Type *(Pycairo_CAPI->Win32Surface_Type) +#define PycairoWin32PrintingSurface_Type \ + *(Pycairo_CAPI->Win32PrintingSurface_Type) #endif #if CAIRO_HAS_XCB_SURFACE diff --git a/src/surface.c b/src/surface.c index 7a6fd2e..2d2a1bd 100644 --- a/src/surface.c +++ b/src/surface.c @@ -43,7 +43,8 @@ * PycairoPDFSurface, * PycairoPSSurface, * PycairoSVGSurface, - * PycairoWin32Surface, or + * PycairoWin32Surface, + * PycairoWin32PrintingSurface, or * PycairoXlibSurface from a cairo_surface_t. * surface - a cairo_surface_t to 'wrap' into a Python object. * It is unreferenced if the PycairoSurface creation fails, or if the @@ -89,6 +90,9 @@ PycairoSurface_FromSurface (cairo_surface_t *surface, PyObject *base) { case CAIRO_SURFACE_TYPE_WIN32: type = &PycairoWin32Surface_Type; break; + case CAIRO_SURFACE_TYPE_WIN32_PRINTING: + type = &PycairoWin32PrintingSurface_Type; + break; #endif #if CAIRO_HAS_XCB_SURFACE case CAIRO_SURFACE_TYPE_XCB: @@ -1137,6 +1141,65 @@ PyTypeObject PycairoWin32Surface_Type = { 0, /* tp_is_gc */ 0, /* tp_bases */ }; + +static PyObject * +win32_printing_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds) { + int hdc; + + if (!PyArg_ParseTuple(args, "i:Win32PrintingSurface.__new__", &hdc)) + return NULL; + return PycairoSurface_FromSurface ( + cairo_win32_printing_surface_create ((HDC)hdc), NULL); +} + +static PyMethodDef win32_printing_surface_methods[] = { + {NULL, NULL, 0, NULL}, +}; + +PyTypeObject PycairoWin32PrintingSurface_Type = { + PyObject_HEAD_INIT(NULL) + 0, /* ob_size */ + "cairo.Win32PrintingSurface", /* tp_name */ + sizeof(PycairoWin32PrintingSurface),/* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT, /* tp_flags */ + 0, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + win32_printing_surface_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &PycairoSurface_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + (newfunc)win32_printing_surface_new,/* tp_new */ + 0, /* tp_free */ + 0, /* tp_is_gc */ + 0, /* tp_bases */ +}; #endif /* CAIRO_HAS_WIN32_SURFACE */