[cairo-commit] cairo/src cairo-font.c, 1.57, 1.58 cairo-ft-font.c, 1.80, 1.81 cairo-gstate.c, 1.149, 1.150 cairo-surface.c, 1.82, 1.83 cairo-win32-font.c, 1.28, 1.29 cairo.h, 1.140, 1.141 cairoint.h, 1.171, 1.172

Owen Taylor commit at pdx.freedesktop.org
Thu Jul 28 09:29:49 PDT 2005


Committed by: otaylor

Update of /cvs/cairo/cairo/src
In directory gabe:/tmp/cvs-serv29089/src

Modified Files:
	cairo-font.c cairo-ft-font.c cairo-gstate.c cairo-surface.c 
	cairo-win32-font.c cairo.h cairoint.h 
Log Message:
2005-07-27  Owen Taylor  <otaylor at redhat.com>

        * src/cairo-font.c src/cairoint.h: Define _cairo_font_face_nil.
        (cairo_font_face_reference, cairo_font_face_destroy
        cairo_font_face_set_user_data): Handle a nil font face.
        (cairo_font_face_status): New function.

        * src/cairo-font.c (_cairo_simple_font_face_create)
        src/cairo-ft-font.c (cairo_ft_font_face_create_for_pattern):
        src/cairo-ft-font.c (cairo_ft_font_face_create_for_ft_face):
        src/cairo-win32-font.c (cairo_win32_font_face_create_for_logfontw):
        Return _cairo_font_face_nil on out-of-memory.

        * src/cairo-gstate.c (_cairo_gstate_select_font_face)
        * src/cairo-gstate.c (_cairo_gstate_ensure_font_face): Check return
        of _cairo_simple_font_face_create().

        * src/cairo-gstate.c (_cairo_gstate_set_font_face): Error out
        if font_face has a status.

        * src/cairo-surface.c (cairo_surface_set_user_data): Handle a nil
        surface.


Index: cairo-font.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-font.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -d -r1.57 -r1.58
--- cairo-font.c	27 Jul 2005 23:23:11 -0000	1.57
+++ cairo-font.c	28 Jul 2005 16:29:46 -0000	1.58
@@ -39,12 +39,25 @@
 
 #include "cairoint.h"
 
+/* Forward declare so we can use it as an arbitrary backend for
+ * _cairo_font_face_nil.
+ */
+static const cairo_font_face_backend_t _cairo_simple_font_face_backend;
+
 /* cairo_font_face_t */
 
+const cairo_font_face_t _cairo_font_face_nil = {
+    CAIRO_STATUS_NO_MEMORY,	/* status */
+    -1,		                /* ref_count */
+    { 0, 0, 0, NULL },		/* user_data */
+    &_cairo_simple_font_face_backend
+};
+
 void
 _cairo_font_face_init (cairo_font_face_t               *font_face, 
 		       const cairo_font_face_backend_t *backend)
 {
+    font_face->status = CAIRO_STATUS_SUCCESS;
     font_face->ref_count = 1;
     font_face->backend = backend;
 
@@ -66,6 +79,9 @@
     if (font_face == NULL)
 	return;
 
+    if (font_face->ref_count == (unsigned int)-1)
+	return;
+
     font_face->ref_count++;
 }
 
@@ -83,6 +99,9 @@
     if (font_face == NULL)
 	return;
 
+    if (font_face->ref_count == (unsigned int)-1)
+	return;
+
     if (--(font_face->ref_count) > 0)
 	return;
 
