[cairo-commit] pycairo/cairo cairomodule.c, 1.22, 1.23 pycairo-context.c, 1.34, 1.35 pycairo-font.c, 1.10, 1.11 pycairo.h, 1.20, 1.21 pycairo-private.h, 1.15, 1.16

Steve Chaplin commit at pdx.freedesktop.org
Thu Apr 14 01:55:42 PDT 2005


Committed by: stevech1097

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

Modified Files:
	cairomodule.c pycairo-context.c pycairo-font.c pycairo.h 
	pycairo-private.h 
Log Message:
SC 2005/04/14

Index: cairomodule.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/cairomodule.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- cairomodule.c	14 Apr 2005 01:43:48 -0000	1.22
+++ cairomodule.c	14 Apr 2005 08:55:40 -0000	1.23
@@ -185,7 +185,7 @@
 static struct _PyCairo_FunctionStruct api = {
     pycairo_check_status,
     &PyCairoContext_Type,  PyCairoContext_FromContext,
-    &PyCairoFont_Type,     pycairo_font_wrap,
+    &PyCairoFontFace_Type, PyCairoFontFace_FromFontFace,
     &PyCairoMatrix_Type,   PyCairoMatrix_FromMatrix,
     &PyCairoPattern_Type,  PyCairoPattern_FromPattern,
     &PyCairoSurface_Type,  PyCairoSurface_FromSurface,
@@ -196,28 +196,33 @@
 {
     PyObject *mod;
 
+/*  tp_alloc and tp_new lines not required in Python 2.3+ ?
 #define INIT_TYPE(tp) \
     if (!tp.ob_type) tp.ob_type = &PyType_Type; \
     if (!tp.tp_alloc) tp.tp_alloc = PyType_GenericAlloc; \
     if (!tp.tp_new) tp.tp_new = PyType_GenericNew; \
     if (PyType_Ready(&tp) < 0) \
         return;
+*/
+#define INIT_TYPE(tp) \
+    if (PyType_Ready(&tp) < 0) \
+        return;
 
+    INIT_TYPE(PyCairoContext_Type);
+    INIT_TYPE(PyCairoFontFace_Type);
     INIT_TYPE(PyCairoMatrix_Type);
-    INIT_TYPE(PyCairoSurface_Type);
     INIT_TYPE(PyCairoPattern_Type);
-    INIT_TYPE(PyCairoFont_Type);
-    INIT_TYPE(PyCairoContext_Type);
+    INIT_TYPE(PyCairoSurface_Type);
 
 #undef INIT_TYPE
 
     mod = Py_InitModule("cairo._cairo", cairo_functions);
 
+    PyModule_AddObject(mod, "Context", (PyObject *)&PyCairoContext_Type);
+    PyModule_AddObject(mod, "FontFace",(PyObject *)&PyCairoFontFace_Type);
     PyModule_AddObject(mod, "Matrix",  (PyObject *)&PyCairoMatrix_Type);
-    PyModule_AddObject(mod, "Surface", (PyObject *)&PyCairoSurface_Type);
     PyModule_AddObject(mod, "Pattern", (PyObject *)&PyCairoPattern_Type);
-    PyModule_AddObject(mod, "Font",    (PyObject *)&PyCairoFont_Type);
-    PyModule_AddObject(mod, "Context", (PyObject *)&PyCairoContext_Type);
+    PyModule_AddObject(mod, "Surface", (PyObject *)&PyCairoSurface_Type);
 
     PyModule_AddObject(mod, "_PyCairo_API",
 		       PyCObject_FromVoidPtr(&api, NULL));

Index: pycairo-context.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-context.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- pycairo-context.c	14 Apr 2005 01:43:48 -0000	1.34
+++ pycairo-context.c	14 Apr 2005 08:55:40 -0000	1.35
@@ -834,13 +834,14 @@
 static PyObject *
 pycairo_set_font_face(PyCairoContext *c, PyObject *args)
 {
-    PyCairoFont *font;
+    PyCairoFontFace *ff;
+    /* TODO: font_face or None (NULL) should be allowed */
 
     if (!PyArg_ParseTuple(args, "O!:Context.set_font_face",
-			  &PyCairoFont_Type, &font))
+			  &PyCairoFontFace_Type, &ff))
 	return NULL;
 
-    cairo_set_font_face(c->ctx, font->font);
+    cairo_set_font_face(c->ctx, ff->font_face);
     if (pycairo_check_status(cairo_status(c->ctx)))
 	return NULL;
     Py_RETURN_NONE;
@@ -895,15 +896,18 @@
 static PyObject *
 pycairo_get_font_face(PyCairoContext *c)
 {
-    cairo_font_face_t *font;
+    PyObject *f;
+    cairo_font_face_t *font_face;
 
-    font = cairo_get_font_face(c->ctx);
-    if (!font){
+    font_face = cairo_get_font_face(c->ctx);
+    if (!font_face){
 	pycairo_check_status(cairo_status(c->ctx));
 	return NULL;
     }
-    cairo_font_face_reference(font);
-    return pycairo_font_wrap(font);
+    f = PyCairoFontFace_FromFontFace(font_face);
+    if (f)
+	cairo_font_face_reference(font_face);
+    return f;
 }
 
 static PyObject *

Index: pycairo-font.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-font.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- pycairo-font.c	9 Apr 2005 10:15:57 -0000	1.10
+++ pycairo-font.c	14 Apr 2005 08:55:40 -0000	1.11
@@ -28,7 +28,7 @@
  * the specific language governing rights and limitations.
  *
  * Contributor(s):
- *
+ *                 Steve Chaplin
  */
 
 #ifdef HAVE_CONFIG_H
@@ -37,87 +37,94 @@
 #include "pycairo-private.h"
 #include "pycairo-misc.h"
 
+
+/* PyCairoFontFace_FromFontFace
+ * Create a new PyCairoFontFace from a cairo_font_face_t
+ * Return value: New reference (NULL on failure)
+ */
 PyObject *
-pycairo_font_wrap(cairo_font_face_t *font)
+PyCairoFontFace_FromFontFace(cairo_font_face_t *font_face)
 {
-    PyCairoFont *self;
-
-    self = PyObject_New(PyCairoFont, &PyCairoFont_Type);
-    if (!self) {
-	cairo_font_face_destroy(font);
-	return NULL;
-    }
-
-    self->font = font;
+    PyCairoFontFace *f = (PyCairoFontFace *)PyCairoFontFace_Type.tp_new
+	(&PyCairoFontFace_Type, NULL, NULL);
+    if (f)
+	f->font_face = font_face;
 
-    return (PyObject *)self;
+    return (PyObject *) f;
 }
 
 static void
-pycairo_font_dealloc(PyCairoFont *self)
+font_face_dealloc(PyCairoFontFace *f)
 {
-    if (self->font)
-	cairo_font_face_destroy(self->font);
-    self->font = NULL;
-
-    if (self->ob_type->tp_free)
-	self->ob_type->tp_free((PyObject *)self);
-    else
-	PyObject_Del(self);
+#ifdef DEBUG
+    printf("font_face_dealloc start\n");
+#endif
+    if (f->font_face) {
+	cairo_font_face_destroy(f->font_face);
+	f->font_face = NULL;
+    }
+    f->ob_type->tp_free((PyObject *) f);
+#ifdef DEBUG
+    printf("font_face_dealloc end\n");
+#endif
 }
 
+static PyObject *
+font_face_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+    return type->tp_alloc(type, 0);
+}
 
-static PyMethodDef pycairo_font_methods[] = {
+static PyMethodDef font_face_methods[] = {
     { NULL, NULL, 0 }
 };
 
-static PyGetSetDef pycairo_font_getsets[] = {
+static PyGetSetDef font_face_getsets[] = {
     { NULL, (getter)0, (setter)0 }
 };
 
 
-PyTypeObject PyCairoFont_Type = {
-    PyObject_HEAD_INIT(NULL)
+PyTypeObject PyCairoFontFace_Type = {
+    PyObject_HEAD_INIT(&PyType_Type)
     0,                                  /* ob_size */
-    "cairo.Font",                       /* tp_name */
-    sizeof(PyCairoFont),                /* tp_basicsize */
+    "cairo.FontFace",                   /* tp_name */
+    sizeof(PyCairoFontFace),            /* tp_basicsize */
     0,                                  /* tp_itemsize */
-    /* methods */
-    (destructor)pycairo_font_dealloc,   /* tp_dealloc */
-    (printfunc)0,                       /* tp_print */
+    (destructor)font_face_dealloc,      /* tp_dealloc */
+    0,                                  /* tp_print */
     0,                                  /* tp_getattr */
     0,                                  /* tp_setattr */
-    (cmpfunc)0,                         /* tp_compare */
-    (reprfunc)0,                        /* tp_repr */
+    0,                                  /* tp_compare */
+    0,                                  /* tp_repr */
     0,                                  /* tp_as_number */
     0,                                  /* tp_as_sequence */
     0,                                  /* tp_as_mapping */
-    (hashfunc)0,                        /* tp_hash */
-    (ternaryfunc)0,                     /* tp_call */
-    (reprfunc)0,                        /* tp_str */
+    0,                                  /* tp_hash */
+    0,                                  /* tp_call */
+    0,                                  /* tp_str */
     0,                                  /* tp_getattro */
     0,                                  /* tp_setattro */
     0,                                  /* tp_as_buffer */
     Py_TPFLAGS_DEFAULT,                 /* tp_flags */
-    NULL, /* Documentation string */
-    (traverseproc)0,                    /* tp_traverse */
-    (inquiry)0,                         /* tp_clear */
-    (richcmpfunc)0,                     /* tp_richcompare */
+    NULL,                               /* tp_doc */
+    0,                                  /* tp_traverse */
+    0,                                  /* tp_clear */
+    0,                                  /* tp_richcompare */
     0,                                  /* tp_weaklistoffset */
-    (getiterfunc)0,                     /* tp_iter */
-    (iternextfunc)0,                    /* tp_iternext */
-    pycairo_font_methods,               /* tp_methods */
+    0,                                  /* tp_iter */
+    0,                                  /* tp_iternext */
+    font_face_methods,                  /* tp_methods */
     0,                                  /* tp_members */
-    pycairo_font_getsets,               /* tp_getset */
-    (PyTypeObject *)0,                  /* tp_base */
-    (PyObject *)0,                      /* tp_dict */
+    font_face_getsets,                  /* tp_getset */
+    &PyBaseObject_Type,                 /* tp_base */
+    0,                                  /* tp_dict */
     0,                                  /* tp_descr_get */
     0,                                  /* tp_descr_set */
     0,                                  /* tp_dictoffset */
-    (initproc)0,                        /* tp_init */
-    (allocfunc)0,                       /* tp_alloc */
-    (newfunc)0,                         /* tp_new */
+    0,                                  /* tp_init */
+    0,                                  /* tp_alloc */
+    (newfunc)font_face_new,             /* tp_new */
     0,                                  /* tp_free */
-    (inquiry)0,                         /* tp_is_gc */
-    (PyObject *)0,                      /* tp_bases */
+    0,                                  /* tp_is_gc */
+    0,                                  /* tp_bases */
 };

Index: pycairo.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- pycairo.h	14 Apr 2005 01:43:48 -0000	1.20
+++ pycairo.h	14 Apr 2005 08:55:40 -0000	1.21
@@ -47,18 +47,18 @@
 
 typedef struct {
     PyObject_HEAD
-    cairo_font_face_t *font;
-} PyCairoFont;
+    cairo_font_face_t *font_face;
+} PyCairoFontFace;
 
 typedef struct {
     PyObject_HEAD
-    cairo_pattern_t *pattern;
-} PyCairoPattern;
+    cairo_matrix_t matrix;
+} PyCairoMatrix;
 
 typedef struct {
     PyObject_HEAD
-    cairo_matrix_t matrix;
-} PyCairoMatrix;
+    cairo_pattern_t *pattern;
+} PyCairoPattern;
 
 typedef struct {
     PyObject_HEAD
@@ -71,7 +71,7 @@
     PyTypeObject *context_type;
     PyObject *(* context_wrap)(cairo_t *ctx);
     PyTypeObject *font_type;
-    PyObject *(* font_wrap)(cairo_font_face_t *font);
+    PyObject *(* font_wrap)(cairo_font_face_t *font_face);
     PyTypeObject *matrix_type;
     PyObject *(* matrix_wrap)(cairo_matrix_t *matrix);
     PyTypeObject *pattern_type;
@@ -88,17 +88,17 @@
 struct _PyCairo_FunctionStruct *_PyCairo_API;
 #endif
 
-#define pycairo_check_status       (_PyCairo_API->check_status)
-#define PyCairoContext_Type       *(_PyCairo_API->context_type)
-#define PyCairoContext_FromContext (_PyCairo_API->context_wrap)
-#define PyCairoMatrix_Type        *(_PyCairo_API->matrix_type)
-#define PyCairoMatrix_FromMatrix   (_PyCairo_API->matrix_wrap)
-#define PyCairoPattern_Type       *(_PyCairo_API->pattern_type)
-#define PyCairoPattern_FromPattern (_PyCairo_API->pattern_wrap)
-#define PyCairoSurface_Type       *(_PyCairo_API->surface_type)
-#define PyCairoSurface_FromSurface (_PyCairo_API->surface_wrap)
-#define PyCairoFont_Type          *(_PyCairo_API->font_type)
-#define pycairo_font_wrap          (_PyCairo_API->font_wrap)
+#define pycairo_check_status         (_PyCairo_API->check_status)
+#define PyCairoContext_Type         *(_PyCairo_API->context_type)
+#define PyCairoContext_FromContext   (_PyCairo_API->context_wrap)
+#define PyCairoFontFace_Type        *(_PyCairo_API->font_type)
+#define PyCairoFontFace_FronFontFace (_PyCairo_API->font_wrap)
+#define PyCairoMatrix_Type          *(_PyCairo_API->matrix_type)
+#define PyCairoMatrix_FromMatrix     (_PyCairo_API->matrix_wrap)
+#define PyCairoPattern_Type         *(_PyCairo_API->pattern_type)
+#define PyCairoPattern_FromPattern   (_PyCairo_API->pattern_wrap)
+#define PyCairoSurface_Type         *(_PyCairo_API->surface_type)
+#define PyCairoSurface_FromSurface   (_PyCairo_API->surface_wrap)
 
 #define init_pycairo() { \
     PyObject *pycairo = PyImport_ImportModule("cairo._cairo"); \

Index: pycairo-private.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-private.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- pycairo-private.h	14 Apr 2005 01:43:48 -0000	1.15
+++ pycairo-private.h	14 Apr 2005 08:55:40 -0000	1.16
@@ -43,7 +43,7 @@
 
 
 extern PyTypeObject PyCairoContext_Type;
-extern PyTypeObject PyCairoFont_Type;
+extern PyTypeObject PyCairoFontFace_Type;
 extern PyTypeObject PyCairoMatrix_Type;
 extern PyTypeObject PyCairoPattern_Type;
 extern PyTypeObject PyCairoSurface_Type;
@@ -52,7 +52,7 @@
 
 /* takes ownership of reference */
 PyObject *PyCairoContext_FromContext(cairo_t *ctx);
-PyObject *pycairo_font_wrap(cairo_font_face_t *font);
+PyObject *PyCairoFontFace_FromFontFace(cairo_font_face_t *font_face);
 PyObject *PyCairoMatrix_FromMatrix(const cairo_matrix_t *matrix);
 PyObject *PyCairoPattern_FromPattern(cairo_pattern_t *pattern);
 PyObject *PyCairoSurface_FromSurface(cairo_surface_t *surface, PyObject *base);




More information about the cairo-commit mailing list