cairo 1.17.5 → 1.17.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,6 +17,8 @@
17
17
  #endif
18
18
 
19
19
  #ifdef CAIRO_HAS_QUARTZ_SURFACE
20
+ static ID cr_id_image_surface;
21
+
20
22
  # ifndef HAVE_TYPE_ENUM_RUBY_VALUE_TYPE
21
23
  enum ruby_value_type {
22
24
  RUBY_T_DATA = T_DATA
@@ -132,7 +134,7 @@ cr_quartz_surface_initialize (int argc, VALUE *argv, VALUE self)
132
134
  }
133
135
 
134
136
  rb_cairo_surface_check_status (surface);
135
- DATA_PTR (self) = surface;
137
+ RTYPEDDATA_DATA (self) = surface;
136
138
  if (rb_block_given_p ())
137
139
  rb_cairo__surface_yield_and_finish (self);
138
140
  return Qnil;
@@ -167,7 +169,8 @@ cr_quartz_image_surface_initialize (VALUE self, VALUE image_surface)
167
169
 
168
170
  surface = cairo_quartz_image_surface_create (RVAL2CRSURFACE (image_surface));
169
171
  rb_cairo_surface_check_status (surface);
170
- DATA_PTR (self) = surface;
172
+ RTYPEDDATA_DATA (self) = surface;
173
+ rb_ivar_set (self, cr_id_image_surface, image_surface);
171
174
  if (rb_block_given_p ())
172
175
  rb_cairo__surface_yield_and_finish (self);
173
176
  return Qnil;
@@ -199,6 +202,8 @@ Init_cairo_quartz_surface (void)
199
202
 
200
203
  /* Quartz image surface */
201
204
  #ifdef RB_CAIRO_HAS_QUARTZ_IMAGE_SURFACE
205
+ cr_id_image_surface = rb_intern ("image_surface");
206
+
202
207
  rb_define_method (rb_cCairo_QuartzImageSurface, "initialize",
203
208
  cr_quartz_image_surface_initialize, 1);
