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>
28 #include <cairo-pdf.h>
30 #include "cairo-test.h"
32 /* This test exists to test the various features of cairo-pdf.h.
34 * Currently, this test exercises the following function calls:
36 * cairo_pdf_surface_set_size
39 #define INCHES_TO_POINTS(in) ((in) * 72.0)
40 #define MM_TO_POINTS(mm) ((mm) / 25.4 * 72.0)
43 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
46 const char *page_size
;
47 const char *page_size_alias
;
48 const char *orientation
;
49 double width_in_points
;
50 double height_in_points
;
52 {"na_letter_8.5x11in", "letter", "portrait",
53 INCHES_TO_POINTS(8.5), INCHES_TO_POINTS(11)},
54 {"na_letter_8.5x11in", "letter", "landscape",
55 INCHES_TO_POINTS(11), INCHES_TO_POINTS(8.5)},
56 {"iso_a4_210x297mm", "a4", "portrait",
57 MM_TO_POINTS(210), MM_TO_POINTS(297)},
58 {"iso_a4_210x297mm", "a4", "landscape",
59 MM_TO_POINTS(297), MM_TO_POINTS(210)},
60 {"iso_a5_148x210mm", "a5", "portrait",
61 MM_TO_POINTS(148), MM_TO_POINTS(210)},
62 {"iso_a5_148x210mm", "a5", "landscape",
63 MM_TO_POINTS(210), MM_TO_POINTS(148)},
64 {"iso_a6_105x148mm", "a6", "portrait",
65 MM_TO_POINTS(105), MM_TO_POINTS(148)},
66 {"iso_a6_105x148mm", "a6", "landscape",
67 MM_TO_POINTS(148), MM_TO_POINTS(105)},
68 {"iso_a7_74x105mm", "a7", "portrait",
69 MM_TO_POINTS(74), MM_TO_POINTS(105)},
70 {"iso_a7_74x105mm", "a7", "landscape",
71 MM_TO_POINTS(105), MM_TO_POINTS(74)},
72 {"iso_a8_52x74mm", "a8", "portrait",
73 MM_TO_POINTS(52), MM_TO_POINTS(74)},
74 {"iso_a8_52x74mm", "a8", "landscape",
75 MM_TO_POINTS(74), MM_TO_POINTS(52)},
76 {"iso_a9_37x52mm", "a9", "portrait",
77 MM_TO_POINTS(37), MM_TO_POINTS(52)},
78 {"iso_a9_37x52mm", "a9", "landscape",
79 MM_TO_POINTS(52), MM_TO_POINTS(37)},
80 {"iso_a10_26x37mm", "a10", "portrait",
81 MM_TO_POINTS(26), MM_TO_POINTS(37)},
82 {"iso_a10_26x37mm", "a10", "landscape",
83 MM_TO_POINTS(37), MM_TO_POINTS(26)}
89 cairo_surface_t
*surface
;
91 cairo_status_t status
;
95 cairo_test_init ("pdf-features");
97 filename
= "pdf-features.pdf";
99 /* The initial size passed here is the default size that will be
100 * inheritable by each page. That is, any page for which this
101 * initial size applies will not have its own /MediaBox entry in
103 surface
= cairo_pdf_surface_create (filename
,
104 INCHES_TO_POINTS(8.5),
105 INCHES_TO_POINTS(11));
107 cr
= cairo_create (surface
);
109 cairo_select_font_face (cr
, "Bitstream Vera Sans",
110 CAIRO_FONT_SLANT_NORMAL
,
111 CAIRO_FONT_WEIGHT_NORMAL
);
112 cairo_set_font_size (cr
, TEXT_SIZE
);
114 for (i
=0; i
< ARRAY_SIZE(pages
); i
++)
116 cairo_pdf_surface_set_size (surface
,
117 pages
[i
].width_in_points
,
118 pages
[i
].height_in_points
);
120 cairo_move_to (cr
, TEXT_SIZE
, TEXT_SIZE
);
121 cairo_show_text (cr
, pages
[i
].page_size
);
122 cairo_show_text (cr
, " - ");
123 cairo_show_text (cr
, pages
[i
].orientation
);
124 cairo_show_page (cr
);
127 status
= cairo_status (cr
);
130 cairo_surface_destroy (surface
);
133 cairo_test_log ("Failed to create pdf surface for file %s: %s\n",
134 filename
, cairo_status_to_string (status
));
135 return CAIRO_TEST_FAILURE
;
138 printf ("pdf-features: Please check %s to ensure it looks/prints correctly.\n", filename
);
142 return CAIRO_TEST_SUCCESS
;