rsvg2 1.0.3-x86-mingw32 → 1.1.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,222 +1,37 @@
1
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>
2
+ /*
3
+ * Copyright (C) 2011 Ruby-GNOME2 Project Team
4
+ * Copyright (C) 2005-2006 Ruby-GNOME2 Project Team
5
+ * Copyright (C) 2004 Kouhei Sutou <kou@cozmixng.org>
6
+ *
7
+ * This library is free software; you can redistribute it and/or
8
+ * modify it under the terms of the GNU Lesser General Public
9
+ * License as published by the Free Software Foundation; either
10
+ * version 2.1 of the License, or (at your option) any later version.
11
+ *
12
+ * This library is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ * Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public
18
+ * License along with this library; if not, write to the Free Software
19
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
+ * MA 02110-1301 USA
21
+ */
22
+
23
+ #include "rsvg2.h"
24
+
25
+ #define RG_TARGET_NAMESPACE mRSVG
37
26
 
38
27
  #define RBRSVG_MAJOR_VERSION RBGLIB_MAJOR_VERSION
39
28
  #define RBRSVG_MINOR_VERSION RBGLIB_MINOR_VERSION
40
29
  #define RBRSVG_MICRO_VERSION RBGLIB_MICRO_VERSION
41
30
 
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
-
31
+ void Init_rsvg2(void);
217
32
 
218
33
  static VALUE
219
- rb_rsvg_set_default_dpi(VALUE self, VALUE dpi)
34
+ rg_m_set_default_dpi(VALUE self, VALUE dpi)
220
35
  {
221
36
  #ifdef HAVE_RSVG_SET_DEFAULT_DPI
222
37
  rsvg_set_default_dpi(NUM2DBL(dpi));
@@ -227,7 +42,7 @@ rb_rsvg_set_default_dpi(VALUE self, VALUE dpi)
227
42
  }
228
43
 
229
44
  static VALUE
230
- rb_rsvg_set_default_dpi_x_y(VALUE self, VALUE dpi_x, VALUE dpi_y)
45
+ rg_m_set_default_dpi_x_y(VALUE self, VALUE dpi_x, VALUE dpi_y)
231
46
  {
232
47
  #ifdef HAVE_RSVG_SET_DEFAULT_DPI_X_Y
233
48
  rsvg_set_default_dpi_x_y(NUM2DBL(dpi_x), NUM2DBL(dpi_y));
@@ -237,202 +52,9 @@ rb_rsvg_set_default_dpi_x_y(VALUE self, VALUE dpi_x, VALUE dpi_y)
237
52
  return self;
238
53
  }
239
54
 
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
55
  /* Convenience API */
434
56
  static VALUE
435
- rb_rsvg_pixbuf_from_file(VALUE self, VALUE file_name)
57
+ rg_m_pixbuf_from_file(VALUE self, VALUE file_name)
436
58
  {
437
59
  VALUE rb_pixbuf;
438
60
  GdkPixbuf *pixbuf;
@@ -448,7 +70,7 @@ rb_rsvg_pixbuf_from_file(VALUE self, VALUE file_name)
448
70
  }
449
71
 
450
72
  static VALUE