204
209
  rb_define_method (rb_cCairo_QuartzImageSurface, "image",
@@ -2,7 +2,7 @@
2
2
  /*
3
3
  * Ruby Cairo Binding
4
4
  *
5
- * Copyright 2005-2014 Kouhei Sutou <kou@cozmixng.org>
5
+ * Copyright 2005-2022 Sutou Kouhei <kou@cozmixng.org>
6
6
  *
7
7
  * This file is made available under the same terms as Ruby
8
8
  *
@@ -12,13 +12,24 @@
12
12
 
13
13
  VALUE rb_cCairo_Rectangle;
14
14
 
15
- #define _SELF ((cairo_rectangle_int_t *)DATA_PTR (self))
15
+ #define _SELF ((cairo_rectangle_int_t *)RTYPEDDATA_DATA (self))
16
16
 
17
17
  #if CAIRO_CHECK_VERSION(1, 10, 0)
18
+ static const rb_data_type_t cr_rectangle_type = {
19
+ "Cairo::Rectangle",
20
+ {
21
+ NULL,
22
+ ruby_xfree,
23
+ },
24
+ NULL,
25
+ NULL,
26
+ RUBY_TYPED_FREE_IMMEDIATELY,
27
+ };
28
+
18
29
  static VALUE
19
30
  cr_rectangle_allocate (VALUE klass)
20
31
  {
21
- return Data_Wrap_Struct (klass, NULL, xfree, NULL);
32
+ return TypedData_Wrap_Struct (klass, &cr_rectangle_type, NULL);
22
33
  }
23
34
 
24
35
  static VALUE
@@ -28,7 +39,7 @@ cr_rectangle_initialize (VALUE self, VALUE x, VALUE y,
28
39
  cairo_rectangle_int_t *rectangle;
29
40
 
30
41
  rectangle = ALLOC (cairo_rectangle_int_t);
31
- DATA_PTR (self) = rectangle;
42
+ RTYPEDDATA_DATA (self) = rectangle;
32
43
 
33
44
  rectangle->x = NUM2INT (x);
34
45
  rectangle->y = NUM2INT (y);
@@ -2,7 +2,7 @@
2
2
  /*
3
3
  * Ruby Cairo Binding
4
4
  *
5
- * Copyright 2010 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
  *
@@ -18,6 +18,23 @@ VALUE rb_cCairo_Region = Qnil;
18
18
 
19
19
  #define _SELF (RVAL2CRREGION(self))
20
20
 
21
+ static void
22
+ cr_region_free (void *ptr)
23
+ {
24
+ cairo_region_destroy ((cairo_region_t *) ptr);
25
+ }
26
+
27
+ static const rb_data_type_t cr_region_type = {
28
+ "Cairo::Region",
29
+ {
30
+ NULL,
31
+ cr_region_free,
32
+ },
33
+ NULL,
34
+ NULL,
35
+ RUBY_TYPED_FREE_IMMEDIATELY,
36
+ };
37
+
21
38
  static inline void
22
39
  cr_region_check_status (cairo_region_t *region)
23
40
  {
@@ -32,26 +49,17 @@ rb_cairo_region_from_ruby_object (VALUE obj)
32
49
  {
33
50
  rb_raise (rb_eTypeError, "not a cairo region");
34
51
  }
35
- Data_Get_Struct (obj, cairo_region_t, region);
52
+ TypedData_Get_Struct (obj, cairo_region_t, &cr_region_type, region);
36
53
  return region;
37
54
  }
38
55
 
39
- static void
40
- cr_region_free (void *ptr)
41
- {
42
- if (ptr)
43
- {
44
- cairo_region_destroy ((cairo_region_t *) ptr);
45
- }
46
- }
47
-
48
56
  VALUE
49
57
  rb_cairo_region_to_ruby_object (cairo_region_t *region)
50
58
  {
51
59
  if (region)
52
60
  {
53
61
  cairo_region_reference (region);
54
- return Data_Wrap_Struct (rb_cCairo_Region, NULL, cr_region_free, region);
62
+ return TypedData_Wrap_Struct (rb_cCairo_Region, &cr_region_type, region);
55
63
  }
56
64
  else
57
65
  {
@@ -62,7 +70,7 @@ rb_cairo_region_to_ruby_object (cairo_region_t *region)
62
70
  static VALUE
63
71
  cr_region_allocate (VALUE klass)
64
72
  {
65
- return Data_Wrap_Struct (klass, NULL, cr_region_free, NULL);
73
+ return TypedData_Wrap_Struct (klass, &cr_region_type, NULL);
66
74
  }
67
75
 
68
76
  static VALUE
@@ -98,7 +106,7 @@ cr_region_initialize (int argc, VALUE *argv, VALUE self)
98
106
  region = cairo_region_create_rectangles (rectangles, argc);
99
107
  }
100
108
  cr_region_check_status (region);
101
- DATA_PTR (self) = region;
109
+ RTYPEDDATA_DATA (self) = region;
102
110
  return Qnil;
103
111
  }
104
112
 
@@ -5,7 +5,7 @@
5
5
  * $Author: kou $
6
6
  * $Date: 2008-09-19 12:56:27 $
7
7
  *
8
- * Copyright 2005-2019 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
  *
@@ -19,6 +19,23 @@ VALUE rb_cCairo_ScaledFont;
19
19
 
20
20
  #define _SELF(self) (RVAL2CRSCALEDFONT(self))
21
21
 
22
+ static void
23
+ cr_scaled_font_free (void *ptr)
24
+ {
25
+ cairo_scaled_font_destroy ((cairo_scaled_font_t *) ptr);
26
+ }
27
+
28
+ static const rb_data_type_t cr_scaled_font_type = {
29
+ "Cairo::ScaledFont",
30
+ {
31
+ NULL,
32
+ cr_scaled_font_free,
33
+ },
34
+ NULL,
35
+ NULL,
36
+ RUBY_TYPED_FREE_IMMEDIATELY,
37
+ };
38
+
22
39
  static inline void
23
40
  cr_scaled_font_check_status (cairo_scaled_font_t *font)
24
41
  {
@@ -33,27 +50,19 @@ rb_cairo_scaled_font_from_ruby_object (VALUE obj)
33
50
  {
34
51
  rb_raise (rb_eTypeError, "not a cairo scaled font");
35
52
  }
36
- Data_Get_Struct (obj, cairo_scaled_font_t, font);
53
+ TypedData_Get_Struct (obj, cairo_scaled_font_t, &cr_scaled_font_type, font);
37
54
  return font;
38
55
  }
39
56
 
40
- static void
41
- cr_scaled_font_free (void *ptr)
42
- {
43
- if (ptr)
44
- {
45
- cairo_scaled_font_destroy ((cairo_scaled_font_t *) ptr);
46
- }
47
- }
48
-
49
57
  VALUE
50
58
  rb_cairo_scaled_font_to_ruby_object (cairo_scaled_font_t *font)
51
59
  {
52
60
  if (font)
53
61
  {
54
62
  cairo_scaled_font_reference (font);
55
- return Data_Wrap_Struct (rb_cCairo_ScaledFont, NULL,
56
- cr_scaled_font_free, font);
63
+ return TypedData_Wrap_Struct (rb_cCairo_ScaledFont,
64
+ &cr_scaled_font_type,
65
+ font);
57
66
  }
58
67
  else
59
68
  {
@@ -64,7 +73,7 @@ rb_cairo_scaled_font_to_ruby_object (cairo_scaled_font_t *font)
64
73
  static VALUE
65
74
  cr_scaled_font_allocate (VALUE klass)
66
75
  {
67
- return Data_Wrap_Struct (klass, NULL, cr_scaled_font_free, NULL);
76
+ return TypedData_Wrap_Struct (klass, &cr_scaled_font_type, NULL);
68
77
  }
69
78
 
70
79
  static VALUE
@@ -78,7 +87,7 @@ cr_scaled_font_initialize (VALUE self, VALUE face, VALUE matrix,
78
87
  RVAL2CRMATRIX (ctm),
79
88
  RVAL2CRFONTOPTIONS (options));
80
89
  cr_scaled_font_check_status (font);
81
- DATA_PTR (self) = font;
90
+ RTYPEDDATA_DATA (self) = font;
82
91
  return Qnil;
83
92
  }
84
93
 
@@ -2,7 +2,7 @@
2
2
  /*
3
3
  * Ruby Cairo Binding
4
4
  *
5
- * Copyright 2005-2019 Kouhei Sutou <kou@cozmixng.org>
5
+ * Copyright 2005-2022 Sutou Kouhei <kou@cozmixng.org>
6
6
  * Copyright 2014 Patrick Hanevold <patrick.hanevold@gmail.com>
7
7
  * Copyright 2005 Øyvind Kolås <pippin@freedesktop.org>
8
8
  * Copyright 2004-2005 MenTaLguY <mental@rydia.com>
@@ -103,6 +103,18 @@ static cairo_user_data_key_t cr_finished_key;
103
103
 
104
104
  #define _SELF (RVAL2CRSURFACE(self))
105
105
 
106
+ static void cr_surface_free (void *ptr);
107
+ static const rb_data_type_t cr_surface_type = {
108
+ "Cairo::Surface",
109
+ {
110
+ NULL,
111
+ cr_surface_free,
112
+ },
113
+ NULL,
114
+ NULL,
115
+ RUBY_TYPED_FREE_IMMEDIATELY,
116
+ };
117
+
106
118
  static VALUE
107
119
  cr_paper_parse (VALUE paper_description)
108
120
  {
@@ -232,6 +244,28 @@ rb_cairo_surface_adjust_memory_usage (cairo_surface_t *surface,
232
244
  #endif
233
245
  }
234
246
 
247
+ static cairo_surface_t *
248
+ rb_cairo_surface_from_ruby_object_without_null_check (VALUE obj)
249
+ {
250
+ cairo_surface_t *surface;
251
+ if (!rb_cairo__is_kind_of (obj, rb_cCairo_Surface))
252
+ {
253
+ rb_raise (rb_eTypeError, "not a cairo surface");
254
+ }
255
+ TypedData_Get_Struct (obj, cairo_surface_t, &cr_surface_type, surface);
256
+ return surface;
257
+ }
258
+
259
+ cairo_surface_t *
260
+ rb_cairo_surface_from_ruby_object (VALUE obj)
261
+ {
262
+ cairo_surface_t *surface =
263
+ rb_cairo_surface_from_ruby_object_without_null_check (obj);
264
+ if (!surface)
265
+ rb_cairo_check_status (CAIRO_STATUS_NULL_POINTER);
266
+ return surface;
267
+ }
268
+
235
269
  static void
236
270
  cr_surface_destroy_raw (cairo_surface_t *surface)
237
271
  {
@@ -246,7 +280,7 @@ cr_surface_destroy (VALUE self)
246
280
 
247
281
  surface = _SELF;
248
282
  cr_surface_destroy_raw (surface);
249
- DATA_PTR (self) = NULL;
283
+ RTYPEDDATA_DATA (self) = NULL;
250
284
 
251
285
  return self;
252
286
  }
@@ -254,7 +288,7 @@ cr_surface_destroy (VALUE self)
254
288
  static VALUE
255
289
  cr_surface_destroy_with_destroy_check (VALUE self)
256
290
  {
257
- if (_SELF)
291
+ if (rb_cairo_surface_from_ruby_object_without_null_check (self))
258
292
  cr_surface_destroy (self);
259
293
  return Qnil;
260
294
  }
@@ -407,21 +441,6 @@ cr_surface_xml_supported_p (VALUE klass)
407
441
  #endif
408
442
  }
409
443
 
410
- /* constructor/de-constructor */
411
- cairo_surface_t *
412
- rb_cairo_surface_from_ruby_object (VALUE obj)
413
- {
414
- cairo_surface_t *surface;
415
- if (!rb_cairo__is_kind_of (obj, rb_cCairo_Surface))
416
- {
417
- rb_raise (rb_eTypeError, "not a cairo surface");
418
- }
419
- Data_Get_Struct (obj, cairo_surface_t, surface);
420
- if (!surface)
421
- rb_cairo_check_status (CAIRO_STATUS_NULL_POINTER);
422
- return surface;
423
- }
424
-
425
444
  static rb_cairo__object_holder_t *
426
445
  cr_object_holder_new (VALUE object)
427
446
  {
@@ -454,7 +473,7 @@ rb_cairo_surface_to_ruby_object (cairo_surface_t *surface)
454
473
  klass = cr_surface_get_klass (surface);
455
474
  cairo_surface_reference (surface);
456
475
  rb_cairo_surface_adjust_memory_usage (surface, CR_TRUE);
457
- return Data_Wrap_Struct (klass, NULL, cr_surface_free, surface);
476
+ return TypedData_Wrap_Struct (klass, &cr_surface_type, surface);
458
477
  }
459
478
  else
460
479
  {
@@ -477,7 +496,7 @@ rb_cairo_surface_to_ruby_object_with_destroy (cairo_surface_t *surface)
477
496
  static VALUE
478
497
  cr_surface_allocate (VALUE klass)
479
498
  {
480
- return Data_Wrap_Struct (klass, NULL, cr_surface_free, NULL);
499
+ return TypedData_Wrap_Struct (klass, &cr_surface_type, NULL);
481
500
  }
482
501
 
483
502
  static VALUE
@@ -515,6 +534,7 @@ cr_surface_finish (VALUE self)
515
534
  cairo_surface_finish (surface);
516
535
  cairo_surface_set_user_data (surface, &cr_finished_key, (void *)CR_TRUE, NULL);
517
536
  cairo_surface_set_user_data (surface, &cr_object_holder_key, NULL, NULL);
537
+ RTYPEDDATA_DATA (self) = NULL;
518
538
 
519
539
  if (closure && !NIL_P (closure->error))
520
540
  rb_exc_raise (closure->error);
@@ -531,7 +551,7 @@ rb_cairo__surface_yield_and_finish (VALUE self)
531
551
 
532
552
  rb_result = rb_yield (self);
533
553
 
534
- surface = _SELF;
554
+ surface = rb_cairo_surface_from_ruby_object_without_null_check (self);
535
555
  if (!surface)
536
556
  return rb_result;
537
557
  if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS)
@@ -730,6 +750,11 @@ cr_surface_write_to_png (VALUE self, VALUE filename)
730
750
  static VALUE
731
751
  cr_surface_write_to_png_generic (VALUE self, VALUE target)
732
752
  {
753
+ if (rb_respond_to (target, rb_cairo__io_id_to_path) &&
754
+ !rb_respond_to (target, rb_cairo__io_id_to_io))
755
+ {
756
+ target = rb_funcall (target, rb_cairo__io_id_to_path, 0);
757
+ }
733
758
  if (rb_respond_to (target, rb_cairo__io_id_write))
734
759
  return cr_surface_write_to_png_stream (self, target);
735
760
  else
@@ -995,7 +1020,7 @@ cr_image_surface_create_from_png_generic (VALUE klass, VALUE target)
995
1020
 
996
1021
  rb_cairo_surface_check_status (surface);
997
1022
  rb_surface = cr_surface_allocate (klass);
998
- DATA_PTR (rb_surface) = surface;
1023
+ RTYPEDDATA_DATA (rb_surface) = surface;
999
1024
  return rb_surface;
1000
1025
  }
1001
1026
  #endif
@@ -1052,7 +1077,7 @@ cr_image_surface_initialize (int argc, VALUE *argv, VALUE self)
1052
1077
  rb_cairo__inspect (rb_ary_new3 (4, arg1, arg2, arg3, arg4)));
