diff options
author | Kristian Høgsberg <krh@redhat.com> | 2005-01-26 13:41:55 +0000 |
---|---|---|
committer | Kristian Høgsberg <krh@redhat.com> | 2005-01-26 13:41:55 +0000 |
commit | d4fb5c92407f31291041f421360ea83a209ea2ad (patch) | |
tree | 4b5b83675f1b4c37f03600269535f554a685d12a | |
parent | 6dce601fd3cd7f6c8ebe72240e6be7c223ccbdcb (diff) |
New test case, covering various combinations of pattern types, drawing operations and clipping. Currently fails, for some combinations, coverage-ref.png is just a placeholder.
Added this PNG from cairo-snippets to use for pattern fills.
expose PNG loading to test cases.
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | test/Makefile.am | 7 | ||||
-rw-r--r-- | test/cairo-test.c | 23 | ||||
-rw-r--r-- | test/cairo-test.h | 4 | ||||
-rw-r--r-- | test/cairo_test.c | 23 | ||||
-rw-r--r-- | test/cairo_test.h | 4 | ||||
-rw-r--r-- | test/coverage-ref.png | bin | 0 -> 629 bytes | |||
-rw-r--r-- | test/coverage.c | 181 | ||||
-rw-r--r-- | test/romedalen.png | bin | 0 -> 80944 bytes |
9 files changed, 253 insertions, 2 deletions
@@ -1,3 +1,16 @@ +2005-01-26 Kristian Høgsberg <krh@redhat.com> + + * test/Makefile.am, test/coverage.c, test/coverage-ref.png: New + test case, covering various combinations of pattern types, drawing + operations and clipping. Currently fails, for some combinations, + coverage-ref.png is just a placeholder. + + * test/romedalen.png: Added this PNG from cairo-snippets to use + for pattern fills. + + * test/cairo_test.c, test/cairo_test.h: expose PNG loading to test + cases. + 2005-01-26 Alexander Larsson <alexl@redhat.com> * src/cairo_ft_font.c: (_ft_unscaled_font_set_scale): diff --git a/test/Makefile.am b/test/Makefile.am index 4b3bc165..5c66b0a2 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -5,7 +5,8 @@ leaky_polygon \ line_width \ move_to_show_surface \ text_cache_crash \ -text_rotate +text_rotate \ +coverage # And all new test go here too. I really don't like having to repeat # this list. Anyone know a good way to avoid it? Can I use a wildcard @@ -29,7 +30,8 @@ move_to_show_surface-ref.png # be fixed before the code is committed. XFAIL_TESTS = \ move_to_show_surface \ -text_rotate +text_rotate \ +coverage check_PROGRAMS = $(TESTS) @@ -62,6 +64,7 @@ line_width_SOURCES = line_width.c $(cairo_test_lib) move_to_show_surface_SOURCES = move_to_show_surface.c $(cairo_test_lib) text_cache_crash_SOURCES = text_cache_crash.c $(cairo_test_lib) text_rotate_SOURCES = text_rotate.c $(cairo_test_lib) +coverage_SOURCES = coverage.c $(cairo_test_lib) noinst_PROGRAMS = imagediff imagediff_SOURCES = imagediff.c $(cairo_test_lib) diff --git a/test/cairo-test.c b/test/cairo-test.c index 605cfe53..978404d1 100644 --- a/test/cairo-test.c +++ b/test/cairo-test.c @@ -166,3 +166,26 @@ BAIL: return ret; } + +cairo_pattern_t * +cairo_test_create_png_pattern (cairo_t *cr, const char *filename) +{ + cairo_surface_t *image; + cairo_pattern_t *pattern; + unsigned char *buffer; + int w, h, stride; + read_png_status_t status; + + status = read_png_argb32 (filename, &buffer, &w,&h, &stride); + if (status != READ_PNG_SUCCESS) + return NULL; + + image = cairo_surface_create_for_image (buffer, CAIRO_FORMAT_ARGB32, + w, h, stride); + + cairo_surface_set_repeat (image, 1); + + pattern = cairo_pattern_create_for_surface (image); + + return pattern; +} diff --git a/test/cairo-test.h b/test/cairo-test.h index 58936d56..912ce891 100644 --- a/test/cairo-test.h +++ b/test/cairo-test.h @@ -47,5 +47,9 @@ typedef void (*cairo_test_draw_function_t) (cairo_t *cr, int width, int height) cairo_test_status_t cairo_test (cairo_test_t *test, cairo_test_draw_function_t draw); +cairo_pattern_t * +cairo_test_create_png_pattern (cairo_t *cr, const char *filename); + + #endif diff --git a/test/cairo_test.c b/test/cairo_test.c index 605cfe53..978404d1 100644 --- a/test/cairo_test.c +++ b/test/cairo_test.c @@ -166,3 +166,26 @@ BAIL: return ret; } + +cairo_pattern_t * +cairo_test_create_png_pattern (cairo_t *cr, const char *filename) +{ + cairo_surface_t *image; + cairo_pattern_t *pattern; + unsigned char *buffer; + int w, h, stride; + read_png_status_t status; + + status = read_png_argb32 (filename, &buffer, &w,&h, &stride); + if (status != READ_PNG_SUCCESS) + return NULL; + + image = cairo_surface_create_for_image (buffer, CAIRO_FORMAT_ARGB32, + w, h, stride); + + cairo_surface_set_repeat (image, 1); + + pattern = cairo_pattern_create_for_surface (image); + + return pattern; +} diff --git a/test/cairo_test.h b/test/cairo_test.h index 58936d56..912ce891 100644 --- a/test/cairo_test.h +++ b/test/cairo_test.h @@ -47,5 +47,9 @@ typedef void (*cairo_test_draw_function_t) (cairo_t *cr, int width, int height) cairo_test_status_t cairo_test (cairo_test_t *test, cairo_test_draw_function_t draw); +cairo_pattern_t * +cairo_test_create_png_pattern (cairo_t *cr, const char *filename); + + #endif diff --git a/test/coverage-ref.png b/test/coverage-ref.png Binary files differnew file mode 100644 index 00000000..74c13890 --- /dev/null +++ b/test/coverage-ref.png diff --git a/test/coverage.c b/test/coverage.c new file mode 100644 index 00000000..554b5eda --- /dev/null +++ b/test/coverage.c @@ -0,0 +1,181 @@ +/* + * 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: Kristian Høgsberg <krh@redhat.com> + */ + +#include <math.h> +#include "cairo_test.h" + +#define WIDTH 64 +#define HEIGHT 64 +#define PAD 10 + +/* XXX The test image uses Bitstream Vera Sans as the font - how do we + * ensure that it's available? Can we ship it with this test? */ + +const char fontname[] = "Bitstream Vera Sans"; +const int fontsize = 40; +const char png_filename[] = "romedalen.png"; + +static void +set_solid_pattern (cairo_t *cr, int x, int y) +{ + cairo_set_rgb_color (cr, 0, 0, 0.6); + cairo_set_alpha (cr, 1.0); +} + +static void +set_translucent_pattern (cairo_t *cr, int x, int y) +{ + cairo_set_rgb_color (cr, 0, 0, 0.6); + cairo_set_alpha (cr, 0.5); +} + +static void +set_gradient_pattern (cairo_t *cr, int x, int y) +{ + cairo_pattern_t *pattern; + + pattern = + cairo_pattern_create_linear (x, y, x + WIDTH, y + HEIGHT); + cairo_pattern_add_color_stop (pattern, 0, 1, 1, 1, 1); + cairo_pattern_add_color_stop (pattern, 1, 0, 0, 0.4, 1); + cairo_set_pattern (cr, pattern); + cairo_set_alpha (cr, 1); +} + +static void +set_image_pattern (cairo_t *cr, int x, int y) +{ + cairo_pattern_t *pattern; + + pattern = cairo_test_create_png_pattern (cr, png_filename); + cairo_set_pattern (cr, pattern); + cairo_set_alpha (cr, 1); +} + +static void +set_translucent_image_pattern (cairo_t *cr, int x, int y) +{ + cairo_pattern_t *pattern; + + pattern = cairo_test_create_png_pattern (cr, png_filename); + cairo_set_pattern (cr, pattern); + cairo_set_alpha (cr, 0.5); +} + +static void +draw_text (cairo_t *cr, int x, int y) +{ + cairo_rel_move_to (cr, 0, fontsize); + cairo_show_text (cr, "Aa"); +} + +static void +draw_polygon (cairo_t *cr, int x, int y) +{ + cairo_new_path (cr); + cairo_move_to (cr, x, y); + cairo_line_to (cr, x, y + HEIGHT); + cairo_line_to (cr, x + WIDTH / 2, y + 3 * HEIGHT / 4); + cairo_line_to (cr, x + WIDTH, y + HEIGHT); + cairo_line_to (cr, x + WIDTH, y); + cairo_line_to (cr, x + WIDTH / 2, y + HEIGHT / 4); + cairo_close_path (cr); + cairo_fill (cr); +} + +static void (*pattern_funcs[])(cairo_t *cr, int x, int y) = { + set_solid_pattern, + set_translucent_pattern, + set_gradient_pattern, + set_image_pattern, + set_translucent_image_pattern +}; + +static void (*draw_funcs[])(cairo_t *cr, int x, int y) = { + draw_text, + draw_polygon, +}; + +#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) +#define IMAGE_WIDTH (ARRAY_SIZE (pattern_funcs) * (WIDTH + PAD) + PAD) +#define IMAGE_HEIGHT (ARRAY_SIZE (draw_funcs) * (HEIGHT + PAD) * 2 + PAD) + +static cairo_test_t test = { + "coverage", + "Various coverage test of cairo", + IMAGE_WIDTH, IMAGE_HEIGHT +}; + + +static void +draw (cairo_t *cr, int width, int height) +{ + /* TODO: pattern fill, gradient fill, clipping, gradient clipping, + path+solid alpha mask clipping */ + + int i, j, x, y; + + cairo_select_font (cr, fontname, + CAIRO_FONT_SLANT_NORMAL, + CAIRO_FONT_WEIGHT_BOLD); + cairo_scale_font (cr, fontsize); + + for (j = 0; j < ARRAY_SIZE (draw_funcs); j++) { + for (i = 0; i < ARRAY_SIZE (pattern_funcs); i++) { + x = i * (WIDTH + PAD) + PAD; + y = j * (HEIGHT + PAD) + PAD; + cairo_move_to (cr, x, y); + pattern_funcs[i] (cr, x, y); + draw_funcs[j] (cr, x, y); + } + } + + for (j = 0; j < ARRAY_SIZE (draw_funcs); j++) { + for (i = 0; i < ARRAY_SIZE (pattern_funcs); i++) { + x = i * (WIDTH + PAD) + PAD; + y = (ARRAY_SIZE (draw_funcs) + j) * (HEIGHT + PAD) + PAD; + + cairo_save (cr); + + cairo_new_path (cr); + cairo_arc (cr, x + WIDTH / 2, y + HEIGHT / 2, + WIDTH / 3, 0, 2 * M_PI); + cairo_clip (cr); + + cairo_move_to (cr, x, y); + pattern_funcs[i] (cr, x, y); + draw_funcs[j] (cr, x, y); + + cairo_restore (cr); + + } + } +} + +int +main (void) +{ + return cairo_test (&test, draw); +} diff --git a/test/romedalen.png b/test/romedalen.png Binary files differnew file mode 100644 index 00000000..0c41eb0c --- /dev/null +++ b/test/romedalen.png |