cairo 1.17.5 → 1.17.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@
5
5
  * $Author: kou $
6
6
  * $Date: 2008-09-26 14:13:58 $
7
7
  *
8
- * Copyright 2003-2019 Sutou Kouhei <kou@cozmixng.org>
8
+ * Copyright 2003-2022 Sutou Kouhei <kou@cozmixng.org>
9
9
  * Copyright 2005 Øyvind Kolås <pippin@freedesktop.org>
10
10
  * Copyright 2004-2005 MenTaLguY <mental@rydia.com>
11
11
  *
@@ -39,6 +39,9 @@ static ID cr_id_new;
39
39
 
40
40
  static ID cr_id_init;
41
41
  static ID cr_id_render_glyph;
42
+ # if CAIRO_CHECK_VERSION(1, 17, 6)
43
+ static ID cr_id_render_color_glyph;
44
+ #endif
42
45
  static ID cr_id_text_to_glyphs;
43
46
  static ID cr_id_unicode_to_glyph;
44
47
 
@@ -52,6 +55,24 @@ static ID cr_id_at_need_cluster_flags;
52
55
 
53
56
  #define _SELF (RVAL2CRFONTFACE(self))
54
57
 
58
+ static void
59
+ cr_font_face_free (void *ptr)
60
+ {
61
+ cairo_font_face_t *face = ptr;
62
+ cairo_font_face_destroy (face);
63
+ }
64
+
65
+ static const rb_data_type_t cr_font_face_type = {
66
+ "Cairo::FontFace",
67
+ {
68
+ NULL,
69
+ cr_font_face_free,
70
+ },
71
+ NULL,
72
+ NULL,
73
+ RUBY_TYPED_FREE_IMMEDIATELY,
74
+ };
75
+
55
76
  static inline void
56
77
  cr_font_face_check_status (cairo_font_face_t *face)
57
78
  {
@@ -69,23 +90,13 @@ rb_cairo_font_face_from_ruby_object (VALUE obj)
69
90
  "not a cairo font face: %s",
70
91
  rb_cairo__inspect (obj));
71
92
  }
72
- Data_Get_Struct (obj, cairo_font_face_t, face);
93
+ TypedData_Get_Struct (obj, cairo_font_face_t, &cr_font_face_type, face);
73
94
  if (!face)
74
95
  rb_cairo_check_status (CAIRO_STATUS_NULL_POINTER);
75
96
  cr_font_face_check_status (face);
76
97
  return face;
77
98
  }
78
99
 
79
- static void
80
- cr_font_face_free (void *ptr)
81
- {
82
- if (ptr)
83
- {
84
- cairo_font_face_t *face = ptr;
85
- cairo_font_face_destroy (face);
86
- }
87
- }
88
-
89
100
  VALUE
90
101
  rb_cairo_font_face_to_ruby_object (cairo_font_face_t *face)
91
102
  {
@@ -113,7 +124,7 @@ rb_cairo_font_face_to_ruby_object (cairo_font_face_t *face)
113
124
  break;
114
125
  }
115
126
  cairo_font_face_reference (face);
116
- return Data_Wrap_Struct (klass, NULL, cr_font_face_free, face);
127
+ return TypedData_Wrap_Struct (klass, &cr_font_face_type, face);
117
128
  }
118
129
  else
119
130
  {
@@ -124,7 +135,7 @@ rb_cairo_font_face_to_ruby_object (cairo_font_face_t *face)
124
135
  static VALUE
125
136
  cr_font_face_allocate (VALUE klass)
126
137
  {
127
- return Data_Wrap_Struct (klass, NULL, cr_font_face_free, NULL);
138
+ return TypedData_Wrap_Struct (klass, &cr_font_face_type, NULL);
128
139
  }
129
140
 
130
141
  static VALUE
@@ -272,7 +283,7 @@ cr_freetype_font_face_initialize (VALUE self, VALUE path)
272
283
  rb_cairo_check_status (status);
273
284
  }
274
285
 
275
- DATA_PTR (self) = face;
286
+ RTYPEDDATA_DATA (self) = face;
276
287
 
