[cairo-commit] 4 commits - src/cairo.c src/cairo-scaled-font.c test/get-path-extents.c test/in-fill-trapezoid.c test/text-zero-len.c

Chris Wilson ickle at kemper.freedesktop.org
Thu Jan 17 05:58:14 PST 2008


 src/cairo-scaled-font.c  |   19 ++++++++++++++++---
 src/cairo.c              |   35 +++++++++++++++++++----------------
 test/get-path-extents.c  |   19 ++++++++++++++++++-
 test/in-fill-trapezoid.c |   20 ++++++++++++++++++++
 test/text-zero-len.c     |   33 +++++++++++++++++++++++++++++++++
 5 files changed, 106 insertions(+), 20 deletions(-)

New commits:
commit 7b1a0eddacb290ae0d67fa974da1697b2c9ce38c
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Jan 17 13:51:21 2008 +0000

    [test/get-path-extents] Exercise cairo_scaled_font_text_extents()
    
    Compare cairo_scaled_font_text_extents() to cairo_text_extents() in
    order to provide test coverage of cairo_scaled_font_text_extents().

diff --git a/test/get-path-extents.c b/test/get-path-extents.c
index ba2b116..b20b13f 100644
--- a/test/get-path-extents.c
+++ b/test/get-path-extents.c
@@ -102,7 +102,7 @@ draw (cairo_t *cr, int width, int height)
     cairo_surface_t *surface;
     cairo_t         *cr2;
     const char      *phase;
-    cairo_text_extents_t extents;
+    cairo_text_extents_t extents, scaled_font_extents;
     cairo_test_status_t ret = CAIRO_TEST_SUCCESS;
 
     surface = cairo_surface_create_similar (cairo_get_group_target (cr),
@@ -219,6 +219,23 @@ draw (cairo_t *cr, int width, int height)
 			    CAIRO_FONT_WEIGHT_NORMAL);
     cairo_set_font_size (cr2, 12);
     cairo_text_extents (cr2, "The quick brown fox jumped over the lazy dog.", &extents);
+    /* double check that the two methods of measuring the text agree... */
+    cairo_scaled_font_text_extents (cairo_get_scaled_font (cr2),
+	                     "The quick brown fox jumped over the lazy dog.",
+			     &scaled_font_extents);
+    if (memcmp (&extents, &scaled_font_extents, sizeof (extents))) {
+	cairo_test_log ("Error: cairo_text_extents() does not match cairo_scaled_font_text_extents() - font extents (%f, %f) x (%f, %f) should be (%f, %f) x (%f, %f)\n",
+		        scaled_font_extents.x_bearing,
+			scaled_font_extents.y_bearing,
+			scaled_font_extents.width,
+			scaled_font_extents.height,
+			extents.x_bearing,
+			extents.y_bearing,
+			extents.width,
+			extents.height);
+	ret = CAIRO_TEST_FAILURE;
+    }
+
     cairo_move_to (cr2, -extents.x_bearing, -extents.y_bearing);
     cairo_text_path (cr2, "The quick brown fox jumped over the lazy dog.");
     cairo_set_line_width (cr2, 2.0);
commit dbc97c2576320126e0cddd833ac88320af995d77
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Jan 17 13:41:19 2008 +0000

    [text] Set the extents on the error paths.
    
    Ensure the text extents are initialized (zeroed) if we encounter an
    error along for any of the text extents functions.

diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index f8b124b..6e7d414 100644
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -901,15 +901,28 @@ cairo_scaled_font_text_extents (cairo_scaled_font_t   *scaled_font,
     int num_glyphs;
 
     if (scaled_font->status)
-	return;
+	goto ZERO_EXENTS;
+
+    if (utf8 == NULL)
+	goto ZERO_EXENTS;
 
     status = _cairo_scaled_font_text_to_glyphs (scaled_font, 0., 0., utf8, &glyphs, &num_glyphs);
     if (status) {
         status = _cairo_scaled_font_set_error (scaled_font, status);
-        return;
+	goto ZERO_EXENTS;
     }
     cairo_scaled_font_glyph_extents (scaled_font, glyphs, num_glyphs, extents);
     free (glyphs);
+
+    return;
+
+ZERO_EXENTS:
+    extents->x_bearing = 0.0;
+    extents->y_bearing = 0.0;
+    extents->width  = 0.0;
+    extents->height = 0.0;
+    extents->x_advance = 0.0;
+    extents->y_advance = 0.0;
 }
 
 /**
@@ -945,7 +958,7 @@ cairo_scaled_font_glyph_extents (cairo_scaled_font_t   *scaled_font,
     if (scaled_font->status) {
 	extents->x_bearing = 0.0;
 	extents->y_bearing = 0.0;
-	extents->width = 0.0;
+	extents->width  = 0.0;
 	extents->height = 0.0;
 	extents->x_advance = 0.0;
 	extents->y_advance = 0.0;
diff --git a/src/cairo.c b/src/cairo.c
index 676aeb1..2eac030 100644
--- a/src/cairo.c
+++ b/src/cairo.c
@@ -2812,18 +2812,18 @@ cairo_text_extents (cairo_t              *cr,
     int num_glyphs;
     double x, y;
 
+    extents->x_bearing = 0.0;
+    extents->y_bearing = 0.0;
+    extents->width  = 0.0;
+    extents->height = 0.0;
+    extents->x_advance = 0.0;
+    extents->y_advance = 0.0;
+
     if (cr->status)
 	return;
 
-    if (utf8 == NULL) {
-	extents->x_bearing = 0.0;
-	extents->y_bearing = 0.0;
-	extents->width = 0.0;
-	extents->height = 0.0;
-	extents->x_advance = 0.0;
-	extents->y_advance = 0.0;
+    if (utf8 == NULL)
 	return;
-    }
 
     cairo_get_current_point (cr, &x, &y);
 
@@ -2831,14 +2831,10 @@ cairo_text_extents (cairo_t              *cr,
 					   x, y,
 					   &glyphs, &num_glyphs);
 
-    if (status) {
-	if (glyphs)
-	    free (glyphs);
-	_cairo_set_error (cr, status);
-	return;
-    }
-
-    status = _cairo_gstate_glyph_extents (cr->gstate, glyphs, num_glyphs, extents);
+    if (status == CAIRO_STATUS_SUCCESS)
+	status = _cairo_gstate_glyph_extents (cr->gstate,
+		                              glyphs, num_glyphs,
+					      extents);
     if (glyphs)
 	free (glyphs);
 
@@ -2872,6 +2868,13 @@ cairo_glyph_extents (cairo_t                *cr,
 {
     cairo_status_t status;
 
+    extents->x_bearing = 0.0;
+    extents->y_bearing = 0.0;
+    extents->width  = 0.0;
+    extents->height = 0.0;
+    extents->x_advance = 0.0;
+    extents->y_advance = 0.0;
+
     if (cr->status)
 	return;
 
commit aec7ae67aa72f3105232fa7a66c1ea013c840da1
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Jan 17 13:28:55 2008 +0000

    [test/text-zero-len] Test the public cairo_scaled_font_* with NULLs.
    
    Pass NULL to cairo_scaled_font_(text|glyph)_extents() to test the
    consistency of the extents API.

diff --git a/test/text-zero-len.c b/test/text-zero-len.c
index e64daa8..b8cdce6 100644
--- a/test/text-zero-len.c
+++ b/test/text-zero-len.c
@@ -71,6 +71,7 @@ draw (cairo_t *cr, int width, int height)
 {
     cairo_text_extents_t nil_extents;
     cairo_text_extents_t extents;
+    cairo_scaled_font_t *scaled_font;
 
     cairo_select_font_face (cr, "Bitstream Vera Sans",
 			    CAIRO_FONT_SLANT_NORMAL,
@@ -121,6 +122,38 @@ draw (cairo_t *cr, int width, int height)
 	return CAIRO_TEST_FAILURE;
     }
 
+    scaled_font = cairo_get_scaled_font (cr);
+
+    memset (&extents, 0xff, sizeof (cairo_text_extents_t));
+    cairo_scaled_font_text_extents (scaled_font, "", &extents);
+    if (! text_extents_equal (&extents, &nil_extents)) {
+	cairo_test_log ("Error: cairo_scaled_font_text_extents(\"\"); extents (%g, %g, %g, %g, %g, %g)\n",
+		        extents.x_bearing, extents.y_bearing,
+			extents.width, extents.height,
+			extents.x_advance, extents.y_advance);
+	return CAIRO_TEST_FAILURE;
+    }
+
+    memset (&extents, 0xff, sizeof (cairo_text_extents_t));
+    cairo_scaled_font_text_extents (scaled_font, NULL, &extents);
+    if (! text_extents_equal (&extents, &nil_extents)) {
+	cairo_test_log ("Error: cairo_scaled_font_text_extents(NULL); extents (%g, %g, %g, %g, %g, %g)\n",
+		        extents.x_bearing, extents.y_bearing,
+			extents.width, extents.height,
+			extents.x_advance, extents.y_advance);
+	return CAIRO_TEST_FAILURE;
+    }
+
+    memset (&extents, 0xff, sizeof (cairo_text_extents_t));
+    cairo_scaled_font_glyph_extents (scaled_font, (void*)8, 0, &extents);
+    if (! text_extents_equal (&extents, &nil_extents)) {
+	cairo_test_log ("Error: cairo_scaled_font_glyph_extents(NULL); extents (%g, %g, %g, %g, %g, %g)\n",
+		        extents.x_bearing, extents.y_bearing,
+			extents.width, extents.height,
+			extents.x_advance, extents.y_advance);
+	return CAIRO_TEST_FAILURE;
+    }
+
     return CAIRO_TEST_SUCCESS;
 }
 
commit 390e22894b093184e489ea762ffc29eeb1c81d2b
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Jan 17 13:13:40 2008 +0000

    [test/in-fill-trapezoid] Add a few holes.
    
    Complete the coverage of _cairo_trap_contains() by cutting holes out of
    the simple shapes.

diff --git a/test/in-fill-trapezoid.c b/test/in-fill-trapezoid.c
index 0e9f058..a544e43 100644
--- a/test/in-fill-trapezoid.c
+++ b/test/in-fill-trapezoid.c
@@ -40,6 +40,8 @@ draw (cairo_t *cr, int width, int height)
 {
     cairo_test_status_t ret = CAIRO_TEST_SUCCESS;
 
+    cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
+
     /* simple rectangle */
     cairo_new_path (cr);
     cairo_rectangle (cr, -10, -10, 20, 20);
@@ -56,6 +58,24 @@ draw (cairo_t *cr, int width, int height)
 	ret = CAIRO_TEST_FAILURE;
     }
 
+    /* holey rectangle */
+    cairo_new_path (cr);
+    cairo_rectangle (cr, -10, -10, 20, 20);
+    cairo_rectangle (cr, -5, -5, 10, 10);
+    if (cairo_in_fill (cr, 0, 0)) {
+	cairo_test_log ("Error: Found an unexpected point inside rectangular hole\n");
+	ret = CAIRO_TEST_FAILURE;
+    }
+
+    /* holey circle */
+    cairo_new_path (cr);
+    cairo_arc (cr, 0, 0, 10, 0, 2 * M_PI);
+    cairo_arc (cr, 0, 0, 5, 0, 2 * M_PI);
+    if (cairo_in_fill (cr, 0, 0)) {
+	cairo_test_log ("Error: Found an unexpected point inside circular hole\n");
+	ret = CAIRO_TEST_FAILURE;
+    }
+
     return ret;
 }
 


More information about the cairo-commit mailing list