]> git.cworth.org Git - svg2png/blob - svg2pdf.c
1dab19e2fd52cef617ddd0a935c7665703e83423
[svg2png] / svg2pdf.c
1 /*
2  * Copyright © 2005 Red Hat, Inc.
3  * Copyright © 2006 Red Hat, Inc.
4  * Copyright © 2007 Red Hat, Inc.
5  *
6  * Permission to use, copy, modify, distribute, and sell this software
7  * and its documentation for any purpose is hereby granted without
8  * fee, provided that the above copyright notice appear in all copies
9  * and that both that copyright notice and this permission notice
10  * appear in supporting documentation, and that the name of
11  * Red Hat, Inc. not be used in advertising or publicity pertaining to
12  * distribution of the software without specific, written prior
13  * permission. Red Hat, Inc. makes no representations about the
14  * suitability of this software for any purpose.  It is provided "as
15  * is" without express or implied warranty.
16  *
17  * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
18  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
19  * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
20  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
21  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
22  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
23  * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24  *
25  * Authors: Kristian Høgsberg <krh@redhat.com>
26  *          Carl Worth <cworth@redhat.com>
27  *          Behdad Esfahbod <besfahbo@redhat.com>
28  */
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <librsvg/rsvg.h>
33 #include <librsvg/rsvg-cairo.h>
34
35 #include <cairo-pdf.h>
36
37 #define FAIL(msg)                                                       \
38     do { fprintf (stderr, "FAIL: %s\n", msg); exit (-1); } while (0)
39
40 #define PIXELS_PER_POINT 1
41
42 int main (int argc, char *argv[])
43 {
44     GError *error = NULL;
45     RsvgHandle *handle;
46     RsvgDimensionData dim;
47     double width, height;
48     const char *filename = argv[1];
49     const char *output_filename = argv[2];
50     cairo_surface_t *surface;
51     cairo_t *cr;
52     cairo_status_t status;
53
54     if (argc != 3)
55         FAIL ("usage: svg2pdf input_file.svg output_file.pdf");
56
57     g_type_init ();
58
59     rsvg_set_default_dpi (72.0);
60     handle = rsvg_handle_new_from_file (filename, &error);
61     if (error != NULL)
62         FAIL (error->message);
63
64     rsvg_handle_get_dimensions (handle, &dim);
65     width = dim.width;
66     height = dim.height;
67
68     surface = cairo_pdf_surface_create (output_filename, width, height);
69     cr = cairo_create (surface);
70
71     /* Clear background */
72     cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
73     cairo_paint (cr);
74
75     rsvg_handle_render_cairo (handle, cr);
76
77     status = cairo_status (cr);
78     if (status)
79         FAIL (cairo_status_to_string (status));
80
81     cairo_destroy (cr);
82     cairo_surface_destroy (surface);
83
84     return 0;
85 }