2 * Copyright © 2005 Red Hat, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Red Hat, Inc. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior
11 * permission. Red Hat, Inc. makes no representations about the
12 * suitability of this software for any purpose. It is provided "as
13 * is" without express or implied warranty.
15 * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
18 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
21 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Author: Kristian Høgsberg <krh@redhat.com>
28 #include <cairo-svg.h>
29 #include "cairo-test.h"
31 /* Test SVG clipping */
33 #define WIDTH_IN_POINTS 600
34 #define HEIGHT_IN_POINTS 600
37 test_clip (cairo_t *cr, double width, double height)
41 /* Basic test; set a square clip and draw a circle to be clipped
44 cairo_rectangle (cr, 100, 100, 400, 400);
46 cairo_arc (cr, 300, 300, 210, 0, 2 * M_PI);
47 cairo_set_source_rgb (cr, 1, 0, 0);
50 /* Add a plus shaped clip path to the square clip and draw a big
51 * green square to test the new clip path. */
55 cairo_rectangle (cr, 250, 100, 100, 400);
56 cairo_rectangle (cr, 100, 250, 400, 100);
59 cairo_rectangle (cr, 0, 0, 600, 600);
60 cairo_set_source_rgb (cr, 0, 1, 0);
65 /* Set a bezier shape in addition to the rectangle clip set before
66 * the cairo_save() to verify that we successfully removed the
67 * plus shaped clip path and can set a new clip.*/
69 cairo_move_to (cr, 600, 0);
70 cairo_curve_to (cr, 300, 600, 0, 300, 600, 0);
73 cairo_rectangle (cr, 0, 0, 600, 600);
74 cairo_set_source_rgb (cr, 0, 0, 1);
77 /* Create a new context for this surface to test overlapped
78 * drawing from two contexts */
79 cr2 = cairo_create (cairo_get_group_target (cr));
81 /* Using the new context, draw a black vertical line, which should
82 * appear unclipped on top of everything drawn so far. */
83 cairo_move_to (cr2, 110, 0);
84 cairo_line_to (cr2, 110, 600);
87 /* Using the first context, draw another black vertical line.
88 * This line should be clipped agaist the bezier clipping path set
90 cairo_set_source_rgb (cr, 0, 0, 0);
91 cairo_move_to (cr, 400, 0);
92 cairo_line_to (cr, 400, 600);
97 /* Test reset clip. Draw a transparent black circle over
98 * everything. Specifically, make sure the circle extends outside
99 * the square clip set at the top of this function. */
100 cairo_reset_clip (cr);
101 cairo_arc (cr, 300, 300, 220, 0, 2 * M_PI);
102 cairo_set_source_rgba (cr, 0, 0, 0, 0.2);
106 static cairo_test_status_t
107 preamble (cairo_test_context_t *ctx)
110 const char *filename = "svg-clip.out.svg";
111 cairo_surface_t *surface;
113 if (! cairo_test_is_target_enabled (ctx, "svg11") &&
114 ! cairo_test_is_target_enabled (ctx, "svg12"))
116 return CAIRO_TEST_UNTESTED;
119 surface = cairo_svg_surface_create (filename,
120 WIDTH_IN_POINTS, HEIGHT_IN_POINTS);
121 if (cairo_surface_status (surface)) {
123 "Failed to create svg surface for file %s: %s\n",
124 filename, cairo_status_to_string (cairo_surface_status (surface)));
125 return CAIRO_TEST_FAILURE;
128 cr = cairo_create (surface);
130 test_clip (cr, WIDTH_IN_POINTS, HEIGHT_IN_POINTS);
131 cairo_show_page (cr);
134 cairo_surface_destroy (surface);
136 printf ("svg-clip: Please check %s to make sure it looks happy.\n",
138 return CAIRO_TEST_SUCCESS;
141 CAIRO_TEST (svg_clip,
143 "svg, clip", /* keywords */
144 NULL, /* requirements */