1053
1078
 
1054
1079
  rb_cairo_surface_check_status (surface);
1055
- DATA_PTR (self) = surface;
1080
+ RTYPEDDATA_DATA (self) = surface;
1056
1081
  rb_cairo_surface_adjust_memory_usage (surface, CR_TRUE);
1057
1082
  if (rb_block_given_p ())
1058
1083
  rb_cairo__surface_yield_and_finish (self);
@@ -1173,7 +1198,7 @@ cr_ ## type ## _surface_initialize (int argc, VALUE *argv, VALUE self) \
1173
1198
  } \
1174
1199
  \
1175
1200
  rb_cairo_surface_check_status (surface); \
1176
- DATA_PTR (self) = surface; \
1201
+ RTYPEDDATA_DATA (self) = surface; \
1177
1202
  if (rb_block_given_p ()) \
1178
1203
  rb_cairo__surface_yield_and_finish (self); \
1179
1204
  return Qnil; \
@@ -1328,6 +1353,26 @@ cr_pdf_surface_set_thumbnail_size (VALUE self,
1328
1353
  return Qnil;
1329
1354
  }
1330
1355
  # endif
1356
+
1357
+ # if CAIRO_CHECK_VERSION(1, 17, 6)
1358
+ static VALUE
1359
+ cr_pdf_surface_set_custom_metadata (VALUE self,
1360
+ VALUE rb_name,
1361
+ VALUE rb_value)
1362
+ {
1363
+ cairo_surface_t *surface;
1364
+ const char *name;
1365
+ const char *value;
1366
+
1367
+ surface = _SELF;
1368
+ name = RVAL2CSTR (rb_name);
1369
+ value = RVAL2CSTR (rb_value);
1370
+ cairo_pdf_surface_set_custom_metadata (surface, name, value);
1371
+ rb_cairo_surface_check_status (surface);
1372
+
1373
+ return Qnil;
1374
+ }
1375
+ # endif
1331
1376
  #endif
