summaryrefslogtreecommitdiff
path: root/doc/tutorial/src/include/cairo-tutorial-pdf.h
blob: 00d0f188e5be5a14cac1d42e13a6eedbc89b504b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* cairo-tutorial-png.h - a tutorial framework for cairo to write a PNG image
 *
 * Copyright © 2005, Carl Worth
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
 */

#include <cairo.h>
#include <cairo-pdf.h>

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>

#ifndef WIDTH
#define WIDTH 400
#endif

#ifndef HEIGHT
#define HEIGHT 400
#endif

static void
draw (cairo_t *cr, int width, int height);

int
main (int argc, char **argv)
{
    cairo_surface_t *surface;
    cairo_t *cr;
    char *filename, *dash;

    filename = strdup (argv[0]);
    assert (filename != NULL);

    dash = strrchr (filename, '-');

    if (strcmp (dash, "-pdf") == 0) {
	*dash = '.';
    } else {
	char *new_filename;
	new_filename = malloc (strlen (filename) + 5);
	sprintf (new_filename, "%s.pdf", filename);
	free (filename);
	filename = new_filename;
    }

    surface = cairo_pdf_surface_create (filename, WIDTH, HEIGHT);

    cr = cairo_create (surface);

    draw (cr, WIDTH, HEIGHT);

    cairo_show_page (cr);

    cairo_surface_destroy (surface);
    cairo_destroy (cr);

    free (filename);

    return 0;
}