[cairo-commit] pycairo/cairo pycairo.h, 1.14, 1.15 pycairo-context.c, 1.28, 1.29 pycairo-matrix.c, 1.6, 1.7 pycairo-surface.c, 1.16, 1.17

Steve Chaplin commit at pdx.freedesktop.org
Fri Apr 8 01:51:19 PDT 2005


Committed by: stevech1097

Update of /cvs/cairo/pycairo/cairo
In directory gabe:/tmp/cvs-serv15724/cairo

Modified Files:
	pycairo.h pycairo-context.c pycairo-matrix.c pycairo-surface.c 
Log Message:
SC 2005/04/08

Index: pycairo.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- pycairo.h	8 Apr 2005 03:24:49 -0000	1.14
+++ pycairo.h	8 Apr 2005 08:51:17 -0000	1.15
@@ -42,7 +42,7 @@
 
 typedef struct {
     PyObject_HEAD
-    cairo_matrix_t *matrix;
+    cairo_matrix_t matrix;
 } PyCairoMatrix;
 
 typedef struct {

Index: pycairo-context.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-context.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- pycairo-context.c	8 Apr 2005 03:24:49 -0000	1.28
+++ pycairo-context.c	8 Apr 2005 08:51:17 -0000	1.29
@@ -251,6 +251,15 @@
 }
 
 static PyObject *
+pycairo_identity_matrix(PyCairoContext *self)
+{
+    cairo_identity_matrix(self->ctx);
+    if (pycairo_check_status(cairo_status(self->ctx)))
+	return NULL;
+    Py_RETURN_NONE;
+}
+
+static PyObject *
 pycairo_reset_clip(PyCairoContext *self)
 {
     cairo_reset_clip(self->ctx);
@@ -485,7 +494,7 @@
 			  &PyCairoMatrix_Type, &matrix))
 	return NULL;
 
-    cairo_transform(self->ctx, matrix->matrix);
+    cairo_transform(self->ctx, &matrix->matrix);
     if (pycairo_check_status(cairo_status(self->ctx)))
 	return NULL;
     Py_RETURN_NONE;
@@ -500,16 +509,7 @@
 			   &PyCairoMatrix_Type, &matrix))
 	return NULL;
 
-    cairo_set_matrix(self->ctx, matrix->matrix);
-    if (pycairo_check_status(cairo_status(self->ctx)))
-	return NULL;
-    Py_RETURN_NONE;
-}
-
-static PyObject *
-pycairo_identity_matrix(PyCairoContext *self)
-{
-    cairo_identity_matrix(self->ctx);
+    cairo_set_matrix(self->ctx, &matrix->matrix);
     if (pycairo_check_status(cairo_status(self->ctx)))
 	return NULL;
     Py_RETURN_NONE;
@@ -784,29 +784,29 @@
 }
 
 static PyObject *
-pycairo_set_font_size(PyCairoContext *self, PyObject *args)
+pycairo_set_font_matrix(PyCairoContext *self, PyObject *args)
 {
-    double scale;
+    PyCairoMatrix *matrix;
 
-    if (!PyArg_ParseTuple(args, "d:Context.set_font_size", &scale))
+    if (!PyArg_ParseTuple(args, "O!:Context.set_font_matrix",
+			  &PyCairoMatrix_Type, &matrix))
 	return NULL;
 
-    cairo_set_font_size(self->ctx, scale);
+    cairo_set_font_matrix(self->ctx, &matrix->matrix);
     if (pycairo_check_status(cairo_status(self->ctx)))
 	return NULL;
     Py_RETURN_NONE;
 }
 
 static PyObject *