277
288
  return Qnil;
278
289
  }
@@ -321,7 +332,7 @@ cr_toy_font_face_initialize (int argc, VALUE *argv, VALUE self)
321
332
 
322
333
  face = cairo_toy_font_face_create (family, slant, weight);
323
334
  cr_font_face_check_status (face);
324
- DATA_PTR (self) = face;
335
+ RTYPEDDATA_DATA (self) = face;
325
336
 
326
337
  return Qnil;
327
338
  }
@@ -463,10 +474,11 @@ cr_user_font_face_render_glyph_func_after (VALUE user_data)
463
474
  }
464
475
 
465
476
  static cairo_status_t
466
- cr_user_font_face_render_glyph_func (cairo_scaled_font_t *scaled_font,
467
- unsigned long glyph,
468
- cairo_t *cr,
469
- cairo_text_extents_t *extents)
477
+ cr_user_font_face_render_glyph_func_internal (cairo_scaled_font_t *scaled_font,
478
+ unsigned long glyph,
479
+ cairo_t *cr,
480
+ cairo_text_extents_t *extents,
481
+ ID id_registered_method_name)
470
482
  {
471
483
  cairo_status_t status = CAIRO_STATUS_SUCCESS;
472
484
  cairo_font_face_t *face;
@@ -476,11 +488,12 @@ cr_user_font_face_render_glyph_func (cairo_scaled_font_t *scaled_font,
476
488
 
477
489
  face = cairo_scaled_font_get_font_face (scaled_font);
478
490
  self = (VALUE)cairo_font_face_get_user_data (face, &ruby_object_key);
479
- receiver = rb_ivar_get (self, cr_id_render_glyph);
480
- if (NIL_P (receiver) && rb_obj_respond_to (self, cr_id_render_glyph, Qtrue))
491
+ receiver = rb_ivar_get (self, id_registered_method_name);
492
+ if (NIL_P (receiver) &&
493
+ rb_obj_respond_to (self, id_registered_method_name, Qtrue))
481
494
  {
482
495
  receiver = self;
483
- id_method_name = cr_id_render_glyph;
496
+ id_method_name = id_registered_method_name;
484
497
  }
485
498
 
486
499
  if (!NIL_P (receiver))
@@ -507,6 +520,34 @@ cr_user_font_face_render_glyph_func (cairo_scaled_font_t *scaled_font,
507
520
  return status;
508
521
  }
509
522
 
523
+ static cairo_status_t
524
+ cr_user_font_face_render_glyph_func (cairo_scaled_font_t *scaled_font,
525
+ unsigned long glyph,
526
+ cairo_t *cr,
527
+ cairo_text_extents_t *extents)
528
+ {
529
+ return cr_user_font_face_render_glyph_func_internal (scaled_font,
530
+ glyph,
531
+ cr,
532
+ extents,
533
+ cr_id_render_glyph);
534
+ }
535
+
536
+ #if CAIRO_CHECK_VERSION(1, 17, 6)
537
+ static cairo_status_t
538
+ cr_user_font_face_render_color_glyph_func (cairo_scaled_font_t *scaled_font,
539
+ unsigned long glyph,
540
+ cairo_t *cr,
541
+ cairo_text_extents_t *extents)
542
+ {
543
+ return cr_user_font_face_render_glyph_func_internal (scaled_font,
544
+ glyph,
545
+ cr,
546
+ extents,
547
+ cr_id_render_color_glyph);
548
+ }
549
+ #endif
550
+
510
551
  typedef struct _cr_text_to_glyphs_after_hook_data {
511
552
  VALUE text_to_glyphs_data;
512
553
  cairo_glyph_t **glyphs;
@@ -703,6 +744,10 @@ cr_user_font_face_initialize (VALUE self)
703
744
  (face, cr_user_font_face_init_func);
704
745
  cairo_user_font_face_set_render_glyph_func
705
746
  (face, cr_user_font_face_render_glyph_func);
747
+ #if CAIRO_CHECK_VERSION(1, 17, 6)
748
+ cairo_user_font_face_set_render_color_glyph_func
749
+ (face, cr_user_font_face_render_color_glyph_func);
750
+ #endif
706
751
  cairo_user_font_face_set_text_to_glyphs_func
707
752
  (face, cr_user_font_face_text_to_glyphs_func);
708
753
  cairo_user_font_face_set_unicode_to_glyph_func
@@ -713,7 +758,7 @@ cr_user_font_face_initialize (VALUE self)
713
758
  rb_ivar_set (self, cr_id_text_to_glyphs, Qnil);
714
759
  rb_ivar_set (self, cr_id_unicode_to_glyph, Qnil);
715
760
 
716
- DATA_PTR (self) = face;
761
+ RTYPEDDATA_DATA (self) = face;
717
762
 
718
763
  return Qnil;
719
764
  }
@@ -732,6 +777,15 @@ cr_user_font_face_on_render_glyph (VALUE self)
732
777
  return self;
733
778
  }
734
779
 
780
+ #if CAIRO_CHECK_VERSION(1, 17, 6)
781
+ static VALUE
782
+ cr_user_font_face_on_render_color_glyph (VALUE self)
783
+ {
784
+ rb_ivar_set (self, cr_id_render_color_glyph, rb_block_proc ());
785
+ return self;
786
+ }
787
+ #endif
788
+
735
789
  static VALUE
736
790
  cr_user_font_face_on_text_to_glyphs (VALUE self)
737
791
  {
@@ -804,6 +858,9 @@ Init_cairo_font (void)
804
858
 
805
859
  cr_id_init = rb_intern ("init");
806
860
  cr_id_render_glyph = rb_intern ("render_glyph");
861
+ # if CAIRO_CHECK_VERSION(1, 17, 6)
862
+ cr_id_render_color_glyph = rb_intern ("render_color_glyph");
863
+ #endif
807
864
  cr_id_text_to_glyphs = rb_intern ("text_to_glyphs");
808
865
  cr_id_unicode_to_glyph = rb_intern ("unicode_to_glyph");
809
866
 
@@ -867,6 +924,10 @@ Init_cairo_font (void)
867
924
  cr_user_font_face_on_init, 0);
868
925
  rb_define_method (rb_cCairo_UserFontFace, "on_render_glyph",
869
926
  cr_user_font_face_on_render_glyph, 0);
927
+ #if CAIRO_CHECK_VERSION(1, 17, 6)
928
+ rb_define_method (rb_cCairo_UserFontFace, "on_render_color_glyph",
929
+ cr_user_font_face_on_render_color_glyph, 0);
930
+ #endif
870
931
  rb_define_method (rb_cCairo_UserFontFace, "on_text_to_glyphs",
871
932
  cr_user_font_face_on_text_to_glyphs, 0);
872
933
  rb_define_method (rb_cCairo_UserFontFace, "on_unicode_to_glyph",
@@ -5,7 +5,7 @@
5
5
  * $Author: kou $
6
6
  * $Date: 2008-09-19 12:56:27 $
7
7
  *
8
- * Copyright 2005-2021 Sutou Kouhei <kou@cozmixng.org>
8
+ * Copyright 2005-2022 Sutou Kouhei <kou@cozmixng.org>
9
9
  *
10
10
  * This file is made available under the same terms as Ruby
11
11
  *
@@ -18,6 +18,23 @@
18
18
 
19
19
  VALUE rb_cCairo_FontOptions;
20
20
 
21
+ static void
22
+ cr_options_free (void *ptr)
23
+ {
24
+ cairo_font_options_destroy ((cairo_font_options_t *) ptr);
25
+ }
26
+
27
+ static const rb_data_type_t cr_font_options_type = {
28
+ "Cairo::FontOptions",
29
+ {
30
+ NULL,
31
+ cr_options_free,
32
+ },
33
+ NULL,
34
+ NULL,
35
+ RUBY_TYPED_FREE_IMMEDIATELY,
36
+ };
37
+
21
38
  static inline void
22
39
  cr_options_check_status (cairo_font_options_t *options)
23
40
  {
@@ -32,19 +49,13 @@ rb_cairo_font_options_from_ruby_object (VALUE obj)
32
49
  {
33
50
  rb_raise (rb_eTypeError, "not a cairo font options");
34
51
  }
35
- Data_Get_Struct (obj, cairo_font_options_t, options);
52
+ TypedData_Get_Struct (obj,
53
+ cairo_font_options_t,
54
+ &cr_font_options_type,
55
+ options);
36
56
  return options;
37
57
  }
38
58
 
39
- static void
40
- cr_options_free (void *ptr)
41
- {
42
- if (ptr)
43
- {
44
- cairo_font_options_destroy ((cairo_font_options_t *) ptr);
45
- }
46
- }
47
-
48
59
  VALUE
49
60
  rb_cairo_font_options_to_ruby_object (cairo_font_options_t *options)
50
61
  {
@@ -53,8 +64,9 @@ rb_cairo_font_options_to_ruby_object (cairo_font_options_t *options)
53
64
  cairo_font_options_t *copied_options;
54
65
  copied_options = cairo_font_options_copy (options);
55
66
  cr_options_check_status (copied_options);
56
- return Data_Wrap_Struct (rb_cCairo_FontOptions, NULL,
57
- cr_options_free, copied_options);
67
+ return TypedData_Wrap_Struct (rb_cCairo_FontOptions,
68
+ &cr_font_options_type,
69
+ copied_options);
58
70
  }
59
71
  else
60
72
  {
@@ -65,7 +77,7 @@ rb_cairo_font_options_to_ruby_object (cairo_font_options_t *options)
65
77
  static VALUE
66
78
  cr_options_allocate (VALUE klass)
67
79
  {
68
- return Data_Wrap_Struct (klass, NULL, cr_options_free, NULL);
80
+ return TypedData_Wrap_Struct (klass, &cr_font_options_type, NULL);
69
81
  }
70
82
 
71
83
  static VALUE
@@ -75,7 +87,7 @@ cr_options_create (VALUE self)
75
87
 
76
88
  options = cairo_font_options_create ();
77
89
  cr_options_check_status (options);
78
- DATA_PTR (self) = options;
90
+ RTYPEDDATA_DATA (self) = options;
79
91
  return Qnil;
80
92
  }
81
93
 
@@ -5,6 +5,7 @@
5
5
  * $Author: kou $
6
6
  * $Date: 2008-08-16 08:16:39 $
7
7
  *
8
+ * Copyright 2005-2022 Sutou Kouhei <kou@cozmixng.org>
8
9
  * Copyright 2005 Øyvind Kolås <pippin@freedesktop.org>
9
10
  * Copyright 2004-2005 MenTaLguY <mental@rydia.com>
10
11
  *
@@ -20,6 +21,17 @@ VALUE rb_cCairo_Glyph;
20
21
 
21
22
  #define _SELF(self) (RVAL2CRGLYPH(self))
22
23
 
24
+ static const rb_data_type_t cr_glyph_type = {
25
+ "Cairo::Glyph",
26
+ {
27
+ NULL,
28
+ ruby_xfree,
29
+ },
30
+ NULL,
31
+ NULL,
32
+ RUBY_TYPED_FREE_IMMEDIATELY,
33
+ };
34
+
23
35
  cairo_glyph_t *
24
36
  rb_cairo_glyph_from_ruby_object (VALUE obj)
25
37
  {
@@ -28,19 +40,10 @@ rb_cairo_glyph_from_ruby_object (VALUE obj)
28
40
  {
29
41
  rb_raise (rb_eTypeError, "not a cairo glyph");
30
42
  }
31
- Data_Get_Struct (obj, cairo_glyph_t, glyph);
43
+ TypedData_Get_Struct (obj, cairo_glyph_t, &cr_glyph_type, glyph);
32
44
  return glyph;
33
45
  }
34
46
 
35
- static void
36
- cr_glyph_free (void *ptr)
37
- {
38
- if (ptr)
39
- {
40
- xfree (ptr);
41
- }
42
- }
43
-
44
47
  VALUE
45
48
  rb_cairo_glyph_to_ruby_object (cairo_glyph_t *glyph)
46
49
  {
@@ -50,7 +53,7 @@ rb_cairo_glyph_to_ruby_object (cairo_glyph_t *glyph)
50
53
 
51
54
  new_glyph = ALLOC (cairo_glyph_t);
52
55
  *new_glyph = *glyph;
53
- return Data_Wrap_Struct (rb_cCairo_Glyph, NULL, cr_glyph_free, new_glyph);
56
+ return TypedData_Wrap_Struct (rb_cCairo_Glyph, &cr_glyph_type, new_glyph);
54
57
  }
55
58
  else
56
59
  {
@@ -61,7 +64,7 @@ rb_cairo_glyph_to_ruby_object (cairo_glyph_t *glyph)
61
64
  static VALUE
62
65
  cr_glyph_allocate (VALUE klass)
63
66
  {
64
- return Data_Wrap_Struct (klass, NULL, cr_glyph_free, NULL);
67
+ return TypedData_Wrap_Struct (klass, &cr_glyph_type, NULL);
65
68
  }
66
69
 
67
70
  static VALUE
@@ -74,7 +77,7 @@ cr_glyph_initialize (VALUE self, VALUE index, VALUE x, VALUE y)
74
77
  glyph->x = NUM2DBL (x);
75
78
  glyph->y = NUM2DBL (y);
76
79
 
77
- DATA_PTR (self) = glyph;
80
+ RTYPEDDATA_DATA (self) = glyph;
78
81
  return Qnil;
79
82
  }
80
83
 
@@ -5,7 +5,7 @@
5
5
  * $Author: kou $
6
6
  * $Date: 2008-08-14 12:37:50 $
7
7
  *
8
- * Copyright 2006-2008 Kouhei Sutou <kou@cozmixng.org>
8
+ * Copyright 2006-2022 Sutou Kouhei <kou@cozmixng.org>
9
9
  * Copyright 2005 Øyvind Kolås <pippin@freedesktop.org>
10
10
  * Copyright 2004-2005 MenTaLguY <mental@rydia.com>
11
11
  *
@@ -23,6 +23,17 @@ static ID cr_id_equal;
23
23
 
24
24
  #define _SELF (RVAL2CRMATRIX(self))
25
25
 
26
+ static const rb_data_type_t cr_matrix_type = {
27
+ "Cairo::Matrix",
28
+ {
29
+ NULL,
30
+ ruby_xfree,
31
+ },
32
+ NULL,
33
+ NULL,
34
+ RUBY_TYPED_FREE_IMMEDIATELY,
35
+ };
36
+
26
37
  cairo_matrix_t *
27
38
  rb_cairo_matrix_from_ruby_object (VALUE obj)
28
39
  {
@@ -31,19 +42,10 @@ rb_cairo_matrix_from_ruby_object (VALUE obj)
31
42
  {
32
43
  rb_raise (rb_eTypeError, "not a cairo matrix");
33
44
  }
34
- Data_Get_Struct (obj, cairo_matrix_t, matrix);
45
+ TypedData_Get_Struct (obj, cairo_matrix_t, &cr_matrix_type, matrix);
35
46
  return matrix;
36
47
  }
37
48
 
38
- static void
39
- cr_matrix_free (void *ptr)
40
- {
41
- if (ptr)
42
- {
43
- xfree ((cairo_matrix_t *) ptr);
44
- }
45
- }
46
-
47
49
  VALUE
48
50
  rb_cairo_matrix_to_ruby_object (cairo_matrix_t *matrix)
49
51
  {
@@ -51,8 +53,9 @@ rb_cairo_matrix_to_ruby_object (cairo_matrix_t *matrix)
51
53
  {
52
54
  cairo_matrix_t *new_matrix = ALLOC (cairo_matrix_t);
53
55
  *new_matrix = *matrix;
54
- return Data_Wrap_Struct (rb_cCairo_Matrix, NULL,
55
- cr_matrix_free, new_matrix);
56
+ return TypedData_Wrap_Struct (rb_cCairo_Matrix,
57
+ &cr_matrix_type,
58
+ new_matrix);
56
59
  }
57
60
  else
58
61
  {
@@ -63,7 +66,7 @@ rb_cairo_matrix_to_ruby_object (cairo_matrix_t *matrix)
63
66
  static VALUE
64
67
  cr_matrix_allocate (VALUE klass)
65
68
  {
66
- return Data_Wrap_Struct (klass, NULL, cr_matrix_free, NULL);
69
+ return TypedData_Wrap_Struct (klass, &cr_matrix_type, NULL);
67
70
  }
68
71
 
69
72
  static VALUE
@@ -78,7 +81,7 @@ cr_matrix_initialize (VALUE self,
78
81
  NUM2DBL (xx), NUM2DBL (yx),
79
82
  NUM2DBL (xy), NUM2DBL (yy),
80
83
  NUM2DBL (x0), NUM2DBL (y0));
81
- DATA_PTR (self) = matrix;
84
+ RTYPEDDATA_DATA (self) = matrix;
82
85
  return Qnil;
83
86
  }
84
87
 
@@ -5,7 +5,7 @@
5
5
  * $Author: kou $
6
6
  * $Date: 2008-04-04 03:52:31 $
7
7
  *
8
- * Copyright 2005 Kouhei Sutou <kou@cozmixng.org>
8
+ * Copyright 2005-2022 Sutou Kouhei <kou@cozmixng.org>
9
9
  *
10
10
  * This file is made available under the same terms as Ruby
11
11
  *
@@ -223,54 +223,34 @@ cr_path_close_path_initialize (VALUE self)
223
223
  static void
224
224
  cr_path_free (void *ptr)
225
225
  {
226
- if (ptr)
227
- {
228
- cairo_path_destroy ((cairo_path_t *)ptr);
229
- }
226
+ cairo_path_t *path = ptr;
227
+ ruby_xfree (path->data);
228
+ ruby_xfree (path);
230
229
  }
231
230
 
231
+ static const rb_data_type_t cr_path_type = {
232
+ "Cairo::Path",
233
+ {
234
+ NULL,
235
+ cr_path_free,
236
+ },
237
+ NULL,
238
+ NULL,
239
+ RUBY_TYPED_FREE_IMMEDIATELY,
240
+ };
241
+
232
242
  cairo_path_t *
233
243
  rb_cairo_path_from_ruby_object (VALUE obj)
234
244
  {
235
- VALUE context;
236
- cairo_t *cr;
237
- cairo_path_t *path, *copied_path;
245
+ cairo_path_t *path;
238
246
 
239
247
  if (!rb_cairo__is_kind_of (obj, rb_cCairo_Path))
240
248
  {
241
249
  rb_raise (rb_eTypeError, "not a cairo path");
242
250
  }
243
- Data_Get_Struct (obj, cairo_path_t, path);
244
-
245
- context = rb_ivar_get (obj, id_at_context);
246
- if (NIL_P (context))
247
- return path;
248
-
249
- cr = RVAL2CRCONTEXT (context);
250
- if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
251
- return path;
251
+ TypedData_Get_Struct (obj, cairo_path_t, &cr_path_type, path);
252
252
 
253
- copied_path = cairo_copy_path (cr);
254
- rb_ivar_set (obj, id_current_path, CRPATH2RVAL (copied_path));
255
- return copied_path;
256
- }
257
-
258
- static void
259
- cr_path_ensure_internal_context (VALUE rb_path, cairo_path_t *path)
260
- {
261
- cairo_surface_t *surface;
262
- cairo_t *cr;
263
-
264
- if (!NIL_P (rb_ivar_get (rb_path, id_at_context)))
265
- return;
266
-
267
- surface = cairo_image_surface_create (CAIRO_FORMAT_A1, 1, 1);
268
- cr = cairo_create (surface);
269
- if (path->num_data > 0)
270
- cairo_append_path (cr, path);
271
- rb_cairo_check_status (cairo_status (cr));
272
- rb_ivar_set (rb_path, id_at_context, CRCONTEXT2RVAL (cr));
273
- cairo_destroy (cr);
253
+ return path;
274
254
  }
275
255
 
276
256
  VALUE
@@ -279,8 +259,15 @@ rb_cairo_path_to_ruby_object (cairo_path_t *path)
279
259
  if (path)
280
260
  {
281
261
  VALUE rb_path;
282
- rb_path = Data_Wrap_Struct (rb_cCairo_Path, NULL, cr_path_free, path);
283
- cr_path_ensure_internal_context (rb_path, path);
262
+ cairo_path_t *copied_path;
263
+ copied_path = RB_ALLOC (cairo_path_t);
264
+ copied_path->data = RB_ALLOC_N (cairo_path_data_t, path->num_data);
265
+ memcpy(copied_path->data,
266
+ path->data,
267
+ sizeof (cairo_path_data_t) * path->num_data);
268
+ rb_path = TypedData_Wrap_Struct (rb_cCairo_Path,
269
+ &cr_path_type,
270
+ copied_path);
284
271
  return rb_path;
285
272
  }
286
273
  else
@@ -292,7 +279,7 @@ rb_cairo_path_to_ruby_object (cairo_path_t *path)
292
279
  static VALUE
293
280
  cr_path_allocate (VALUE klass)
294
281
  {
295
- return Data_Wrap_Struct (klass, NULL, cr_path_free, NULL);
282
+ return TypedData_Wrap_Struct (klass, &cr_path_type, NULL);
296
283
  }
297
284
 
298
285
  static VALUE
@@ -300,13 +287,11 @@ cr_path_initialize (VALUE self)
300
287
  {
301
288
  cairo_path_t *path;
302
289
 
303
- path = ALLOC(cairo_path_t);
290
+ path = RB_ALLOC (cairo_path_t);
304
291
  path->status = CAIRO_STATUS_SUCCESS;
305
292
  path->data = NULL;
306
293
  path->num_data = 0;
307
-
308
- DATA_PTR (self) = path;
309
- cr_path_ensure_internal_context (self, path);
294
+ RTYPEDDATA_DATA (self) = path;
310
295
 
311
296
  return Qnil;
312
297
  }
@@ -5,7 +5,7 @@
5
5
  * $Author: kou $
6
6
  * $Date: 2008-06-12 10:59:54 $
7
7
  *
8
- * Copyright 2012-2019 Kouhei Sutou <kou@cozmixng.org>
8
+ * Copyright 2012-2022 Sutou Kouhei <kou@cozmixng.org>
9
9
  * Copyright 2005 Øyvind Kolås <pippin@freedesktop.org>
10
10
  * Copyright 2004-2005 MenTaLguY <mental@rydia.com>
11
11
  *
@@ -133,6 +133,23 @@ cr_pattern_raster_source_supported_p (VALUE klass)
133
133
  #endif
134
134
  }
135
135
 
136
+ static void
137
+ cr_pattern_free (void *ptr)
138
+ {
139
+ cairo_pattern_destroy ((cairo_pattern_t *) ptr);
140
+ }
141
+
142
+ static const rb_data_type_t cr_pattern_type = {
143
+ "Cairo::Pattern",
144
+ {
145
+ NULL,
146
+ cr_pattern_free,
147
+ },
148
+ NULL,
149
+ NULL,
150
+ RUBY_TYPED_FREE_IMMEDIATELY,
151
+ };
152
+
136
153
  cairo_pattern_t *
137
154
  rb_cairo_pattern_from_ruby_object (VALUE obj)
138
155
  {
@@ -141,19 +158,10 @@ rb_cairo_pattern_from_ruby_object (VALUE obj)
141
158
  {
142
159
  rb_raise (rb_eTypeError, "not a cairo pattern");
143
160
  }
144
- Data_Get_Struct (obj, cairo_pattern_t, pattern);
161
+ TypedData_Get_Struct (obj, cairo_pattern_t, &cr_pattern_type, pattern);
145
162
  return pattern;
146
163
  }
147
164
 
148
- static void
149
- cr_pattern_free (void *ptr)
150
- {
151
- if (ptr)
152
- {
153
- cairo_pattern_destroy ((cairo_pattern_t *) ptr);
154
- }
155
- }
156
-
157
165
  VALUE
158
166
  rb_cairo_pattern_to_ruby_object (cairo_pattern_t *pattern)
159
167
  {
@@ -162,7 +170,7 @@ rb_cairo_pattern_to_ruby_object (cairo_pattern_t *pattern)
162
170
  VALUE klass;
163
171
  klass = cr_pattern_get_klass (pattern);
164
172
  cairo_pattern_reference (pattern);
165
- return Data_Wrap_Struct (klass, NULL, cr_pattern_free, pattern);
173
+ return TypedData_Wrap_Struct (klass, &cr_pattern_type, pattern);
166
174
  }
167
175
  else
168
176
  {
@@ -173,7 +181,7 @@ rb_cairo_pattern_to_ruby_object (cairo_pattern_t *pattern)
173
181
  static VALUE
174
182
  cr_pattern_allocate (VALUE klass)
175
183
  {
176
- return Data_Wrap_Struct (klass, NULL, cr_pattern_free, NULL);
184
+ return TypedData_Wrap_Struct (klass, &cr_pattern_type, NULL);
177
185
  }
178
186
 
179
187
  static VALUE
@@ -251,7 +259,7 @@ cr_solid_pattern_initialize (int argc, VALUE *argv, VALUE self)
251
259
  }
252
260
 
253
261
  cr_pattern_check_status (pattern);
254
- DATA_PTR (self) = pattern;
262
+ RTYPEDDATA_DATA (self) = pattern;
255
263
  return Qnil;
256
264
  }
257
265
 
@@ -262,7 +270,7 @@ cr_surface_pattern_initialize (VALUE self, VALUE surface)
262
270
 
263
271
  pattern = cairo_pattern_create_for_surface (RVAL2CRSURFACE (surface));
264
272
  cr_pattern_check_status (pattern);
265
- DATA_PTR (self) = pattern;
273
+ RTYPEDDATA_DATA (self) = pattern;
266
274
  return Qnil;
267
275
  }