1332
1377
 
1333
1378
  #ifdef CAIRO_HAS_PS_SURFACE
@@ -1494,7 +1539,7 @@ cr_win32_surface_initialize (int argc, VALUE *argv, VALUE self)
1494
1539
  if (!surface)
1495
1540
  rb_cairo_check_status (CAIRO_STATUS_INVALID_FORMAT);
1496
1541
  rb_cairo_surface_check_status (surface);
1497
- DATA_PTR (self) = surface;
1542
+ RTYPEDDATA_DATA (self) = surface;
1498
1543
  if (rb_block_given_p ())
1499
1544
  rb_cairo__surface_yield_and_finish (self);
1500
1545
  return Qnil;
@@ -1570,7 +1615,7 @@ cr_win32_printing_surface_initialize (VALUE self, VALUE hdc)
1570
1615
 
1571
1616
  surface = cairo_win32_printing_surface_create (NUM2PTR (hdc));
1572
1617
  rb_cairo_surface_check_status (surface);
1573
- DATA_PTR (self) = surface;
1618
+ RTYPEDDATA_DATA (self) = surface;
1574
1619
  if (rb_block_given_p ())
1575
1620
  rb_cairo__surface_yield_and_finish (self);
1576
1621
  return Qnil;
@@ -1625,7 +1670,7 @@ cr_script_surface_initialize (int argc, VALUE *argv, VALUE self)
1625
1670
  surface = cairo_script_surface_create (device, content, width, height);
