[cairo-commit] cairo/test path_data.c,1.1,1.2

Carl Worth commit at pdx.freedesktop.org
Fri Mar 18 14:28:55 PST 2005


Committed by: cworth

Update of /cvs/cairo/cairo/test
In directory gabe:/tmp/cvs-serv19146/test

Modified Files:
	path_data.c 
Log Message:

        * src/cairo-path-data-private.h: * src/cairo.c: (cairo_copy_path),
        (cairo_copy_path_flat),
        (cairo_append_path): Rename cairo_copy_path_data,
        cairop_copy_path_data_flat, and cairo_append_path_data to
        cairo_copy_path, cairo_copy_path_flat, and cairo_append_path.

        * src/cairo.h: Add new cairo_path_t, containing a
        cairo_path_data_t array and an explicit length. Remove
        CAIRO_PATH_END_PATH terminator from cairo_path_data_t.

        * src/cairo_atsui_font.c: (_cairo_atsui_font_glyph_path):
        * src/cairo_font.c: (_cairo_font_glyph_path):
        * src/cairo_ft_font.c: (_move_to), (_line_to), (_conic_to),
        (_cubic_to), (_cairo_ft_font_glyph_path):
        * src/cairo_gstate.c: (_cairo_gstate_interpret_path):
        * src/cairo_path.c: (_cairo_path_init), (_cairo_path_init_copy),
        (_cairo_path_fini), (_cairo_path_move_to),
        (_cairo_path_rel_move_to), (_cairo_path_line_to),
        (_cairo_path_rel_line_to), (_cairo_path_curve_to),
        (_cairo_path_rel_curve_to), (_cairo_path_close_path),
        (_cairo_path_get_current_point), (_cairo_path_add),
        (_cairo_path_add_op_buf), (_cairo_path_new_op_buf),
        (_cairo_path_add_arg_buf), (_cairo_path_new_arg_buf),
        (_cairo_path_interpret):
        * src/cairo_path_bounds.c: (_cairo_path_bounds):
        * src/cairo_path_data.c: (_cairo_path_data_count),
        (_cairo_path_data_populate), (_cairo_path_data_create_real),
        (cairo_path_destroy), (_cairo_path_data_append_to_context):
        * src/cairo_path_fill.c: (_cairo_path_fill_to_traps):
        * src/cairo_path_stroke.c: (_cairo_path_stroke_to_traps):
        * src/cairoint.h:
        * test/path_data.c: (munge_and_set_path), (draw), (main): Rename
        the internal path object from cairo_path_t to cairo_path_real_t.


Index: path_data.c
===================================================================
RCS file: /cvs/cairo/cairo/test/path_data.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- path_data.c	11 Mar 2005 22:29:15 -0000	1.1
+++ path_data.c	18 Mar 2005 22:28:53 -0000	1.2
@@ -42,15 +42,16 @@
 typedef void (*munge_func_t) (double *x, double *y);
 
 static void
-munge_and_set_path (cairo_t	      *cr,
-		    cairo_path_data_t *path,
-		    munge_func_t       munge)
+munge_and_set_path (cairo_t	 *cr,
+		    cairo_path_t *path,
+		    munge_func_t  munge)
 {
+    int i;
     cairo_path_data_t *p;
     double x1, y1, x2, y2, x3, y3;
 
-    p = path;
-    while (1) {
+    for (i=0; i < path->num_data; i += path->data[i].header.length) {
+	p = &path->data[i];
 	switch (p->header.type) {
 	case CAIRO_PATH_MOVE_TO:
 	    x1 = p[1].point.x; y1 = p[1].point.y;
@@ -77,10 +78,7 @@
 	case CAIRO_PATH_CLOSE_PATH:
 	    cairo_close_path (cr);
 	    break;
-	case CAIRO_PATH_END:
-	    return;
 	}
-	p += p->header.length;
     }
 }
 
@@ -95,42 +93,44 @@
 static cairo_test_status_t
 draw (cairo_t *cr, int width, int height)
 {
-    cairo_path_data_t *path;
+    cairo_path_t *path;
 
     /* copy path, munge, and fill */
     cairo_translate (cr, 5, 5);
     make_path (cr);
-    path = cairo_copy_path_data (cr);
+    path = cairo_copy_path (cr);
 
     cairo_new_path (cr);
     munge_and_set_path (cr, path, scale_by_two);
-    free (path);
+    cairo_path_destroy (path);
     cairo_fill (cr);
 
     /* copy flattened path, munge, and fill */
     cairo_translate (cr, 0, 15);
     make_path (cr);
-    path = cairo_copy_path_data_flat (cr);
+    path = cairo_copy_path_flat (cr);
 
     cairo_new_path (cr);
     munge_and_set_path (cr, path, scale_by_two);
-    free (path);
+    cairo_path_destroy (path);
     cairo_fill (cr);
 
     /* append two copies of path, and fill */
     cairo_translate (cr, 0, 15);
     cairo_scale (cr, 2.0, 2.0);
     make_path (cr);
-    path = cairo_copy_path_data (cr);
+    path = cairo_copy_path (cr);
 
     cairo_new_path (cr);
-    cairo_append_path_data (cr, path);
+    cairo_append_path (cr, path);
     cairo_translate (cr, 2.5, 2.5);
-    cairo_append_path_data (cr, path);
+    cairo_append_path (cr, path);
 
     cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
     cairo_fill (cr);
 
+    cairo_path_destroy (path);
+
     return CAIRO_TEST_SUCCESS;
 }
 
@@ -138,27 +138,39 @@
 main (void)
 {
     cairo_t *cr;
-    cairo_path_data_t bogus_path_data;
+    cairo_path_data_t data;
+    cairo_path_t path;
 
-    /* Test a couple error conditions for cairo_append_path_data */
+    /* Test a few error cases for cairo_append_path_data */
     cr = cairo_create ();
-    cairo_append_path_data (cr, NULL);
+    cairo_append_path (cr, NULL);
     if (cairo_status (cr) != CAIRO_STATUS_NULL_POINTER)
 	return 1;
     cairo_destroy (cr);
 
     cr = cairo_create ();
-    bogus_path_data.header.type = CAIRO_PATH_MOVE_TO;
-    bogus_path_data.header.length = 1;
-    cairo_append_path_data (cr, &bogus_path_data);
+    path.data = NULL;
+    path.num_data = 0;
+    cairo_append_path (cr, &path);
+    if (cairo_status (cr) != CAIRO_STATUS_NULL_POINTER)
+	return 1;
+    cairo_destroy (cr);
+
+    cr = cairo_create ();
+    /* Intentionally insert bogus header.length value (otherwise would be 2) */
+    data.header.type = CAIRO_PATH_MOVE_TO;
+    data.header.length = 1;
+    path.data = &data;
+    path.num_data = 1;
+    cairo_append_path (cr, &path);
     if (cairo_status (cr) != CAIRO_STATUS_INVALID_PATH_DATA)
 	return 1;
     cairo_destroy (cr);
 
     /* And test the degnerate case */
     cr = cairo_create ();
-    bogus_path_data.header.type = CAIRO_PATH_END;
-    cairo_append_path_data (cr, &bogus_path_data);
+    path.num_data = 0;
+    cairo_append_path (cr, &path);
     if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
 	return 1;
     cairo_destroy (cr);




More information about the cairo-commit mailing list