-pycairo_set_font_matrix(PyCairoContext *self, PyObject *args)
+pycairo_set_font_size(PyCairoContext *self, PyObject *args)
 {
-    PyCairoMatrix *matrix;
+    double scale;
 
-    if (!PyArg_ParseTuple(args, "O!:Context.set_font_matrix",
-			  &PyCairoMatrix_Type, &matrix))
+    if (!PyArg_ParseTuple(args, "d:Context.set_font_size", &scale))
 	return NULL;
 
-    cairo_set_font_matrix(self->ctx, matrix->matrix);
+    cairo_set_font_size(self->ctx, scale);
     if (pycairo_check_status(cairo_status(self->ctx)))
 	return NULL;
     Py_RETURN_NONE;

Index: pycairo-matrix.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-matrix.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- pycairo-matrix.c	8 Apr 2005 03:24:49 -0000	1.6
+++ pycairo-matrix.c	8 Apr 2005 08:51:17 -0000	1.7
@@ -28,7 +28,7 @@
  * the specific language governing rights and limitations.
  *
  * Contributor(s):
- *
+ *                 Steve Chaplin
  */
 
 #ifdef HAVE_CONFIG_H
@@ -42,46 +42,35 @@
     PyCairoMatrix *self;
 
     self = PyObject_New(PyCairoMatrix, &PyCairoMatrix_Type);
-    if (!self) {
-	cairo_matrix_destroy(matrix); /* deprecated */
-	return NULL;
+    if (self) {
+	self->matrix.xx = matrix->xx;
+	self->matrix.yx = matrix->yx;
+	self->matrix.xy = matrix->xy;
+	self->matrix.yy = matrix->yy;
+	self->matrix.x0 = matrix->x0;
+	self->matrix.y0 = matrix->y0;
     }
-
-    self->matrix = matrix;
-
     return (PyObject *)self;
 }
 
 static int
 pycairo_matrix_init(PyCairoMatrix *self, PyObject *args, PyObject *kwargs)
 {
-    static char *kwlist[] = { "a", "b", "c", "d", "tx", "ty", NULL };
-    double a = 1.0, b = 0.0, c = 0.0, d = 1.0, tx = 0.0, ty = 0.0;
-
-    self->matrix = cairo_matrix_create(); /* deprecated */
-    if (!self->matrix) {
-	PyErr_SetString(PyExc_RuntimeError, "could not create matrix");
-	return -1;
-    }
+    static char *kwlist[] = { "xx", "yx", "xy", "yy", "x0", "y0", NULL };
+    double xx = 1.0, yx = 0.0, xy = 0.0, yy = 1.0, x0 = 0.0, y0 = 0.0;
 
     if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 				     "|dddddd:Matrix.__init__", kwlist,
-				     &a, &b, &c, &d, &tx, &ty))
+				     &xx, &yx, &xy, &yy, &x0, &y0))
 	return -1;
 
-    /*cairo_matrix_set_affine(self->matrix, a, b, c, d, tx, ty);*/
-    cairo_matrix_init(self->matrix, a, b, c, d, tx, ty);
-
+    cairo_matrix_init(&self->matrix, xx, yx, xy, yy, x0, y0);
     return 0;
 }
 
 static void
 pycairo_matrix_dealloc(PyCairoMatrix *self)
 {
-    if (self->matrix)
-	cairo_matrix_destroy(self->matrix); /* deprecated */
-    self->matrix = NULL;
-
     if (self->ob_type->tp_free)
 	self->ob_type->tp_free((PyObject *)self);
     else
@@ -89,55 +78,20 @@
 }
 
 static PyObject *
