From 6ed8a95d6784d1f61406f588189dd76e89775bb8 Mon Sep 17 00:00:00 2001 From: Steve Chaplin Date: Thu, 20 May 2010 11:01:46 +0800 Subject: Add Win32PrintingSurface. --- doc/reference/surfaces.rst | 21 +++++++++++++ src/cairomodule.c | 7 +++++ src/private.h | 1 + src/pycairo.h | 3 ++ src/surface.c | 74 ++++++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 103 insertions(+), 3 deletions(-) diff --git a/doc/reference/surfaces.rst b/doc/reference/surfaces.rst index fbec39e..9827514 100644 --- a/doc/reference/surfaces.rst +++ b/doc/reference/surfaces.rst @@ -627,6 +627,27 @@ Windows windows, bitmaps, and printing device contexts. +class Win32PrintingSurface(:class:`Surface`) +============================================ + +The Win32PrintingSurface is a multi-page vector surface type. + +.. class:: Win32PrintingSurface(hdc) + + :param hdc: the DC to create a surface for + :type hdc: int + :returns: the newly created surface + + Creates a cairo surface that targets the given DC. The DC will be queried + for its initial clip extents, and this will be used as the size of the + cairo surface. The DC should be a printing DC; antialiasing will be + ignored, and GDI will be used as much as possible to draw to the surface. + + The returned surface will be wrapped using the paginated surface to provide + correct complex rendering behaviour; :meth:`.show_page` and associated + methods must be used for correct output. + + class XCBSurface(:class:`Surface`) =================================== diff --git a/src/cairomodule.c b/src/cairomodule.c index bc95108..68fb2f4 100644 --- a/src/cairomodule.c +++ b/src/cairomodule.c @@ -134,8 +134,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, @@ -228,6 +230,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) @@ -310,6 +314,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 708f04c..4e09922 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..c886de8 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,7 @@ 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 fa11413..3c1b11d 100644 --- a/src/surface.c +++ b/src/surface.c @@ -43,8 +43,11 @@ * PycairoPDFSurface, * PycairoPSSurface, * PycairoSVGSurface, - * PycairoWin32Surface, or - * PycairoXlibSurface from a cairo_surface_t. + * PycairoWin32Surface, + * PycairoWin32PrintingSurface, + * PycairoXCBSurface, 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 * cairo_surface_t has an error status. @@ -89,6 +92,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: @@ -1075,10 +1081,10 @@ PyTypeObject PycairoSVGSurface_Type = { #endif /* CAIRO_HAS_SVG_SURFACE */ -/* Class Win32Surface(Surface) -------------------------------------------- */ #if CAIRO_HAS_WIN32_SURFACE #include +/* Class Win32Surface(Surface) -------------------------------------------- */ static PyObject * win32_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds) { int hdc; @@ -1137,6 +1143,68 @@ PyTypeObject PycairoWin32Surface_Type = { 0, /* tp_is_gc */ 0, /* tp_bases */ }; + + +/* Class Win32PrintingSurface(Surface) ------------------------------------ */ +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 */ -- cgit v1.2.1