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: Carl D. Worth <cworth@cworth.org>
26 #include "cairo-test.h"
32 #if CAIRO_HAS_PS_SURFACE
36 #if CAIRO_HAS_PDF_SURFACE
37 #include <cairo-pdf.h>
40 /* The PostScript and PDF backends are now integrated into the main
41 * test suite, so we are getting good verification of most things
44 * One thing that isn't supported there yet is multi-page output. So,
45 * for now we have this one-off test. There's no automatic
46 * verififcation here yet, but you can manually view the output to
47 * make sure it looks happy.
50 #define WIDTH_IN_INCHES 3
51 #define HEIGHT_IN_INCHES 3
52 #define WIDTH_IN_POINTS (WIDTH_IN_INCHES * 72.0)
53 #define HEIGHT_IN_POINTS (HEIGHT_IN_INCHES * 72.0)
54 #define BASENAME "multi-page.out"
57 draw_smiley (cairo_t *cr, double width, double height, double smile_ratio)
59 #define STROKE_WIDTH .04
62 double theta = M_PI / 4 * smile_ratio;
63 double dx = sqrt (0.005) * cos (theta);
64 double dy = sqrt (0.005) * sin (theta);
73 cairo_translate (cr, (width - size) / 2.0, (height - size) / 2.0);
74 cairo_scale (cr, size, size);
77 cairo_arc (cr, 0.5, 0.5, 0.5 - STROKE_WIDTH, 0, 2 * M_PI);
78 cairo_set_source_rgb (cr, 1, 1, 0);
79 cairo_fill_preserve (cr);
81 cairo_set_source_rgb (cr, 0, 0, 0);
84 cairo_set_line_width (cr, STROKE_WIDTH / 2.0);
88 cairo_set_line_width (cr, STROKE_WIDTH);
89 cairo_arc (cr, 0.3, 0.4, STROKE_WIDTH, 0, 2 * M_PI);
91 cairo_arc (cr, 0.7, 0.4, STROKE_WIDTH, 0, 2 * M_PI);
96 0.35 - dx, 0.75 - dy);
100 0.65 + dx, 0.75 - dy);
107 draw_some_pages (cairo_surface_t *surface)
112 cr = cairo_create (surface);
115 for (i=0; i < NUM_FRAMES; i++) {
116 draw_smiley (cr, WIDTH_IN_POINTS, HEIGHT_IN_POINTS,
117 (double) i / (NUM_FRAMES - 1));
119 /* Duplicate the last frame onto another page. (This is just a
120 * way to sneak cairo_copy_page into the test).
122 if (i == (NUM_FRAMES - 1))
123 cairo_copy_page (cr);
125 cairo_show_page (cr);
131 static cairo_test_status_t
132 preamble (cairo_test_context_t *ctx)
134 cairo_surface_t *surface;
135 cairo_status_t status;
137 cairo_test_status_t result = CAIRO_TEST_UNTESTED;
138 const char *path = cairo_test_mkdir (CAIRO_TEST_OUTPUT_DIR) ? CAIRO_TEST_OUTPUT_DIR : ".";
140 #if CAIRO_HAS_PS_SURFACE
141 if (cairo_test_is_target_enabled (ctx, "ps2") ||
142 cairo_test_is_target_enabled (ctx, "ps3"))
144 if (result == CAIRO_TEST_UNTESTED)
145 result = CAIRO_TEST_SUCCESS;
147 xasprintf (&filename, "%s/%s", path, BASENAME ".ps");
148 surface = cairo_ps_surface_create (filename,
149 WIDTH_IN_POINTS, HEIGHT_IN_POINTS);
150 status = cairo_surface_status (surface);
152 cairo_test_log (ctx, "Failed to create ps surface for file %s: %s\n",
153 filename, cairo_status_to_string (status));
154 result = CAIRO_TEST_FAILURE;
157 draw_some_pages (surface);
159 cairo_surface_destroy (surface);
161 printf ("multi-page: Please check %s to ensure it looks happy.\n", filename);
166 #if CAIRO_HAS_PDF_SURFACE
167 if (cairo_test_is_target_enabled (ctx, "pdf")) {
168 if (result == CAIRO_TEST_UNTESTED)
169 result = CAIRO_TEST_SUCCESS;
171 xasprintf (&filename, "%s/%s", path, BASENAME ".pdf");
172 surface = cairo_pdf_surface_create (filename,
173 WIDTH_IN_POINTS, HEIGHT_IN_POINTS);
174 status = cairo_surface_status (surface);
176 cairo_test_log (ctx, "Failed to create pdf surface for file %s: %s\n",
177 filename, cairo_status_to_string (status));
178 result = CAIRO_TEST_FAILURE;
181 draw_some_pages (surface);
183 cairo_surface_destroy (surface);
185 printf ("multi-page: Please check %s to ensure it looks happy.\n", filename);
193 CAIRO_TEST (multi_page,
194 "Check the paginated surfaces handle multiple pages.",
195 "paginated", /* keywords */
196 "target=vector", /* requirements */