cairo 1.17.6 → 1.17.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7b1853ada5ca7f86bebe04e05e51c0b49a84fb7782bb2156db4d1825f75cc415
4
- data.tar.gz: 326f5322f9e2b66e115d656a762384e5caaa18ecba44c576a805c5989278d330
3
+ metadata.gz: f5ac730747ea5dada591e534a7c0653a0d1ad3fa3962dfdd01173e0074ff835c
4
+ data.tar.gz: 2fbccb304f8b4dbd3a89df42c9f1779b45a84b2f4c9be5ab591992eb9d7c3d31
5
5
  SHA512:
6
- metadata.gz: db4171dfe178c24f632f38fcbbd1960412160dd999bdd925b6501c663641a308acab2bd6fa2f9a84b3e18c30821ce3f6514b7dac809fd2b965f25c79051f66bd
7
- data.tar.gz: d9ef0bedc2b597617415c88d3734a4fe33a38bffc7a49939d671e4eed88f0da07f741fad595315376a76504dca36f35186563945a124d43510338ecd16970337
6
+ metadata.gz: 389eeca0e8c453e3c1b2ebe10053a1713c1c1ae93b22e46100b5bc1c39d566f00f60a1c676ae288e06fa9fdea6f24db8e107d53355bd52bc0e067e5b8b4fe073
7
+ data.tar.gz: d107b587d530433a0288f73a5b8d85710e2923213347f88e09de92562645dbcd9e501f8f9ab1bd74bb9ae13559ee94999e94c7555cd96a345b9d1d75965b961c
data/NEWS CHANGED
@@ -1,3 +1,12 @@
1
+ Release 1.17.7 (2022-07-31) Sutou Kouhei <kou@cozmixng.org>
2
+ ===========================================================
3
+
4
+ Fixes
5
+ -----
6
+
7
+ * Fixed a bug that Cairo::UserFontFace#on_render_color_glyph isn't
8
+ called.
9
+
1
10
  Release 1.17.6 (2022-07-30) Sutou Kouhei <kou@cozmixng.org>
2
11
  ===========================================================
3
12
 
data/ext/cairo/rb_cairo.h CHANGED
@@ -65,7 +65,7 @@ RB_CAIRO_BEGIN_DECLS
65
65
 
66
66
  #define RB_CAIRO_VERSION_MAJOR 1
67
67
  #define RB_CAIRO_VERSION_MINOR 17
68
- #define RB_CAIRO_VERSION_MICRO 6
68
+ #define RB_CAIRO_VERSION_MICRO 7
69
69
 
70
70
  RB_CAIRO_VAR VALUE rb_mCairo;
71
71
  RB_CAIRO_VAR VALUE rb_cCairo_Context;
@@ -5,7 +5,7 @@
5
5
  * $Author: kou $
6
6
  * $Date: 2008-09-26 13:52:08 $
7
7
  *
8
- * Copyright 2005-2019 Kouhei Sutou <kou@cozmixng.org>
8
+ * Copyright 2005-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
  *
@@ -40,6 +40,23 @@ cr_check_status (cairo_t *context)
40
40
  rb_cairo_check_status (cairo_status (context));
41
41
  }
42
42
 
43
+ static void
44
+ cr_context_free (void *ptr)
45
+ {
46
+ cairo_destroy ((cairo_t *) ptr);
47
+ }
48
+
49
+ static const rb_data_type_t cr_context_type = {
50
+ "Cairo::Context",
51
+ {
52
+ NULL,
53
+ cr_context_free,
54
+ },
55
+ NULL,
56
+ NULL,
57
+ RUBY_TYPED_FREE_IMMEDIATELY,
58
+ };
59
+
43
60
  /* Functions for manipulating state objects */
44
61
  cairo_t *
45
62
  rb_cairo_context_from_ruby_object (VALUE obj)
