2005-03-11 14:29:15 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2005 Red Hat, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software
|
|
|
|
|
* and its documentation for any purpose is hereby granted without
|
|
|
|
|
* fee, provided that the above copyright notice appear in all copies
|
|
|
|
|
* and that both that copyright notice and this permission notice
|
|
|
|
|
* appear in supporting documentation, and that the name of
|
|
|
|
|
* Red Hat, Inc. not be used in advertising or publicity pertaining to
|
|
|
|
|
* distribution of the software without specific, written prior
|
|
|
|
|
* permission. Red Hat, Inc. makes no representations about the
|
|
|
|
|
* suitability of this software for any purpose. It is provided "as
|
|
|
|
|
* is" without express or implied warranty.
|
|
|
|
|
*
|
|
|
|
|
* RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
|
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
|
* FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
|
|
|
|
|
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
|
|
|
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
|
|
|
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
|
|
|
|
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*
|
|
|
|
|
* Author: Carl D. Worth <cworth@cworth.org>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2005-03-29 00:02:19 +00:00
|
|
|
#include "cairo-test.h"
|
2005-03-11 14:29:15 +00:00
|
|
|
|
|
|
|
|
cairo_test_t test = {
|
2005-03-29 00:02:19 +00:00
|
|
|
"path-data",
|
2005-03-11 14:29:15 +00:00
|
|
|
"Tests calls to path_data functions: cairo_copy_path_data, cairo_copy_path_data_flat, and cairo_append_path_data",
|
|
|
|
|
45, 53
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
scale_by_two (double *x, double *y)
|
|
|
|
|
{
|
|
|
|
|
*x = *x * 2.0;
|
|
|
|
|
*y = *y * 2.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef void (*munge_func_t) (double *x, double *y);
|
|
|
|
|
|
|
|
|
|
static void
|
2005-03-18 14:28:53 +00:00
|
|
|
munge_and_set_path (cairo_t *cr,
|
|
|
|
|
cairo_path_t *path,
|
|
|
|
|
munge_func_t munge)
|
2005-03-11 14:29:15 +00:00
|
|
|
{
|
2005-03-18 14:28:53 +00:00
|
|
|
int i;
|
2005-03-11 14:29:15 +00:00
|
|
|
cairo_path_data_t *p;
|
|
|
|
|
double x1, y1, x2, y2, x3, y3;
|
|
|
|
|
|
2005-03-18 14:28:53 +00:00
|
|
|
for (i=0; i < path->num_data; i += path->data[i].header.length) {
|
|
|
|
|
p = &path->data[i];
|
2005-03-11 14:29:15 +00:00
|
|
|
switch (p->header.type) {
|
|
|
|
|
case CAIRO_PATH_MOVE_TO:
|
|
|
|
|
x1 = p[1].point.x; y1 = p[1].point.y;
|
|
|
|
|
(munge) (&x1, &y1);
|
|
|
|
|
cairo_move_to (cr, x1, y1);
|
|
|
|
|
break;
|
|
|
|
|
case CAIRO_PATH_LINE_TO:
|
|
|
|
|
x1 = p[1].point.x; y1 = p[1].point.y;
|
|
|
|
|
(munge) (&x1, &y1);
|
|
|
|
|
cairo_line_to (cr, x1, y1);
|
|
|
|
|
break;
|
|
|
|
|
case CAIRO_PATH_CURVE_TO:
|
|
|
|
|
x1 = p[1].point.x; y1 = p[1].point.y;
|
|
|
|
|
x2 = p[2].point.x; y2 = p[2].point.y;
|
|
|
|
|
x3 = p[3].point.x; y3 = p[3].point.y;
|
|
|
|
|
(munge) (&x1, &y1);
|
|
|
|
|
(munge) (&x2, &y2);
|
|
|
|
|
(munge) (&x3, &y3);
|
|
|
|
|
cairo_curve_to (cr,
|
|
|
|
|
x1, y1,
|
|
|
|
|
x2, y2,
|
|
|
|
|
x3, y3);
|
|
|
|
|
break;
|
|
|
|
|
case CAIRO_PATH_CLOSE_PATH:
|
|
|
|
|
cairo_close_path (cr);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
make_path (cairo_t *cr)
|
|
|
|
|
{
|
|
|
|
|
cairo_rectangle (cr, 0, 0, 5, 5);
|
|
|
|
|
cairo_move_to (cr, 15, 2.5);
|
|
|
|
|
cairo_arc (cr, 12.5, 2.5, 2.5, 0, 2 * M_PI);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_test_status_t
|
|
|
|
|
draw (cairo_t *cr, int width, int height)
|
|
|
|
|
{
|
2005-03-18 14:28:53 +00:00
|
|
|
cairo_path_t *path;
|
2005-03-11 14:29:15 +00:00
|
|
|
|
|
|
|
|
/* copy path, munge, and fill */
|
|
|
|
|
cairo_translate (cr, 5, 5);
|
|
|
|
|
make_path (cr);
|
2005-03-18 14:28:53 +00:00
|
|
|
path = cairo_copy_path (cr);
|
2005-03-11 14:29:15 +00:00
|
|
|
|
|
|
|
|
cairo_new_path (cr);
|
|
|
|
|
munge_and_set_path (cr, path, scale_by_two);
|
2005-03-18 14:28:53 +00:00
|
|
|
cairo_path_destroy (path);
|
2005-03-11 14:29:15 +00:00
|
|
|
cairo_fill (cr);
|
|
|
|
|
|
|
|
|
|
/* copy flattened path, munge, and fill */
|
|
|
|
|
cairo_translate (cr, 0, 15);
|
|
|
|
|
make_path (cr);
|
2005-03-18 14:28:53 +00:00
|
|
|
path = cairo_copy_path_flat (cr);
|
2005-03-11 14:29:15 +00:00
|
|
|
|
|
|
|
|
cairo_new_path (cr);
|
|
|
|
|
munge_and_set_path (cr, path, scale_by_two);
|
2005-03-18 14:28:53 +00:00
|
|
|
cairo_path_destroy (path);
|
2005-03-11 14:29:15 +00:00
|
|
|
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);
|
2005-03-18 14:28:53 +00:00
|
|
|
path = cairo_copy_path (cr);
|
2005-03-11 14:29:15 +00:00
|
|
|
|
|
|
|
|
cairo_new_path (cr);
|
2005-03-18 14:28:53 +00:00
|
|
|
cairo_append_path (cr, path);
|
2005-03-11 14:29:15 +00:00
|
|
|
cairo_translate (cr, 2.5, 2.5);
|
2005-03-18 14:28:53 +00:00
|
|
|
cairo_append_path (cr, path);
|
2005-03-11 14:29:15 +00:00
|
|
|
|
|
|
|
|
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
|
|
|
|
|
cairo_fill (cr);
|
|
|
|
|
|
2005-03-18 14:28:53 +00:00
|
|
|
cairo_path_destroy (path);
|
|
|
|
|
|
2005-03-11 14:29:15 +00:00
|
|
|
return CAIRO_TEST_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main (void)
|
|
|
|
|
{
|
|
|
|
|
cairo_t *cr;
|
2005-03-18 14:28:53 +00:00
|
|
|
cairo_path_data_t data;
|
|
|
|
|
cairo_path_t path;
|
2005-05-06 13:23:41 +00:00
|
|
|
cairo_surface_t *surface;
|
|
|
|
|
|
|
|
|
|
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
|
2005-03-18 14:28:53 +00:00
|
|
|
|
|
|
|
|
/* Test a few error cases for cairo_append_path_data */
|
2005-05-06 13:23:41 +00:00
|
|
|
cr = cairo_create (surface);
|
2005-03-18 14:28:53 +00:00
|
|
|
cairo_append_path (cr, NULL);
|
|
|
|
|
if (cairo_status (cr) != CAIRO_STATUS_NULL_POINTER)
|
|
|
|
|
return 1;
|
|
|
|
|
cairo_destroy (cr);
|
2005-03-11 14:29:15 +00:00
|
|
|
|
2005-07-06 14:52:01 +00:00
|
|
|
cr = cairo_create (surface);
|
|
|
|
|
path.status = -1;
|
|
|
|
|
cairo_append_path (cr, &path);
|
|
|
|
|
if (cairo_status (cr) != CAIRO_STATUS_INVALID_STATUS)
|
|
|
|
|
return 1;
|
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
|
|
|
|
|
cr = cairo_create (surface);
|
|
|
|
|
path.status = CAIRO_STATUS_NO_MEMORY;
|
|
|
|
|
cairo_append_path (cr, &path);
|
|
|
|
|
if (cairo_status (cr) != CAIRO_STATUS_NO_MEMORY)
|
|
|
|
|
return 1;
|
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
|
2005-05-06 13:23:41 +00:00
|
|
|
cr = cairo_create (surface);
|
2005-03-18 14:28:53 +00:00
|
|
|
path.data = NULL;
|
|
|
|
|
path.num_data = 0;
|
2005-07-06 14:52:01 +00:00
|
|
|
path.status = CAIRO_STATUS_SUCCESS;
|
2005-03-18 14:28:53 +00:00
|
|
|
cairo_append_path (cr, &path);
|
2005-03-11 14:29:15 +00:00
|
|
|
if (cairo_status (cr) != CAIRO_STATUS_NULL_POINTER)
|
|
|
|
|
return 1;
|
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
|
2005-05-06 13:23:41 +00:00
|
|
|
cr = cairo_create (surface);
|
2005-03-18 14:28:53 +00:00
|
|
|
/* 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);
|
2005-03-11 14:29:15 +00:00
|
|
|
if (cairo_status (cr) != CAIRO_STATUS_INVALID_PATH_DATA)
|
|
|
|
|
return 1;
|
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
|
|
|
|
|
/* And test the degnerate case */
|
2005-05-06 13:23:41 +00:00
|
|
|
cr = cairo_create (surface);
|
2005-03-18 14:28:53 +00:00
|
|
|
path.num_data = 0;
|
|
|
|
|
cairo_append_path (cr, &path);
|
2005-03-11 14:29:15 +00:00
|
|
|
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
|
|
|
|
|
return 1;
|
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
|
2005-05-06 13:23:41 +00:00
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
|
|
2005-03-11 14:29:15 +00:00
|
|
|
return cairo_test (&test, draw);
|
|
|
|
|
}
|