rsvg.h 8.74 KB
Newer Older
1 2
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: set sw=4 sts=4 expandtab: */
3 4 5 6 7 8
/* 
   rsvg.h: SAX-based renderer for SVG files into a GdkPixbuf.
 
   Copyright (C) 2000 Eazel, Inc.
  
   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 11 12 13 14 15
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.
  
   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
16
   Library General Public License for more details.
17
  
18
   You should have received a copy of the GNU Library General Public
19 20 21 22 23 24 25 26 27 28
   License along with this program; if not, write to the
   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
  
   Author: Raph Levien <raph@artofcode.com>
*/

#ifndef RSVG_H
#define RSVG_H

29 30
#define __RSVG_RSVG_H_INSIDE__

31 32 33
#include <glib-object.h>
#include <gio/gio.h>

34 35
#include <gdk-pixbuf/gdk-pixbuf.h>

36
G_BEGIN_DECLS
37

38 39 40 41 42 43 44 45
#if defined(RSVG_DISABLE_DEPRECATION_WARNINGS) || !GLIB_CHECK_VERSION (2, 31, 0)
#define RSVG_DEPRECATED
#define RSVG_DEPRECATED_FOR(f)
#else
#define RSVG_DEPRECATED G_DEPRECATED
#define RSVG_DEPRECATED_FOR(f) G_DEPRECATED_FOR(f)
#endif

46 47 48 49 50 51
#define RSVG_TYPE_HANDLE                  (rsvg_handle_get_type ())
#define RSVG_HANDLE(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), RSVG_TYPE_HANDLE, RsvgHandle))
#define RSVG_HANDLE_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), RSVG_TYPE_HANDLE, RsvgHandleClass))
#define RSVG_IS_HANDLE(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RSVG_TYPE_HANDLE))
#define RSVG_IS_HANDLE_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), RSVG_TYPE_HANDLE))
#define RSVG_HANDLE_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), RSVG_TYPE_HANDLE, RsvgHandleClass))
52 53

GType rsvg_handle_get_type (void);
54

55
/**
56
 * RsvgError:
57
 * @RSVG_ERROR_FAILED: the request failed
58
 *
59
 * An enumeration representing possible errors
60
 */
61
typedef enum {
62
    RSVG_ERROR_FAILED
63
} RsvgError;
64

65
#define RSVG_ERROR (rsvg_error_quark ())
66
GQuark rsvg_error_quark (void) G_GNUC_CONST;
67

68
/**
69 70
 * RsvgHandle:
 *
71
 * The #RsvgHandle is an object representing the parsed form of a SVG
72
 */
73 74 75
typedef struct _RsvgHandle RsvgHandle;
typedef struct RsvgHandlePrivate RsvgHandlePrivate;
typedef struct _RsvgHandleClass RsvgHandleClass;
76
typedef struct _RsvgDimensionData RsvgDimensionData;
77
typedef struct _RsvgPositionData RsvgPositionData;
78

79 80 81 82 83 84
/**
 * RsvgHandleClass:
 * @parent: parent class
 *
 * Class structure for #RsvgHandle
 */
85
struct _RsvgHandleClass {
86
    GObjectClass parent;
87

88
    /*< private >*/
89
    gpointer _abi_padding[15];
90 91 92
};

struct _RsvgHandle {
93
    GObject parent;
94

95 96
    /*< private >*/

97
    RsvgHandlePrivate *priv;
98

99
    gpointer _abi_padding[15];
100 101
};

102 103 104 105 106 107
/**
 * RsvgDimensionData:
 * @width: SVG's width, in pixels
 * @height: SVG's height, in pixels
 * @em: em
 * @ex: ex
108
 */
109
struct _RsvgDimensionData {
110 111 112 113
    int width;
    int height;
    gdouble em;
    gdouble ex;
114 115
};

116
/**
117
 * RsvgPositionData:
118 119 120
 * @x: position on the x axis
 * @y: position on the y axis
 *
121
 * Position of an SVG fragment.
122
 */
123 124 125 126 127
struct _RsvgPositionData {
    int x;
    int y;
};

128
void rsvg_cleanup (void);
129 130 131 132 133 134 135 136 137

void rsvg_set_default_dpi	(double dpi);
void rsvg_set_default_dpi_x_y	(double dpi_x, double dpi_y);

void rsvg_handle_set_dpi	(RsvgHandle * handle, double dpi);
void rsvg_handle_set_dpi_x_y	(RsvgHandle * handle, double dpi_x, double dpi_y);

RsvgHandle  *rsvg_handle_new		(void);
gboolean     rsvg_handle_write		(RsvgHandle * handle, const guchar * buf, 
138
                                     gsize count, GError ** error);
139 140 141 142
gboolean     rsvg_handle_close		(RsvgHandle * handle, GError ** error);
GdkPixbuf   *rsvg_handle_get_pixbuf	(RsvgHandle * handle);
GdkPixbuf   *rsvg_handle_get_pixbuf_sub (RsvgHandle * handle, const char *id);

143 144
const char  *rsvg_handle_get_base_uri (RsvgHandle * handle);
void         rsvg_handle_set_base_uri (RsvgHandle * handle, const char *base_uri);
145 146

void rsvg_handle_get_dimensions (RsvgHandle * handle, RsvgDimensionData * dimension_data);
147

148
gboolean rsvg_handle_get_dimensions_sub (RsvgHandle * handle, RsvgDimensionData * dimension_data, const char *id);
149
gboolean rsvg_handle_get_position_sub (RsvgHandle * handle, RsvgPositionData * position_data, const char *id);
150