-pycairo_matrix_repr(PyCairoMatrix *self)
-{
-    char buf[256];
-    double a, b, c, d, tx, ty;
-
-    cairo_matrix_get_affine(self->matrix, &a, &b, &c, &d, &tx, &ty); /* deprecated */
-    PyOS_snprintf(buf, sizeof(buf), "cairo.Matrix(%g, %g, %g, %g, %g, %g)",
-		  a, b, c, d, tx, ty);
-    return PyString_FromString(buf);
-}
-
-static PyObject *
-pycairo_matrix_richcmp(PyCairoMatrix *self, PyCairoMatrix *other, int op)
+pycairo_matrix_invert(PyCairoMatrix *self)
 {
-    double a1, b1, c1, d1, tx1, ty1;
-    double a2, b2, c2, d2, tx2, ty2;
-    int equal;
-    PyObject *ret;
-
-    if (!PyObject_TypeCheck(other, &PyCairoMatrix_Type) ||
-	!(op == Py_EQ || op == Py_NE)) {
-	Py_INCREF(Py_NotImplemented);
-	return Py_NotImplemented;
+    if (pycairo_check_status(cairo_matrix_invert(&self->matrix))) {
+	return NULL;
     }
-
-    cairo_matrix_get_affine(self->matrix, &a1, &b1, &c1, &d1, &tx1, &ty1); /* deprecated */
-    cairo_matrix_get_affine(other->matrix, &a2, &b2, &c2, &d2, &tx2, &ty2); /* deprecated */
-    equal = a1 == a2 &&	b1 == b2 && c1 == c2 && d1 == d2 &&
-	tx1 == tx2 && ty1 == ty2;
-
-    if (op == Py_EQ)
-	ret = equal ? Py_True : Py_False;
-    else
-	ret = equal ? Py_False : Py_True;
-    Py_INCREF(ret);
-    return ret;
+    Py_RETURN_NONE;
 }
 
 static PyObject *
 pycairo_matrix_multiply(PyCairoMatrix *self, PyCairoMatrix *other)
 {
-    cairo_matrix_t *result;
-
-    result = cairo_matrix_create(); /* deprecated */
-    if (!result)
-	return PyErr_NoMemory();
-
-    cairo_matrix_multiply(result, self->matrix, other->matrix);
-    return pycairo_matrix_wrap(result);
+    cairo_matrix_t result;
+    cairo_matrix_multiply(&result, &self->matrix, &other->matrix);
+    return pycairo_matrix_wrap(&result);
 }
 
 static PyNumberMethods pycairo_matrix_as_number = {
@@ -167,74 +121,77 @@
 };
 
 static PyObject *
-pycairo_matrix_translate(PyCairoMatrix *self, PyObject *args)
+pycairo_matrix_repr(PyCairoMatrix *self)
 {
-    double tx, ty;
-    cairo_matrix_t *other;
-
-    if (!PyArg_ParseTuple(args, "dd:Matrix.translate", &tx, &ty))
-	return NULL;
-    
-    other = cairo_matrix_create(); /* deprecated */
-    if (!other)
-	return PyErr_NoMemory();
+    char buf[256];
 
-    cairo_matrix_copy(other, self->matrix);
-    cairo_matrix_translate(other, tx, ty);
-    return pycairo_matrix_wrap(other);
+    PyOS_snprintf(buf, sizeof(buf), "cairo.Matrix(%g, %g, %g, %g, %g, %g)",
+		  self->matrix.xx, self->matrix.yx, 
+		  self->matrix.xy, self->matrix.yy, 
+		  self->matrix.x0, self->matrix.y0);
+    return PyString_FromString(buf);
 }
 
 static PyObject *
-pycairo_matrix_scale(PyCairoMatrix *self, PyObject *args)
+pycairo_matrix_richcmp(PyCairoMatrix *self, PyCairoMatrix *other, int op)
 {
-    double sx, sy;
-    cairo_matrix_t *other;
+    int equal;
+    PyObject *ret;
+    cairo_matrix_t *mx1 = &self->matrix;
+    cairo_matrix_t *mx2 = &other->matrix;
 
-    if (!PyArg_ParseTuple(args, "dd:Matrix.scale", &sx, &sy))
-	return NULL;
-    
-    other = cairo_matrix_create(); /* deprecated */
-    if (!other)
-	return PyErr_NoMemory();
+    if (!PyObject_TypeCheck(other, &PyCairoMatrix_Type) ||
+	!(op == Py_EQ || op == Py_NE)) {
+	Py_INCREF(Py_NotImplemented);
+	return Py_NotImplemented;
+    }
 
-    cairo_matrix_copy(other, self->matrix);
-    cairo_matrix_scale(other, sx, sy);
-    return pycairo_matrix_wrap(other);
+    equal = mx1->xx == mx2->xx && mx1->yx == mx2->yx &&
+	mx1->xy == mx2->xy && mx1->yy == mx2->yy &&
+	mx1->x0 == mx2->x0 && mx1->y0 == mx2->y0;
+
+    if (op == Py_EQ)
+	ret = equal ? Py_True : Py_False;
+    else
+	ret = equal ? Py_False : Py_True;
+    Py_INCREF(ret);
+    return ret;
 }
 
 static PyObject *
 pycairo_matrix_rotate(PyCairoMatrix *self, PyObject *args)
 {
     double radians;
-    cairo_matrix_t *other;
 
     if (!PyArg_ParseTuple(args, "d:Matrix.rotate", &radians))
 	return NULL;
     
-    other = cairo_matrix_create(); /* deprecated */
-    if (!other)
-	return PyErr_NoMemory();
-
-    cairo_matrix_copy(other, self->matrix);
-    cairo_matrix_rotate(other, radians);
-    return pycairo_matrix_wrap(other);
+    cairo_matrix_rotate(&self->matrix, radians);
+    Py_RETURN_NONE;
 }
 
 static PyObject *
-pycairo_matrix_invert(PyCairoMatrix *self)
+pycairo_matrix_scale(PyCairoMatrix *self, PyObject *args)
 {
-    cairo_matrix_t *other;
+    double sx, sy;
 
-    other = cairo_matrix_create(); /* deprecated */
-    if (!other)
-	return PyErr_NoMemory();
+    if (!PyArg_ParseTuple(args, "dd:Matrix.scale", &sx, &sy))
+	return NULL;
+    
+    cairo_matrix_scale(&self->matrix, sx, sy);
+    Py_RETURN_NONE;
+}
 
-    cairo_matrix_copy(other, self->matrix);
-    if (pycairo_check_status(cairo_matrix_invert(other))) {
-	cairo_matrix_destroy(other); /* deprecated */
+static PyObject *
+pycairo_matrix_translate(PyCairoMatrix *self, PyObject *args)
+{
+    double tx, ty;
+
+    if (!PyArg_ParseTuple(args, "dd:Matrix.translate", &tx, &ty))
 	return NULL;
-    }
-    return pycairo_matrix_wrap(other);
+    
+    cairo_matrix_translate(&self->matrix, tx, ty);
+    Py_RETURN_NONE;
 }
 
 static PyObject *
@@ -245,7 +202,7 @@
     if (!PyArg_ParseTuple(args, "dd:Matrix.transform_distance", &dx, &dy))
 	return NULL;
 
-    cairo_matrix_transform_distance(self->matrix, &dx, &dy);
+    cairo_matrix_transform_distance(&self->matrix, &dx, &dy);
     return Py_BuildValue("(dd)", dx, dy);
 }
 