268
276
 
@@ -275,7 +283,7 @@ cr_linear_pattern_initialize (VALUE self, VALUE x0, VALUE y0,
275
283
  pattern = cairo_pattern_create_linear (NUM2DBL (x0), NUM2DBL (y0),
276
284
  NUM2DBL (x1), NUM2DBL (y1));
277
285
  cr_pattern_check_status (pattern);
278
- DATA_PTR (self) = pattern;
286
+ RTYPEDDATA_DATA (self) = pattern;
279
287
  return Qnil;
280
288
  }
281
289
 
@@ -290,7 +298,7 @@ cr_radial_pattern_initialize (VALUE self, VALUE cx0, VALUE cy0, VALUE radius0,
290
298
  NUM2DBL (cx1), NUM2DBL (cy1),
291
299
  NUM2DBL (radius1));
292
300
  cr_pattern_check_status (pattern);
293
- DATA_PTR (self) = pattern;
301
+ RTYPEDDATA_DATA (self) = pattern;
294
302
  return Qnil;
295
303
  }
296
304
 
@@ -518,7 +526,7 @@ cr_mesh_pattern_initialize (VALUE self)
518
526
 
519
527
  pattern = cairo_pattern_create_mesh ();
520
528
  cr_pattern_check_status (pattern);
521
- DATA_PTR (self) = pattern;
529
+ RTYPEDDATA_DATA (self) = pattern;
522
530
  return Qnil;
523
531
  }
524
532
 
@@ -916,7 +924,7 @@ cr_raster_source_pattern_initialize (int argc, VALUE *argv, VALUE self)
916
924
  content, width, height);
917
925
  cr_pattern_check_status (pattern);
918
926
 
919
- DATA_PTR (self) = pattern;
927
+ RTYPEDDATA_DATA (self) = pattern;
920
928
  rb_iv_set (self, "@acquire", Qnil);
921
929
  rb_iv_set (self, "@release", Qnil);
922
930
  rb_iv_set (self, "@snapshot", Qnil);