1 | /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- |
---|
2 | |
---|
3 | test-rsvg.c: Command line utility for exercising rsvg. |
---|
4 | |
---|
5 | Copyright (C) 2000 Eazel, Inc. |
---|
6 | Copyright (C) 2002 Dom Lachowicz |
---|
7 | |
---|
8 | This program is free software; you can redistribute it and/or |
---|
9 | modify it under the terms of the GNU Library General Public License as |
---|
10 | published by the Free Software Foundation; either version 2 of the |
---|
11 | License, or (at your option) any later version. |
---|
12 | |
---|
13 | This program is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | Library General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU Library General Public |
---|
19 | License along with this program; if not, write to the |
---|
20 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
21 | Boston, MA 02111-1307, USA. |
---|
22 | |
---|
23 | Author: Raph Levien <raph@artofcode.com> |
---|
24 | */ |
---|
25 | |
---|
26 | #include "config.h" |
---|
27 | #include "rsvg.h" |
---|
28 | |
---|
29 | #include <popt.h> |
---|
30 | #include <stdio.h> |
---|
31 | #include <stdlib.h> |
---|
32 | #include <string.h> |
---|
33 | |
---|
34 | int |
---|
35 | main (int argc, const char **argv) |
---|
36 | { |
---|
37 | poptContext popt_context; |
---|
38 | double x_zoom = 1.0; |
---|
39 | double y_zoom = 1.0; |
---|
40 | double dpi = -1.0; |
---|
41 | int width = -1; |
---|
42 | int height = -1; |
---|
43 | int bVersion = 0; |
---|
44 | char * format = "png"; |
---|
45 | |
---|
46 | struct poptOption options_table[] = { |
---|
47 | { "dpi" , 'd', POPT_ARG_DOUBLE, &dpi, 0, "Pixels Per Inch", "<float>"}, |
---|
48 | { "x-zoom", 'x', POPT_ARG_DOUBLE, &x_zoom, 0, "x zoom factor", "<float>" }, |
---|
49 | { "y-zoom", 'y', POPT_ARG_DOUBLE, &y_zoom, 0, "y zoom factor", "<float>" }, |
---|
50 | { "width", 'w', POPT_ARG_INT, &width, 0, "width", "<int>" }, |
---|
51 | { "height", 'h', POPT_ARG_INT, &height, 0, "height", "<int>" }, |
---|
52 | { "format", 'f', POPT_ARG_STRING, &format, 0, "save format", "[png, jpeg]"}, |
---|
53 | { "version", 'v', POPT_ARG_NONE, &bVersion, 0, "show version information", NULL }, |
---|
54 | POPT_AUTOHELP |
---|
55 | POPT_TABLEEND |
---|
56 | }; |
---|
57 | int c; |
---|
58 | const char * const *args; |
---|
59 | gint n_args = 0; |
---|
60 | GdkPixbuf *pixbuf; |
---|
61 | |
---|
62 | popt_context = poptGetContext ("rsvg", argc, argv, options_table, 0); |
---|
63 | poptSetOtherOptionHelp(popt_context, "[OPTIONS...] file.svg file.png"); |
---|
64 | |
---|
65 | c = poptGetNextOpt (popt_context); |
---|
66 | args = poptGetArgs (popt_context); |
---|
67 | |
---|
68 | if (bVersion != 0) |
---|
69 | { |
---|
70 | printf ("rsvg version %s\n", VERSION); |
---|
71 | return 0; |
---|
72 | } |
---|
73 | |
---|
74 | if (args) |
---|
75 | { |
---|
76 | while (args[n_args] != NULL) |
---|
77 | n_args++; |
---|
78 | } |
---|
79 | |
---|
80 | if (n_args != 2) |
---|
81 | { |
---|
82 | poptPrintHelp (popt_context, stderr, 0); |
---|
83 | poptFreeContext (popt_context); |
---|
84 | return 1; |
---|
85 | } |
---|
86 | |
---|
87 | if (strstr (format, "jpeg") != NULL) |
---|
88 | format = "jpeg"; |
---|
89 | else |
---|
90 | format = "png"; |
---|
91 | |
---|
92 | g_type_init (); |
---|
93 | |
---|
94 | if (dpi > 0.) |
---|
95 | rsvg_set_default_dpi (dpi); |
---|
96 | |
---|
97 | /* if both are unspecified, assume user wants to zoom the pixbuf in at least 1 dimension */ |
---|
98 | if (width == -1 && height == -1) |
---|
99 | pixbuf = rsvg_pixbuf_from_file_at_zoom (args[0], x_zoom, y_zoom, NULL); |
---|
100 | /* if both are unspecified, assume user wants to resize pixbuf in at least 1 dimension */ |
---|
101 | else if (x_zoom == 1.0 && y_zoom == 1.0) |
---|
102 | pixbuf = rsvg_pixbuf_from_file_at_size (args[0], width, height, NULL); |
---|
103 | else |
---|
104 | /* assume the user wants to zoom the pixbuf, but cap the maximum size */ |
---|
105 | pixbuf = rsvg_pixbuf_from_file_at_zoom_with_max (args[0], x_zoom, y_zoom, |
---|
106 | width, height, NULL); |
---|
107 | |
---|
108 | if (pixbuf) |
---|
109 | gdk_pixbuf_save (pixbuf, args[1], format, NULL, NULL); |
---|
110 | else { |
---|
111 | poptFreeContext (popt_context); |
---|
112 | fprintf (stderr, "Error loading SVG file.\n"); |
---|
113 | return 1; |
---|
114 | } |
---|
115 | |
---|
116 | poptFreeContext (popt_context); |
---|
117 | return 0; |
---|
118 | } |
---|