@@ -101,6 +120,22 @@
 }
 
 /**
+ * cairo_font_face_status:
+ * @surface: a #cairo_font_face_t
+ * 
+ * Checks whether an error has previously occurred for this
+ * font face
+ * 
+ * Return value: %CAIRO_STATUS_SUCCESS or another error such as
+ *   %CAIRO_STATUS_NO_MEMORY.
+ **/
+cairo_status_t
+cairo_font_face_status (cairo_font_face_t *font_face)
+{
+    return font_face->status;
+}
+
+/**
  * cairo_font_face_get_user_data:
  * @font_face: a #cairo_font_face_t
  * @key: the address of the #cairo_user_data_key_t the user data was
@@ -142,6 +177,9 @@
 			       void			   *user_data,
 			       cairo_destroy_func_t	    destroy)
 {
+    if (font_face->ref_count == -1)
+	return CAIRO_STATUS_NO_MEMORY;
+    
     return _cairo_user_data_array_set_data (&font_face->user_data,
 					    key, user_data, destroy);
 }
@@ -159,8 +197,6 @@
     cairo_font_weight_t weight;
 };
 
-static const cairo_font_face_backend_t _cairo_simple_font_face_backend;
-
 /* We maintain a global cache from family/weight/slant => cairo_font_face_t
  * for cairo_simple_font_t. The primary purpose of this cache is to provide
  * unique cairo_font_face_t values so that our cache from
@@ -406,15 +442,18 @@
     cache = _get_global_simple_cache ();
     if (cache == NULL) {
 	_unlock_global_simple_cache ();
-	return NULL;
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
+	return (cairo_font_face_t *)&_cairo_font_face_nil;
     }
     status = _cairo_cache_lookup (cache, &key, (void **) &entry, &created_entry);
     if (status == CAIRO_STATUS_SUCCESS && !created_entry)
 	cairo_font_face_reference (&entry->font_face->base);
     
     _unlock_global_simple_cache ();
-    if (status)
-	return NULL;
+    if (status) {
+	_cairo_error (status);
+	return (cairo_font_face_t *)&_cairo_font_face_nil;
+    }
 
     return &entry->font_face->base;
 }
@@ -463,7 +502,8 @@
  * Checks whether an error has previously occurred for this
  * scaled_font.
  * 
- * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NULL_POINTER.
+ * Return value: %CAIRO_STATUS_SUCCESS or another error such as
+ *   %CAIRO_STATUS_NO_MEMORY.
  **/
 cairo_status_t
 cairo_scaled_font_status (cairo_scaled_font_t *scaled_font)
@@ -791,6 +831,9 @@
     cairo_cache_t *cache;
     cairo_status_t status;
 
+    if (font_face->status)
+	return (cairo_scaled_font_t*) &_cairo_scaled_font_nil;
+
     key.font_face = font_face;
     key.font_matrix = font_matrix;
     key.ctm = ctm;
@@ -810,7 +853,7 @@
     
     _unlock_global_font_cache ();
     if (status) {
-	_cairo_error (CAIRO_STATUS_NO_MEMORY);
+	_cairo_error (status);
 	return (cairo_scaled_font_t*) &_cairo_scaled_font_nil;
     }
     

Index: cairo-ft-font.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-ft-font.c,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -d -r1.80 -r1.81
--- cairo-ft-font.c	27 Jul 2005 23:23:11 -0000	1.80
+++ cairo-ft-font.c	28 Jul 2005 16:29:46 -0000	1.81
@@ -2274,13 +2274,20 @@
     cairo_font_face_t *font_face;
 
     unscaled = _ft_unscaled_font_get_for_pattern (pattern);
-    if (unscaled == NULL)
-	return NULL;
+    if (unscaled == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
+	return (cairo_font_face_t *)&_cairo_font_face_nil;
+    }
 
     font_face = _ft_font_face_create (unscaled, _get_pattern_load_flags (pattern));
     _cairo_unscaled_font_destroy (&unscaled->base);
 
