1 /* 
2    rsvg.d: SAX-based renderer for SVG files into a GdkPixbuf.
3  
4    Copyright (C) 2000 Eazel, Inc.
5   
6    This program is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Library General Public License as
8    published by the Free Software Foundation; either version 2 of the
9    License, or (at your option) any later version.
10   
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Library General Public License for more details.
15   
16    You should have received a copy of the GNU Library General Public
17    License along with this program; if not, write to the
18    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19    Boston, MA 02111-1307, USA.
20   
21    Author: Raph Levien <raph@artofcode.com>
22 */
23 
24 module rsvg.rsvg;
25 import cairo.c.cairo;
26 
27 extern(C) {
28 
29 alias ulong GType;
30 alias uint GQuark;
31 
32 struct GError {
33     uint domain;
34     int code;
35     char* message;
36 }
37 
38 // dummies
39 struct GdkPixbuf {}
40 struct GObject {}
41 struct GObjectClass {}
42 struct GFile {}
43 struct GInputStream {}
44 struct GCancellable {}
45 struct RsvgHandlePrivate {}
46 
47 GType rsvg_handle_get_type ();
48 
49 /**
50  * RsvgError:
51  * @RSVG_ERROR_FAILED: the request failed
52  *
53  * An enumeration representing possible errors
54  */
55 enum RSvgError {
56     RSVG_ERROR_FAILED
57 }
58 
59 GQuark rsvg_error_quark ();
60 
61 /**
62  * RsvgHandleClass:
63  * @parent: parent class
64  *
65  * Class structure for #RsvgHandle
66  */
67 struct RsvgHandleClass {
68     GObjectClass parent;
69 
70     /*< private >*/
71     void* _abi_padding[15];
72 }
73 
74 /**
75  * RsvgHandle:
76  *
77  * The #RsvgHandle is an object representing the parsed form of a SVG
78  */
79 struct RsvgHandle {
80     GObject parent;
81 
82     /*< private >*/
83 
84     RsvgHandlePrivate *priv;
85 
86     void* _abi_padding[15];
87 }
88 
89 /**
90  * RsvgDimensionData:
91  * @width: SVG's width, in pixels
92  * @height: SVG's height, in pixels
93  * @em: em
94  * @ex: ex
95  */
96 struct RsvgDimensionData {
97     int width;
98     int height;
99     double em;
100     double ex;
101 }
102 
103 /**
104  * RsvgPositionData:
105  * @x: position on the x axis
106  * @y: position on the y axis
107  *
108  * Position of an SVG fragment.
109  */
110 struct RsvgPositionData {
111     int x;
112     int y;
113 }
114 
115 void rsvg_cleanup ();
116 
117 void rsvg_set_default_dpi	(double dpi);
118 void rsvg_set_default_dpi_x_y	(double dpi_x, double dpi_y);
119 
120 void rsvg_handle_set_dpi	(RsvgHandle * handle, double dpi);
121 void rsvg_handle_set_dpi_x_y	(RsvgHandle * handle, double dpi_x, double dpi_y);
122 
123 RsvgHandle  *rsvg_handle_new	();
124 bool     rsvg_handle_write		(RsvgHandle * handle, const ubyte * buf, 
125                                  int count, GError ** error);
126 bool     rsvg_handle_close		(RsvgHandle * handle, GError ** error);
127 GdkPixbuf   *rsvg_handle_get_pixbuf	(RsvgHandle * handle);
128 GdkPixbuf   *rsvg_handle_get_pixbuf_sub (RsvgHandle * handle, const char *id);
129 
130 const(char) *rsvg_handle_get_base_uri (RsvgHandle * handle);
131 void         rsvg_handle_set_base_uri (RsvgHandle * handle, const char *base_uri);
132 
133 void rsvg_handle_get_dimensions (RsvgHandle * handle, RsvgDimensionData * dimension_data);
134 
135 bool rsvg_handle_get_dimensions_sub (RsvgHandle * handle, RsvgDimensionData * dimension_data, const char *id);
136 bool rsvg_handle_get_position_sub (RsvgHandle * handle, RsvgPositionData * position_data, const char *id);
137 
138 bool rsvg_handle_has_sub (RsvgHandle * handle, const char *id);
139 
140 /* GIO APIs */
141 
142 /**
143  * RsvgHandleFlags:
144  * @RSVG_HANDLE_FLAGS_NONE: none
145  * @RSVG_HANDLE_FLAG_UNLIMITED: Allow any SVG XML without size limitations.
146  *   For security reasons, this should only be used for trusted input!
147  *   Since: 2.40.3
148  * @RSVG_HANDLE_FLAG_KEEP_IMAGE_DATA: Keeps the image data when loading images,
149  *  for use by cairo when painting to e.g. a PDF surface. This will make the
150  *  resulting PDF file smaller and faster.
151  *  Since: 2.40.3
152  */
153 enum RsvgHandleFlags/*< flags >*/ 
154 {
155     NONE            = 0,
156     UNLIMITED       = 1 << 0,
157     KEEP_IMAGE_DATA = 1 << 1
158 }
159 
160 RsvgHandle *rsvg_handle_new_with_flags (RsvgHandleFlags flags);
161 
162 void rsvg_handle_set_base_gfile (RsvgHandle *handle,
163                                  GFile      *base_file);
164 
165 bool rsvg_handle_read_stream_sync (RsvgHandle   *handle,
166                                    GInputStream *stream,
167                                    GCancellable *cancellable,
168                                    GError      **error);
169 
170 RsvgHandle *rsvg_handle_new_from_gfile_sync (GFile          *file,
171                                              RsvgHandleFlags flags,
172                                              GCancellable   *cancellable,
173                                              GError        **error);
174 
175 RsvgHandle *rsvg_handle_new_from_stream_sync (GInputStream   *input_stream,
176                                               GFile          *base_file,
177                                               RsvgHandleFlags flags,
178                                               GCancellable   *cancellable,
179                                               GError        **error);
180 
181 RsvgHandle *rsvg_handle_new_from_data (const ubyte * data, int data_len, GError ** error);
182 RsvgHandle *rsvg_handle_new_from_file (const ubyte * file_name, GError ** error);
183 
184 GType rsvg_error_get_type();
185 GType rsvg_handle_flags_get_type();
186 
187 /**
188  * CSS
189  */
190 enum RsvgAspectRatios {
191     RSVG_ASPECT_RATIO_NONE = 0,
192     RSVG_ASPECT_RATIO_XMIN_YMIN = 1 << 0,
193     RSVG_ASPECT_RATIO_XMID_YMIN = 1 << 1,
194     RSVG_ASPECT_RATIO_XMAX_YMIN = 1 << 2,
195     RSVG_ASPECT_RATIO_XMIN_YMID = 1 << 3,
196     RSVG_ASPECT_RATIO_XMID_YMID = 1 << 4,
197     RSVG_ASPECT_RATIO_XMAX_YMID = 1 << 5,
198     RSVG_ASPECT_RATIO_XMIN_YMAX = 1 << 6,
199     RSVG_ASPECT_RATIO_XMID_YMAX = 1 << 7,
200     RSVG_ASPECT_RATIO_XMAX_YMAX = 1 << 8,
201     RSVG_ASPECT_RATIO_SLICE = 1 << 31
202 }
203 
204 /* This one is semi-public for mis-use in rsvg-convert */
205 int	    rsvg_css_parse_color        (const char *str, bool * inherit);
206 
207 enum RsvgSizeType {
208     ZOOM,
209     WH,
210     WH_MAX,
211     ZOOM_MAX
212 }
213 
214 struct RsvgSizeCallbackData {
215     RsvgSizeType type;
216     double x_zoom;
217     double y_zoom;
218     int width;
219     int height;
220 
221     bool keep_aspect_ratio;
222 }
223 
224 void _rsvg_size_callback (int *width, int *height, void* data);
225 
226 bool rsvg_handle_render_cairo     (RsvgHandle * handle, cairo_t * cr);
227 bool rsvg_handle_render_cairo_sub (RsvgHandle * handle, cairo_t * cr, const char *id);
228 
229 void rsvg_term();
230 
231 }