@@ -257,14 +214,14 @@
     if (!PyArg_ParseTuple(args, "dd:Matrix.transform_point", &x, &y))
 	return NULL;
 
-    cairo_matrix_transform_point(self->matrix, &x, &y);
+    cairo_matrix_transform_point(&self->matrix, &x, &y);
     return Py_BuildValue("(dd)", x, y);
 }
 
 static PyMethodDef pycairo_matrix_methods[] = {
-    { "invert", (PyCFunction)pycairo_matrix_invert, METH_VARARGS },
-    { "rotate", (PyCFunction)pycairo_matrix_rotate, METH_VARARGS },
-    { "scale", (PyCFunction)pycairo_matrix_scale, METH_VARARGS },
+    { "invert",   (PyCFunction)pycairo_matrix_invert,     METH_NOARGS },
+    { "rotate",   (PyCFunction)pycairo_matrix_rotate,     METH_VARARGS },
+    { "scale",    (PyCFunction)pycairo_matrix_scale,      METH_VARARGS },
     { "transform_distance", (PyCFunction)pycairo_matrix_transform_distance,
       METH_VARARGS },
     { "transform_point", (PyCFunction)pycairo_matrix_transform_point,
@@ -296,10 +253,10 @@
     (setattrofunc)0,                    /* tp_setattro */
     0,                                  /* tp_as_buffer */
     Py_TPFLAGS_DEFAULT,                 /* tp_flags */
-    NULL, /* Documentation string */
+    NULL,                               /* Documentation string */
     (traverseproc)0,                    /* tp_traverse */
     (inquiry)0,                         /* tp_clear */
-    (richcmpfunc)pycairo_matrix_richcmp, /* tp_richcompare */
+    (richcmpfunc)pycairo_matrix_richcmp,/* tp_richcompare */
     0,                                  /* tp_weaklistoffset */
     (getiterfunc)0,                     /* tp_iter */
     (iternextfunc)0,                    /* tp_iternext */

Index: pycairo-surface.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-surface.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- pycairo-surface.c	6 Apr 2005 13:52:59 -0000	1.16
+++ pycairo-surface.c	8 Apr 2005 08:51:17 -0000	1.17
@@ -200,19 +200,13 @@
 static PyObject *
 pycairo_surface_get_matrix(PyCairoSurface *self)
 {
-    cairo_matrix_t *matrix;
+    cairo_matrix_t matrix;
     cairo_status_t status;
 
-    matrix = cairo_matrix_create();
-    if (!matrix)
-	return PyErr_NoMemory();
-
-    status = cairo_surface_get_matrix(self->surface, matrix);
-    if (pycairo_check_status(status)){
-	cairo_matrix_destroy(matrix);
+    status = cairo_surface_get_matrix(self->surface, &matrix);
+    if (pycairo_check_status(status))
 	return NULL;
-    }
-    return pycairo_matrix_wrap(matrix);
+    return pycairo_matrix_wrap(&matrix);
 }
 
 static PyObject *
@@ -252,7 +246,7 @@
 			  &PyCairoMatrix_Type, &matrix))
 	return NULL;
 
-    cairo_surface_set_matrix(self->surface, matrix->matrix);
+    cairo_surface_set_matrix(self->surface, &matrix->matrix);
     Py_RETURN_NONE;
 }
 




More information about the cairo-commit mailing list