[cairo-commit] test/font-matrix-translation.c

Behdad Esfahbod behdad at kemper.freedesktop.org
Fri Jan 25 04:02:32 PST 2008


 test/font-matrix-translation.c |   31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

New commits:
commit 83bd590760629b61898ed403e273046545f26767
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Fri Jan 25 07:02:25 2008 -0500

    [test] Test that cairo_text_extents() and cairo_scaled_font_text_extents() match
    in results.

diff --git a/test/font-matrix-translation.c b/test/font-matrix-translation.c
index 067cbb5..f831cbc 100644
--- a/test/font-matrix-translation.c
+++ b/test/font-matrix-translation.c
@@ -38,15 +38,44 @@ cairo_test_t test = {
     draw
 };
 
+static cairo_bool_t
+text_extents_equal (const cairo_text_extents_t *A,
+	            const cairo_text_extents_t *B)
+{
+    return A->x_bearing == B->x_bearing &&
+	   A->y_bearing == B->y_bearing &&
+	   A->width     == B->width     &&
+	   A->height    == B->height    &&
+	   A->x_advance == B->x_advance &&
+	   A->y_advance == B->y_advance;
+}
+
 static void
 box_text (cairo_t *cr, const char *utf8, double x, double y)
 {
     double line_width;
-    cairo_text_extents_t extents;
+    cairo_text_extents_t extents = {}, scaled_extents = {};
+    cairo_scaled_font_t *scaled_font;
 
     cairo_save (cr);
 
     cairo_text_extents (cr, utf8, &extents);
+
+    scaled_font = cairo_get_scaled_font (cr);
+    cairo_scaled_font_text_extents (scaled_font, TEXT, &scaled_extents);
+    if (! text_extents_equal (&extents, &scaled_extents)) {
+        cairo_test_log ("Error: extents differ when they shouldn't:\n"
+			"cairo_text_extents(); extents (%g, %g, %g, %g, %g, %g)\n",
+			"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,
+		        scaled_extents.x_bearing, scaled_extents.y_bearing,
+			scaled_extents.width, scaled_extents.height,
+			scaled_extents.x_advance, scaled_extents.y_advance);
+        return CAIRO_TEST_FAILURE;
+    }
+
     line_width = cairo_get_line_width (cr);
     cairo_rectangle (cr,
 		     x + extents.x_bearing - line_width / 2,


More information about the cairo-commit mailing list