1626
1671
 
1627
1672
  rb_cairo_surface_check_status (surface);
1628
- DATA_PTR (self) = surface;
1673
+ RTYPEDDATA_DATA (self) = surface;
1629
1674
  if (rb_block_given_p ())
1630
1675
  rb_cairo__surface_yield_and_finish (self);
1631
1676
  return Qnil;
@@ -1680,7 +1725,7 @@ cr_recording_surface_initialize (int argc, VALUE *argv, VALUE self)
1680
1725
 
1681
1726
  surface = cairo_recording_surface_create (content, &extents);
1682
1727
  rb_cairo_surface_check_status (surface);
1683
- DATA_PTR (self) = surface;
1728
+ RTYPEDDATA_DATA (self) = surface;
1684
1729
  if (rb_block_given_p ())
1685
1730
  rb_cairo__surface_yield_and_finish (self);
1686
1731
  return Qnil;
@@ -1757,7 +1802,7 @@ cr_gl_surface_initialize (int argc, VALUE *argv, VALUE self)
1757
1802
  surface = cairo_gl_surface_create (device, content, width, height);
1758
1803
 
1759
1804
  rb_cairo_surface_check_status (surface);
1760
- DATA_PTR (self) = surface;
1805
+ RTYPEDDATA_DATA (self) = surface;
1761
1806
  if (rb_block_given_p ())
