1 /* gcc `pkg-config --cflags --libs librsvg-2.0 cairo-png` -o svg2png svg2png.c
3 * Copyright © 2005 Red Hat, Inc.
4 * Copyright © 2006 Red Hat, Inc.
5 * Copyright © 2007 Red Hat, Inc.
7 * Permission is hereby granted, free of charge, to any person
8 * obtaining a copy of this software and associated documentation
9 * files (the "Software"), to deal in the Software without
10 * restriction, including without limitation the rights to use, copy,
11 * modify, merge, publish, distribute, sublicense, and/or sell copies
12 * of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
22 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * Authors: Kristian Høgsberg <krh@redhat.com>
28 * Carl Worth <cworth@redhat.com>
29 * Behdad Esfahbod <besfahbo@redhat.com>
34 #include <librsvg/rsvg.h>
35 #include <librsvg/rsvg-cairo.h>
40 do { fprintf (stderr, "FAIL: %s\n", msg); exit (-1); } while (0)
42 int main (int argc, char *argv[])
46 RsvgDimensionData dim;
48 const char *filename = argv[1];
49 const char *output_filename = argv[2];
50 cairo_surface_t *surface;
52 cairo_status_t status;
55 FAIL ("usage: svg2png input_file.svg output_file.png");
59 rsvg_set_default_dpi (72.0);
60 handle = rsvg_handle_new_from_file (filename, &error);
62 FAIL (error->message);
64 rsvg_handle_get_dimensions (handle, &dim);
68 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
69 cr = cairo_create (surface);
71 rsvg_handle_render_cairo (handle, cr);
73 status = cairo_status (cr);
75 FAIL (cairo_status_to_string (status));
77 cairo_surface_write_to_png (surface, output_filename);
80 cairo_surface_destroy (surface);