451
- rb_rsvg_pixbuf_from_file_at_zoom(VALUE self, VALUE file_name,
73
+ rg_m_pixbuf_from_file_at_zoom(VALUE self, VALUE file_name,
452
74
  VALUE x_zoom, VALUE y_zoom)
453
75
  {
454
76
  VALUE rb_pixbuf;
@@ -468,7 +90,7 @@ rb_rsvg_pixbuf_from_file_at_zoom(VALUE self, VALUE file_name,
468
90
  }
469
91
 
470
92
  static VALUE
471
- rb_rsvg_pixbuf_from_file_at_size(VALUE self, VALUE file_name,
93
+ rg_m_pixbuf_from_file_at_size(VALUE self, VALUE file_name,
472
94
  VALUE width, VALUE height)
473
95
  {
474
96
  VALUE rb_pixbuf;
@@ -488,7 +110,7 @@ rb_rsvg_pixbuf_from_file_at_size(VALUE self, VALUE file_name,
488
110
  }
489
111
 
490
112
  static VALUE
491
- rb_rsvg_pixbuf_from_file_at_max_size(VALUE self, VALUE file_name,
113
+ rg_m_pixbuf_from_file_at_max_size(VALUE self, VALUE file_name,
492
114
  VALUE max_width, VALUE max_height)
493
115
  {
494
116
  VALUE rb_pixbuf;
@@ -508,7 +130,7 @@ rb_rsvg_pixbuf_from_file_at_max_size(VALUE self, VALUE file_name,
508
130
  }
509
131
 
510
132
  static VALUE
511
- rb_rsvg_pixbuf_from_file_at_zoom_with_max(VALUE self,
133
+ rg_m_pixbuf_from_file_at_zoom_with_max(VALUE self,
512
134
  VALUE file_name,
513
135
  VALUE x_zoom,
514
136
  VALUE y_zoom,
@@ -533,158 +155,8 @@ rb_rsvg_pixbuf_from_file_at_zoom_with_max(VALUE self,
533
155
  return rb_pixbuf;
534
156
  }
535
157
 
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
158
  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)
159
+ rg_s_cairo_available_p(VALUE self)
688
160
  {
689
161
  #ifdef HAVE_LIBRSVG_RSVG_CAIRO_H
690
162
  return Qtrue;
@@ -693,154 +165,42 @@ rb_rsvg_cairo_available(VALUE self)
693
165
  #endif
694
166
  }
695
167
 
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
168
  void
715
169
  Init_rsvg2(void)
716
170
  {
717
- VALUE mRSVG = rb_define_module("RSVG");
171
+ VALUE RG_TARGET_NAMESPACE = rb_define_module("RSVG");
718
172
 
719
173
  #if LIBRSVG_CHECK_VERSION(2, 9, 0)
720
174
  rsvg_init();
721
175
  atexit(rsvg_term);
722
176
  #endif
723
177
 
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");
178
+ G_DEF_ERROR(RSVG_ERROR, "Error", RG_TARGET_NAMESPACE, rb_eRuntimeError, RSVG_TYPE_ERROR);
737
179
 
738
- rb_define_const(mRSVG, "BINDING_VERSION",
180
+ rb_define_const(RG_TARGET_NAMESPACE, "BINDING_VERSION",
739
181
  rb_ary_new3(3,
740
182
  INT2FIX(RBRSVG_MAJOR_VERSION),
741
183
  INT2FIX(RBRSVG_MINOR_VERSION),
742
184
  INT2FIX(RBRSVG_MICRO_VERSION)));
743
185
 
744
- rb_define_const(mRSVG, "BUILD_VERSION",
186
+ rb_define_const(RG_TARGET_NAMESPACE, "BUILD_VERSION",
745
187
  rb_ary_new3(3,
746
188
  INT2FIX(LIBRSVG_MAJOR_VERSION),
747
189
  INT2FIX(LIBRSVG_MINOR_VERSION),
748
190
  INT2FIX(LIBRSVG_MICRO_VERSION)));
749
191
 
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
192
+ RG_DEF_MODFUNC(set_default_dpi, 1);
193
+ RG_DEF_MODFUNC(set_default_dpi_x_y, 2);
800
194
 
801
195
  /* 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
-
196
+ RG_DEF_MODFUNC(pixbuf_from_file, 1);
197
+ RG_DEF_MODFUNC(pixbuf_from_file_at_zoom, 3);
198
+ RG_DEF_MODFUNC(pixbuf_from_file_at_size, 3);
199
+ RG_DEF_MODFUNC(pixbuf_from_file_at_max_size, 3);
200
+ RG_DEF_MODFUNC(pixbuf_from_file_at_zoom_with_max, 5);
824
201
 
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
202
+ RG_DEF_SMETHOD_P(cairo_available, 0);
844
203
 
845
- G_DEF_SETTERS(cHandle);
204
+ Init_rsvg_handle(RG_TARGET_NAMESPACE);
205
+ Init_rsvg_dimensiondata(RG_TARGET_NAMESPACE);
846
206
  }