1762
1807
  rb_cairo__surface_yield_and_finish (self);
1763
1808
  return Qnil;
@@ -1804,7 +1849,7 @@ cr_gl_texture_surface_initialize (int argc, VALUE *argv, VALUE self)
1804
1849
  height);
1805
1850
 
1806
1851
  rb_cairo_surface_check_status (surface);
1807
- DATA_PTR (self) = surface;
1852
+ RTYPEDDATA_DATA (self) = surface;
1808
1853
  if (rb_block_given_p ())
1809
1854
  rb_cairo__surface_yield_and_finish (self);
1810
1855
  return Qnil;
@@ -1854,7 +1899,7 @@ cr_tee_surface_initialize (VALUE self, VALUE master)
1854
1899
 
1855
1900
  surface = cairo_tee_surface_create (RVAL2CRSURFACE (master));
1856
1901
  rb_cairo_surface_check_status (surface);
1857
- DATA_PTR (self) = surface;
1902
+ RTYPEDDATA_DATA (self) = surface;
1858
1903
  rb_iv_set (self, "surfaces", rb_ary_new3 (1, master));
1859
1904
  if (rb_block_given_p ())
1860
1905
  rb_cairo__surface_yield_and_finish (self);
@@ -1976,7 +2021,7 @@ cr_xml_surface_initialize (int argc, VALUE *argv, VALUE self)
1976
2021
  surface = cairo_xml_surface_create (device, content, width, height);
