[test] Add test case for a leaky dashed rectangle.
[cairo/haiku.git] / test / ps-features.c
blob597b73cf1989332f59dc54bf9c28cd640ff63f82
1 /*
2 * Copyright © 2006 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 <stdio.h>
27 #include <cairo.h>
28 #include <cairo-ps.h>
30 #include "cairo-test.h"
32 /* This test exists to test the various features of cairo-ps.h.
34 * Currently, this test exercises the following function calls:
36 * cairo_ps_surface_set_size
37 * cairo_ps_surface_dsc_comment
38 * cairo_ps_surface_dsc_begin_setup
39 * cairo_ps_surface_dsc_begin_page_setup
42 #define INCHES_TO_POINTS(in) ((in) * 72.0)
43 #define MM_TO_POINTS(mm) ((mm) / 25.4 * 72.0)
44 #define TEXT_SIZE 12
46 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
48 struct {
49 const char *page_size;
50 const char *page_size_alias;
51 const char *orientation;
52 double width_in_points;
53 double height_in_points;
54 } pages[] = {
55 {"na_letter_8.5x11in", "letter", "portrait",
56 INCHES_TO_POINTS(8.5), INCHES_TO_POINTS(11)},
57 {"na_letter_8.5x11in", "letter", "landscape",
58 INCHES_TO_POINTS(11), INCHES_TO_POINTS(8.5)},
59 {"iso_a4_210x297mm", "a4", "portrait",
60 MM_TO_POINTS(210), MM_TO_POINTS(297)},
61 {"iso_a4_210x297mm", "a4", "landscape",
62 MM_TO_POINTS(297), MM_TO_POINTS(210)},
63 {"iso_a5_148x210mm", "a5", "portrait",
64 MM_TO_POINTS(148), MM_TO_POINTS(210)},
65 {"iso_a5_148x210mm", "a5", "landscape",
66 MM_TO_POINTS(210), MM_TO_POINTS(148)},
67 {"iso_a6_105x148mm", "a6", "portrait",
68 MM_TO_POINTS(105), MM_TO_POINTS(148)},
69 {"iso_a6_105x148mm", "a6", "landscape",
70 MM_TO_POINTS(148), MM_TO_POINTS(105)},
71 {"iso_a7_74x105mm", "a7", "portrait",
72 MM_TO_POINTS(74), MM_TO_POINTS(105)},
73 {"iso_a7_74x105mm", "a7", "landscape",
74 MM_TO_POINTS(105), MM_TO_POINTS(74)},
75 {"iso_a8_52x74mm", "a8", "portrait",
76 MM_TO_POINTS(52), MM_TO_POINTS(74)},
77 {"iso_a8_52x74mm", "a8", "landscape",
78 MM_TO_POINTS(74), MM_TO_POINTS(52)},
79 {"iso_a9_37x52mm", "a9", "portrait",
80 MM_TO_POINTS(37), MM_TO_POINTS(52)},
81 {"iso_a9_37x52mm", "a9", "landscape",
82 MM_TO_POINTS(52), MM_TO_POINTS(37)},
83 {"iso_a10_26x37mm", "a10", "portrait",
84 MM_TO_POINTS(26), MM_TO_POINTS(37)},
85 {"iso_a10_26x37mm", "a10", "landscape",
86 MM_TO_POINTS(37), MM_TO_POINTS(26)}
89 int
90 main (void)
92 cairo_surface_t *surface;
93 cairo_t *cr;
94 cairo_status_t status;
95 const char *filename;
96 size_t i;
97 char dsc[255];
99 cairo_test_init ("ps-features");
101 filename = "ps-features.ps";
103 /* We demonstrate that the initial size doesn't matter (we're
104 * passing 0,0), if we use cairo_ps_surface_set_size on the first
105 * page. */
106 surface = cairo_ps_surface_create (filename, 0, 0);
108 cairo_ps_surface_dsc_comment (surface, "%%Title: ps-features");
109 cairo_ps_surface_dsc_comment (surface, "%%Copyright: Copyright (C) 2006 Red Hat, Inc.");
111 cairo_ps_surface_dsc_begin_setup (surface);
112 cairo_ps_surface_dsc_comment (surface, "%%IncludeFeature: *PageSize letter");
113 cairo_ps_surface_dsc_comment (surface, "%%IncludeFeature: *MediaColor White");
115 cr = cairo_create (surface);
117 cairo_select_font_face (cr, "Bitstream Vera Sans",
118 CAIRO_FONT_SLANT_NORMAL,
119 CAIRO_FONT_WEIGHT_NORMAL);
120 cairo_set_font_size (cr, TEXT_SIZE);
122 for (i=0; i < ARRAY_SIZE(pages); i++) {
123 cairo_ps_surface_set_size (surface,
124 pages[i].width_in_points,
125 pages[i].height_in_points);
126 cairo_ps_surface_dsc_begin_page_setup (surface);
127 snprintf (dsc, 255, "%%IncludeFeature: *PageSize %s", pages[i].page_size_alias);
128 cairo_ps_surface_dsc_comment (surface, dsc);
129 if (i % 2) {
130 snprintf (dsc, 255, "%%IncludeFeature: *MediaType Glossy");
131 cairo_ps_surface_dsc_comment (surface, dsc);
134 cairo_move_to (cr, TEXT_SIZE, TEXT_SIZE);
135 cairo_show_text (cr, pages[i].page_size);
136 cairo_show_text (cr, " - ");
137 cairo_show_text (cr, pages[i].orientation);
138 cairo_show_page (cr);
141 status = cairo_status (cr);
143 cairo_destroy (cr);
144 cairo_surface_destroy (surface);
146 if (status) {
147 cairo_test_log ("Failed to create ps surface for file %s: %s\n",
148 filename, cairo_status_to_string (status));
149 return CAIRO_TEST_FAILURE;
152 printf ("ps-features: Please check %s to ensure it looks/prints correctly.\n", filename);
154 cairo_test_fini ();
156 return CAIRO_TEST_SUCCESS;