[cairo] [PATCH 3/3] [cairo-ft-font] Cleanup _cairo_error usage and add more annotations.

Jeff Muizelaar jeff at infidigm.net
Fri Sep 28 07:49:38 PDT 2007


---

 src/cairo-ft-font.c |   59 +++++++++++++++++++--------------------------------
 1 files changed, 22 insertions(+), 37 deletions(-)


diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 3262163..7a0adeb 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -329,8 +329,7 @@ _cairo_ft_unscaled_font_init (cairo_ft_unscaled_font_t *unscaled,
 
 	filename_copy = strdup (filename);
 	if (filename_copy == NULL) {
-	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
-	    return CAIRO_STATUS_NO_MEMORY;
+	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	}
 
 	_cairo_ft_unscaled_font_init_key (unscaled, filename_copy, id);
@@ -661,8 +660,7 @@ _cairo_ft_unscaled_font_set_scale (cairo_ft_unscaled_font_t *unscaled,
 				  sf.y_scale * 64.0,
 				  0, 0);
 	if (error) {
-	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
-	    return CAIRO_STATUS_NO_MEMORY;
+	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	}
     } else {
 	double min_distance = DBL_MAX;
@@ -693,8 +691,7 @@ _cairo_ft_unscaled_font_set_scale (cairo_ft_unscaled_font_t *unscaled,
 					unscaled->face->available_sizes[best_i].width,
 					unscaled->face->available_sizes[best_i].height);
 	if (error) {
-	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
-	    return CAIRO_STATUS_NO_MEMORY;
+	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	}
     }
 