1977
2022
 
1978
2023
  rb_cairo_surface_check_status (surface);
1979
- DATA_PTR (self) = surface;
2024
+ RTYPEDDATA_DATA (self) = surface;
1980
2025
  if (rb_block_given_p ())
1981
2026
  rb_cairo__surface_yield_and_finish (self);
1982
2027
  return Qnil;
@@ -2177,6 +2222,11 @@ Init_cairo_surface (void)
2177
2222
  }
2178
2223
  # endif
2179
2224
 
2225
+ # if CAIRO_CHECK_VERSION(1, 17, 6)
2226
+ rb_define_method (rb_cCairo_PDFSurface, "set_custom_metadata",
2227
+ cr_pdf_surface_set_custom_metadata, 2);
2228
+ # endif
2229
+
2180
2230
  RB_CAIRO_DEF_SETTERS (rb_cCairo_PDFSurface);
2181
2231
  #endif
2182
2232
 
@@ -5,7 +5,7 @@
5
5
  * $Author: kou $
6
6
  * $Date: 2008-08-16 08:16:40 $
7
7
  *
8
- * Copyright 2008 Kouhei Sutou <kou@cozmixng.org>
8
+ * Copyright 2008-2022 Sutou Kouhei <kou@cozmixng.org>
9
9
  *
10
10
  * This file is made available under the same terms as Ruby
11
11
  *
@@ -20,6 +20,17 @@ VALUE rb_cCairo_TextCluster = Qnil;
20
20
  #if CAIRO_CHECK_VERSION(1, 7, 2)
21
21
  #define _SELF(self) (RVAL2CRTEXTCLUSTER(self))
22
22
 
23
+ static const rb_data_type_t cr_text_cluster_type = {
24
+ "Cairo::TextCluster",
25
+ {
26
+ NULL,
27
+ ruby_xfree,
28
+ },
29
+ NULL,
30
+ NULL,
31
+ RUBY_TYPED_FREE_IMMEDIATELY,
32
+ };
33
+
23
34
  cairo_text_cluster_t *
24
35
  rb_cairo_text_cluster_from_ruby_object (VALUE obj)
25
36
  {
@@ -29,19 +40,13 @@ rb_cairo_text_cluster_from_ruby_object (VALUE obj)
29
40
  rb_raise (rb_eTypeError,
30
41
  "not a cairo cluster: %s", rb_cairo__inspect (obj));
31
42
  }
32
- Data_Get_Struct (obj, cairo_text_cluster_t, cluster);
43
+ TypedData_Get_Struct (obj,
44
+ cairo_text_cluster_t,
45
+ &cr_text_cluster_type,
46
+ cluster);
33
47
  return cluster;
34
48
  }
35
49
 
36
- static void
37
- cr_text_cluster_free (void *ptr)
38
- {
39
- if (ptr)
40
- {
41
- xfree (ptr);
42
- }
43
- }
44
-
45
50
  VALUE
46
51
  rb_cairo_text_cluster_to_ruby_object (cairo_text_cluster_t *cluster)
47
52
  {
@@ -51,8 +56,9 @@ rb_cairo_text_cluster_to_ruby_object (cairo_text_cluster_t *cluster)
51
56
 
52
57
  new_cluster = ALLOC (cairo_text_cluster_t);
53
58
  *new_cluster = *cluster;
54
- return Data_Wrap_Struct (rb_cCairo_TextCluster, NULL,
55
- cr_text_cluster_free, new_cluster);
59
+ return TypedData_Wrap_Struct (rb_cCairo_TextCluster,
60
+ &cr_text_cluster_type,
61
+ new_cluster);
56
62
  }
57
63
  else