151 152
gboolean rsvg_handle_has_sub (RsvgHandle * handle, const char *id);

153 154
/* GIO APIs */

155 156 157
/**
 * RsvgHandleFlags:
 * @RSVG_HANDLE_FLAGS_NONE: none
158 159 160
 * @RSVG_HANDLE_FLAG_UNLIMITED: Allow any SVG XML without size limitations.
 *   For security reasons, this should only be used for trusted input!
 *   Since: 2.40.3
161 162 163 164
 * @RSVG_HANDLE_FLAG_KEEP_IMAGE_DATA: Keeps the image data when loading images,
 *  for use by cairo when painting to e.g. a PDF surface. This will make the
 *  resulting PDF file smaller and faster.
 *  Since: 2.40.3
165
 */
166 167
typedef enum /*< flags >*/ 
{
168 169 170
    RSVG_HANDLE_FLAGS_NONE           = 0,
    RSVG_HANDLE_FLAG_UNLIMITED       = 1 << 0,
    RSVG_HANDLE_FLAG_KEEP_IMAGE_DATA = 1 << 1
171 172
} RsvgHandleFlags;

173 174
RsvgHandle *rsvg_handle_new_with_flags (RsvgHandleFlags flags);

175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
void        rsvg_handle_set_base_gfile (RsvgHandle *handle,
                                        GFile      *base_file);

gboolean    rsvg_handle_read_stream_sync (RsvgHandle   *handle,
                                          GInputStream *stream,
                                          GCancellable *cancellable,
                                          GError      **error);

RsvgHandle *rsvg_handle_new_from_gfile_sync (GFile          *file,
                                             RsvgHandleFlags flags,
                                             GCancellable   *cancellable,
                                             GError        **error);

RsvgHandle *rsvg_handle_new_from_stream_sync (GInputStream   *input_stream,
                                              GFile          *base_file,
                                              RsvgHandleFlags flags,
                                              GCancellable   *cancellable,
                                              GError        **error);

194 195
RsvgHandle *rsvg_handle_new_from_data (const guint8 * data, gsize data_len, GError ** error);
RsvgHandle *rsvg_handle_new_from_file (const gchar * file_name, GError ** error);
196

197 198
void rsvg_handle_internal_set_testing (RsvgHandle *handle, gboolean testing);

199
/* BEGIN deprecated APIs. Do not use! */
200

201 202
#ifndef __GI_SCANNER__

203 204 205 206 207
RSVG_DEPRECATED_FOR(g_type_init)
void rsvg_init (void);
RSVG_DEPRECATED
void rsvg_term (void);

208
RSVG_DEPRECATED_FOR(g_object_unref)
209
void rsvg_handle_free (RsvgHandle * handle);
210

211
/**
212
 * RsvgSizeFunc:
213 214 215
 * @width: (out): the width of the SVG
 * @height: (out): the height of the SVG
 * @user_data: user data
216 217
 *
 * Function to let a user of the library specify the SVG's dimensions
218
 *
219
 * Deprecated: Set up a cairo matrix and use rsvg_handle_render_cairo() instead.
220
 * See the documentation for rsvg_handle_set_size_callback() for an example.
221
 */
222
typedef /* RSVG_DEPRECATED */ void (*RsvgSizeFunc) (gint * width, gint * height, gpointer user_data);
223 224

RSVG_DEPRECATED
225
void rsvg_handle_set_size_callback (RsvgHandle * handle,
226 227
                                    RsvgSizeFunc size_func,
                                    gpointer user_data, GDestroyNotify user_data_destroy);
228

229
/* GdkPixbuf convenience API */
230

231
RSVG_DEPRECATED
232
GdkPixbuf *rsvg_pixbuf_from_file            (const gchar * file_name, GError ** error);
233
RSVG_DEPRECATED
234 235
GdkPixbuf *rsvg_pixbuf_from_file_at_zoom    (const gchar * file_name,
                                             double x_zoom, double y_zoom, GError ** error);
236
RSVG_DEPRECATED
237 238
GdkPixbuf *rsvg_pixbuf_from_file_at_size    (const gchar * file_name, gint width, gint height,
                                             GError ** error);
239
RSVG_DEPRECATED
240 241
GdkPixbuf *rsvg_pixbuf_from_file_at_max_size    (const gchar * file_name,
                                                 gint max_width, gint max_height, GError ** error);
242
RSVG_DEPRECATED
243
GdkPixbuf *rsvg_pixbuf_from_file_at_zoom_with_max (const gchar * file_name,
244 245 246
                                                   double x_zoom,
                                                   double y_zoom,
                                                   gint max_width, gint max_height, GError ** error);
247

248 249 250 251 252 253 254
RSVG_DEPRECATED
const char *rsvg_handle_get_title       (RsvgHandle * handle);
RSVG_DEPRECATED
const char *rsvg_handle_get_desc        (RsvgHandle * handle);
RSVG_DEPRECATED
const char *rsvg_handle_get_metadata    (RsvgHandle * handle);

255 256
#endif /* !__GI_SCANNER__ */

257
/* END deprecated APIs. */
258

259
G_END_DECLS
260

261 262 263 264 265 266
#include "librsvg-enum-types.h"
#include "librsvg-features.h"
#include "rsvg-cairo.h"

#undef __RSVG_RSVG_H_INSIDE__

267
#endif                          /* RSVG_H */