@@ -750,8 +747,7 @@ _get_bitmap_surface (FT_Bitmap		     *bitmap,
 	} else {
 	    data = _cairo_malloc_ab (height, stride);
 	    if (!data) {
-		_cairo_error (CAIRO_STATUS_NO_MEMORY);
-		return CAIRO_STATUS_NO_MEMORY;
+		return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    }
 
 	    if (stride == bitmap->pitch) {
@@ -800,8 +796,7 @@ _get_bitmap_surface (FT_Bitmap		     *bitmap,
 	    } else {
 		data = _cairo_malloc_ab (height, stride);
 		if (!data) {
-		    _cairo_error (CAIRO_STATUS_NO_MEMORY);
-		    return CAIRO_STATUS_NO_MEMORY;
+		    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 		}
 		memcpy (data, bitmap->buffer, stride * height);
 	    }
@@ -844,8 +839,7 @@ _get_bitmap_surface (FT_Bitmap		     *bitmap,
 	    if (data_rgba == NULL) {
 		if (own_buffer)
 		    free (bitmap->buffer);
-		_cairo_error (CAIRO_STATUS_NO_MEMORY);
-		return CAIRO_STATUS_NO_MEMORY;
+		return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    }
 
 	    os = 1;
@@ -913,8 +907,7 @@ _get_bitmap_surface (FT_Bitmap		     *bitmap,
     default:
 	if (own_buffer)
 	    free (bitmap->buffer);
-	_cairo_error (CAIRO_STATUS_NO_MEMORY);
-	return CAIRO_STATUS_NO_MEMORY;
+	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
 
     *surface = (cairo_image_surface_t *)
@@ -923,7 +916,7 @@ _get_bitmap_surface (FT_Bitmap		     *bitmap,
 					     width, height, stride);
     if ((*surface)->base.status) {
 	free (data);
-	return CAIRO_STATUS_NO_MEMORY;
+	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
 
     if (subpixel)
@@ -996,7 +989,7 @@ _render_glyph_outline (FT_Face                    face,
 	(*surface) = (cairo_image_surface_t *)
 	    cairo_image_surface_create_for_data (NULL, format, 0, 0, 0);
 	if ((*surface)->base.status)
-	    return CAIRO_STATUS_NO_MEMORY;
+	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     } else  {
 
 	matrix.xx = matrix.yy = 0x10000L;
@@ -1044,16 +1037,14 @@ _render_glyph_outline (FT_Face                    face,
 	bitmap.buffer = calloc (1, stride * bitmap.rows);
 
 	if (bitmap.buffer == NULL) {
-	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
-	    return CAIRO_STATUS_NO_MEMORY;
+	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	}
 
 	FT_Outline_Translate (outline, -cbox.xMin*hmul, -cbox.yMin*vmul);
 
 	if (FT_Outline_Get_Bitmap (glyphslot->library, outline, &bitmap) != 0) {
 	    free (bitmap.buffer);
-	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
-	    return CAIRO_STATUS_NO_MEMORY;
+	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	}
 
 	status = _get_bitmap_surface (&bitmap, TRUE, font_options, surface);
@@ -1095,8 +1086,7 @@ _render_glyph_bitmap (FT_Face		      face,
     /* XXX ignoring all other errors for now.  They are not fatal, typically
      * just a glyph-not-found. */
     if (error == FT_Err_Out_Of_Memory) {
-	_cairo_error (CAIRO_STATUS_NO_MEMORY);
-	return CAIRO_STATUS_NO_MEMORY;
+	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
 
     status = _get_bitmap_surface (&glyphslot->bitmap, FALSE, font_options, surface);
@@ -1194,7 +1184,7 @@ _transform_glyph_bitmap (cairo_matrix_t         * shape,
     width = (width + 3) & ~3;
     image = cairo_image_surface_create (CAIRO_FORMAT_A8, width, height);
     if (image->status)
-	return CAIRO_STATUS_NO_MEMORY;
+	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     /* Initialize it to empty
      */
@@ -1592,8 +1582,7 @@ _cairo_ft_scaled_font_create_toy (cairo_toy_font_face_t	      *toy_face,
 
     pattern = FcPatternCreate ();
     if (!pattern) {
-	_cairo_error (CAIRO_STATUS_NO_MEMORY);
-	return CAIRO_STATUS_NO_MEMORY;
+	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
 
     switch (toy_face->weight)
@@ -1664,8 +1653,7 @@ _cairo_ft_scaled_font_create_toy (cairo_toy_font_face_t	      *toy_face,
 	*font = new_font;
 	return CAIRO_STATUS_SUCCESS;
     } else {
-	_cairo_error (CAIRO_STATUS_NO_MEMORY);
-	return CAIRO_STATUS_NO_MEMORY;
+	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
 }
 
@@ -1799,7 +1787,7 @@ _decompose_glyph_outline (FT_Face		  face,
 
     path = _cairo_path_fixed_create ();
     if (!path)
-	return CAIRO_STATUS_NO_MEMORY;
+	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     glyph = face->glyph;
 
@@ -1807,8 +1795,7 @@ _decompose_glyph_outline (FT_Face		  face,
     FT_Outline_Transform (&glyph->outline, &invert_y);
     if (FT_Outline_Decompose (&glyph->outline, &outline_funcs, path)) {
 	_cairo_path_fixed_destroy (path);
-	_cairo_error (CAIRO_STATUS_NO_MEMORY);
-	return CAIRO_STATUS_NO_MEMORY;
+	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
 
     status = _cairo_path_fixed_close_path (path);
@@ -1863,7 +1850,7 @@ _cairo_ft_scaled_glyph_init (void			*abstract_font,
 
     face = _cairo_ft_unscaled_font_lock_face (unscaled);
     if (!face)
-	return CAIRO_STATUS_NO_MEMORY;
+	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     status = _cairo_ft_unscaled_font_set_scale (scaled_font->unscaled,
 				                &scaled_font->base.scale);
@@ -1892,7 +1879,7 @@ _cairo_ft_scaled_glyph_init (void			*abstract_font,
     /* XXX ignoring all other errors for now.  They are not fatal, typically
      * just a glyph-not-found. */
     if (error == FT_Err_Out_Of_Memory) {
-	status = CAIRO_STATUS_NO_MEMORY;
+	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto FAIL;
     }
 
@@ -2045,8 +2032,7 @@ _cairo_ft_scaled_glyph_init (void			*abstract_font,
 	     * just a glyph-not-found. */
 	    if (error == FT_Err_Out_Of_Memory) {
 		_cairo_ft_unscaled_font_unlock_face (unscaled);
-		_cairo_error (CAIRO_STATUS_NO_MEMORY);
-		return CAIRO_STATUS_NO_MEMORY;
+		return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    }
 #if HAVE_FT_GLYPHSLOT_EMBOLDEN
 	    /*
@@ -2113,7 +2099,7 @@ _cairo_ft_load_truetype_table (void	       *abstract_font,
 #if HAVE_FT_LOAD_SFNT_TABLE
     face = _cairo_ft_unscaled_font_lock_face (unscaled);
     if (!face)
-	return CAIRO_STATUS_NO_MEMORY;
+	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     if (FT_IS_SFNT (face) &&
 	FT_Load_Sfnt_Table (face, tag, offset, buffer, length) == 0)
@@ -2258,8 +2244,7 @@ _cairo_ft_font_face_scaled_font_create (void                     *abstract_face,
     if (*scaled_font) {
 	return CAIRO_STATUS_SUCCESS;
     } else {
-	_cairo_error (CAIRO_STATUS_NO_MEMORY);
-	return CAIRO_STATUS_NO_MEMORY;
+	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
 }
 



More information about the cairo mailing list