summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSteve Chaplin <>2012-08-04 12:29:32 +0800
committerSteve Chaplin <>2012-08-04 12:29:32 +0800
commitc55e63970befc87120ceacae5fc9ffba0881d33d (patch)
treed5c01141dd136e0cdec1a92134dc44079febc068 /src
parent9576b3d77034d91f456a5b199a9fc9cc2fde3c08 (diff)
New methods added:
cairo_in_clip cairo_surface_create_for_rectangle cairo_pdf_surface_restrict_to_version cairo_pdf_version_to_string New constants added: cairo.PDF_VERSION_1_4 cairo.PDF_VERSION_1_5
Diffstat (limited to 'src')
-rw-r--r--src/cairomodule.c10
-rw-r--r--src/context.c15
-rw-r--r--src/surface.c63
3 files changed, 79 insertions, 9 deletions
diff --git a/src/cairomodule.c b/src/cairomodule.c
index 886c6d5..3a15d44 100644
--- a/src/cairomodule.c
+++ b/src/cairomodule.c
@@ -24,6 +24,11 @@
#include "config.h"
#include "private.h"
+/* to read CAIRO_PDF_VERSION_* constants */
+#ifdef CAIRO_HAS_PDF_SURFACE
+# include <cairo-pdf.h>
+#endif
+
/* to read CAIRO_PS_LEVEL_* constants */
#ifdef CAIRO_HAS_PS_SURFACE
# include <cairo-ps.h>
@@ -535,6 +540,11 @@ PyInit__cairo(void)
CONSTANT(PATH_CURVE_TO);
CONSTANT(PATH_CLOSE_PATH);
+#ifdef CAIRO_HAS_PDF_SURFACE
+ CONSTANT(PDF_VERSION_1_4);
+ CONSTANT(PDF_VERSION_1_5);
+#endif
+
#ifdef CAIRO_HAS_PS_SURFACE
CONSTANT(PS_LEVEL_2);
CONSTANT(PS_LEVEL_3);
diff --git a/src/context.c b/src/context.c
index 9bee5d4..984cdfc 100644
--- a/src/context.c
+++ b/src/context.c
@@ -530,6 +530,20 @@ pycairo_identity_matrix (PycairoContext *o) {
}
static PyObject *
+pycairo_in_clip (PycairoContext *o, PyObject *args) {
+ double x, y;
+ PyObject *result;
+
+ if (!PyArg_ParseTuple (args, "dd:Context.in_clip", &x, &y))
+ return NULL;
+
+ result = cairo_in_clip (o->ctx, x, y) ? Py_True : Py_False;
+ RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
+ Py_INCREF(result);
+ return result;
+}
+
+static PyObject *
pycairo_in_fill (PycairoContext *o, PyObject *args) {
double x, y;
PyObject *result;
@@ -1266,6 +1280,7 @@ static PyMethodDef pycairo_methods[] = {
{"glyph_path", (PyCFunction)pycairo_glyph_path, METH_VARARGS},
{"has_current_point",(PyCFunction)pycairo_has_current_point, METH_NOARGS},
{"identity_matrix", (PyCFunction)pycairo_identity_matrix, METH_NOARGS},
+ {"in_clip", (PyCFunction)pycairo_in_clip, METH_VARARGS},
{"in_fill", (PyCFunction)pycairo_in_fill, METH_VARARGS},
{"in_stroke", (PyCFunction)pycairo_in_stroke, METH_VARARGS},
{"line_to", (PyCFunction)pycairo_line_to, METH_VARARGS},
diff --git a/src/surface.c b/src/surface.c
index 4701a4b..1589a70 100644
--- a/src/surface.c
+++ b/src/surface.c
@@ -202,6 +202,20 @@ surface_create_similar (PycairoSurface *o, PyObject *args) {
}
static PyObject *
+surface_create_for_rectangle (PycairoSurface *o, PyObject *args) {
+ double x, y, width, height;
+
+ if (!PyArg_ParseTuple (args, "dddd:Surface.create_for_rectangle",
+ &x, &y, &width, &height))
+
+ return NULL;
+ return PycairoSurface_FromSurface (
+ cairo_surface_create_for_rectangle (o->surface,
+ x, y, width, height),
+ NULL);
+}
+
+static PyObject *
surface_finish (PycairoSurface *o) {
cairo_surface_finish (o->surface);
Py_CLEAR(o->base);
@@ -352,6 +366,8 @@ static PyMethodDef surface_methods[] = {
*/
{"copy_page", (PyCFunction)surface_copy_page, METH_NOARGS},
{"create_similar", (PyCFunction)surface_create_similar, METH_VARARGS},
+ {"create_for_rectangle", (PyCFunction)surface_create_for_rectangle,
+ METH_VARARGS},
{"finish", (PyCFunction)surface_finish, METH_NOARGS},
{"flush", (PyCFunction)surface_flush, METH_NOARGS},
{"get_content", (PyCFunction)surface_get_content, METH_NOARGS},
@@ -742,6 +758,17 @@ pdf_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
}
static PyObject *
+pdf_surface_restrict_to_version (PycairoPDFSurface *o, PyObject *args) {
+ int version;
+
+ if (!PyArg_ParseTuple(args, "i:PDFSurface.restrict_to_version", &version))
+ return NULL;
+ cairo_pdf_surface_restrict_to_version (o->surface, version);
+ RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
+ Py_RETURN_NONE;
+}
+
+static PyObject *
pdf_surface_set_size (PycairoPDFSurface *o, PyObject *args) {
double width_in_points, height_in_points;
@@ -753,8 +780,28 @@ pdf_surface_set_size (PycairoPDFSurface *o, PyObject *args) {
Py_RETURN_NONE;
}
+/* METH_STATIC */
+static PyObject *
+pdf_surface_pdf_version_to_string (PyObject *self, PyObject *args) {
+ int version;
+ if (!PyArg_ParseTuple(args, "i:pdf_version_to_string", &version))
+ return NULL;
+ const char *s = cairo_pdf_version_to_string (version);
+ if (s == NULL){
+ PyErr_SetString(CairoError, "pdf_version_to_string: "
+ "invalid level argument");
+ return NULL;
+ }
+ return PyUnicode_DecodeASCII(s, strlen(s), NULL);
+}
+
static PyMethodDef pdf_surface_methods[] = {
- {"set_size", (PyCFunction)pdf_surface_set_size, METH_VARARGS },
+ {"restrict_to_version", (PyCFunction)pdf_surface_restrict_to_version,
+ METH_VARARGS },
+ {"set_size", (PyCFunction)pdf_surface_set_size, METH_VARARGS },
+ /* pdf_get_levels - not implemented yet */
+ {"pdf_version_to_string", (PyCFunction)pdf_surface_pdf_version_to_string,
+ METH_VARARGS | METH_STATIC},
{NULL, NULL, 0, NULL},
};
@@ -902,11 +949,9 @@ ps_surface_ps_level_to_string (PyObject *self, PyObject *args) {
return NULL;
const char *s = cairo_ps_level_to_string (level);
if (s == NULL){
- PyErr_SetString(CairoError, "ps_level_to_string: "
- "invalid level argument");
+ PyErr_SetString(CairoError, "ps_level_to_string: invalid level argument");
return NULL;
}
- //return PyUnicode_FromString(s);
return PyUnicode_DecodeASCII(s, strlen(s), NULL);
}
@@ -944,16 +989,16 @@ ps_surface_set_size (PycairoPSSurface *o, PyObject *args) {
}
static PyMethodDef ps_surface_methods[] = {
- {"dsc_begin_page_setup",
- (PyCFunction)ps_surface_dsc_begin_page_setup, METH_NOARGS },
+ {"dsc_begin_page_setup", (PyCFunction)ps_surface_dsc_begin_page_setup,
+ METH_NOARGS },
{"dsc_begin_setup", (PyCFunction)ps_surface_dsc_begin_setup, METH_NOARGS },
{"dsc_comment", (PyCFunction)ps_surface_dsc_comment, METH_VARARGS },
{"get_eps", (PyCFunction)ps_surface_get_eps, METH_NOARGS },
- /* ps_get_levels - not implemented yet*/
+ /* ps_get_levels - not implemented yet */
{"ps_level_to_string", (PyCFunction)ps_surface_ps_level_to_string,
- METH_VARARGS | METH_STATIC},
+ METH_VARARGS | METH_STATIC},
{"restrict_to_level", (PyCFunction)ps_surface_restrict_to_level,
- METH_VARARGS },
+ METH_VARARGS },
{"set_eps", (PyCFunction)ps_surface_set_eps, METH_VARARGS },
{"set_size", (PyCFunction)ps_surface_set_size, METH_VARARGS },
{NULL, NULL, 0, NULL},