summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRenato Florentino Garcia <fgarcia.renato@gmail.com>2019-02-19 14:14:23 -0300
committerChristoph Reiter <reiter.christoph@gmail.com>2019-02-22 16:34:12 +0000
commitd519d8c245a0ee0da964692149a3140d996dbc2a (patch)
treec2a1bbac70b1a2c6b2a5fa7a840837141c4e743d
parent627dd81ac478ede4d29b242482e61e204ce2f896 (diff)
downloadpygobject-d519d8c245a0ee0da964692149a3140d996dbc2a.tar.gz
Add cairo_matrix_t converter to GValue.
-rw-r--r--gi/pygi-foreign-cairo.c34
-rw-r--r--tests/test_cairo.py2
2 files changed, 36 insertions, 0 deletions
diff --git a/gi/pygi-foreign-cairo.c b/gi/pygi-foreign-cairo.c
index efb62544..399fe75e 100644
--- a/gi/pygi-foreign-cairo.c
+++ b/gi/pygi-foreign-cairo.c
@@ -583,6 +583,36 @@ cairo_matrix_release (GIBaseInfo *base_info,
Py_RETURN_NONE;
}
+static int
+cairo_matrix_to_gvalue (GValue *value, PyObject *obj)
+{
+ cairo_matrix_t *matrix;
+
+ if (!PyObject_TypeCheck (obj, &PycairoMatrix_Type)) {
+ PyErr_SetString (PyExc_TypeError, "Expected cairo.Matrix");
+ return -1;
+ }
+
+ matrix = &(( (PycairoMatrix*) obj)->matrix);
+ if (!matrix) {
+ return -1;
+ }
+
+ g_value_set_boxed (value, matrix);
+ return 0;
+}
+
+static PyObject *
+cairo_matrix_from_gvalue (const GValue *value)
+{
+ cairo_matrix_t *matrix = g_value_get_boxed(value);
+ if (!matrix) {
+ Py_RETURN_NONE;
+ }
+
+ return PycairoMatrix_FromMatrix (matrix);
+}
+
static PyMethodDef _gi_cairo_functions[] = { {0,} };
PYGLIB_MODULE_START(_gi_cairo, "_gi_cairo")
{
@@ -644,6 +674,10 @@ PYGLIB_MODULE_START(_gi_cairo, "_gi_cairo")
cairo_region_from_arg,
cairo_region_release);
+ pyg_register_gtype_custom (CAIRO_GOBJECT_TYPE_MATRIX,
+ cairo_matrix_from_gvalue,
+ cairo_matrix_to_gvalue);
+
pyg_register_gtype_custom (CAIRO_GOBJECT_TYPE_CONTEXT,
cairo_context_from_gvalue,
cairo_context_to_gvalue);
diff --git a/tests/test_cairo.py b/tests/test_cairo.py
index d03e85df..37a6ac38 100644
--- a/tests/test_cairo.py
+++ b/tests/test_cairo.py
@@ -34,12 +34,14 @@ class Test(unittest.TestCase):
def test_gvalue_converters(self):
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 10, 10)
context = cairo.Context(surface)
+ matrix = cairo.Matrix()
objects = {
'CairoContext': context,
'CairoSurface': surface,
'CairoFontFace': context.get_font_face(),
'CairoScaledFont': context.get_scaled_font(),
'CairoPattern': context.get_source(),
+ 'CairoMatrix': matrix,
}
for type_name, cairo_obj in objects.items():
gtype = GObject.type_from_name(type_name)