00d0f188e5be5a14cac1d42e13a6eedbc89b504b
[platform/core/graphics/cairo.git] / doc / tutorial / src / include / cairo-tutorial-pdf.h
1 /* cairo-tutorial-png.h - a tutorial framework for cairo to write a PNG image
2  *
3  * Copyright © 2005, Carl Worth
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
17  */
18
19 #include <cairo.h>
20 #include <cairo-pdf.h>
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <assert.h>
25 #include <string.h>
26
27 #ifndef WIDTH
28 #define WIDTH 400
29 #endif
30
31 #ifndef HEIGHT
32 #define HEIGHT 400
33 #endif
34
35 static void
36 draw (cairo_t *cr, int width, int height);
37
38 int
39 main (int argc, char **argv)
40 {
41     cairo_surface_t *surface;
42     cairo_t *cr;
43     char *filename, *dash;
44
45     filename = strdup (argv[0]);
46     assert (filename != NULL);
47
48     dash = strrchr (filename, '-');
49
50     if (strcmp (dash, "-pdf") == 0) {
51         *dash = '.';
52     } else {
53         char *new_filename;
54         new_filename = malloc (strlen (filename) + 5);
55         sprintf (new_filename, "%s.pdf", filename);
56         free (filename);
57         filename = new_filename;
58     }
59
60     surface = cairo_pdf_surface_create (filename, WIDTH, HEIGHT);
61
62     cr = cairo_create (surface);
63
64     draw (cr, WIDTH, HEIGHT);
65
66     cairo_show_page (cr);
67
68     cairo_surface_destroy (surface);
69     cairo_destroy (cr);
70
71     free (filename);
72
73     return 0;
74 }