@@ -49,7 +66,7 @@ rb_cairo_context_from_ruby_object (VALUE obj)
49
66
  {
50
67
  rb_raise (rb_eTypeError, "not a cairo graphics context");
51
68
  }
52
- Data_Get_Struct (obj, cairo_t, context);
69
+ TypedData_Get_Struct (obj, cairo_t, &cr_context_type, context);
53
70
  if (!context)
54
71
  rb_cairo_check_status (CAIRO_STATUS_NULL_POINTER);
55
72
  return context;
@@ -67,22 +84,13 @@ cr_object_holder_free (void *ptr)
67
84
  rb_cairo__object_holder_free (rb_cCairo_Context, ptr);
68
85
  }
69
86
 
70
- static void
71
- cr_context_free (void *ptr)
72
- {
73
- if (ptr)
74
- {
75
- cairo_destroy ((cairo_t *) ptr);
76
- }
77
- }
78
-
79
87
  VALUE
80
88
  rb_cairo_context_to_ruby_object (cairo_t *cr)
81
89
  {
82
90
  if (cr)
83
91
  {
84
92
  cairo_reference (cr);
85
- return Data_Wrap_Struct (rb_cCairo_Context, NULL, cr_context_free, cr);
93
+ return TypedData_Wrap_Struct (rb_cCairo_Context, &cr_context_type, cr);
86
94
  }
87
95
  else
88
96
  {
@@ -93,7 +101,7 @@ rb_cairo_context_to_ruby_object (cairo_t *cr)
93
101
  static VALUE
94
102
  cr_allocate (VALUE klass)
95
103
  {
96
- return Data_Wrap_Struct (klass, NULL, cr_context_free, NULL);
104
+ return TypedData_Wrap_Struct (klass, &cr_context_type, NULL);
97
105
  }
98
106
 
99
107
  static void
@@ -1595,20 +1603,26 @@ static VALUE
1595
1603
  cr_copy_path (VALUE self)
1596
1604
  {
1597
1605
  cairo_path_t *path;
1606
+ VALUE rb_path;
1598
1607
 
1599
1608
  path = cairo_copy_path (_SELF);
1600
1609
  rb_cairo_check_status (path->status);
1601
- return CRPATH2RVAL (path);
1610
+ rb_path = CRPATH2RVAL (path);
1611
+ cairo_path_destroy (path);
1612
+ return rb_path;
1602
1613
  }
1603
1614
 
1604
1615
  static VALUE
1605
1616
  cr_copy_path_flat (VALUE self)
1606
1617
  {
1607
1618
  cairo_path_t *path;
1619
+ VALUE rb_path;
1608
1620
 
1609
- path = cairo_copy_path_flat (_SELF);
1621
+ path = cairo_copy_path_flat (_SELF);
1610
1622
  rb_cairo_check_status (path->status);
1611
- return CRPATH2RVAL (path);
1623
+ rb_path = CRPATH2RVAL (path);
1624
+ cairo_path_destroy (path);
1625
+ return rb_path;
1612
1626
  }
1613
1627
 
1614
1628
  static VALUE
@@ -2,7 +2,7 @@
2
2
  /*
3
3
  * Ruby Cairo Binding
4
4
  *
5
- * Copyright 2010-2019 Kouhei Sutou <kou@cozmixng.org>
5
+ * Copyright 2010-2022 Sutou Kouhei <kou@cozmixng.org>
6
6
  *
7
7
  * This file is made available under the same terms as Ruby
8
8
  *
@@ -117,6 +117,24 @@ cr_device_xml_supported_p (VALUE klass)
117
117
  }
118
118
 
119
119
  /* constructor/de-constructor */
120
+ static void
121
+ cr_device_free (void *ptr)
122
+ {
123
+ cairo_device_t *device = ptr;
124
+ cairo_device_destroy (device);
125
+ }
126
+
127
+ static const rb_data_type_t cr_device_type = {
128
+ "Cairo::Device",
129
+ {
130
+ NULL,
131
+ cr_device_free,
132
+ },
133
+ NULL,
134
+ NULL,
135
+ RUBY_TYPED_FREE_IMMEDIATELY,
136
+ };
137
+
120
138
  cairo_device_t *
121
139
  rb_cairo_device_from_ruby_object (VALUE obj)
122
140
  {
@@ -125,7 +143,7 @@ rb_cairo_device_from_ruby_object (VALUE obj)
125
143
  {
126
144
  rb_raise (rb_eTypeError, "not a cairo device");
127
145
  }
128
- Data_Get_Struct (obj, cairo_device_t, device);
146
+ TypedData_Get_Struct (obj, cairo_device_t, &cr_device_type, device);
129
147
  if (!device)
130
148
  rb_cairo_check_status (CAIRO_STATUS_NULL_POINTER);
131
149
  return device;
@@ -145,15 +163,6 @@ cr_object_holder_free (void *ptr)
145
163
  }
146
164
  #endif
147
165
 
148
- static void
149
- cr_device_free (void *ptr)
150
- {
151
- cairo_device_t *device = ptr;
152
-
153
- if (device)
154
- cairo_device_destroy (device);
155
- }
156
-
157
166
  VALUE
158
167
  rb_cairo_device_to_ruby_object (cairo_device_t *device)
159
168
  {
@@ -162,7 +171,7 @@ rb_cairo_device_to_ruby_object (cairo_device_t *device)
162
171
  VALUE klass;
163
172
  klass = cr_device_get_klass (device);
164
173
  cairo_device_reference (device);
165
- return Data_Wrap_Struct (klass, NULL, cr_device_free, device);
174
+ return TypedData_Wrap_Struct (klass, &cr_device_type, device);
166
175
  }
167
176
  else
168
177
  {
@@ -185,7 +194,7 @@ rb_cairo_device_to_ruby_object_with_destroy (cairo_device_t *device)
185
194
  static VALUE
186
195
  cr_device_allocate (VALUE klass)
187
196
  {
188
- return Data_Wrap_Struct (klass, NULL, cr_device_free, NULL);
197
+ return TypedData_Wrap_Struct (klass, &cr_device_type, NULL);
189
198
  }
190
199
 
191
200
  static VALUE
@@ -5,6 +5,7 @@
5
5
  * $Author: kou $
6
6
  * $Date: 2008-08-17 05:12:37 $
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
  *
@@ -19,6 +20,17 @@ VALUE rb_cCairo_FontExtents;
19
20
 
20
21
  #define _SELF(self) (RVAL2CRFONTEXTENTS(self))
21
22
 
23
+ static const rb_data_type_t cr_font_extents_type = {
24
+ "Cairo::FontExtents",
25
+ {
26
+ NULL,
27
+ ruby_xfree,
28
+ },
29
+ NULL,
30
+ NULL,
31
+ RUBY_TYPED_FREE_IMMEDIATELY,
32
+ };
33
+
22
34
  cairo_font_extents_t *
23
35
  rb_cairo_font_extents_from_ruby_object (VALUE obj)
24
36
  {
@@ -27,7 +39,10 @@ rb_cairo_font_extents_from_ruby_object (VALUE obj)
27
39
  {
28
40
  rb_raise (rb_eTypeError, "not a cairo font extents");
29
41
  }
30
- Data_Get_Struct (obj, cairo_font_extents_t, extents);
42
+ TypedData_Get_Struct (obj,
43
+ cairo_font_extents_t,
44
+ &cr_font_extents_type,
45
+ extents);
31
46
  return extents;
32
47
  }
33
48
 
@@ -38,7 +53,9 @@ rb_cairo_font_extents_to_ruby_object (cairo_font_extents_t *extents)
38
53
  {
39
54
  cairo_font_extents_t *new_extents = ALLOC (cairo_font_extents_t);
40
55
  *new_extents = *extents;
41
- return Data_Wrap_Struct (rb_cCairo_FontExtents, NULL, -1, new_extents);
56
+ return TypedData_Wrap_Struct (rb_cCairo_FontExtents,
57
+ &cr_font_extents_type,
58
+ new_extents);
42
59
  }
43
60
  else
44
61
  {
@@ -49,7 +66,7 @@ rb_cairo_font_extents_to_ruby_object (cairo_font_extents_t *extents)
49
66
  static VALUE
50
67
  cr_font_extents_allocate (VALUE klass)
51
68
  {
52
- return Data_Wrap_Struct (klass, NULL, -1, NULL);
69
+ return TypedData_Wrap_Struct (klass, &cr_font_extents_type, NULL);
53
70
  }
54
71
 
55
72
  static VALUE
@@ -55,6 +55,24 @@ static ID cr_id_at_need_cluster_flags;
55
55
 
56
56
  #define _SELF (RVAL2CRFONTFACE(self))
57
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
+
58
76
  static inline void
59
77
  cr_font_face_check_status (cairo_font_face_t *face)
60
78
  {
@@ -72,23 +90,13 @@ rb_cairo_font_face_from_ruby_object (VALUE obj)
72
90
  "not a cairo font face: %s",
73
91
  rb_cairo__inspect (obj));
74
92
  }
75
- Data_Get_Struct (obj, cairo_font_face_t, face);
93
+ TypedData_Get_Struct (obj, cairo_font_face_t, &cr_font_face_type, face);
76
94
  if (!face)
77
95
  rb_cairo_check_status (CAIRO_STATUS_NULL_POINTER);
78
96
  cr_font_face_check_status (face);
79
97
  return face;
80
98
  }
81
99
 
82
- static void
83
- cr_font_face_free (void *ptr)
84
- {
85
- if (ptr)
86
- {
87
- cairo_font_face_t *face = ptr;
88
- cairo_font_face_destroy (face);
89
- }
90
- }
91
-
92
100
  VALUE
93
101
  rb_cairo_font_face_to_ruby_object (cairo_font_face_t *face)
94
102
  {
@@ -116,7 +124,7 @@ rb_cairo_font_face_to_ruby_object (cairo_font_face_t *face)
116
124
  break;
117
125
  }
118
126
  cairo_font_face_reference (face);
119
- return Data_Wrap_Struct (klass, NULL, cr_font_face_free, face);
127
+ return TypedData_Wrap_Struct (klass, &cr_font_face_type, face);
120
128
  }
121
129
  else
122
130
  {
@@ -127,7 +135,7 @@ rb_cairo_font_face_to_ruby_object (cairo_font_face_t *face)
127
135
  static VALUE
128
136
  cr_font_face_allocate (VALUE klass)
129
137
  {
130
- return Data_Wrap_Struct (klass, NULL, cr_font_face_free, NULL);
138
+ return TypedData_Wrap_Struct (klass, &cr_font_face_type, NULL);
131
139
  }
132
140
 
133
141
  static VALUE
@@ -480,7 +488,7 @@ cr_user_font_face_render_glyph_func_internal (cairo_scaled_font_t *scaled_font,
480
488
 
481
489
  face = cairo_scaled_font_get_font_face (scaled_font);
482
490
  self = (VALUE)cairo_font_face_get_user_data (face, &ruby_object_key);
483
- receiver = rb_ivar_get (self, cr_id_render_glyph);
491
+ receiver = rb_ivar_get (self, id_registered_method_name);
484
492
  if (NIL_P (receiver) &&
485
493
  rb_obj_respond_to (self, id_registered_method_name, Qtrue))
486
494
  {
@@ -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
@@ -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
@@ -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
@@ -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
294
  DATA_PTR (self) = path;
309
- cr_path_ensure_internal_context (self, path);
310
295
 
311
296
  return Qnil;
312
297
  }