-    return font_face;
+    if (font_face)
+	return font_face;
+    else {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
+	return (cairo_font_face_t *)&_cairo_font_face_nil;
+    }
 }
 
 /**
@@ -2316,13 +2323,20 @@
     cairo_font_face_t *font_face;
 
     unscaled = _ft_unscaled_font_create_from_face (face);
-    if (unscaled == NULL)
-	return NULL;
+    if (unscaled == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
+	return (cairo_font_face_t *)&_cairo_font_face_nil;
+    }
 
     font_face = _ft_font_face_create (unscaled, load_flags);
     _cairo_unscaled_font_destroy (&unscaled->base);
 
-    return font_face;
+    if (font_face) {
+	return font_face;
+    } else {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
+	return (cairo_font_face_t *)&_cairo_font_face_nil;
+    }
 }
 
 /**

Index: cairo-gstate.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-gstate.c,v
retrieving revision 1.149
retrieving revision 1.150
diff -u -d -r1.149 -r1.150
--- cairo-gstate.c	27 Jul 2005 22:39:35 -0000	1.149
+++ cairo-gstate.c	28 Jul 2005 16:29:46 -0000	1.150
@@ -1838,8 +1838,8 @@
     cairo_font_face_t *font_face;
 
     font_face = _cairo_simple_font_face_create (family, slant, weight);
-    if (!font_face)
-	return CAIRO_STATUS_NO_MEMORY;
+    if (font_face->status)
+	return font_face->status;
 
     _cairo_gstate_set_font_face (gstate, font_face);
     cairo_font_face_destroy (font_face);
@@ -1989,11 +1989,15 @@
 _cairo_gstate_ensure_font_face (cairo_gstate_t *gstate)
 {
     if (!gstate->font_face) {
-	gstate->font_face = _cairo_simple_font_face_create (CAIRO_FONT_FAMILY_DEFAULT,
-							    CAIRO_FONT_SLANT_DEFAULT,
-							    CAIRO_FONT_WEIGHT_DEFAULT);
-	if (!gstate->font_face)
-	    return CAIRO_STATUS_NO_MEMORY;
+	cairo_font_face_t *font_face;
+
+	font_face = _cairo_simple_font_face_create (CAIRO_FONT_FAMILY_DEFAULT,
+						    CAIRO_FONT_SLANT_DEFAULT,
+						    CAIRO_FONT_WEIGHT_DEFAULT);
+	if (font_face->status)
+	    return font_face->status;
+	else
+	    gstate->font_face = font_face;
     }
     
     return CAIRO_STATUS_SUCCESS;
@@ -2079,6 +2083,9 @@
 _cairo_gstate_set_font_face (cairo_gstate_t    *gstate, 
 			     cairo_font_face_t *font_face)
 {
+    if (font_face->status)
+	return font_face->status;
+    
     if (font_face != gstate->font_face) {
 	if (gstate->font_face)
 	    cairo_font_face_destroy (gstate->font_face);

Index: cairo-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-surface.c,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -d -r1.82 -r1.83
--- cairo-surface.c	27 Jul 2005 23:23:11 -0000	1.82
+++ cairo-surface.c	28 Jul 2005 16:29:46 -0000	1.83
@@ -338,6 +338,9 @@
 			     void			 *user_data,
 			     cairo_destroy_func_t	 destroy)
 {
+    if (surface->ref_count == -1)
+	return CAIRO_STATUS_NO_MEMORY;
+    
     return _cairo_user_data_array_set_data (&surface->user_data,
 					    key, user_data, destroy);
 }

Index: cairo-win32-font.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-win32-font.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- cairo-win32-font.c	27 Jul 2005 23:23:11 -0000	1.28
+++ cairo-win32-font.c	28 Jul 2005 16:29:46 -0000	1.29
@@ -1344,8 +1344,10 @@
     cairo_win32_font_face_t *font_face;
 
     font_face = malloc (sizeof (cairo_win32_font_face_t));
-    if (!font_face)
-	return NULL;
+    if (!font_face) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
+	return (cairo_font_face_t *)&_cairo_font_face_nil;
+    }
     
     font_face->logfont = *logfont;
     

Index: cairo.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo.h,v
retrieving revision 1.140
retrieving revision 1.141
diff -u -d -r1.140 -r1.141
--- cairo.h	27 Jul 2005 22:39:35 -0000	1.140
+++ cairo.h	28 Jul 2005 16:29:47 -0000	1.141
@@ -875,6 +875,9 @@
 void
 cairo_font_face_destroy (cairo_font_face_t *font_face);
 
+cairo_status_t
+cairo_font_face_status (cairo_font_face_t *font_face);
+
 void *
 cairo_font_face_get_user_data (cairo_font_face_t	   *font_face,
 			       const cairo_user_data_key_t *key);

Index: cairoint.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairoint.h,v
retrieving revision 1.171
retrieving revision 1.172
diff -u -d -r1.171 -r1.172
--- cairoint.h	27 Jul 2005 23:23:11 -0000	1.171
+++ cairoint.h	28 Jul 2005 16:29:47 -0000	1.172
@@ -469,6 +469,7 @@
 };
 
 struct _cairo_font_face {
+    cairo_status_t status;
     int ref_count;
     cairo_user_data_array_t user_data;
     const cairo_font_face_backend_t *backend;
@@ -1302,6 +1303,8 @@
 _cairo_scaled_font_set_error (cairo_scaled_font_t *scaled_font,
 			      cairo_status_t status);
 
+extern const cairo_font_face_t _cairo_font_face_nil;
+
 cairo_private void
 _cairo_font_face_init (cairo_font_face_t               *font_face,
 		       const cairo_font_face_backend_t *backend);




More information about the cairo-commit mailing list