58
64
  {
@@ -63,7 +69,7 @@ rb_cairo_text_cluster_to_ruby_object (cairo_text_cluster_t *cluster)
63
69
  static VALUE
64
70
  cr_text_cluster_allocate (VALUE klass)
65
71
  {
66
- return Data_Wrap_Struct (klass, NULL, cr_text_cluster_free, NULL);
72
+ return TypedData_Wrap_Struct (klass, &cr_text_cluster_type, NULL);
67
73
  }
68
74
 
69
75
  static VALUE
@@ -75,7 +81,7 @@ cr_text_cluster_initialize (VALUE self, VALUE num_bytes, VALUE num_glyphs)
75
81
  cluster->num_bytes = NUM2INT (num_bytes);
76
82
  cluster->num_glyphs = NUM2INT (num_glyphs);
77
83
 
78
- DATA_PTR (self) = cluster;
84
+ RTYPEDDATA_DATA (self) = cluster;
79
85
  return Qnil;
80
86
  }
81
87
 
@@ -5,6 +5,7 @@
5
5
  * $Author: kou $
6
6
  * $Date: 2008-08-17 05:41:28 $
7
7
  *
8
+ * Copyright 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_TextExtents;
19
20
 
20
21
  #define _SELF(self) (RVAL2CRTEXTEXTENTS(self))
21
22
 
23
+ static const rb_data_type_t cr_text_extents_type = {
24
+ "Cairo::TextExtents",
25
+ {
26
+ NULL,
27
+ ruby_xfree,
28
+ },
29
+ NULL,
30
+ NULL,
31
+ RUBY_TYPED_FREE_IMMEDIATELY,
32
+ };
33
+
22
34
  cairo_text_extents_t *
23
35
  rb_cairo_text_extents_from_ruby_object (VALUE obj)
24
36
  {
@@ -27,7 +39,10 @@ rb_cairo_text_extents_from_ruby_object (VALUE obj)
27
39
  {
28
40
  rb_raise (rb_eTypeError, "not a cairo text_extents");
29
41
  }
30
- Data_Get_Struct (obj, cairo_text_extents_t, extents);
42
+ TypedData_Get_Struct (obj,
43
+ cairo_text_extents_t,
44
+ &cr_text_extents_type,
45
+ extents);
31
46
  return extents;
32
47
  }
33
48
 
@@ -38,7 +53,9 @@ rb_cairo_text_extents_to_ruby_object (cairo_text_extents_t *extents)
38
53
  {
39
54
  cairo_text_extents_t *new_extents = ALLOC (cairo_text_extents_t);
40
55
  *new_extents = *extents;
41
- return Data_Wrap_Struct (rb_cCairo_TextExtents, NULL, -1, new_extents);
56
+ return TypedData_Wrap_Struct (rb_cCairo_TextExtents,
57
+ &cr_text_extents_type,
58
+ new_extents);
42
59
  }
43
60
  else
44
61
  {
@@ -49,7 +66,7 @@ rb_cairo_text_extents_to_ruby_object (cairo_text_extents_t *extents)
49
66
  static VALUE
50
67
  cr_text_extents_allocate (VALUE klass)
51
68
  {
52
- return Data_Wrap_Struct (klass, NULL, -1, NULL);
69
+ return TypedData_Wrap_Struct (klass, &cr_text_extents_type, NULL);
53
70
  }
54
71
 
55
72
  static VALUE
@@ -65,7 +82,7 @@ cr_text_extents_initialize (VALUE self)
65
82
  extents->x_advance = 1.0;
66
83
  extents->y_advance = 0.0;
67
84
 
68
- DATA_PTR (self) = extents;
85
+ RTYPEDDATA_DATA (self) = extents;
69
86
 
70
87
  return Qnil;
71
88
  }
data/test/test_context.rb CHANGED
@@ -129,4 +129,18 @@ class ContextTest < Test::Unit::TestCase
129
129
  context.raw_address > 0
130
130
  end
131
131
  end
132
+
133
+ def test_hairline
134
+ only_cairo_version(1, 17, 6)
135
+
136
+ Cairo::Context.create(@surface) do |context|
137
+ assert do
138
+ not context.hairline?
139
+ end
140
+ context.hairline = true
141
+ assert do
142
+ context.hairline?
143
+ end
144
+ end
145
+ end
132
146
  end