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>
30 #if CAIRO_HAS_PS_SURFACE
34 #if CAIRO_HAS_PDF_SURFACE
35 #include <cairo-pdf.h>
38 #include "cairo-test.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)
56 draw_smiley (cairo_t
*cr
, double width
, double height
, double smile_ratio
)
58 #define STROKE_WIDTH .04
61 double theta
= M_PI
/ 4 * smile_ratio
;
62 double dx
= sqrt (0.005) * cos (theta
);
63 double dy
= sqrt (0.005) * sin (theta
);
72 cairo_translate (cr
, (width
- size
) / 2.0, (height
- size
) / 2.0);
73 cairo_scale (cr
, size
, size
);
76 cairo_arc (cr
, 0.5, 0.5, 0.5 - STROKE_WIDTH
, 0, 2 * M_PI
);
77 cairo_set_source_rgb (cr
, 1, 1, 0);
78 cairo_fill_preserve (cr
);
80 cairo_set_source_rgb (cr
, 0, 0, 0);
83 cairo_set_line_width (cr
, STROKE_WIDTH
/ 2.0);
87 cairo_set_line_width (cr
, STROKE_WIDTH
);
88 cairo_arc (cr
, 0.3, 0.4, STROKE_WIDTH
, 0, 2 * M_PI
);
90 cairo_arc (cr
, 0.7, 0.4, STROKE_WIDTH
, 0, 2 * M_PI
);
95 0.35 - dx
, 0.75 - dy
);
99 0.65 + dx
, 0.75 - dy
);
106 draw_some_pages (cairo_surface_t
*surface
)
111 cr
= cairo_create (surface
);
114 for (i
=0; i
< NUM_FRAMES
; i
++) {
115 draw_smiley (cr
, WIDTH_IN_POINTS
, HEIGHT_IN_POINTS
,
116 (double) i
/ (NUM_FRAMES
- 1));
118 /* Duplicate the last frame onto another page. (This is just a
119 * way to sneak cairo_copy_page into the test).
121 if (i
== (NUM_FRAMES
- 1))
122 cairo_copy_page (cr
);
124 cairo_show_page (cr
);
130 static cairo_test_status_t
131 preamble (cairo_test_context_t
*ctx
)
133 cairo_surface_t
*surface
;
134 cairo_status_t status
;
135 const char *filename
;
136 cairo_test_status_t result
= CAIRO_TEST_UNTESTED
;
138 #if CAIRO_HAS_PS_SURFACE
139 if (cairo_test_is_target_enabled (ctx
, "ps2") ||
140 cairo_test_is_target_enabled (ctx
, "ps3"))
142 if (result
== CAIRO_TEST_UNTESTED
)
143 result
= CAIRO_TEST_SUCCESS
;
145 filename
= "multi-page.out.ps";
146 surface
= cairo_ps_surface_create (filename
,
147 WIDTH_IN_POINTS
, HEIGHT_IN_POINTS
);
148 status
= cairo_surface_status (surface
);
150 cairo_test_log (ctx
, "Failed to create ps surface for file %s: %s\n",
151 filename
, cairo_status_to_string (status
));
152 result
= CAIRO_TEST_FAILURE
;
155 draw_some_pages (surface
);
157 cairo_surface_destroy (surface
);
159 printf ("multi-page: Please check %s to ensure it looks happy.\n", filename
);
163 #if CAIRO_HAS_PDF_SURFACE
164 if (cairo_test_is_target_enabled (ctx
, "pdf")) {
165 if (result
== CAIRO_TEST_UNTESTED
)
166 result
= CAIRO_TEST_SUCCESS
;
168 filename
= "multi-page.out.pdf";
169 surface
= cairo_pdf_surface_create (filename
,
170 WIDTH_IN_POINTS
, HEIGHT_IN_POINTS
);
171 status
= cairo_surface_status (surface
);
173 cairo_test_log (ctx
, "Failed to create pdf surface for file %s: %s\n",
174 filename
, cairo_status_to_string (status
));
175 result
= CAIRO_TEST_FAILURE
;
178 draw_some_pages (surface
);
180 cairo_surface_destroy (surface
);
182 printf ("multi-page: Please check %s to ensure it looks happy.\n", filename
);
189 CAIRO_TEST (multi_page
,
190 "Check the paginated surfaces handle multiple pages.",
191 "paginated", /* keywords */
192 "target=vector", /* requirements */