[PATCH] [cairo-scaled-font] Use cairo_scaled_font_status() instead of open-coding.

Chris Wilson chris at chris-wilson.co.uk
Fri Feb 22 11:43:05 PST 2008


Use cairo_scaled_font_status() in guards instead of scaled_font->status.
---
 src/cairo-scaled-font.c |   77 ++++++++++++++++++++++++++++------------------
 1 files changed, 47 insertions(+), 30 deletions(-)

diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index e929dae..c083607 100644
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -247,7 +247,7 @@ _cairo_scaled_font_set_error (cairo_scaled_font_t *scaled_font,
 cairo_font_type_t
 cairo_scaled_font_get_type (cairo_scaled_font_t *scaled_font)
 {
-    if (CAIRO_REFERENCE_COUNT_IS_INVALID (&scaled_font->ref_count))
+    if (cairo_scaled_font_status (scaled_font))
 	return CAIRO_FONT_TYPE_TOY;
 
     return scaled_font->backend->type;
@@ -266,6 +266,9 @@ cairo_scaled_font_get_type (cairo_scaled_font_t *scaled_font)
 cairo_status_t
 cairo_scaled_font_status (cairo_scaled_font_t *scaled_font)
 {
+    if (scaled_font == NULL)
+	return CAIRO_STATUS_NULL_POINTER;
+
     return scaled_font->status;
 }
 slim_hidden_def (cairo_scaled_font_status);
@@ -466,6 +469,10 @@ _cairo_scaled_font_init (cairo_scaled_font_t               *scaled_font,
 {
     cairo_status_t status;
 
+    status = cairo_font_face_status (font_face);
+    if (status)
+	return status;
+
     status = cairo_font_options_status ((cairo_font_options_t *) options);
     if (status)
 	return status;
@@ -626,8 +633,9 @@ cairo_scaled_font_create (cairo_font_face_t          *font_face,
     cairo_scaled_font_map_t *font_map;
     cairo_scaled_font_t key, *scaled_font = NULL;
 
-    if (font_face->status)
-	return _cairo_scaled_font_create_in_error (font_face->status);
+    status = cairo_font_face_status (font_face);
+    if (status)
+	return _cairo_scaled_font_create_in_error (status);
 
     status = cairo_font_options_status ((cairo_font_options_t *) options);
     if (status)
@@ -777,7 +785,7 @@ cairo_scaled_font_t *
 cairo_scaled_font_reference (cairo_scaled_font_t *scaled_font)
 {
     if (scaled_font == NULL ||
-	    CAIRO_REFERENCE_COUNT_IS_INVALID (&scaled_font->ref_count))
+	CAIRO_REFERENCE_COUNT_IS_INVALID (&scaled_font->ref_count))
 	return scaled_font;
 
     assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&scaled_font->ref_count));
@@ -803,7 +811,7 @@ cairo_scaled_font_destroy (cairo_scaled_font_t *scaled_font)
     cairo_scaled_font_t *lru = NULL;
 
     if (scaled_font == NULL ||
-	    CAIRO_REFERENCE_COUNT_IS_INVALID (&scaled_font->ref_count))
+	CAIRO_REFERENCE_COUNT_IS_INVALID (&scaled_font->ref_count))
 	return;
 
     font_map = _cairo_scaled_font_map_lock ();
@@ -867,7 +875,7 @@ unsigned int
 cairo_scaled_font_get_reference_count (cairo_scaled_font_t *scaled_font)
 {
     if (scaled_font == NULL ||
-	    CAIRO_REFERENCE_COUNT_IS_INVALID (&scaled_font->ref_count))
+	CAIRO_REFERENCE_COUNT_IS_INVALID (&scaled_font->ref_count))
 	return 0;
 
     return CAIRO_REFERENCE_COUNT_GET_VALUE (&scaled_font->ref_count);
@@ -891,8 +899,7 @@ void *
 cairo_scaled_font_get_user_data (cairo_scaled_font_t	     *scaled_font,
 				 const cairo_user_data_key_t *key)
 {
-    return _cairo_user_data_array_get_data (&scaled_font->user_data,
-					    key);
+    return _cairo_user_data_array_get_data (&scaled_font->user_data, key);
 }
 
 /**
@@ -939,6 +946,14 @@ void
 cairo_scaled_font_extents (cairo_scaled_font_t  *scaled_font,
 			   cairo_font_extents_t *extents)
 {
+    if (cairo_scaled_font_status (scaled_font)) {
+	extents->ascent  = 0.0;
+	extents->descent = 0.0;
+	extents->height  = 0.0;
+	extents->max_x_advance = 0.0;
+	extents->max_y_advance = 0.0;
+    }
+
     *extents = scaled_font->extents;
 }
 slim_hidden_def (cairo_scaled_font_extents);
@@ -975,7 +990,7 @@ cairo_scaled_font_text_extents (cairo_scaled_font_t   *scaled_font,
     cairo_glyph_t *glyphs;
     int num_glyphs;
 
-    if (scaled_font->status)
+    if (cairo_scaled_font_status (scaled_font))
 	goto ZERO_EXTENTS;
 
     if (utf8 == NULL)
@@ -1029,7 +1044,7 @@ cairo_scaled_font_glyph_extents (cairo_scaled_font_t   *scaled_font,
     cairo_bool_t visible = FALSE;
     cairo_scaled_glyph_t *scaled_glyph = NULL;
 
-    if (scaled_font->status) {
+    if (cairo_scaled_font_status (scaled_font)) {
 	extents->x_bearing = 0.0;
 	extents->y_bearing = 0.0;
 	extents->width  = 0.0;
@@ -1063,7 +1078,7 @@ cairo_scaled_font_glyph_extents (cairo_scaled_font_t   *scaled_font,
 	top = scaled_glyph->metrics.y_bearing + glyphs[i].y;
 	bottom = top + scaled_glyph->metrics.height;
 
-	if (!visible) {
+	if (! visible) {
 	    visible = TRUE;
 	    min_x = left;
 	    max_x = right;
@@ -1118,14 +1133,14 @@ _cairo_scaled_font_text_to_glyphs (cairo_scaled_font_t *scaled_font,
 				   double		y,
 				   const char          *utf8,
 				   cairo_glyph_t      **glyphs,
-				   int 		       *num_glyphs)
+				   int		       *num_glyphs)
 {
     int i;
     uint32_t *ucs4 = NULL;
     cairo_status_t status;
     cairo_scaled_glyph_t *scaled_glyph;
 
-    status = scaled_font->status;
+    status = cairo_scaled_font_status (scaled_font);
     if (status)
 	return status;
 
@@ -1197,13 +1212,14 @@ _cairo_scaled_font_glyph_device_extents (cairo_scaled_font_t	 *scaled_font,
 					 int                      num_glyphs,
 					 cairo_rectangle_int_t   *extents)
 {
-    cairo_status_t status = CAIRO_STATUS_SUCCESS;
+    cairo_status_t status;
     int i;
     cairo_point_int_t min = { CAIRO_RECT_INT_MAX, CAIRO_RECT_INT_MAX };
     cairo_point_int_t max = { CAIRO_RECT_INT_MIN, CAIRO_RECT_INT_MIN };
 
-    if (scaled_font->status)
-	return scaled_font->status;
+    status = cairo_scaled_font_status (scaled_font);
+    if (status)
+	return status;
 
     assert (CAIRO_HOLDS_MUTEX (scaled_font->mutex));
 
@@ -1272,10 +1288,11 @@ _cairo_scaled_font_show_glyphs (cairo_scaled_font_t    *scaled_font,
      */
     assert (op != CAIRO_OPERATOR_SOURCE && op != CAIRO_OPERATOR_CLEAR);
 
-    if (scaled_font->status)
-	return scaled_font->status;
+    status = cairo_scaled_font_status (scaled_font);
+    if (status)
+	return status;
 
-    if (!num_glyphs)
+    if (! num_glyphs)
 	return CAIRO_STATUS_SUCCESS;
 
     assert (CAIRO_HOLDS_MUTEX (scaled_font->mutex));
@@ -1353,7 +1370,6 @@ _cairo_scaled_font_show_glyphs (cairo_scaled_font_t    *scaled_font,
 						   width, height);
 	    if (new_mask->status) {
 		status = new_mask->status;
-		cairo_surface_destroy (new_mask);
 		goto CLEANUP_MASK;
 	    }
 
@@ -1586,7 +1602,7 @@ _cairo_scaled_font_glyph_path (cairo_scaled_font_t *scaled_font,
     cairo_scaled_glyph_path_closure_t closure;
     cairo_path_fixed_t *glyph_path;
 
-    status = scaled_font->status;
+    status = cairo_scaled_font_status (scaled_font);
     if (status)
 	return status;
 
@@ -1784,13 +1800,14 @@ _cairo_scaled_glyph_lookup (cairo_scaled_font_t *scaled_font,
 			    cairo_scaled_glyph_info_t info,
 			    cairo_scaled_glyph_t **scaled_glyph_ret)
 {
-    cairo_status_t		status = CAIRO_STATUS_SUCCESS;
+    cairo_status_t		status;
     cairo_cache_entry_t		key;
     cairo_scaled_glyph_t	*scaled_glyph;
     cairo_scaled_glyph_info_t	need_info;
 
-    if (scaled_font->status)
-	return scaled_font->status;
+    status = cairo_scaled_font_status (scaled_font);
+    if (status)
+	return status;
 
     assert (CAIRO_HOLDS_MUTEX (scaled_font->mutex));
 
@@ -1799,8 +1816,8 @@ _cairo_scaled_glyph_lookup (cairo_scaled_font_t *scaled_font,
      * Check cache for glyph
      */
     info |= CAIRO_SCALED_GLYPH_INFO_METRICS;
-    if (!_cairo_cache_lookup (scaled_font->glyphs, &key,
-			      (cairo_cache_entry_t **) &scaled_glyph))
+    if (! _cairo_cache_lookup (scaled_font->glyphs, &key,
+			       (cairo_cache_entry_t **) &scaled_glyph))
     {
 	/*
 	 * On miss, create glyph and insert into cache
@@ -1881,7 +1898,7 @@ _cairo_scaled_glyph_lookup (cairo_scaled_font_t *scaled_font,
 cairo_font_face_t *
 cairo_scaled_font_get_font_face (cairo_scaled_font_t *scaled_font)
 {
-    if (scaled_font->status)
+    if (cairo_scaled_font_status (scaled_font))
 	return (cairo_font_face_t*) &_cairo_font_face_nil;
 
     return scaled_font->font_face;
@@ -1902,7 +1919,7 @@ void
 cairo_scaled_font_get_font_matrix (cairo_scaled_font_t	*scaled_font,
 				   cairo_matrix_t	*font_matrix)
 {
-    if (scaled_font->status) {
+    if (cairo_scaled_font_status (scaled_font)) {
 	cairo_matrix_init_identity (font_matrix);
 	return;
     }
@@ -1924,7 +1941,7 @@ void
 cairo_scaled_font_get_ctm (cairo_scaled_font_t	*scaled_font,
 			   cairo_matrix_t	*ctm)
 {
-    if (scaled_font->status) {
+    if (cairo_scaled_font_status (scaled_font)) {
 	cairo_matrix_init_identity (ctm);
 	return;
     }
@@ -1950,7 +1967,7 @@ cairo_scaled_font_get_font_options (cairo_scaled_font_t		*scaled_font,
     if (cairo_font_options_status (options))
 	return;
 
-    if (scaled_font->status) {
+    if (cairo_scaled_font_status (scaled_font)) {
 	_cairo_font_options_init_default (options);
 	return;
     }
-- 
1.5.3.8


--=-BzpsUfdHqkE+TbB0ojYn
Content-Disposition: attachment; filename=0055-cairo-font-face-Use-cairo_font_face_status-in-pr.patch
Content-Type: application/mbox; name=0055-cairo-font-face-Use-cairo_font_face_status-in-pr.patch
Content-Transfer-Encoding: 7bit



More information about the cairo mailing list