summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Chaplin <>2012-08-16 20:56:02 +0800
committerSteve Chaplin <>2012-08-16 20:56:02 +0800
commitcd463341de185094455cf5869a442aa02b8b812e (patch)
tree2ec8356934959b99b7f9e2d6437742bcc019489c
parentcdec5e4c0a9ef4ad7b0413e4dc1e21f81841b064 (diff)
downloadpycairo-cd463341de185094455cf5869a442aa02b8b812e.tar.gz
Add new constants:
cairo.SVG_VERSION_1_1 cairo.SVG_VERSION_1_2 Add new functions: cairo_svg_surface_restrict_to_version () cairo_svg_version_to_string ()
-rw-r--r--doc/reference/surfaces.rst37
-rw-r--r--src/cairomodule.c10
-rw-r--r--src/surface.c40
3 files changed, 75 insertions, 12 deletions
diff --git a/doc/reference/surfaces.rst b/doc/reference/surfaces.rst
index 8a0e13d..ef01c8e 100644
--- a/doc/reference/surfaces.rst
+++ b/doc/reference/surfaces.rst
@@ -384,6 +384,10 @@ multi-page vector surface backend.
.. versionadded:: 1.2
+ .. staticmethod:: pdf_get_versions()
+
+ Not implemented in pycairo (yet)
+
.. staticmethod:: pdf_version_to_string(level)
:param level: a :ref:`PDF_VERSION <constants_PDF_VERSION>`
@@ -573,6 +577,10 @@ is a multi-page vector surface backend.
.. versionadded:: 1.6
+ .. staticmethod:: ps_get_levels()
+
+ Not implemented in pycairo (yet)
+
.. staticmethod:: ps_level_to_string(level)
:param level: a :ref:`PS_LEVEL <constants_PS_LEVEL>`
@@ -715,18 +723,37 @@ multi-page vector surface backend
:raises: *MemoryError* in case of no memory
- .. method:: get_versions
+ .. method:: restrict_to_version(version)
- Not implemented in pycairo (yet)
+ :param version: a :ref:`SVG_VERSION <constants_SVG_VERSION>`
- .. method:: restrict_to_version
+ Restricts the generated SVG file to *version*. See
+ :meth:`.svg_get_versions` for a list of available version values that can
+ be used here.
- Not implemented in pycairo (yet)
+ This function should only be called before any drawing operations have
+ been performed on the given surface. The simplest way to do this is to
+ call this function immediately after creating the surface.
- .. method:: version_to_string
+ .. versionadded:: 1.10.2
+
+ .. staticmethod:: svg_get_versions()
Not implemented in pycairo (yet)
+ .. staticmethod:: svg_version_to_string(level)
+
+ :param level: a :ref:`SVG_VERSION <constants_SVG_VERSION>`
+ :returns: the string associated to given version.
+ :rtype: str
+ :raises: :exc:`cairo.Error` if *version* isn't valid.
+
+ Get the string representation of the given *version*. See
+ :meth:`.svg_get_versions` for a way to get the list of valid level
+ ids.
+
+ .. versionadded:: 1.10.2
+
class Win32Surface(:class:`Surface`)
====================================
diff --git a/src/cairomodule.c b/src/cairomodule.c
index ab70319..08d823a 100644
--- a/src/cairomodule.c
+++ b/src/cairomodule.c
@@ -34,6 +34,11 @@
# include <cairo-ps.h>
#endif
+/* to read CAIRO_SVG_VERSION_* constants */
+#ifdef CAIRO_HAS_SVG_SURFACE
+# include <cairo-svg.h>
+#endif
+
/* for XCB api */
#if defined(CAIRO_HAS_XCB_SURFACE) && defined(HAVE_XPYB)
xpyb_CAPI_t *xpyb_CAPI;
@@ -566,6 +571,11 @@ PyInit__cairo(void)
CONSTANT(PS_LEVEL_3);
#endif
+#ifdef CAIRO_HAS_SVG_SURFACE
+ CONSTANT(SVG_VERSION_1_1);
+ CONSTANT(SVG_VERSION_1_2);
+#endif
+
CONSTANT(SUBPIXEL_ORDER_DEFAULT);
CONSTANT(SUBPIXEL_ORDER_RGB);
CONSTANT(SUBPIXEL_ORDER_BGR);
diff --git a/src/surface.c b/src/surface.c
index 1589a70..204af68 100644
--- a/src/surface.c
+++ b/src/surface.c
@@ -799,7 +799,7 @@ static PyMethodDef pdf_surface_methods[] = {
{"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_get_versions - not implemented yet */
{"pdf_version_to_string", (PyCFunction)pdf_surface_pdf_version_to_string,
METH_VARARGS | METH_STATIC},
{NULL, NULL, 0, NULL},
@@ -1199,13 +1199,39 @@ svg_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
return PycairoSurface_FromSurface (sfc, obj);
}
+static PyObject *
+svg_surface_restrict_to_version (PycairoSVGSurface *o, PyObject *args) {
+ int version;
+
+ if (!PyArg_ParseTuple(args, "i:SVGSurface.restrict_to_version", &version))
+ return NULL;
+ cairo_svg_surface_restrict_to_version (o->surface, version);
+ RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
+ Py_RETURN_NONE;
+}
+
+/* METH_STATIC */
+static PyObject *
+svg_surface_svg_version_to_string (PyObject *self, PyObject *args) {
+ int version;
+ if (!PyArg_ParseTuple(args, "i:svg_version_to_string", &version))
+ return NULL;
+ const char *s = cairo_svg_version_to_string (version);
+ if (s == NULL){
+ PyErr_SetString(CairoError, "svg_version_to_string: "
+ "invalid level argument");
+ return NULL;
+ }
+ return PyUnicode_DecodeASCII(s, strlen(s), NULL);
+}
+
static PyMethodDef svg_surface_methods[] = {
- /* TODO
- * cairo_svg_surface_restrict_to_version
- * cairo_svg_get_versions
- * cairo_svg_version_to_string
- */
- {NULL, NULL, 0, NULL},
+ {"restrict_to_version", (PyCFunction)svg_surface_restrict_to_version,
+ METH_VARARGS },
+ /* svg_get_versions - not implemented yet */
+ {"svg_version_to_string", (PyCFunction)svg_surface_svg_version_to_string,
+ METH_VARARGS | METH_STATIC},
+ {NULL, NULL, 0, NULL},
};
PyTypeObject PycairoSVGSurface_Type = {