rsvg2 0.90.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ install:
2
+ $(MAKEDIRS) $(libdir)/pkgconfig
3
+ $(INSTALL_DATA) ruby-rsvg2.pc $(libdir)/pkgconfig
@@ -0,0 +1,79 @@
1
+ =begin
2
+ extconf.rb for Ruby/RSVG extention library
3
+ =end
4
+
5
+ require 'pathname'
6
+
7
+ base_dir = Pathname(__FILE__).dirname.parent.parent.expand_path
8
+ top_dir = base_dir.parent
9
+ top_build_dir = Pathname(".").parent.parent.parent.expand_path
10
+
11
+ mkmf_gnome2_dir = top_dir + "glib2" + 'lib'
12
+ version_suffix = ""
13
+ unless mkmf_gnome2_dir.exist?
14
+ if /(-\d+\.\d+\.\d+)\z/ =~ base_dir.basename.to_s
15
+ version_suffix = $1
16
+ mkmf_gnome2_dir = top_dir + "glib2#{version_suffix}" + 'lib'
17
+ end
18
+ end
19
+
20
+ $LOAD_PATH.unshift(mkmf_gnome2_dir.to_s)
21
+
22
+ module_name = "rsvg2"
23
+ package_id = "librsvg-2.0"
24
+
25
+ require 'mkmf-gnome2'
26
+
27
+ setup_win32(module_name, base_dir)
28
+
29
+ PKGConfig.have_package(package_id) or exit 1
30
+
31
+ rsvg_header = "librsvg/rsvg.h"
32
+ have_func("rsvg_set_default_dpi", rsvg_header)
33
+ have_func("rsvg_set_default_dpi_x_y", rsvg_header)
34
+ have_func("rsvg_handle_set_dpi", rsvg_header)
35
+ have_func("rsvg_handle_set_dpi_x_y", rsvg_header)
36
+ have_func("rsvg_handle_get_metadata", rsvg_header)
37
+ have_func("rsvg_handle_free", rsvg_header)
38
+ have_func("rsvg_handle_get_pixbuf_sub", rsvg_header)
39
+ have_header("librsvg/rsvg-gz.h")
40
+ have_type("RsvgDimensionData", "librsvg/rsvg.h")
41
+
42
+ if have_header("librsvg/rsvg-cairo.h")
43
+ options = {}
44
+ rcairo_source_dir_names = ["rcairo"]
45
+ if /mingw|cygwin|mswin32/ =~ RUBY_PLATFORM
46
+ rcairo_source_dir_names.unshift("rcairo.win32")
47
+ end
48
+ rcairo_source_dir_names.each do |rcairo_source_dir_name|
49
+ rcairo_source_dir = top_dir.parent.expand_path + rcairo_source_dir_name
50
+ if rcairo_source_dir.exist?
51
+ options[:rcairo_source_dir] = rcairo_source_dir.to_s
52
+ break
53
+ end
54
+ end
55
+ check_cairo(options)
56
+ end
57
+
58
+ ["glib2"].each do |package|
59
+ directory = "#{package}#{version_suffix}"
60
+ build_dir = "#{directory}/tmp/#{RUBY_PLATFORM}/#{package}/#{RUBY_VERSION}"
61
+ add_depend_package(package, "#{directory}/ext/#{package}",
62
+ top_dir.to_s,
63
+ :top_build_dir => top_build_dir.to_s,
64
+ :target_build_dir => build_dir)
65
+ end
66
+
67
+ create_pkg_config_file("Ruby/RSVG", package_id, nil, "ruby-rsvg2.pc")
68
+
69
+ $defs << " -DRUBY_RSVG2_COMPILATION"
70
+ enum_type_prefix = "librsvg-enum-types"
71
+ unless have_header("librsvg/#{enum_type_prefix}.h")
72
+ include_paths = PKGConfig.cflags_only_I("librsvg-2.0")
73
+ include_path = include_paths.split.find do |x|
74
+ /librsvg/.match(x)
75
+ end.sub(/^-I/, "")
76
+ headers = Dir.glob(File.join(include_path, "librsvg", "*.h"))
77
+ glib_mkenums(enum_type_prefix, headers, "RSVG_TYPE_", ["librsvg/rsvg.h"])
78
+ end
79
+ create_makefile(module_name)
@@ -0,0 +1,846 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /**********************************************************************
3
+
4
+ rbrsvg.c -
5
+
6
+ $Author: ggc $
7
+ $Date: 2007/07/13 16:07:34 $
8
+
9
+ Copyright (C) 2005-2006 Ruby-GNOME2 Project Team
10
+ Copyright (C) 2004 Kouhei Sutou <kou@cozmixng.org>
11
+
12
+ **********************************************************************/
13
+
14
+ #include <ruby.h>
15
+
16
+ #include <rbglib.h>
17
+ #include <rbgobject.h>
18
+
19
+ #ifdef HAVE_LIBRSVG_RSVG_GZ_H
20
+ # include <librsvg/rsvg-gz.h>
21
+ #else
22
+ # include <librsvg/rsvg.h>
23
+ #endif
24
+
25
+ #ifdef HAVE_RB_CAIRO_H
26
+ # include <rb_cairo.h>
27
+ # include <librsvg/rsvg-cairo.h>
28
+ #endif
29
+
30
+ #ifdef HAVE_LIBRSVG_LIBRSVG_ENUM_TYPES_H
31
+ # include <librsvg/librsvg-enum-types.h>
32
+ #else
33
+ # include "librsvg-enum-types.h"
34
+ #endif
35
+
36
+ #include <librsvg/librsvg-features.h>
37
+
38
+ #define RBRSVG_MAJOR_VERSION RBGLIB_MAJOR_VERSION
39
+ #define RBRSVG_MINOR_VERSION RBGLIB_MINOR_VERSION
40
+ #define RBRSVG_MICRO_VERSION RBGLIB_MICRO_VERSION
41
+
42
+ #define LIBRSVG_CHECK_VERSION(major, minor, micro) \
43
+ (LIBRSVG_MAJOR_VERSION > (major) || \
44
+ (LIBRSVG_MAJOR_VERSION == (major) && LIBRSVG_MINOR_VERSION > (minor)) || \
45
+ (LIBRSVG_MAJOR_VERSION == (major) && LIBRSVG_MINOR_VERSION == (minor) && \
46
+ LIBRSVG_MICRO_VERSION >= (micro)))
47
+
48
+ #ifdef RSVG_TYPE_HANDLE
49
+ # define _SELF(self) (RSVG_HANDLE(RVAL2GOBJ(self)))
50
+ #else
51
+ # define _SELF(self) ((RsvgHandle *)DATA_PTR(self))
52
+ #endif
53
+ #define RVAL2DIM(obj) ((RsvgDimensionData *)DATA_PTR(obj))
54
+
55
+ static VALUE cHandle;
56
+
57
+ static ID id_call;
58
+ static ID id_callback;
59
+ static ID id_closed;
60
+ static ID id_to_s;
61
+
62
+ static void
63
+ exec_callback(gint *width, gint *height, gpointer self)
64
+ {
65
+ VALUE result;
66
+ result = rb_funcall(rb_ivar_get((VALUE)self, id_callback),
67
+ id_call, 2, INT2NUM(*width), INT2NUM(*height));
68
+ if (T_ARRAY == TYPE(result)) {
69
+ VALUE w, h;
70
+ w = rb_ary_entry(result, 0);
71
+ h = rb_ary_entry(result, 1);
72
+ if (!NIL_P(w)) {
73
+ *width = NUM2INT(w);
74
+ }
75
+ if (!NIL_P(h)) {
76
+ *height = NUM2INT(h);
77
+ }
78
+ }
79
+ }
80
+
81
+ #ifdef HAVE_TYPE_RSVGDIMENSIONDATA
82
+ static VALUE
83
+ to_s(VALUE obj)
84
+ {
85
+ return rb_funcall(obj, id_to_s, 0);
86
+ }
87
+
88
+ static VALUE cDim;
89
+
90
+ static void
91
+ rb_rsvg_dim_free(RsvgDimensionData *dimp)
92
+ {
93
+ if (dimp) {
94
+ free(dimp);
95
+ }
96
+ }
97
+
98
+ static VALUE
99
+ rb_rsvg_dim_alloc(VALUE klass)
100
+ {
101
+ RsvgDimensionData *dimp;
102
+ return Data_Make_Struct(klass, RsvgDimensionData, 0,
103
+ rb_rsvg_dim_free, dimp);
104
+ }
105
+
106
+ static VALUE
107
+ rb_rsvg_dim_initialize(int argc, VALUE *argv, VALUE self)
108
+ {
109
+ VALUE width, height, em, ex;
110
+ RsvgDimensionData *dimp;
111
+
112
+ dimp = RVAL2DIM(self);
113
+ rb_scan_args(argc, argv, "04", &width, &height, &em, &ex);
114
+
115
+ if (!NIL_P(width))
116
+ dimp->width = NUM2INT(width);
117
+ if (!NIL_P(height))
118
+ dimp->height = NUM2INT(height);
119
+ if (!NIL_P(em))
120
+ dimp->em = NUM2DBL(em);
121
+ if (!NIL_P(ex))
122
+ dimp->ex = NUM2DBL(ex);
123
+
124
+ return Qnil;
125
+ }
126
+
127
+ static VALUE
128
+ rb_rsvg_dim_get_width(VALUE self)
129
+ {
130
+ return INT2NUM(RVAL2DIM(self)->width);
131
+ }
132
+
133
+ static VALUE
134
+ rb_rsvg_dim_set_width(VALUE self, VALUE width)
135
+ {
136
+ RVAL2DIM(self)->width = NUM2INT(width);
137
+ return Qnil;
138
+ }
139
+
140
+ static VALUE
141
+ rb_rsvg_dim_get_height(VALUE self)
142
+ {
143
+ return INT2NUM(RVAL2DIM(self)->height);
144
+ }
145
+
146
+ static VALUE
147
+ rb_rsvg_dim_set_height(VALUE self, VALUE height)
148
+ {
149
+ RVAL2DIM(self)->height = NUM2INT(height);
150
+ return Qnil;
151
+ }
152
+
153
+ static VALUE
154
+ rb_rsvg_dim_get_em(VALUE self)
155
+ {
156
+ return rb_float_new(RVAL2DIM(self)->em);
157
+ }
158
+
159
+ static VALUE
160
+ rb_rsvg_dim_set_em(VALUE self, VALUE em)
161
+ {
162
+ RVAL2DIM(self)->em = NUM2DBL(em);
163
+ return Qnil;
164
+ }
165
+
166
+ static VALUE
167
+ rb_rsvg_dim_get_ex(VALUE self)
168
+ {
169
+ return rb_float_new(RVAL2DIM(self)->ex);
170
+ }
171
+
172
+ static VALUE
173
+ rb_rsvg_dim_set_ex(VALUE self, VALUE ex)
174
+ {
175
+ RVAL2DIM(self)->ex = NUM2DBL(ex);
176
+ return Qnil;
177
+ }
178
+
179
+ static VALUE
180
+ rb_rsvg_dim_to_a(VALUE self)
181
+ {
182
+ return rb_ary_new3(4,
183
+ rb_rsvg_dim_get_width(self),
184
+ rb_rsvg_dim_get_height(self),
185
+ rb_rsvg_dim_get_em(self),
186
+ rb_rsvg_dim_get_ex(self));
187
+ }
188
+
189
+ static VALUE
190
+ rb_rsvg_dim_to_s(VALUE self)
191
+ {
192
+ VALUE ret;
193
+
194
+ ret = rb_str_new2("#<");
195
+ rb_str_cat2(ret, rb_obj_classname(self));
196
+ rb_str_cat2(ret, ":");
197
+ rb_str_concat(ret, rb_funcall(INT2NUM(self), id_to_s, 0));
198
+ rb_str_cat2(ret, " ");
199
+
200
+ rb_str_cat2(ret, "width=");
201
+ rb_str_concat(ret, to_s(rb_rsvg_dim_get_width(self)));
202
+ rb_str_cat2(ret, ", ");
203
+ rb_str_cat2(ret, "height=");
204
+ rb_str_concat(ret, to_s(rb_rsvg_dim_get_height(self)));
205
+ rb_str_cat2(ret, ", ");
206
+ rb_str_cat2(ret, "em=");
207
+ rb_str_concat(ret, to_s(rb_rsvg_dim_get_em(self)));
208
+ rb_str_cat2(ret, ", ");
209
+ rb_str_cat2(ret, "ex=");
210
+ rb_str_concat(ret, to_s(rb_rsvg_dim_get_ex(self)));
211
+ rb_str_cat2(ret, ">");
212
+
213
+ return ret;
214
+ }
215
+ #endif
216
+
217
+
218
+ static VALUE
219
+ rb_rsvg_set_default_dpi(VALUE self, VALUE dpi)
220
+ {
221
+ #ifdef HAVE_RSVG_SET_DEFAULT_DPI
222
+ rsvg_set_default_dpi(NUM2DBL(dpi));
223
+ #else
224
+ rb_warning("rsvg_set_default_dpi isn't supported in your librsvg");
225
+ #endif
226
+ return self;
227
+ }
228
+
229
+ static VALUE
230
+ rb_rsvg_set_default_dpi_x_y(VALUE self, VALUE dpi_x, VALUE dpi_y)
231
+ {
232
+ #ifdef HAVE_RSVG_SET_DEFAULT_DPI_X_Y
233
+ rsvg_set_default_dpi_x_y(NUM2DBL(dpi_x), NUM2DBL(dpi_y));
234
+ #else
235
+ rb_warning("rsvg_set_default_dpi_x_y isn't supported in your librsvg");
236
+ #endif
237
+ return self;
238
+ }
239
+
240
+ static VALUE
241
+ rb_rsvg_handle_set_dpi(VALUE self, VALUE dpi)
242
+ {
243
+ #ifdef HAVE_RSVG_HANDLE_SET_DPI
244
+ rsvg_handle_set_dpi(_SELF(self), NUM2DBL(dpi));
245
+ #else
246
+ rb_warning("rsvg_handle_set_dpi isn't supported in your librsvg");
247
+ #endif
248
+ return self;
249
+ }
250
+
251
+ static VALUE
252
+ rb_rsvg_handle_set_dpi_x_y(VALUE self, VALUE dpi_x, VALUE dpi_y)
253
+ {
254
+ #ifdef HAVE_RSVG_HANDLE_SET_DPI_X_Y
255
+ rsvg_handle_set_dpi_x_y(_SELF(self), NUM2DBL(dpi_x), NUM2DBL(dpi_y));
256
+ #else
257
+ rb_warning("rsvg_handle_set_dpi_x_y isn't supported in your librsvg");
258
+ #endif
259
+ return self;
260
+ }
261
+
262
+ #ifndef RSVG_TYPE_HANDLE
263
+ static void
264
+ rb_rsvg_handle_free(RsvgHandle *handle)
265
+ {
266
+ if (handle) {
267
+ rsvg_handle_free(handle);
268
+ }
269
+ }
270
+
271
+ static VALUE
272
+ rb_rsvg_handle_alloc(VALUE klass)
273
+ {
274
+ return Data_Wrap_Struct(klass, 0, rb_rsvg_handle_free, 0);
275
+ }
276
+ #endif
277
+
278
+ #if LIBRSVG_CHECK_VERSION(2, 14, 0)
279
+ static VALUE
280
+ rb_rsvg_handle_new_from_data(VALUE self, VALUE data)
281
+ {
282
+ GError *error = NULL;
283
+ RsvgHandle *handle;
284
+
285
+ handle = rsvg_handle_new_from_data((const guint8 *)RVAL2CSTR(data),
286
+ RSTRING_LEN(data), &error);
287
+
288
+ if (error)
289
+ RAISE_GERROR(error);
290
+
291
+ return GOBJ2RVAL(handle);
292
+ }
293
+
294
+ static VALUE
295
+ rb_rsvg_handle_new_from_file(VALUE self, VALUE file)
296
+ {
297
+ GError *error = NULL;
298
+ RsvgHandle *handle;
299
+
300
+ handle = rsvg_handle_new_from_file((const gchar *)RVAL2CSTR(file),
301
+ &error);
302
+
303
+ if (error)
304
+ RAISE_GERROR(error);
305
+
306
+ return GOBJ2RVAL(handle);
307
+ }
308
+ #endif
309
+
310
+ static VALUE
311
+ rb_rsvg_handle_initialize(int argc, VALUE *argv, VALUE self)
312
+ {
313
+ RsvgHandle *handle;
314
+ VALUE gz;
315
+ rb_scan_args(argc, argv, "01", &gz);
316
+
317
+ #if LIBRSVG_CHECK_VERSION(2, 11, 0)
318
+ handle = rsvg_handle_new();
319
+ #else
320
+ if (RVAL2CBOOL(gz)) {
321
+ # ifdef HAVE_LIBRSVG_RSVG_GZ_H
322
+ handle = rsvg_handle_new_gz();
323
+ # else
324
+ rb_warning("gz handling is not supported in your librsvg");
325
+ handle = rsvg_handle_new();
326
+ # endif
327
+ } else {
328
+ handle = rsvg_handle_new();
329
+ }
330
+ #endif
331
+
332
+ #ifdef RSVG_TYPE_HANDLE
333
+ G_INITIALIZE(self, handle);
334
+ #else
335
+ DATA_PTR(self) = handle;
336
+ #endif
337
+
338
+ rb_ivar_set(self, id_closed, Qfalse);
339
+ return Qnil;
340
+ }
341
+
342
+ static VALUE
343
+ rb_rsvg_handle_set_size_callback(VALUE self)
344
+ {
345
+ rb_ivar_set(self, id_callback, rb_block_proc());
346
+ rsvg_handle_set_size_callback(_SELF(self), exec_callback,
347
+ (gpointer)self, NULL);
348
+ return self;
349
+ }
350
+
351
+ static VALUE
352
+ rb_rsvg_handle_write(VALUE self, VALUE buf)
353
+ {
354
+ gboolean result;
355
+ GError *error = NULL;
356
+
357
+ result = rsvg_handle_write(_SELF(self), (const guchar*)RVAL2CSTR(buf),
358
+ RSTRING_LEN(buf), &error);
359
+
360
+ if (!result) RAISE_GERROR(error);
361
+
362
+ return CBOOL2RVAL(result);
363
+ }
364
+
365
+ static VALUE
366
+ rb_rsvg_handle_close(VALUE self)
367
+ {
368
+ gboolean result;
369
+ GError *error = NULL;
370
+
371
+ if (RVAL2CBOOL(rb_ivar_get(self, id_closed))) {
372
+ return Qnil;
373
+ }
374
+
375
+ result = rsvg_handle_close(_SELF(self), &error);
376
+
377
+ if (result) {
378
+ rb_ivar_set(self, id_closed, Qtrue);
379
+ } else {
380
+ RAISE_GERROR(error);
381
+ }
382
+
383
+ return CBOOL2RVAL(result);
384
+ }
385
+
386
+ static VALUE
387
+ rb_rsvg_handle_closed(VALUE self)
388
+ {
389
+ return rb_ivar_get(self, id_closed);
390
+ }
391
+
392
+ static VALUE
393
+ rb_rsvg_handle_get_pixbuf(int argc, VALUE *argv, VALUE self)
394
+ {
395
+ VALUE id;
396
+ VALUE rb_pixbuf;
397
+ GdkPixbuf *pixbuf = NULL;
398
+
399
+ rb_scan_args(argc, argv, "01", &id);
400
+ if (NIL_P(id)) {
401
+ pixbuf = rsvg_handle_get_pixbuf(_SELF(self));
402
+ } else {
403
+ #ifdef HAVE_RSVG_HANDLE_GET_PIXBUF_SUB
404
+ pixbuf = rsvg_handle_get_pixbuf_sub(_SELF(self),
405
+ (const char *)RVAL2CSTR(id));
406
+ #else
407
+ rb_warning("rsvg_handle_get_pixbuf_sub isn't "
408
+ "supported in your librsvg");
409
+ #endif
410
+ }
411
+
412
+ rb_pixbuf = GOBJ2RVAL(pixbuf);
413
+ if (pixbuf)
414
+ g_object_unref(pixbuf);
415
+ return rb_pixbuf;
416
+ }
417
+
418
+ #if LIBRSVG_CHECK_VERSION(2, 9, 0)
419
+ static VALUE
420
+ rb_rsvg_handle_get_base_uri(VALUE self)
421
+ {
422
+ return CSTR2RVAL(rsvg_handle_get_base_uri(_SELF(self)));
423
+ }
424
+
425
+ static VALUE
426
+ rb_rsvg_handle_set_base_uri(VALUE self, VALUE base_uri)
427
+ {
428
+ rsvg_handle_set_base_uri(_SELF(self), RVAL2CSTR(base_uri));
429
+ return self;
430
+ }
431
+ #endif
432
+
433
+ /* Convenience API */
434
+ static VALUE
435
+ rb_rsvg_pixbuf_from_file(VALUE self, VALUE file_name)
436
+ {
437
+ VALUE rb_pixbuf;
438
+ GdkPixbuf *pixbuf;
439
+ GError *error = NULL;
440
+
441
+ pixbuf = rsvg_pixbuf_from_file(RVAL2CSTR(file_name), &error);
442
+
443
+ if (error) RAISE_GERROR(error);
444
+
445
+ rb_pixbuf = GOBJ2RVAL(pixbuf);
446
+ g_object_unref(pixbuf);
447
+ return rb_pixbuf;
448
+ }
449
+
450
+ static VALUE
451
+ rb_rsvg_pixbuf_from_file_at_zoom(VALUE self, VALUE file_name,
452
+ VALUE x_zoom, VALUE y_zoom)
453
+ {
454
+ VALUE rb_pixbuf;
455
+ GdkPixbuf *pixbuf;
456
+ GError *error = NULL;
457
+
458
+ pixbuf = rsvg_pixbuf_from_file_at_zoom(RVAL2CSTR(file_name),
459
+ NUM2DBL(x_zoom),
460
+ NUM2DBL(y_zoom),
461
+ &error);
462
+
463
+ if (error) RAISE_GERROR(error);
464
+
465
+ rb_pixbuf = GOBJ2RVAL(pixbuf);
466
+ g_object_unref(pixbuf);
467
+ return rb_pixbuf;
468
+ }
469
+
470
+ static VALUE
471
+ rb_rsvg_pixbuf_from_file_at_size(VALUE self, VALUE file_name,
472
+ VALUE width, VALUE height)
473
+ {
474
+ VALUE rb_pixbuf;
475
+ GdkPixbuf *pixbuf;
476
+ GError *error = NULL;
477
+
478
+ pixbuf = rsvg_pixbuf_from_file_at_size(RVAL2CSTR(file_name),
479
+ NUM2INT(width),
480
+ NUM2INT(height),
481
+ &error);
482
+
483
+ if (error) RAISE_GERROR(error);
484
+
485
+ rb_pixbuf = GOBJ2RVAL(pixbuf);
486
+ g_object_unref(pixbuf);
487
+ return rb_pixbuf;
488
+ }
489
+
490
+ static VALUE
491
+ rb_rsvg_pixbuf_from_file_at_max_size(VALUE self, VALUE file_name,
492
+ VALUE max_width, VALUE max_height)
493
+ {
494
+ VALUE rb_pixbuf;
495
+ GdkPixbuf *pixbuf;
496
+ GError *error = NULL;
497
+
498
+ pixbuf = rsvg_pixbuf_from_file_at_max_size(RVAL2CSTR(file_name),
499
+ NUM2INT(max_width),
500
+ NUM2INT(max_height),
501
+ &error);
502
+
503
+ if (error) RAISE_GERROR(error);
504
+
505
+ rb_pixbuf = GOBJ2RVAL(pixbuf);
506
+ g_object_unref(pixbuf);
507
+ return rb_pixbuf;
508
+ }
509
+
510
+ static VALUE
511
+ rb_rsvg_pixbuf_from_file_at_zoom_with_max(VALUE self,
512
+ VALUE file_name,
513
+ VALUE x_zoom,
514
+ VALUE y_zoom,
515
+ VALUE max_width,
516
+ VALUE max_height)
517
+ {
518
+ VALUE rb_pixbuf;
519
+ GdkPixbuf *pixbuf;
520
+ GError *error = NULL;
521
+
522
+ pixbuf = rsvg_pixbuf_from_file_at_zoom_with_max(RVAL2CSTR(file_name),
523
+ NUM2DBL(x_zoom),
524
+ NUM2DBL(y_zoom),
525
+ NUM2INT(max_width),
526
+ NUM2INT(max_height),
527
+ &error);
528
+
529
+ if (error) RAISE_GERROR(error);
530
+
531
+ rb_pixbuf = GOBJ2RVAL(pixbuf);
532
+ g_object_unref(pixbuf);
533
+ return rb_pixbuf;
534
+ }
535
+
536
+ #ifdef HAVE_TYPE_RSVGDIMENSIONDATA
537
+ static VALUE
538
+ rb_rsvg_handle_get_dim(VALUE self)
539
+ {
540
+ RsvgDimensionData dim;
541
+ VALUE args[4];
542
+
543
+ rsvg_handle_get_dimensions(_SELF(self), &dim);
544
+ args[0] = INT2NUM(dim.width);
545
+ args[1] = INT2NUM(dim.height);
546
+ args[2] = rb_float_new(dim.em);
547
+ args[3] = rb_float_new(dim.ex);
548
+ return rb_class_new_instance(sizeof(args) / sizeof(VALUE),
549
+ args, cDim);
550
+ }
551
+ #endif
552
+
553
+ /* Accessibility API */
554
+ static VALUE
555
+ rb_rsvg_handle_get_title(VALUE self)
556
+ {
557
+ return CSTR2RVAL(rsvg_handle_get_title(_SELF(self)));
558
+ }
559
+
560
+ static VALUE
561
+ rb_rsvg_handle_get_desc(VALUE self)
562
+ {
563
+ return CSTR2RVAL(rsvg_handle_get_desc(_SELF(self)));
564
+ }
565
+
566
+ #ifdef HAVE_RSVG_HANDLE_GET_METADATA
567
+ static VALUE
568
+ rb_rsvg_handle_get_metadata(VALUE self)
569
+ {
570
+ return CSTR2RVAL(rsvg_handle_get_metadata(_SELF(self)));
571
+ }
572
+ #endif
573
+
574
+
575
+ #if !LIBRSVG_CHECK_VERSION(2, 11, 0)
576
+ /* Extended Convenience API */
577
+ static VALUE
578
+ rb_rsvg_pixbuf_from_file_at_size_ex(VALUE self, VALUE file_name,
579
+ VALUE width, VALUE height)
580
+ {
581
+ VALUE rb_pixbuf;
582
+ GdkPixbuf *pixbuf;
583
+ GError *error = NULL;
584
+
585
+ pixbuf = rsvg_pixbuf_from_file_at_size_ex(_SELF(self),
586
+ RVAL2CSTR(file_name),
587
+ NUM2INT(width),
588
+ NUM2INT(height),
589
+ &error);
590
+
591
+ if (error) RAISE_GERROR(error);
592
+
593
+ rb_pixbuf = GOBJ2RVAL(pixbuf);
594
+ g_object_unref(pixbuf);
595
+ return rb_pixbuf;
596
+ }
597
+
598
+ static VALUE
599
+ rb_rsvg_pixbuf_from_file_ex(VALUE self, VALUE file_name)
600
+ {
601
+ VALUE rb_pixbuf;
602
+ GdkPixbuf *pixbuf;
603
+ GError *error = NULL;
604
+
605
+ pixbuf = rsvg_pixbuf_from_file_ex(_SELF(self),
606
+ RVAL2CSTR(file_name),
607
+ &error);
608
+
609
+ if (error) RAISE_GERROR(error);
610
+
611
+ rb_pixbuf = GOBJ2RVAL(pixbuf);
612
+ g_object_unref(pixbuf);
613
+ return rb_pixbuf;
614
+ }
615
+
616
+ static VALUE
617
+ rb_rsvg_pixbuf_from_file_at_zoom_ex(VALUE self, VALUE file_name,
618
+ VALUE x_zoom, VALUE y_zoom)
619
+ {
620
+ VALUE rb_pixbuf;
621
+ GdkPixbuf *pixbuf;
622
+ GError *error = NULL;
623
+
624
+ pixbuf = rsvg_pixbuf_from_file_at_zoom_ex(_SELF(self),
625
+ RVAL2CSTR(file_name),
626
+ NUM2DBL(x_zoom),
627
+ NUM2DBL(y_zoom),
628
+ &error);
629
+
630
+ if (error) RAISE_GERROR(error);
631
+
632
+ rb_pixbuf = GOBJ2RVAL(pixbuf);
633
+ g_object_unref(pixbuf);
634
+ return rb_pixbuf;
635
+ }
636
+
637
+ static VALUE
638
+ rb_rsvg_pixbuf_from_file_at_max_size_ex(VALUE self, VALUE file_name,
639
+ VALUE max_width, VALUE max_height)
640
+ {
641
+ VALUE rb_pixbuf;
642
+ GdkPixbuf *pixbuf;
643
+ GError *error = NULL;
644
+
645
+ pixbuf = rsvg_pixbuf_from_file_at_max_size_ex(_SELF(self),
646
+ RVAL2CSTR(file_name),
647
+ NUM2INT(max_width),
648
+ NUM2INT(max_height),
649
+ &error);
650
+
651
+ if (error) RAISE_GERROR(error);
652
+
653
+ rb_pixbuf = GOBJ2RVAL(pixbuf);
654
+ g_object_unref(pixbuf);
655
+ return rb_pixbuf;
656
+ }
657
+
658
+ static VALUE
659
+ rb_rsvg_pixbuf_from_file_at_zoom_with_max_ex(VALUE self,
660
+ VALUE file_name,
661
+ VALUE x_zoom,
662
+ VALUE y_zoom,
663
+ VALUE max_width,
664
+ VALUE max_height)
665
+ {
666
+ VALUE rb_pixbuf;
667
+ GdkPixbuf *pixbuf;
668
+ GError *error = NULL;
669
+
670
+ pixbuf = rsvg_pixbuf_from_file_at_zoom_with_max_ex(_SELF(self),
671
+ RVAL2CSTR(file_name),
672
+ NUM2DBL(x_zoom),
673
+ NUM2DBL(y_zoom),
674
+ NUM2INT(max_width),
675
+ NUM2INT(max_height),
676
+ &error);
677
+
678
+ if (error) RAISE_GERROR(error);
679
+
680
+ rb_pixbuf = GOBJ2RVAL(pixbuf);
681
+ g_object_unref(pixbuf);
682
+ return rb_pixbuf;
683
+ }
684
+ #endif
685
+
686
+ static VALUE
687
+ rb_rsvg_cairo_available(VALUE self)
688
+ {
689
+ #ifdef HAVE_LIBRSVG_RSVG_CAIRO_H
690
+ return Qtrue;
691
+ #else
692
+ return Qfalse;
693
+ #endif
694
+ }
695
+
696
+ #ifdef HAVE_LIBRSVG_RSVG_CAIRO_H
697
+ static VALUE
698
+ rb_rsvg_handle_render_cairo(int argc, VALUE *argv, VALUE self)
699
+ {
700
+ VALUE cr, id;
701
+ rb_scan_args(argc, argv, "11", &cr, &id);
702
+
703
+ if (NIL_P(id)) {
704
+ rsvg_handle_render_cairo( _SELF(self), RVAL2CRCONTEXT(cr));
705
+ } else {
706
+ rsvg_handle_render_cairo_sub( _SELF(self), RVAL2CRCONTEXT(cr),
707
+ (const char *)RVAL2CSTR(id));
708
+ }
709
+
710
+ return Qnil;
711
+ }
712
+ #endif
713
+
714
+ void
715
+ Init_rsvg2(void)
716
+ {
717
+ VALUE mRSVG = rb_define_module("RSVG");
718
+
719
+ #if LIBRSVG_CHECK_VERSION(2, 9, 0)
720
+ rsvg_init();
721
+ atexit(rsvg_term);
722
+ #endif
723
+
724
+ #ifdef RSVG_TYPE_HANDLE
725
+ cHandle = G_DEF_CLASS(RSVG_TYPE_HANDLE, "Handle", mRSVG);
726
+ #else
727
+ cHandle = rb_define_class_under(mRSVG, "Handle", rb_cObject);
728
+ rb_define_alloc_func(cHandle, rb_rsvg_handle_alloc);
729
+ #endif
730
+
731
+ G_DEF_ERROR(RSVG_ERROR, "Error", mRSVG, rb_eRuntimeError, RSVG_TYPE_ERROR);
732
+
733
+ id_call = rb_intern("call");
734
+ id_callback = rb_intern("callback");
735
+ id_closed = rb_intern("closed");
736
+ id_to_s = rb_intern("to_s");
737
+
738
+ rb_define_const(mRSVG, "BINDING_VERSION",
739
+ rb_ary_new3(3,
740
+ INT2FIX(RBRSVG_MAJOR_VERSION),
741
+ INT2FIX(RBRSVG_MINOR_VERSION),
742
+ INT2FIX(RBRSVG_MICRO_VERSION)));
743
+
744
+ rb_define_const(mRSVG, "BUILD_VERSION",
745
+ rb_ary_new3(3,
746
+ INT2FIX(LIBRSVG_MAJOR_VERSION),
747
+ INT2FIX(LIBRSVG_MINOR_VERSION),
748
+ INT2FIX(LIBRSVG_MICRO_VERSION)));
749
+
750
+
751
+ rb_define_module_function(mRSVG, "set_default_dpi",
752
+ rb_rsvg_set_default_dpi, 1);
753
+ rb_define_module_function(mRSVG, "set_default_dpi_x_y",
754
+ rb_rsvg_set_default_dpi_x_y, 2);
755
+
756
+ #ifdef HAVE_TYPE_RSVGDIMENSIONDATA
757
+ cDim = rb_define_class_under(mRSVG, "DimensionData", rb_cObject);
758
+
759
+ rb_define_alloc_func(cDim, rb_rsvg_dim_alloc);
760
+ rb_define_method(cDim, "initialize", rb_rsvg_dim_initialize, -1);
761
+
762
+ rb_define_method(cDim, "width", rb_rsvg_dim_get_width, 0);
763
+ rb_define_method(cDim, "set_width", rb_rsvg_dim_set_width, 1);
764
+ rb_define_method(cDim, "height", rb_rsvg_dim_get_height, 0);
765
+ rb_define_method(cDim, "set_height", rb_rsvg_dim_set_height, 1);
766
+ rb_define_method(cDim, "em", rb_rsvg_dim_get_em, 0);
767
+ rb_define_method(cDim, "set_em", rb_rsvg_dim_set_em, 1);
768
+ rb_define_method(cDim, "ex", rb_rsvg_dim_get_ex, 0);
769
+ rb_define_method(cDim, "set_ex", rb_rsvg_dim_set_ex, 1);
770
+
771
+ rb_define_method(cDim, "to_s", rb_rsvg_dim_to_s, 0);
772
+ rb_define_method(cDim, "to_a", rb_rsvg_dim_to_a, 0);
773
+ rb_define_alias(cDim, "to_ary", "to_a");
774
+
775
+ G_DEF_SETTERS(cDim);
776
+ #endif
777
+
778
+
779
+ #if LIBRSVG_CHECK_VERSION(2, 14, 0)
780
+ rb_define_module_function(cHandle, "new_from_data",
781
+ rb_rsvg_handle_new_from_data, 1);
782
+ rb_define_module_function(cHandle, "new_from_file",
783
+ rb_rsvg_handle_new_from_file, 1);
784
+ #endif
785
+
786
+ rb_define_method(cHandle, "initialize", rb_rsvg_handle_initialize, -1);
787
+ rb_define_method(cHandle, "set_size_callback",
788
+ rb_rsvg_handle_set_size_callback, 0);
789
+ rb_define_method(cHandle, "set_dpi", rb_rsvg_handle_set_dpi, 1);
790
+ rb_define_method(cHandle, "set_dpi_x_y", rb_rsvg_handle_set_dpi_x_y, 2);
791
+ rb_define_method(cHandle, "write", rb_rsvg_handle_write, 1);
792
+ rb_define_method(cHandle, "close", rb_rsvg_handle_close, 0);
793
+ rb_define_method(cHandle, "closed?", rb_rsvg_handle_closed, 0);
794
+ rb_define_method(cHandle, "pixbuf", rb_rsvg_handle_get_pixbuf, -1);
795
+
796
+ #if LIBRSVG_CHECK_VERSION(2, 9, 0)
797
+ rb_define_method(cHandle, "base_uri", rb_rsvg_handle_get_base_uri, 0);
798
+ rb_define_method(cHandle, "set_base_uri", rb_rsvg_handle_set_base_uri, 1);
799
+ #endif
800
+
801
+ /* Convenience API */
802
+ rb_define_module_function(mRSVG, "pixbuf_from_file",
803
+ rb_rsvg_pixbuf_from_file, 1);
804
+ rb_define_module_function(mRSVG, "pixbuf_from_file_at_zoom",
805
+ rb_rsvg_pixbuf_from_file_at_zoom, 3);
806
+ rb_define_module_function(mRSVG, "pixbuf_from_file_at_size",
807
+ rb_rsvg_pixbuf_from_file_at_size, 3);
808
+ rb_define_module_function(mRSVG, "pixbuf_from_file_at_max_size",
809
+ rb_rsvg_pixbuf_from_file_at_max_size, 3);
810
+ rb_define_module_function(mRSVG, "pixbuf_from_file_at_zoom_with_max",
811
+ rb_rsvg_pixbuf_from_file_at_zoom_with_max, 5);
812
+
813
+ #ifdef HAVE_TYPE_RSVGDIMENSIONDATA
814
+ rb_define_method(cHandle, "dimensions", rb_rsvg_handle_get_dim, 0);
815
+ #endif
816
+
817
+ /* Accessibility API */
818
+ rb_define_method(cHandle, "title", rb_rsvg_handle_get_title, 0);
819
+ rb_define_method(cHandle, "desc", rb_rsvg_handle_get_desc, 0);
820
+ #ifdef HAVE_RSVG_HANDLE_GET_METADATA
821
+ rb_define_method(cHandle, "metadata", rb_rsvg_handle_get_metadata, 0);
822
+ #endif
823
+
824
+
825
+ #if !LIBRSVG_CHECK_VERSION(2, 11, 0)
826
+ /* Extended Convenience API */
827
+ rb_define_method(cHandle, "pixbuf_from_file_at_size",
828
+ rb_rsvg_pixbuf_from_file_at_size_ex, 3);
829
+ rb_define_method(cHandle, "pixbuf_from_file",
830
+ rb_rsvg_pixbuf_from_file_ex, 1);
831
+ rb_define_method(cHandle, "pixbuf_from_file_at_zoom",
832
+ rb_rsvg_pixbuf_from_file_at_zoom_ex, 3);
833
+ rb_define_method(cHandle, "pixbuf_from_file_at_max_size",
834
+ rb_rsvg_pixbuf_from_file_at_max_size_ex, 3);
835
+ rb_define_method(cHandle, "pixbuf_from_file_at_zoom_with_max",
836
+ rb_rsvg_pixbuf_from_file_at_zoom_with_max_ex, 5);
837
+ #endif
838
+
839
+ rb_define_singleton_method(mRSVG, "cairo_available?",
840
+ rb_rsvg_cairo_available, 0);
841
+ #ifdef HAVE_LIBRSVG_RSVG_CAIRO_H
842
+ rb_define_method(cHandle, "render_cairo", rb_rsvg_handle_render_cairo, -1);
843
+ #endif
844
+
845
+ G_DEF_SETTERS(cHandle);
846
+ }