cairo 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of cairo might be problematic. Click here for more details.
- data/AUTHORS +4 -0
- data/COPYING +59 -0
- data/ChangeLog +792 -0
- data/GPL +340 -0
- data/NEWS +29 -0
- data/README +32 -0
- data/Rakefile +103 -0
- data/extconf.rb +115 -0
- data/pkg-config.rb +126 -0
- data/samples/pac.rb +106 -0
- data/samples/pac2.rb +177 -0
- data/samples/png.rb +43 -0
- data/samples/scalable.rb +58 -0
- data/samples/text-on-path.rb +61 -0
- data/samples/text2.rb +127 -0
- data/src/cairo.def +58 -0
- data/src/lib/cairo.rb +77 -0
- data/src/lib/cairo/context.rb +13 -0
- data/src/lib/cairo/context/circle.rb +9 -0
- data/src/lib/cairo/context/path.rb +127 -0
- data/src/lib/cairo/context/quad.rb +19 -0
- data/src/lib/cairo/context/rectangle.rb +33 -0
- data/src/rb_cairo.c +90 -0
- data/src/rb_cairo.h +180 -0
- data/src/rb_cairo_constants.c +342 -0
- data/src/rb_cairo_context.c +1403 -0
- data/src/rb_cairo_exception.c +192 -0
- data/src/rb_cairo_font_extents.c +124 -0
- data/src/rb_cairo_font_face.c +63 -0
- data/src/rb_cairo_font_options.c +195 -0
- data/src/rb_cairo_glyph.c +158 -0
- data/src/rb_cairo_matrix.c +257 -0
- data/src/rb_cairo_path.c +88 -0
- data/src/rb_cairo_pattern.c +480 -0
- data/src/rb_cairo_private.c +51 -0
- data/src/rb_cairo_private.h +23 -0
- data/src/rb_cairo_scaled_font.c +184 -0
- data/src/rb_cairo_surface.c +837 -0
- data/src/rb_cairo_text_extents.c +137 -0
- metadata +89 -0
@@ -0,0 +1,158 @@
|
|
1
|
+
/* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
|
2
|
+
/*
|
3
|
+
* Ruby Cairo Binding
|
4
|
+
*
|
5
|
+
* $Author: kou $
|
6
|
+
* $Date: 2007/03/06 12:17:34 $
|
7
|
+
*
|
8
|
+
* Copyright 2005 Øyvind Kolås <pippin@freedesktop.org>
|
9
|
+
* Copyright 2004-2005 MenTaLguY <mental@rydia.com>
|
10
|
+
*
|
11
|
+
* This file is made available under the same terms as Ruby
|
12
|
+
*
|
13
|
+
*/
|
14
|
+
|
15
|
+
|
16
|
+
#include "rb_cairo.h"
|
17
|
+
|
18
|
+
VALUE rb_cCairo_Glyph;
|
19
|
+
|
20
|
+
#define _SELF(self) (RVAL2CRGLYPH(self))
|
21
|
+
|
22
|
+
cairo_glyph_t *
|
23
|
+
rb_cairo_glyph_from_ruby_object (VALUE obj)
|
24
|
+
{
|
25
|
+
cairo_glyph_t *glyph;
|
26
|
+
if (!RTEST (rb_obj_is_kind_of (obj, rb_cCairo_Glyph)))
|
27
|
+
{
|
28
|
+
rb_raise (rb_eTypeError, "not a cairo glyph");
|
29
|
+
}
|
30
|
+
Data_Get_Struct (obj, cairo_glyph_t, glyph);
|
31
|
+
return glyph;
|
32
|
+
}
|
33
|
+
|
34
|
+
static void
|
35
|
+
cr_glyph_free (void *ptr)
|
36
|
+
{
|
37
|
+
if (ptr)
|
38
|
+
{
|
39
|
+
free (ptr);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
VALUE
|
44
|
+
rb_cairo_glyph_to_ruby_object (cairo_glyph_t *glyph)
|
45
|
+
{
|
46
|
+
if (glyph)
|
47
|
+
{
|
48
|
+
cairo_glyph_t *new_glyph = ALLOC (cairo_glyph_t);
|
49
|
+
*new_glyph = *glyph;
|
50
|
+
return Data_Wrap_Struct (rb_cCairo_Glyph, NULL, cr_glyph_free, new_glyph);
|
51
|
+
}
|
52
|
+
else
|
53
|
+
{
|
54
|
+
return Qnil;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
static VALUE
|
59
|
+
cr_glyph_allocate (VALUE klass)
|
60
|
+
{
|
61
|
+
return Data_Wrap_Struct (klass, NULL, cr_glyph_free, NULL);
|
62
|
+
}
|
63
|
+
|
64
|
+
static VALUE
|
65
|
+
cr_glyph_initialize (VALUE self, VALUE index, VALUE x, VALUE y)
|
66
|
+
{
|
67
|
+
cairo_glyph_t *glyph;
|
68
|
+
|
69
|
+
glyph = ALLOC (cairo_glyph_t);
|
70
|
+
glyph->index = NUM2ULONG (index);
|
71
|
+
glyph->x = NUM2DBL (x);
|
72
|
+
glyph->y = NUM2DBL (y);
|
73
|
+
|
74
|
+
DATA_PTR (self) = glyph;
|
75
|
+
return Qnil;
|
76
|
+
}
|
77
|
+
|
78
|
+
static VALUE
|
79
|
+
cr_glyph_index (VALUE self)
|
80
|
+
{
|
81
|
+
return ULONG2NUM (_SELF(self)->index);
|
82
|
+
}
|
83
|
+
|
84
|
+
static VALUE
|
85
|
+
cr_glyph_x (VALUE self)
|
86
|
+
{
|
87
|
+
return rb_float_new (_SELF(self)->x);
|
88
|
+
}
|
89
|
+
|
90
|
+
static VALUE
|
91
|
+
cr_glyph_y (VALUE self)
|
92
|
+
{
|
93
|
+
return rb_float_new (_SELF(self)->y);
|
94
|
+
}
|
95
|
+
|
96
|
+
static VALUE
|
97
|
+
cr_glyph_set_index (VALUE self, VALUE index)
|
98
|
+
{
|
99
|
+
_SELF(self)->index = NUM2ULONG (index);
|
100
|
+
return self;
|
101
|
+
}
|
102
|
+
|
103
|
+
static VALUE
|
104
|
+
cr_glyph_set_x (VALUE self, VALUE x)
|
105
|
+
{
|
106
|
+
_SELF(self)->x = NUM2DBL (x);
|
107
|
+
return self;
|
108
|
+
}
|
109
|
+
|
110
|
+
static VALUE
|
111
|
+
cr_glyph_set_y (VALUE self, VALUE y)
|
112
|
+
{
|
113
|
+
_SELF(self)->y = NUM2DBL (y);
|
114
|
+
return self;
|
115
|
+
}
|
116
|
+
|
117
|
+
static VALUE
|
118
|
+
cr_glyph_to_s (VALUE self)
|
119
|
+
{
|
120
|
+
VALUE ret;
|
121
|
+
|
122
|
+
ret = rb_str_new2 ("#<");
|
123
|
+
rb_str_cat2 (ret, rb_class2name (CLASS_OF (self)));
|
124
|
+
rb_str_cat2 (ret, ": ");
|
125
|
+
rb_str_cat2 (ret, "index=");
|
126
|
+
rb_str_concat (ret, rb_inspect (cr_glyph_index (self)));
|
127
|
+
rb_str_cat2 (ret, ", ");
|
128
|
+
rb_str_cat2 (ret, "x=");
|
129
|
+
rb_str_concat (ret, rb_inspect (cr_glyph_x (self)));
|
130
|
+
rb_str_cat2 (ret, ", ");
|
131
|
+
rb_str_cat2 (ret, "y=");
|
132
|
+
rb_str_concat (ret, rb_inspect (cr_glyph_y (self)));
|
133
|
+
rb_str_cat2 (ret, ">");
|
134
|
+
|
135
|
+
return ret;
|
136
|
+
}
|
137
|
+
|
138
|
+
|
139
|
+
void
|
140
|
+
Init_cairo_glyph (void)
|
141
|
+
{
|
142
|
+
rb_cCairo_Glyph = rb_define_class_under (rb_mCairo, "Glyph", rb_cObject);
|
143
|
+
|
144
|
+
rb_define_alloc_func (rb_cCairo_Glyph, cr_glyph_allocate);
|
145
|
+
|
146
|
+
rb_define_method (rb_cCairo_Glyph, "initialize", cr_glyph_initialize, 3);
|
147
|
+
|
148
|
+
rb_define_method (rb_cCairo_Glyph, "index", cr_glyph_index, 0);
|
149
|
+
rb_define_method (rb_cCairo_Glyph, "x", cr_glyph_x, 0);
|
150
|
+
rb_define_method (rb_cCairo_Glyph, "y", cr_glyph_y, 0);
|
151
|
+
rb_define_method (rb_cCairo_Glyph, "set_index", cr_glyph_set_index, 1);
|
152
|
+
rb_define_method (rb_cCairo_Glyph, "set_x", cr_glyph_set_x, 1);
|
153
|
+
rb_define_method (rb_cCairo_Glyph, "set_y", cr_glyph_set_y, 1);
|
154
|
+
|
155
|
+
rb_define_method (rb_cCairo_Glyph, "to_s", cr_glyph_to_s, 0);
|
156
|
+
|
157
|
+
RB_CAIRO_DEF_SETTERS (rb_cCairo_Glyph);
|
158
|
+
}
|
@@ -0,0 +1,257 @@
|
|
1
|
+
/* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
|
2
|
+
/*
|
3
|
+
* Ruby Cairo Binding
|
4
|
+
*
|
5
|
+
* $Author: kou $
|
6
|
+
* $Date: 2007/03/06 12:17:34 $
|
7
|
+
*
|
8
|
+
* Copyright 2005 Øyvind Kolås <pippin@freedesktop.org>
|
9
|
+
* Copyright 2004-2005 MenTaLguY <mental@rydia.com>
|
10
|
+
*
|
11
|
+
* This file is made available under the same terms as Ruby
|
12
|
+
*
|
13
|
+
*/
|
14
|
+
|
15
|
+
|
16
|
+
#include "rb_cairo.h"
|
17
|
+
#include "rb_cairo_private.h"
|
18
|
+
|
19
|
+
VALUE rb_cCairo_Matrix;
|
20
|
+
|
21
|
+
#define _SELF (RVAL2CRMATRIX(self))
|
22
|
+
|
23
|
+
cairo_matrix_t *
|
24
|
+
rb_cairo_matrix_from_ruby_object (VALUE obj)
|
25
|
+
{
|
26
|
+
cairo_matrix_t *matrix;
|
27
|
+
if (!RTEST (rb_obj_is_kind_of (obj, rb_cCairo_Matrix)))
|
28
|
+
{
|
29
|
+
rb_raise (rb_eTypeError, "not a cairo matrix");
|
30
|
+
}
|
31
|
+
Data_Get_Struct (obj, cairo_matrix_t, matrix);
|
32
|
+
return matrix;
|
33
|
+
}
|
34
|
+
|
35
|
+
static void
|
36
|
+
cr_matrix_free (void *ptr)
|
37
|
+
{
|
38
|
+
if (ptr)
|
39
|
+
{
|
40
|
+
free ((cairo_matrix_t *) ptr);
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
VALUE
|
45
|
+
rb_cairo_matrix_to_ruby_object (cairo_matrix_t *matrix)
|
46
|
+
{
|
47
|
+
if (matrix)
|
48
|
+
{
|
49
|
+
cairo_matrix_t *new_matrix = ALLOC (cairo_matrix_t);
|
50
|
+
*new_matrix = *matrix;
|
51
|
+
return Data_Wrap_Struct (rb_cCairo_Matrix, NULL,
|
52
|
+
cr_matrix_free, new_matrix);
|
53
|
+
}
|
54
|
+
else
|
55
|
+
{
|
56
|
+
return Qnil;
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
static VALUE
|
61
|
+
cr_matrix_allocate (VALUE klass)
|
62
|
+
{
|
63
|
+
return Data_Wrap_Struct (klass, NULL, cr_matrix_free, NULL);
|
64
|
+
}
|
65
|
+
|
66
|
+
static VALUE
|
67
|
+
cr_matrix_initialize (VALUE self,
|
68
|
+
VALUE xx, VALUE yx,
|
69
|
+
VALUE xy, VALUE yy,
|
70
|
+
VALUE x0, VALUE y0)
|
71
|
+
{
|
72
|
+
cairo_matrix_t *matrix = ALLOC (cairo_matrix_t);
|
73
|
+
|
74
|
+
cairo_matrix_init (matrix,
|
75
|
+
NUM2DBL (xx), NUM2DBL (yx),
|
76
|
+
NUM2DBL (xy), NUM2DBL (yy),
|
77
|
+
NUM2DBL (x0), NUM2DBL (y0));
|
78
|
+
DATA_PTR (self) = matrix;
|
79
|
+
return Qnil;
|
80
|
+
}
|
81
|
+
|
82
|
+
static VALUE
|
83
|
+
cr_matrix_init_identity (VALUE self)
|
84
|
+
{
|
85
|
+
cairo_matrix_t matrix;
|
86
|
+
cairo_matrix_init_identity (&matrix);
|
87
|
+
return CRMATRIX2RVAL (&matrix);
|
88
|
+
}
|
89
|
+
|
90
|
+
static VALUE
|
91
|
+
cr_matrix_init_translate (VALUE self, VALUE tx, VALUE ty)
|
92
|
+
{
|
93
|
+
cairo_matrix_t matrix;
|
94
|
+
cairo_matrix_init_translate (&matrix, NUM2DBL (tx), NUM2DBL (ty));
|
95
|
+
return CRMATRIX2RVAL (&matrix);
|
96
|
+
}
|
97
|
+
|
98
|
+
static VALUE
|
99
|
+
cr_matrix_init_scale (VALUE self, VALUE sx, VALUE sy)
|
100
|
+
{
|
101
|
+
cairo_matrix_t matrix;
|
102
|
+
cairo_matrix_init_scale (&matrix, NUM2DBL (sx), NUM2DBL (sy));
|
103
|
+
return CRMATRIX2RVAL (&matrix);
|
104
|
+
}
|
105
|
+
|
106
|
+
static VALUE
|
107
|
+
cr_matrix_init_rotate (VALUE self, VALUE radius)
|
108
|
+
{
|
109
|
+
cairo_matrix_t matrix;
|
110
|
+
cairo_matrix_init_rotate (&matrix, NUM2DBL (radius));
|
111
|
+
return CRMATRIX2RVAL (&matrix);
|
112
|
+
}
|
113
|
+
|
114
|
+
static VALUE
|
115
|
+
cr_matrix_identity (VALUE self)
|
116
|
+
{
|
117
|
+
cairo_matrix_init_identity (_SELF);
|
118
|
+
return self;
|
119
|
+
}
|
120
|
+
|
121
|
+
static VALUE
|
122
|
+
cr_matrix_translate (VALUE self, VALUE tx, VALUE ty)
|
123
|
+
{
|
124
|
+
cairo_matrix_translate (_SELF, NUM2DBL (tx), NUM2DBL (ty));
|
125
|
+
return self;
|
126
|
+
}
|
127
|
+
|
128
|
+
static VALUE
|
129
|
+
cr_matrix_scale (VALUE self, VALUE sx, VALUE sy)
|
130
|
+
{
|
131
|
+
cairo_matrix_scale (_SELF, NUM2DBL (sx), NUM2DBL (sy));
|
132
|
+
return self;
|
133
|
+
}
|
134
|
+
|
135
|
+
static VALUE
|
136
|
+
cr_matrix_rotate (VALUE self, VALUE radians)
|
137
|
+
{
|
138
|
+
cairo_matrix_rotate (_SELF, NUM2DBL (radians));
|
139
|
+
return self;
|
140
|
+
}
|
141
|
+
|
142
|
+
static VALUE
|
143
|
+
cr_matrix_invert (VALUE self)
|
144
|
+
{
|
145
|
+
rb_cairo_check_status (cairo_matrix_invert (_SELF));
|
146
|
+
return self;
|
147
|
+
}
|
148
|
+
|
149
|
+
static VALUE
|
150
|
+
cr_matrix_multiply (VALUE self, VALUE other)
|
151
|
+
{
|
152
|
+
cairo_matrix_multiply (_SELF, _SELF, RVAL2CRMATRIX (other));
|
153
|
+
return self;
|
154
|
+
}
|
155
|
+
|
156
|
+
static VALUE
|
157
|
+
cr_matrix_transform_distance (VALUE self, VALUE dx, VALUE dy)
|
158
|
+
{
|
159
|
+
double pair[2];
|
160
|
+
pair[0] = NUM2DBL (dx);
|
161
|
+
pair[1] = NUM2DBL (dy);
|
162
|
+
cairo_matrix_transform_distance (_SELF, pair, pair + 1);
|
163
|
+
return rb_cairo__float_array (pair, 2);
|
164
|
+
}
|
165
|
+
|
166
|
+
static VALUE
|
167
|
+
cr_matrix_transform_point (VALUE self, VALUE x, VALUE y)
|
168
|
+
{
|
169
|
+
double pair[2];
|
170
|
+
pair[0] = NUM2DBL (x);
|
171
|
+
pair[1] = NUM2DBL (y);
|
172
|
+
cairo_matrix_transform_point (_SELF, pair, pair + 1);
|
173
|
+
return rb_cairo__float_array (pair, 2);
|
174
|
+
}
|
175
|
+
|
176
|
+
|
177
|
+
/* Utilities */
|
178
|
+
static VALUE
|
179
|
+
cr_matrix_set (VALUE self,
|
180
|
+
VALUE xx, VALUE yx,
|
181
|
+
VALUE xy, VALUE yy,
|
182
|
+
VALUE x0, VALUE y0)
|
183
|
+
{
|
184
|
+
cairo_matrix_init (_SELF,
|
185
|
+
NUM2DBL (xx), NUM2DBL (yx),
|
186
|
+
NUM2DBL (xy), NUM2DBL (yy),
|
187
|
+
NUM2DBL (x0), NUM2DBL (y0));
|
188
|
+
return self;
|
189
|
+
}
|
190
|
+
|
191
|
+
static VALUE
|
192
|
+
cr_matrix_to_a (VALUE self)
|
193
|
+
{
|
194
|
+
cairo_matrix_t *matrix = _SELF;
|
195
|
+
double affine[6];
|
196
|
+
affine[0] = matrix->xx;
|
197
|
+
affine[1] = matrix->yx;
|
198
|
+
affine[2] = matrix->xy;
|
199
|
+
affine[3] = matrix->yy;
|
200
|
+
affine[4] = matrix->x0;
|
201
|
+
affine[5] = matrix->y0;
|
202
|
+
return rb_cairo__float_array (affine, 6);
|
203
|
+
}
|
204
|
+
|
205
|
+
static VALUE
|
206
|
+
cr_matrix_to_s(VALUE self)
|
207
|
+
{
|
208
|
+
VALUE ret;
|
209
|
+
|
210
|
+
ret = rb_str_new2 ("#<");
|
211
|
+
rb_str_cat2 (ret, rb_class2name (CLASS_OF (self)));
|
212
|
+
rb_str_cat2 (ret, ":");
|
213
|
+
rb_str_concat (ret, rb_inspect (cr_matrix_to_a (self)));
|
214
|
+
rb_str_cat2 (ret, ">");
|
215
|
+
|
216
|
+
return ret;
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
void
|
221
|
+
Init_cairo_matrix (void)
|
222
|
+
{
|
223
|
+
rb_cCairo_Matrix =
|
224
|
+
rb_define_class_under (rb_mCairo, "Matrix", rb_cObject);
|
225
|
+
|
226
|
+
rb_define_alloc_func (rb_cCairo_Matrix, cr_matrix_allocate);
|
227
|
+
|
228
|
+
rb_define_singleton_method (rb_cCairo_Matrix, "identity",
|
229
|
+
cr_matrix_init_identity, 0);
|
230
|
+
rb_define_singleton_method (rb_cCairo_Matrix, "translate",
|
231
|
+
cr_matrix_init_translate, 2);
|
232
|
+
rb_define_singleton_method (rb_cCairo_Matrix, "scale",
|
233
|
+
cr_matrix_init_scale, 2);
|
234
|
+
rb_define_singleton_method (rb_cCairo_Matrix, "rotate",
|
235
|
+
cr_matrix_init_rotate, 1);
|
236
|
+
|
237
|
+
rb_define_method (rb_cCairo_Matrix, "initialize", cr_matrix_initialize, 6);
|
238
|
+
|
239
|
+
rb_define_method (rb_cCairo_Matrix, "identity!", cr_matrix_identity, 0);
|
240
|
+
rb_define_method (rb_cCairo_Matrix, "translate!", cr_matrix_translate, 2);
|
241
|
+
rb_define_method (rb_cCairo_Matrix, "scale!", cr_matrix_scale, 2);
|
242
|
+
rb_define_method (rb_cCairo_Matrix, "rotate!", cr_matrix_rotate, 1);
|
243
|
+
rb_define_method (rb_cCairo_Matrix, "invert!", cr_matrix_invert, 0);
|
244
|
+
rb_define_method (rb_cCairo_Matrix, "multiply!", cr_matrix_multiply, 1);
|
245
|
+
rb_define_method (rb_cCairo_Matrix, "matrix_distance",
|
246
|
+
cr_matrix_transform_distance, 2);
|
247
|
+
rb_define_method (rb_cCairo_Matrix, "transform_point",
|
248
|
+
cr_matrix_transform_point, 2);
|
249
|
+
|
250
|
+
/* Utilities */
|
251
|
+
rb_define_method (rb_cCairo_Matrix, "set", cr_matrix_set, 6);
|
252
|
+
rb_define_method (rb_cCairo_Matrix, "to_a", cr_matrix_to_a, 0);
|
253
|
+
rb_define_method (rb_cCairo_Matrix, "to_s", cr_matrix_to_s, 0);
|
254
|
+
|
255
|
+
|
256
|
+
RB_CAIRO_DEF_SETTERS (rb_cCairo_Matrix);
|
257
|
+
}
|
data/src/rb_cairo_path.c
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
/* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
|
2
|
+
/*
|
3
|
+
* Ruby Cairo Binding
|
4
|
+
*
|
5
|
+
* $Author: kou $
|
6
|
+
* $Date: 2007/03/06 12:17:34 $
|
7
|
+
*
|
8
|
+
* Copyright 2005 Kouhei Sutou <kou@cozmixng.org>
|
9
|
+
*
|
10
|
+
* This file is made available under the same terms as Ruby
|
11
|
+
*
|
12
|
+
*/
|
13
|
+
|
14
|
+
#include "rb_cairo.h"
|
15
|
+
|
16
|
+
#define _SELF(self) (RVAL2CRPATH (self))
|
17
|
+
|
18
|
+
VALUE rb_cCairo_Path;
|
19
|
+
|
20
|
+
cairo_path_t *
|
21
|
+
rb_cairo_path_from_ruby_object (VALUE obj)
|
22
|
+
{
|
23
|
+
cairo_path_t *path;
|
24
|
+
if (!RTEST (rb_obj_is_kind_of (obj, rb_cCairo_Path)))
|
25
|
+
{
|
26
|
+
rb_raise (rb_eTypeError, "not a cairo path");
|
27
|
+
}
|
28
|
+
Data_Get_Struct (obj, cairo_path_t, path);
|
29
|
+
return path;
|
30
|
+
}
|
31
|
+
|
32
|
+
static void
|
33
|
+
cr_path_free (void *ptr)
|
34
|
+
{
|
35
|
+
if (ptr)
|
36
|
+
{
|
37
|
+
cairo_path_destroy ((cairo_path_t *)ptr);
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
VALUE
|
42
|
+
rb_cairo_path_to_ruby_object (cairo_path_t *path)
|
43
|
+
{
|
44
|
+
if (path)
|
45
|
+
{
|
46
|
+
return Data_Wrap_Struct (rb_cCairo_Path, NULL, cr_path_free, path);
|
47
|
+
}
|
48
|
+
else
|
49
|
+
{
|
50
|
+
return Qnil;
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
static VALUE
|
55
|
+
cr_path_each (VALUE self)
|
56
|
+
{
|
57
|
+
cairo_path_t *path = _SELF(self);
|
58
|
+
int i, j;
|
59
|
+
|
60
|
+
for (i = 0; i < path->num_data; i += path->data[i].header.length)
|
61
|
+
{
|
62
|
+
cairo_path_data_t *data = &(path->data[i]);
|
63
|
+
VALUE points;
|
64
|
+
|
65
|
+
points = rb_ary_new ();
|
66
|
+
|
67
|
+
for (j = 1; j < data->header.length; j++)
|
68
|
+
{
|
69
|
+
rb_ary_push (points, rb_ary_new3 (2,
|
70
|
+
rb_float_new (data[j].point.x),
|
71
|
+
rb_float_new (data[j].point.y)));
|
72
|
+
}
|
73
|
+
rb_yield_values (2, INT2FIX (data->header.type), points);
|
74
|
+
}
|
75
|
+
|
76
|
+
return self;
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
void
|
81
|
+
Init_cairo_path (void)
|
82
|
+
{
|
83
|
+
rb_cCairo_Path = rb_define_class_under (rb_mCairo, "Path", rb_cObject);
|
84
|
+
|
85
|
+
rb_include_module (rb_cCairo_Path, rb_mEnumerable);
|
86
|
+
|
87
|
+
rb_define_method (rb_cCairo_Path, "each", cr_path_each, 0);
|
88
|
+
}
|