[cairo-commit] pycairo/cairo pycairo-font.c,1.19,1.20

Steve Chaplin commit at pdx.freedesktop.org
Tue May 17 21:42:44 PDT 2005


Committed by: stevech1097

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

Modified Files:
	pycairo-font.c 
Log Message:
SC

Index: pycairo-font.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-font.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- pycairo-font.c	17 May 2005 02:44:20 -0000	1.19
+++ pycairo-font.c	18 May 2005 04:42:42 -0000	1.20
@@ -45,41 +45,49 @@
  * Return value: New reference or NULL on failure
  */
 PyObject *
-PycairoFontFace_FromFontFace(cairo_font_face_t *font_face)
+PycairoFontFace_FromFontFace (cairo_font_face_t *font_face)
 {
-    PyObject *f;
+    PyObject *o;
 
     assert (font_face != NULL);	
-    f = PycairoFontFace_Type.tp_alloc (&PycairoFontFace_Type, 0);
-    if (f)
-	((PycairoFontFace *)f)->font_face = font_face;
+    o = PycairoFontFace_Type.tp_alloc (&PycairoFontFace_Type, 0);
+    if (o)
+	((PycairoFontFace *)o)->font_face = font_face;
     else
 	cairo_font_face_destroy (font_face);
-    return f;
+    return o;
 }
 
 static void
-font_face_dealloc(PycairoFontFace *f)
+font_face_dealloc (PycairoFontFace *o)
 {
 #ifdef DEBUG
     printf("font_face_dealloc start\n");
 #endif
-    if (f->font_face) {
-	cairo_font_face_destroy(f->font_face);
-	f->font_face = NULL;
+    if (o->font_face) {
+	cairo_font_face_destroy (o->font_face);
+	o->font_face = NULL;
     }
-    f->ob_type->tp_free((PyObject *) f);
+    o->ob_type->tp_free((PyObject *) o);
 #ifdef DEBUG
     printf("font_face_dealloc end\n");
 #endif
 }
 
 static PyObject *
-font_face_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+font_face_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
     return type->tp_alloc(type, 0);
 }
 
+static int
+font_face_init (PycairoFontFace *o, PyObject *args, PyObject *kwds)
+{
+    PyErr_SetString (PyExc_TypeError, "The FontFace type cannot be "
+		     "instantiated, use Context.get_font_face()");
+    return -1;
+}
+
 /*
 static PyMethodDef font_face_methods[] = {
      * methods never exposed in a language binding:
@@ -129,7 +137,7 @@
     0,                                  /* tp_descr_get */
     0,                                  /* tp_descr_set */
     0,                                  /* tp_dictoffset */
-    0,                                  /* tp_init */
+    (initproc)font_face_init,           /* tp_init */
     0,                                  /* tp_alloc */
     (newfunc)font_face_new,             /* tp_new */
     0,                                  /* tp_free */
@@ -141,70 +149,73 @@
 /* class cairo.ScaledFont ------------------------------------------------- */
 
 /* PycairoScaledFont_FromScaledFont
- * Create a new PycairoScaledFont from a cairo_font_face_t
- * Return value: New reference (NULL on failure)
+ * Create a new PycairoScaledFont from a cairo_scaled_font_t
+ * scaled_font - a cairo_scaled_font_t to 'wrap' into a Python object.
+ *               it is unreferenced if the PycairoScaledFont creation fails
+ * Return value: New reference or NULL on failure
  */
 PyObject *
-PycairoScaledFont_FromScaledFont(cairo_scaled_font_t *scaled_font)
+PycairoScaledFont_FromScaledFont (cairo_scaled_font_t *scaled_font)
 {
-    PycairoScaledFont *f = (PycairoScaledFont *)PycairoScaledFont_Type.tp_new
-	(&PycairoScaledFont_Type, NULL, NULL);
-    if (f)
-	f->scaled_font = scaled_font;
+    PyObject *o;
 
-    return (PyObject *) f;
+    assert (scaled_font != NULL);	
+    o = PycairoScaledFont_Type.tp_alloc (&PycairoScaledFont_Type, 0);
+    if (o)
+	((PycairoScaledFont *)o)->scaled_font = scaled_font;
+    else
+	cairo_scaled_font_destroy (scaled_font);
+    return o;
 }
 
 static void
-scaled_font_dealloc(PycairoScaledFont *f)
+scaled_font_dealloc(PycairoScaledFont *o)
 {
 #ifdef DEBUG
     printf("scaled_font_dealloc start\n");
 #endif
-    if (f->scaled_font) {
-	cairo_scaled_font_destroy(f->scaled_font);
-	f->scaled_font = NULL;
+    if (o->scaled_font) {
+	cairo_scaled_font_destroy (o->scaled_font);
+	o->scaled_font = NULL;
     }
-    f->ob_type->tp_free((PyObject *) f);
+    o->ob_type->tp_free((PyObject *) o);
 #ifdef DEBUG
     printf("scaled_font_dealloc end\n");
 #endif
 }
 
 static PyObject *
-scaled_font_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
-    return type->tp_alloc(type, 0);
-}
-
-static int
-scaled_font_init(PycairoScaledFont *sf, PyObject *args, PyObject *kwds)
+scaled_font_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
     PycairoFontFace *ff;
     PycairoMatrix *mx1, *mx2;
-    cairo_scaled_font_t *scaled_font;
 
     if (!PyArg_ParseTuple(args, "O!O!O!:ScaledFont.__init__",
 			  &PycairoFontFace_Type, &ff,
 			  &PycairoMatrix_Type, &mx1,
 			  &PycairoMatrix_Type, &mx2))
-	return -1;
+	return NULL;
 
-    sf->scaled_font = cairo_scaled_font_create (ff->font_face, &mx1->matrix, 
-						&mx2->matrix);
-    if (!sf->scaled_font) {
-	Py_DECREF(sf);
-	PyErr_NoMemory();
-	return -1;
+    PyObject *o = type->tp_alloc(type, 0);
+    if (o) {
+	cairo_scaled_font_t *scaled_font = cairo_scaled_font_create 
+	    (ff->font_face, &mx1->matrix, &mx2->matrix);
+
+	if (!scaled_font) {
+	    Py_DECREF(o);
+	    return PyErr_NoMemory();
+	} else {
+	    ((PycairoScaledFont *)o)->scaled_font = scaled_font;
+	}
     }
-    return 0;
+    return o;
 }
 
 static PyObject *
-scaled_font_extents (PycairoScaledFont *sf)
+scaled_font_extents (PycairoScaledFont *o)
 {
     cairo_font_extents_t e;
-    cairo_status_t status = cairo_scaled_font_extents (sf->scaled_font, &e);
+    cairo_status_t status = cairo_scaled_font_extents (o->scaled_font, &e);
     if (Pycairo_check_status (status))
 	return NULL;
     return Py_BuildValue ("(ddddd)", e.ascent, e.descent, e.height, 
@@ -263,7 +274,7 @@
     0,                                  /* tp_descr_get */
     0,                                  /* tp_descr_set */
     0,                                  /* tp_dictoffset */
-    (initproc)scaled_font_init,         /* tp_init */
+    0,                                  /* tp_init */
     0,                                  /* tp_alloc */
     (newfunc)scaled_font_new,           /* tp_new */
     0,                                  /* tp_free */




More information about the cairo-commit mailing list