cairo 1.4.1 → 1.5.0
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/ChangeLog +259 -0
- data/NEWS +32 -0
- data/README +5 -0
- data/Rakefile +88 -4
- data/misc/update-colors.rb +143 -0
- data/samples/.#blur.rb.1.1 +36 -0
- data/samples/blur.rb +47 -0
- data/samples/pac.rb +22 -28
- data/samples/pac2.rb +26 -32
- data/samples/png.rb +34 -31
- data/samples/scalable.rb +24 -26
- data/samples/text-on-path.rb +6 -7
- data/samples/text2.rb +16 -18
- data/src/cairo.def +31 -0
- data/src/lib/cairo.rb +25 -7
- data/src/lib/cairo/color.rb +255 -0
- data/src/lib/cairo/colors.rb +656 -0
- data/src/lib/cairo/constants.rb +21 -0
- data/src/lib/cairo/context.rb +16 -2
- data/src/lib/cairo/context/blur.rb +45 -0
- data/src/lib/cairo/context/circle.rb +2 -2
- data/src/lib/cairo/context/color.rb +11 -0
- data/src/lib/cairo/context/path.rb +17 -28
- data/src/lib/cairo/path.rb +15 -0
- data/src/lib/cairo/point.rb +7 -0
- data/src/rb_cairo.c +8 -17
- data/src/rb_cairo.h +44 -3
- data/src/rb_cairo_constants.c +129 -137
- data/src/rb_cairo_context.c +224 -112
- data/src/rb_cairo_font_extents.c +4 -3
- data/src/rb_cairo_font_face.c +3 -10
- data/src/rb_cairo_font_options.c +6 -4
- data/src/rb_cairo_glyph.c +4 -3
- data/src/rb_cairo_matrix.c +97 -4
- data/src/rb_cairo_path.c +408 -24
- data/src/rb_cairo_pattern.c +130 -70
- data/src/rb_cairo_private.c +40 -13
- data/src/rb_cairo_private.h +40 -2
- data/src/rb_cairo_scaled_font.c +3 -10
- data/src/rb_cairo_surface.c +172 -50
- data/src/rb_cairo_text_extents.c +3 -2
- metadata +15 -5
- data/src/lib/cairo/context/quad.rb +0 -19
data/src/rb_cairo_font_extents.c
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
* Ruby Cairo Binding
|
4
4
|
*
|
5
5
|
* $Author: kou $
|
6
|
-
* $Date: 2007/03
|
6
|
+
* $Date: 2007/05/03 02:47:39 $
|
7
7
|
*
|
8
8
|
* Copyright 2005 Øyvind Kolås <pippin@freedesktop.org>
|
9
9
|
* Copyright 2004-2005 MenTaLguY <mental@rydia.com>
|
@@ -13,6 +13,7 @@
|
|
13
13
|
*/
|
14
14
|
|
15
15
|
#include "rb_cairo.h"
|
16
|
+
#include "rb_cairo_private.h"
|
16
17
|
|
17
18
|
VALUE rb_cCairo_FontExtents;
|
18
19
|
|
@@ -22,7 +23,7 @@ cairo_font_extents_t *
|
|
22
23
|
rb_cairo_font_extents_from_ruby_object (VALUE obj)
|
23
24
|
{
|
24
25
|
cairo_font_extents_t *extents;
|
25
|
-
if (!
|
26
|
+
if (!rb_cairo__is_kind_of (obj, rb_cCairo_FontExtents))
|
26
27
|
{
|
27
28
|
rb_raise (rb_eTypeError, "not a cairo font extents");
|
28
29
|
}
|
@@ -98,7 +99,7 @@ cr_font_extents_to_s (VALUE self)
|
|
98
99
|
rb_str_cat2 (ret, "max_y_advance=");
|
99
100
|
rb_str_concat (ret, rb_inspect (cr_font_extents_max_y_advance (self)));
|
100
101
|
rb_str_cat2 (ret, ">");
|
101
|
-
|
102
|
+
|
102
103
|
return ret;
|
103
104
|
}
|
104
105
|
|
data/src/rb_cairo_font_face.c
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
* Ruby Cairo Binding
|
4
4
|
*
|
5
5
|
* $Author: kou $
|
6
|
-
* $Date: 2007/
|
6
|
+
* $Date: 2007/05/20 09:25:37 $
|
7
7
|
*
|
8
8
|
* Copyright 2005 Øyvind Kolås <pippin@freedesktop.org>
|
9
9
|
* Copyright 2004-2005 MenTaLguY <mental@rydia.com>
|
@@ -14,6 +14,7 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
#include "rb_cairo.h"
|
17
|
+
#include "rb_cairo_private.h"
|
17
18
|
|
18
19
|
VALUE rb_cCairo_FontFace;
|
19
20
|
|
@@ -23,7 +24,7 @@ cairo_font_face_t *
|
|
23
24
|
rb_cairo_font_face_from_ruby_object (VALUE obj)
|
24
25
|
{
|
25
26
|
cairo_font_face_t *face;
|
26
|
-
if (!
|
27
|
+
if (!rb_cairo__is_kind_of (obj, rb_cCairo_FontFace))
|
27
28
|
{
|
28
29
|
rb_raise (rb_eTypeError, "not a cairo font face");
|
29
30
|
}
|
@@ -46,18 +47,10 @@ rb_cairo_font_face_to_ruby_object (cairo_font_face_t *face)
|
|
46
47
|
}
|
47
48
|
}
|
48
49
|
|
49
|
-
static VALUE
|
50
|
-
cr_font_face_get_type (VALUE self)
|
51
|
-
{
|
52
|
-
return INT2NUM ( cairo_font_face_get_type (_SELF));
|
53
|
-
}
|
54
|
-
|
55
50
|
|
56
51
|
void
|
57
52
|
Init_cairo_font (void)
|
58
53
|
{
|
59
54
|
rb_cCairo_FontFace =
|
60
55
|
rb_define_class_under (rb_mCairo, "FontFace", rb_cObject);
|
61
|
-
|
62
|
-
rb_define_method (rb_cCairo_FontFace, "type", cr_font_face_get_type, 0);
|
63
56
|
}
|
data/src/rb_cairo_font_options.c
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
* Ruby Cairo Binding
|
4
4
|
*
|
5
5
|
* $Author: kou $
|
6
|
-
* $Date: 2007/
|
6
|
+
* $Date: 2007/05/26 15:13:25 $
|
7
7
|
*
|
8
8
|
* Copyright 2005 Kouhei Sutou <kou@cozmixng.org>
|
9
9
|
*
|
@@ -12,6 +12,7 @@
|
|
12
12
|
*/
|
13
13
|
|
14
14
|
#include "rb_cairo.h"
|
15
|
+
#include "rb_cairo_private.h"
|
15
16
|
|
16
17
|
#define _SELF(self) (RVAL2CRFONTOPTIONS(self))
|
17
18
|
|
@@ -27,7 +28,7 @@ cairo_font_options_t *
|
|
27
28
|
rb_cairo_font_options_from_ruby_object (VALUE obj)
|
28
29
|
{
|
29
30
|
cairo_font_options_t *options;
|
30
|
-
if (!
|
31
|
+
if (!rb_cairo__is_kind_of (obj, rb_cCairo_FontOptions))
|
31
32
|
{
|
32
33
|
rb_raise (rb_eTypeError, "not a cairo font options");
|
33
34
|
}
|
@@ -95,7 +96,7 @@ cr_options_merge (VALUE self, VALUE other)
|
|
95
96
|
static VALUE
|
96
97
|
cr_options_equal (VALUE self, VALUE other)
|
97
98
|
{
|
98
|
-
return cairo_font_options_equal (_SELF (self), _SELF (other))
|
99
|
+
return CBOOL2RVAL (cairo_font_options_equal (_SELF (self), _SELF (other)));
|
99
100
|
}
|
100
101
|
|
101
102
|
static VALUE
|
@@ -171,7 +172,8 @@ Init_cairo_font_options (void)
|
|
171
172
|
rb_define_method (rb_cCairo_FontOptions, "initialize", cr_options_create, 0);
|
172
173
|
|
173
174
|
rb_define_method (rb_cCairo_FontOptions, "dup", cr_options_copy, 0);
|
174
|
-
rb_define_method (rb_cCairo_FontOptions, "merge", cr_options_merge, 1);
|
175
|
+
rb_define_method (rb_cCairo_FontOptions, "merge!", cr_options_merge, 1);
|
176
|
+
rb_define_alias (rb_cCairo_FontOptions, "update", "merge!");
|
175
177
|
rb_define_method (rb_cCairo_FontOptions, "eql?", cr_options_equal, 1);
|
176
178
|
rb_define_method (rb_cCairo_FontOptions, "hash", cr_options_hash, 0);
|
177
179
|
rb_define_method (rb_cCairo_FontOptions, "set_antialias",
|
data/src/rb_cairo_glyph.c
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
* Ruby Cairo Binding
|
4
4
|
*
|
5
5
|
* $Author: kou $
|
6
|
-
* $Date: 2007/03
|
6
|
+
* $Date: 2007/05/03 02:47:39 $
|
7
7
|
*
|
8
8
|
* Copyright 2005 Øyvind Kolås <pippin@freedesktop.org>
|
9
9
|
* Copyright 2004-2005 MenTaLguY <mental@rydia.com>
|
@@ -14,6 +14,7 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
#include "rb_cairo.h"
|
17
|
+
#include "rb_cairo_private.h"
|
17
18
|
|
18
19
|
VALUE rb_cCairo_Glyph;
|
19
20
|
|
@@ -23,7 +24,7 @@ cairo_glyph_t *
|
|
23
24
|
rb_cairo_glyph_from_ruby_object (VALUE obj)
|
24
25
|
{
|
25
26
|
cairo_glyph_t *glyph;
|
26
|
-
if (!
|
27
|
+
if (!rb_cairo__is_kind_of (obj, rb_cCairo_Glyph))
|
27
28
|
{
|
28
29
|
rb_raise (rb_eTypeError, "not a cairo glyph");
|
29
30
|
}
|
@@ -131,7 +132,7 @@ cr_glyph_to_s (VALUE self)
|
|
131
132
|
rb_str_cat2 (ret, "y=");
|
132
133
|
rb_str_concat (ret, rb_inspect (cr_glyph_y (self)));
|
133
134
|
rb_str_cat2 (ret, ">");
|
134
|
-
|
135
|
+
|
135
136
|
return ret;
|
136
137
|
}
|
137
138
|
|
data/src/rb_cairo_matrix.c
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
* Ruby Cairo Binding
|
4
4
|
*
|
5
5
|
* $Author: kou $
|
6
|
-
* $Date: 2007/
|
6
|
+
* $Date: 2007/05/21 11:54:44 $
|
7
7
|
*
|
8
8
|
* Copyright 2005 Øyvind Kolås <pippin@freedesktop.org>
|
9
9
|
* Copyright 2004-2005 MenTaLguY <mental@rydia.com>
|
@@ -24,7 +24,7 @@ cairo_matrix_t *
|
|
24
24
|
rb_cairo_matrix_from_ruby_object (VALUE obj)
|
25
25
|
{
|
26
26
|
cairo_matrix_t *matrix;
|
27
|
-
if (!
|
27
|
+
if (!rb_cairo__is_kind_of (obj, rb_cCairo_Matrix))
|
28
28
|
{
|
29
29
|
rb_raise (rb_eTypeError, "not a cairo matrix");
|
30
30
|
}
|
@@ -55,7 +55,7 @@ rb_cairo_matrix_to_ruby_object (cairo_matrix_t *matrix)
|
|
55
55
|
{
|
56
56
|
return Qnil;
|
57
57
|
}
|
58
|
-
}
|
58
|
+
}
|
59
59
|
|
60
60
|
static VALUE
|
61
61
|
cr_matrix_allocate (VALUE klass)
|
@@ -174,6 +174,85 @@ cr_matrix_transform_point (VALUE self, VALUE x, VALUE y)
|
|
174
174
|
}
|
175
175
|
|
176
176
|
|
177
|
+
/* Accessors */
|
178
|
+
static VALUE
|
179
|
+
cr_matrix_get_xx (VALUE self)
|
180
|
+
{
|
181
|
+
return rb_float_new (_SELF->xx);
|
182
|
+
}
|
183
|
+
|
184
|
+
static VALUE
|
185
|
+
cr_matrix_set_xx (VALUE self, VALUE xx)
|
186
|
+
{
|
187
|
+
_SELF->xx = NUM2DBL (xx);
|
188
|
+
return Qnil;
|
189
|
+
}
|
190
|
+
|
191
|
+
static VALUE
|
192
|
+
cr_matrix_get_yx (VALUE self)
|
193
|
+
{
|
194
|
+
return rb_float_new (_SELF->yx);
|
195
|
+
}
|
196
|
+
|
197
|
+
static VALUE
|
198
|
+
cr_matrix_set_yx (VALUE self, VALUE yx)
|
199
|
+
{
|
200
|
+
_SELF->yx = NUM2DBL (yx);
|
201
|
+
return Qnil;
|
202
|
+
}
|
203
|
+
|
204
|
+
static VALUE
|
205
|
+
cr_matrix_get_xy (VALUE self)
|
206
|
+
{
|
207
|
+
return rb_float_new (_SELF->xy);
|
208
|
+
}
|
209
|
+
|
210
|
+
static VALUE
|
211
|
+
cr_matrix_set_xy (VALUE self, VALUE xy)
|
212
|
+
{
|
213
|
+
_SELF->xy = NUM2DBL (xy);
|
214
|
+
return Qnil;
|
215
|
+
}
|
216
|
+
|
217
|
+
static VALUE
|
218
|
+
cr_matrix_get_yy (VALUE self)
|
219
|
+
{
|
220
|
+
return rb_float_new (_SELF->yy);
|
221
|
+
}
|
222
|
+
|
223
|
+
static VALUE
|
224
|
+
cr_matrix_set_yy (VALUE self, VALUE yy)
|
225
|
+
{
|
226
|
+
_SELF->yy = NUM2DBL (yy);
|
227
|
+
return Qnil;
|
228
|
+
}
|
229
|
+
|
230
|
+
static VALUE
|
231
|
+
cr_matrix_get_x0 (VALUE self)
|
232
|
+
{
|
233
|
+
return rb_float_new (_SELF->x0);
|
234
|
+
}
|
235
|
+
|
236
|
+
static VALUE
|
237
|
+
cr_matrix_set_x0 (VALUE self, VALUE x0)
|
238
|
+
{
|
239
|
+
_SELF->x0 = NUM2DBL (x0);
|
240
|
+
return Qnil;
|
241
|
+
}
|
242
|
+
|
243
|
+
static VALUE
|
244
|
+
cr_matrix_get_y0 (VALUE self)
|
245
|
+
{
|
246
|
+
return rb_float_new (_SELF->y0);
|
247
|
+
}
|
248
|
+
|
249
|
+
static VALUE
|
250
|
+
cr_matrix_set_y0 (VALUE self, VALUE y0)
|
251
|
+
{
|
252
|
+
_SELF->y0 = NUM2DBL (y0);
|
253
|
+
return Qnil;
|
254
|
+
}
|
255
|
+
|
177
256
|
/* Utilities */
|
178
257
|
static VALUE
|
179
258
|
cr_matrix_set (VALUE self,
|
@@ -242,11 +321,25 @@ Init_cairo_matrix (void)
|
|
242
321
|
rb_define_method (rb_cCairo_Matrix, "rotate!", cr_matrix_rotate, 1);
|
243
322
|
rb_define_method (rb_cCairo_Matrix, "invert!", cr_matrix_invert, 0);
|
244
323
|
rb_define_method (rb_cCairo_Matrix, "multiply!", cr_matrix_multiply, 1);
|
245
|
-
rb_define_method (rb_cCairo_Matrix, "
|
324
|
+
rb_define_method (rb_cCairo_Matrix, "transform_distance",
|
246
325
|
cr_matrix_transform_distance, 2);
|
247
326
|
rb_define_method (rb_cCairo_Matrix, "transform_point",
|
248
327
|
cr_matrix_transform_point, 2);
|
249
328
|
|
329
|
+
/* Accessors */
|
330
|
+
rb_define_method (rb_cCairo_Matrix, "xx", cr_matrix_get_xx, 0);
|
331
|
+
rb_define_method (rb_cCairo_Matrix, "set_xx", cr_matrix_set_xx, 1);
|
332
|
+
rb_define_method (rb_cCairo_Matrix, "yx", cr_matrix_get_yx, 0);
|
333
|
+
rb_define_method (rb_cCairo_Matrix, "set_yx", cr_matrix_set_yx, 1);
|
334
|
+
rb_define_method (rb_cCairo_Matrix, "xy", cr_matrix_get_xy, 0);
|
335
|
+
rb_define_method (rb_cCairo_Matrix, "set_xy", cr_matrix_set_xy, 1);
|
336
|
+
rb_define_method (rb_cCairo_Matrix, "yy", cr_matrix_get_yy, 0);
|
337
|
+
rb_define_method (rb_cCairo_Matrix, "set_yy", cr_matrix_set_yy, 1);
|
338
|
+
rb_define_method (rb_cCairo_Matrix, "x0", cr_matrix_get_x0, 0);
|
339
|
+
rb_define_method (rb_cCairo_Matrix, "set_x0", cr_matrix_set_x0, 1);
|
340
|
+
rb_define_method (rb_cCairo_Matrix, "y0", cr_matrix_get_y0, 0);
|
341
|
+
rb_define_method (rb_cCairo_Matrix, "set_y0", cr_matrix_set_y0, 1);
|
342
|
+
|
250
343
|
/* Utilities */
|
251
344
|
rb_define_method (rb_cCairo_Matrix, "set", cr_matrix_set, 6);
|
252
345
|
rb_define_method (rb_cCairo_Matrix, "to_a", cr_matrix_to_a, 0);
|
data/src/rb_cairo_path.c
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
* Ruby Cairo Binding
|
4
4
|
*
|
5
5
|
* $Author: kou $
|
6
|
-
* $Date: 2007/
|
6
|
+
* $Date: 2007/05/22 11:41:45 $
|
7
7
|
*
|
8
8
|
* Copyright 2005 Kouhei Sutou <kou@cozmixng.org>
|
9
9
|
*
|
@@ -12,23 +12,227 @@
|
|
12
12
|
*/
|
13
13
|
|
14
14
|
#include "rb_cairo.h"
|
15
|
+
#include "rb_cairo_private.h"
|
15
16
|
|
16
17
|
#define _SELF(self) (RVAL2CRPATH (self))
|
17
18
|
|
19
|
+
VALUE rb_cCairo_Point;
|
18
20
|
VALUE rb_cCairo_Path;
|
21
|
+
VALUE rb_cCairo_PathData;
|
22
|
+
VALUE rb_cCairo_PathMoveTo;
|
23
|
+
VALUE rb_cCairo_PathLineTo;
|
24
|
+
VALUE rb_cCairo_PathCurveTo;
|
25
|
+
VALUE rb_cCairo_PathClosePath;
|
19
26
|
|
20
|
-
|
21
|
-
|
27
|
+
static ID id_new, id_current_path;
|
28
|
+
static ID id_at_x, id_at_y, id_at_type, id_at_points, id_at_context;
|
29
|
+
|
30
|
+
static VALUE
|
31
|
+
cr_point_new (VALUE x, VALUE y)
|
22
32
|
{
|
23
|
-
|
24
|
-
|
33
|
+
return rb_funcall (rb_cCairo_Point, id_new, 2, x, y);
|
34
|
+
}
|
35
|
+
|
36
|
+
static VALUE
|
37
|
+
cr_point_initialize (VALUE self, VALUE x, VALUE y)
|
38
|
+
{
|
39
|
+
rb_ivar_set (self, id_at_x, x);
|
40
|
+
rb_ivar_set (self, id_at_y, y);
|
41
|
+
return Qnil;
|
42
|
+
}
|
43
|
+
|
44
|
+
static VALUE
|
45
|
+
cr_point_to_a (VALUE self)
|
46
|
+
{
|
47
|
+
return rb_ary_new3 (2,
|
48
|
+
rb_ivar_get (self, id_at_x),
|
49
|
+
rb_ivar_get (self, id_at_y));
|
50
|
+
}
|
51
|
+
|
52
|
+
static VALUE
|
53
|
+
cr_path_data_initialize (VALUE self, VALUE type, VALUE points)
|
54
|
+
{
|
55
|
+
rb_ivar_set (self, id_at_type, type);
|
56
|
+
rb_ivar_set (self, id_at_points, points);
|
57
|
+
return Qnil;
|
58
|
+
}
|
59
|
+
|
60
|
+
static VALUE
|
61
|
+
cr_path_data_move_to_p (VALUE self)
|
62
|
+
{
|
63
|
+
return CBOOL2RVAL (RVAL2CRPATHDATATYPE (rb_ivar_get (self, id_at_type)) ==
|
64
|
+
CAIRO_PATH_MOVE_TO);
|
65
|
+
}
|
66
|
+
|
67
|
+
static VALUE
|
68
|
+
cr_path_data_line_to_p (VALUE self)
|
69
|
+
{
|
70
|
+
return CBOOL2RVAL (RVAL2CRPATHDATATYPE (rb_ivar_get (self, id_at_type)) ==
|
71
|
+
CAIRO_PATH_LINE_TO);
|
72
|
+
}
|
73
|
+
|
74
|
+
static VALUE
|
75
|
+
cr_path_data_curve_to_p (VALUE self)
|
76
|
+
{
|
77
|
+
return CBOOL2RVAL (RVAL2CRPATHDATATYPE (rb_ivar_get (self, id_at_type)) ==
|
78
|
+
CAIRO_PATH_CURVE_TO);
|
79
|
+
}
|
80
|
+
|
81
|
+
static VALUE
|
82
|
+
cr_path_data_close_path_p (VALUE self)
|
83
|
+
{
|
84
|
+
return CBOOL2RVAL (RVAL2CRPATHDATATYPE (rb_ivar_get (self, id_at_type)) ==
|
85
|
+
CAIRO_PATH_CLOSE_PATH);
|
86
|
+
}
|
87
|
+
|
88
|
+
static VALUE
|
89
|
+
cr_path_data_each (VALUE self)
|
90
|
+
{
|
91
|
+
return rb_ary_each (rb_ivar_get (self, id_at_points));
|
92
|
+
}
|
93
|
+
|
94
|
+
|
95
|
+
static VALUE
|
96
|
+
cr_path_data_to_a (VALUE self)
|
97
|
+
{
|
98
|
+
return rb_ary_new3 (2,
|
99
|
+
rb_ivar_get (self, id_at_type),
|
100
|
+
rb_ivar_get (self, id_at_points));
|
101
|
+
}
|
102
|
+
|
103
|
+
static VALUE
|
104
|
+
cr_path_data_to_ruby_object (cairo_path_data_t *data)
|
105
|
+
{
|
106
|
+
VALUE rb_data = Qnil;
|
107
|
+
|
108
|
+
switch (data->header.type)
|
25
109
|
{
|
26
|
-
|
110
|
+
case CAIRO_PATH_MOVE_TO:
|
111
|
+
rb_data = rb_funcall (rb_cCairo_PathMoveTo, id_new, 2,
|
112
|
+
rb_float_new (data[1].point.x),
|
113
|
+
rb_float_new (data[1].point.y));
|
114
|
+
break;
|
115
|
+
case CAIRO_PATH_LINE_TO:
|
116
|
+
rb_data = rb_funcall (rb_cCairo_PathLineTo, id_new, 2,
|
117
|
+
rb_float_new (data[1].point.x),
|
118
|
+
rb_float_new (data[1].point.y));
|
119
|
+
break;
|
120
|
+
case CAIRO_PATH_CURVE_TO:
|
121
|
+
rb_data = rb_funcall (rb_cCairo_PathCurveTo, id_new, 6,
|
122
|
+
rb_float_new (data[1].point.x),
|
123
|
+
rb_float_new (data[1].point.y),
|
124
|
+
rb_float_new (data[2].point.x),
|
125
|
+
rb_float_new (data[2].point.y),
|
126
|
+
rb_float_new (data[3].point.x),
|
127
|
+
rb_float_new (data[3].point.y));
|
128
|
+
break;
|
129
|
+
case CAIRO_PATH_CLOSE_PATH:
|
130
|
+
rb_data = rb_funcall (rb_cCairo_PathClosePath, id_new, 0);
|
131
|
+
break;
|
27
132
|
}
|
28
|
-
|
29
|
-
return
|
133
|
+
|
134
|
+
return rb_data;
|
135
|
+
|
136
|
+
int i;
|
137
|
+
VALUE points;
|
138
|
+
|
139
|
+
points = rb_ary_new ();
|
140
|
+
for (i = 1; i < data->header.length; i++)
|
141
|
+
{
|
142
|
+
rb_ary_push (points, cr_point_new (rb_float_new (data[i].point.x),
|
143
|
+
rb_float_new (data[i].point.y)));
|
144
|
+
}
|
145
|
+
|
146
|
+
return rb_funcall (rb_cCairo_PathData, id_new, 2,
|
147
|
+
INT2FIX (data->header.type), points);
|
148
|
+
}
|
149
|
+
|
150
|
+
|
151
|
+
static VALUE
|
152
|
+
cr_path_move_to_initialize (int argc, VALUE *argv, VALUE self)
|
153
|
+
{
|
154
|
+
VALUE point, x, y;
|
155
|
+
VALUE super_argv[2];
|
156
|
+
|
157
|
+
rb_scan_args (argc, argv, "11", &x, &y);
|
158
|
+
|
159
|
+
if (argc == 1)
|
160
|
+
point = x;
|
161
|
+
else
|
162
|
+
point = cr_point_new (x, y);
|
163
|
+
|
164
|
+
super_argv[0] = INT2NUM (CAIRO_PATH_MOVE_TO);
|
165
|
+
super_argv[1] = rb_ary_new3 (1, point);
|
166
|
+
rb_call_super (2, super_argv);
|
167
|
+
return Qnil;
|
168
|
+
}
|
169
|
+
|
170
|
+
static VALUE
|
171
|
+
cr_path_line_to_initialize (int argc, VALUE *argv, VALUE self)
|
172
|
+
{
|
173
|
+
VALUE point, x, y;
|
174
|
+
VALUE super_argv[2];
|
175
|
+
|
176
|
+
rb_scan_args (argc, argv, "11", &x, &y);
|
177
|
+
|
178
|
+
if (argc == 1)
|
179
|
+
point = x;
|
180
|
+
else
|
181
|
+
point = cr_point_new (x, y);
|
182
|
+
|
183
|
+
super_argv[0] = INT2NUM (CAIRO_PATH_LINE_TO);
|
184
|
+
super_argv[1] = rb_ary_new3 (1, point);
|
185
|
+
rb_call_super (2, super_argv);
|
186
|
+
return Qnil;
|
187
|
+
}
|
188
|
+
|
189
|
+
static VALUE
|
190
|
+
cr_path_curve_to_initialize (int argc, VALUE *argv, VALUE self)
|
191
|
+
{
|
192
|
+
VALUE point1, point2, point3, x1, y1, x2, y2, x3, y3;
|
193
|
+
VALUE super_argv[2];
|
194
|
+
|
195
|
+
rb_scan_args (argc, argv, "33", &x1, &y1, &x2, &y2, &x3, &y3);
|
196
|
+
|
197
|
+
if (argc == 3)
|
198
|
+
{
|
199
|
+
point1 = x1;
|
200
|
+
point2 = y1;
|
201
|
+
point3 = x2;
|
202
|
+
}
|
203
|
+
else if (argc == 6)
|
204
|
+
{
|
205
|
+
point1 = cr_point_new (x1, y1);
|
206
|
+
point2 = cr_point_new (x2, y2);
|
207
|
+
point3 = cr_point_new (x3, y3);
|
208
|
+
}
|
209
|
+
else
|
210
|
+
{
|
211
|
+
VALUE inspected_arg = rb_inspect (rb_ary_new4 (argc, argv));
|
212
|
+
rb_raise (rb_eArgError,
|
213
|
+
"invalid argument: %s (expect "
|
214
|
+
"(point1, point2, point3) or "
|
215
|
+
"(x1, y1, x2, y2, x3, y3))",
|
216
|
+
StringValuePtr (inspected_arg));
|
217
|
+
}
|
218
|
+
|
219
|
+
super_argv[0] = INT2NUM (CAIRO_PATH_CURVE_TO);
|
220
|
+
super_argv[1] = rb_ary_new3 (3, point1, point2, point3);
|
221
|
+
rb_call_super (2, super_argv);
|
222
|
+
return Qnil;
|
223
|
+
}
|
224
|
+
|
225
|
+
static VALUE
|
226
|
+
cr_path_close_path_initialize (VALUE self)
|
227
|
+
{
|
228
|
+
VALUE super_argv[2];
|
229
|
+
super_argv[0] = INT2NUM (CAIRO_PATH_CLOSE_PATH);
|
230
|
+
super_argv[1] = rb_ary_new ();
|
231
|
+
rb_call_super (2, super_argv);
|
232
|
+
return Qnil;
|
30
233
|
}
|
31
234
|
|
235
|
+
|
32
236
|
static void
|
33
237
|
cr_path_free (void *ptr)
|
34
238
|
{
|
@@ -38,12 +242,59 @@ cr_path_free (void *ptr)
|
|
38
242
|
}
|
39
243
|
}
|
40
244
|
|
245
|
+
cairo_path_t *
|
246
|
+
rb_cairo_path_from_ruby_object (VALUE obj)
|
247
|
+
{
|
248
|
+
VALUE context;
|
249
|
+
cairo_t *cr;
|
250
|
+
cairo_path_t *path, *copied_path;
|
251
|
+
|
252
|
+
if (!rb_cairo__is_kind_of (obj, rb_cCairo_Path))
|
253
|
+
{
|
254
|
+
rb_raise (rb_eTypeError, "not a cairo path");
|
255
|
+
}
|
256
|
+
Data_Get_Struct (obj, cairo_path_t, path);
|
257
|
+
|
258
|
+
context = rb_ivar_get (obj, id_at_context);
|
259
|
+
if (NIL_P (context))
|
260
|
+
return path;
|
261
|
+
|
262
|
+
cr = RVAL2CRCONTEXT (context);
|
263
|
+
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
|
264
|
+
return path;
|
265
|
+
|
266
|
+
copied_path = cairo_copy_path (cr);
|
267
|
+
rb_ivar_set (obj, id_current_path, CRPATH2RVAL (copied_path));
|
268
|
+
return copied_path;
|
269
|
+
}
|
270
|
+
|
271
|
+
static void
|
272
|
+
cr_path_ensure_internal_context (VALUE rb_path, cairo_path_t *path)
|
273
|
+
{
|
274
|
+
cairo_surface_t *surface;
|
275
|
+
cairo_t *cr;
|
276
|
+
|
277
|
+
if (!NIL_P (rb_ivar_get (rb_path, id_at_context)))
|
278
|
+
return;
|
279
|
+
|
280
|
+
surface = cairo_image_surface_create (CAIRO_FORMAT_A1, 1, 1);
|
281
|
+
cr = cairo_create (surface);
|
282
|
+
if (path->num_data > 0)
|
283
|
+
cairo_append_path (cr, path);
|
284
|
+
rb_cairo_check_status (cairo_status (cr));
|
285
|
+
rb_ivar_set (rb_path, id_at_context, CRCONTEXT2RVAL (cr));
|
286
|
+
cairo_destroy (cr);
|
287
|
+
}
|
288
|
+
|
41
289
|
VALUE
|
42
290
|
rb_cairo_path_to_ruby_object (cairo_path_t *path)
|
43
291
|
{
|
44
292
|
if (path)
|
45
293
|
{
|
46
|
-
|
294
|
+
VALUE rb_path;
|
295
|
+
rb_path = Data_Wrap_Struct (rb_cCairo_Path, NULL, cr_path_free, path);
|
296
|
+
cr_path_ensure_internal_context (rb_path, path);
|
297
|
+
return rb_path;
|
47
298
|
}
|
48
299
|
else
|
49
300
|
{
|
@@ -51,38 +302,171 @@ rb_cairo_path_to_ruby_object (cairo_path_t *path)
|
|
51
302
|
}
|
52
303
|
}
|
53
304
|
|
305
|
+
static VALUE
|
306
|
+
cr_path_allocate (VALUE klass)
|
307
|
+
{
|
308
|
+
return Data_Wrap_Struct (klass, NULL, cr_path_free, NULL);
|
309
|
+
}
|
310
|
+
|
311
|
+
static VALUE
|
312
|
+
cr_path_initialize (VALUE self)
|
313
|
+
{
|
314
|
+
cairo_path_t *path;
|
315
|
+
|
316
|
+
path = ALLOC(cairo_path_t);
|
317
|
+
path->status = CAIRO_STATUS_SUCCESS;
|
318
|
+
path->data = NULL;
|
319
|
+
path->num_data = 0;
|
320
|
+
|
321
|
+
DATA_PTR (self) = path;
|
322
|
+
cr_path_ensure_internal_context (self, path);
|
323
|
+
|
324
|
+
return Qnil;
|
325
|
+
}
|
326
|
+
|
327
|
+
static VALUE
|
328
|
+
cr_path_empty_p (VALUE self)
|
329
|
+
{
|
330
|
+
cairo_path_t *path = _SELF (self);
|
331
|
+
|
332
|
+
return CBOOL2RVAL (path->num_data == 0);
|
333
|
+
}
|
334
|
+
|
335
|
+
static int
|
336
|
+
cairo_path_get_size (cairo_path_t *path)
|
337
|
+
{
|
338
|
+
int i, size;
|
339
|
+
|
340
|
+
for (i = 0, size = 0; i < path->num_data; i += path->data[i].header.length)
|
341
|
+
size++;
|
342
|
+
|
343
|
+
return size;
|
344
|
+
}
|
345
|
+
|
346
|
+
static VALUE
|
347
|
+
cr_path_size (VALUE self)
|
348
|
+
{
|
349
|
+
cairo_path_t *path = _SELF (self);
|
350
|
+
return INT2NUM (cairo_path_get_size (path));
|
351
|
+
}
|
352
|
+
|
353
|
+
static VALUE
|
354
|
+
cr_path_ref (VALUE self, VALUE index)
|
355
|
+
{
|
356
|
+
cairo_path_t *path = _SELF (self);
|
357
|
+
int i, requested_index, real_index;
|
358
|
+
|
359
|
+
requested_index = NUM2INT (index);
|
360
|
+
if (requested_index < 0)
|
361
|
+
{
|
362
|
+
requested_index += cairo_path_get_size (path);
|
363
|
+
if (requested_index < 0)
|
364
|
+
return Qnil;
|
365
|
+
}
|
366
|
+
|
367
|
+
|
368
|
+
for (i = 0, real_index = 0; i < requested_index; i++)
|
369
|
+
{
|
370
|
+
if (real_index >= path->num_data)
|
371
|
+
return Qnil;
|
372
|
+
real_index += path->data[real_index].header.length;
|
373
|
+
}
|
374
|
+
|
375
|
+
if (real_index < path->num_data)
|
376
|
+
return cr_path_data_to_ruby_object (&path->data[real_index]);
|
377
|
+
else
|
378
|
+
return Qnil;
|
379
|
+
}
|
380
|
+
|
54
381
|
static VALUE
|
55
382
|
cr_path_each (VALUE self)
|
56
383
|
{
|
57
384
|
cairo_path_t *path = _SELF(self);
|
58
|
-
int i
|
59
|
-
|
385
|
+
int i;
|
386
|
+
|
60
387
|
for (i = 0; i < path->num_data; i += path->data[i].header.length)
|
61
388
|
{
|
62
|
-
|
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);
|
389
|
+
rb_yield (cr_path_data_to_ruby_object (&(path->data[i])));
|
74
390
|
}
|
75
391
|
|
76
392
|
return self;
|
77
393
|
}
|
78
394
|
|
79
|
-
|
80
395
|
void
|
81
396
|
Init_cairo_path (void)
|
82
397
|
{
|
398
|
+
id_new = rb_intern ("new");
|
399
|
+
id_current_path = rb_intern ("current_path");
|
400
|
+
|
401
|
+
id_at_x = rb_intern ("@x");
|
402
|
+
id_at_y = rb_intern ("@y");
|
403
|
+
id_at_type = rb_intern ("@type");
|
404
|
+
id_at_points = rb_intern ("@points");
|
405
|
+
id_at_context = rb_intern ("@context");
|
406
|
+
|
407
|
+
rb_cCairo_Point = rb_define_class_under (rb_mCairo, "Point", rb_cObject);
|
408
|
+
rb_define_attr (rb_cCairo_Point, "x", CR_TRUE, CR_FALSE);
|
409
|
+
rb_define_attr (rb_cCairo_Point, "y", CR_TRUE, CR_FALSE);
|
410
|
+
rb_define_method (rb_cCairo_Point, "initialize", cr_point_initialize, 2);
|
411
|
+
|
412
|
+
rb_define_method (rb_cCairo_Point, "to_a", cr_point_to_a, 0);
|
413
|
+
rb_define_alias (rb_cCairo_Point, "to_ary", "to_a");
|
414
|
+
|
415
|
+
|
416
|
+
rb_cCairo_PathData = rb_define_class_under (rb_mCairo, "PathData", rb_cObject);
|
417
|
+
|
418
|
+
rb_include_module (rb_cCairo_PathData, rb_mEnumerable);
|
419
|
+
|
420
|
+
rb_define_attr (rb_cCairo_PathData, "type", CR_TRUE, CR_FALSE);
|
421
|
+
rb_define_attr (rb_cCairo_PathData, "points", CR_TRUE, CR_FALSE);
|
422
|
+
rb_define_method (rb_cCairo_PathData, "initialize",
|
423
|
+
cr_path_data_initialize, 2);
|
424
|
+
|
425
|
+
rb_define_method (rb_cCairo_PathData, "move_to?", cr_path_data_move_to_p, 0);
|
426
|
+
rb_define_method (rb_cCairo_PathData, "line_to?", cr_path_data_line_to_p, 0);
|
427
|
+
rb_define_method (rb_cCairo_PathData, "curve_to?",
|
428
|
+
cr_path_data_curve_to_p, 0);
|
429
|
+
rb_define_method (rb_cCairo_PathData, "close_path?",
|
430
|
+
cr_path_data_close_path_p, 0);
|
431
|
+
|
432
|
+
rb_define_method (rb_cCairo_PathData, "each", cr_path_data_each, 0);
|
433
|
+
|
434
|
+
rb_define_method (rb_cCairo_PathData, "to_a", cr_path_data_to_a, 0);
|
435
|
+
rb_define_alias (rb_cCairo_PathData, "to_ary", "to_a");
|
436
|
+
|
437
|
+
|
438
|
+
rb_cCairo_PathMoveTo =
|
439
|
+
rb_define_class_under (rb_mCairo, "PathMoveTo", rb_cCairo_PathData);
|
440
|
+
rb_define_method (rb_cCairo_PathMoveTo, "initialize",
|
441
|
+
cr_path_move_to_initialize, -1);
|
442
|
+
|
443
|
+
rb_cCairo_PathLineTo =
|
444
|
+
rb_define_class_under (rb_mCairo, "PathLineTo", rb_cCairo_PathData);
|
445
|
+
rb_define_method (rb_cCairo_PathLineTo, "initialize",
|
446
|
+
cr_path_line_to_initialize, -1);
|
447
|
+
|
448
|
+
rb_cCairo_PathCurveTo =
|
449
|
+
rb_define_class_under (rb_mCairo, "PathCurveTo", rb_cCairo_PathData);
|
450
|
+
rb_define_method (rb_cCairo_PathCurveTo, "initialize",
|
451
|
+
cr_path_curve_to_initialize, -1);
|
452
|
+
|
453
|
+
rb_cCairo_PathClosePath =
|
454
|
+
rb_define_class_under (rb_mCairo, "PathClosePath", rb_cCairo_PathData);
|
455
|
+
rb_define_method (rb_cCairo_PathClosePath, "initialize",
|
456
|
+
cr_path_close_path_initialize, 0);
|
457
|
+
|
458
|
+
|
83
459
|
rb_cCairo_Path = rb_define_class_under (rb_mCairo, "Path", rb_cObject);
|
460
|
+
rb_define_alloc_func (rb_cCairo_Path, cr_path_allocate);
|
84
461
|
|
85
462
|
rb_include_module (rb_cCairo_Path, rb_mEnumerable);
|
86
463
|
|
464
|
+
rb_define_method (rb_cCairo_Path, "initialize", cr_path_initialize, 0);
|
465
|
+
|
466
|
+
rb_define_method (rb_cCairo_Path, "empty?", cr_path_empty_p, 0);
|
467
|
+
rb_define_method (rb_cCairo_Path, "size", cr_path_size, 0);
|
468
|
+
rb_define_alias (rb_cCairo_Path, "length", "size");
|
469
|
+
rb_define_method (rb_cCairo_Path, "[]", cr_path_ref, 1);
|
470
|
+
|
87
471
|
rb_define_method (rb_cCairo_Path, "each", cr_path_each, 0);
|
88
472
|
}
|