cairo 1.17.4 → 1.17.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
  {
@@ -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
+ DATA_PTR (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)
@@ -1328,6 +1348,26 @@ cr_pdf_surface_set_thumbnail_size (VALUE self,
1328
1348
  return Qnil;
1329
1349
  }
1330
1350
  # endif
1351
+
1352
+ # if CAIRO_CHECK_VERSION(1, 17, 6)
1353
+ static VALUE
1354
+ cr_pdf_surface_set_custom_metadata (VALUE self,
1355
+ VALUE rb_name,
1356
+ VALUE rb_value)
1357
+ {
1358
+ cairo_surface_t *surface;
1359
+ const char *name;
1360
+ const char *value;
1361
+
1362
+ surface = _SELF;
1363
+ name = RVAL2CSTR (rb_name);
1364
+ value = RVAL2CSTR (rb_value);
1365
+ cairo_pdf_surface_set_custom_metadata (surface, name, value);
1366
+ rb_cairo_surface_check_status (surface);
1367
+
1368
+ return Qnil;
1369
+ }
1370
+ # endif
1331
1371
  #endif
1332
1372
 
1333
1373
  #ifdef CAIRO_HAS_PS_SURFACE
@@ -2177,6 +2217,11 @@ Init_cairo_surface (void)
2177
2217
  }
2178
2218
  # endif
2179
2219
 
2220
+ # if CAIRO_CHECK_VERSION(1, 17, 6)
2221
+ rb_define_method (rb_cCairo_PDFSurface, "set_custom_metadata",
2222
+ cr_pdf_surface_set_custom_metadata, 2);
2223
+ # endif
2224
+
2180
2225
  RB_CAIRO_DEF_SETTERS (rb_cCairo_PDFSurface);
2181
2226
  #endif
2182
2227
 
@@ -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
@@ -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
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
@@ -119,6 +119,13 @@ class FontFaceTest < Test::Unit::TestCase
119
119
  render_glyph_args << args
120
120
  end
121
121
 
122
+ render_color_glyph_args = []
123
+ if face.respond_to?(:on_render_color_glyph)
124
+ face.on_render_color_glyph do |*args|
125
+ render_color_glyph_args << args
126
+ end
127
+ end
128
+
122
129
  text_to_glyphs_args = []
123
130
  face.on_text_to_glyphs do |*args|
124
131
  text_to_glyphs_args << args
@@ -137,36 +144,56 @@ class FontFaceTest < Test::Unit::TestCase
137
144
  Cairo::Matrix.identity,
138
145
  Cairo::Matrix.identity,
139
146
  Cairo::FontOptions.new)
140
- result = scaled_font.text_to_glyphs(0, 0, "text")
141
- assert_equal([[[Cairo::ScaledFont, Cairo::Context, Cairo::FontExtents]],
142
- [[Cairo::ScaledFont, codepoint("t"),
143
- Cairo::Context, Cairo::TextExtents],
144
- [Cairo::ScaledFont, codepoint("e"),
145
- Cairo::Context, Cairo::TextExtents],
146
- [Cairo::ScaledFont, codepoint("x"),
147
- Cairo::Context, Cairo::TextExtents]],
148
- [[Cairo::ScaledFont, "text",
149
- Cairo::UserFontFace::TextToGlyphsData]],
150
- [[Cairo::ScaledFont, codepoint("t")],
151
- [Cairo::ScaledFont, codepoint("e")],
152
- [Cairo::ScaledFont, codepoint("x")],
153
- [Cairo::ScaledFont, codepoint("t")]],
154
- [[], [], Cairo::TextClusterFlag::BACKWARD]],
155
- [classify_cairo_object(init_args),
156
- classify_cairo_object(render_glyph_args),
157
- classify_cairo_object(text_to_glyphs_args),
158
- classify_cairo_object(unicode_to_glyph_args),
159
- result])
147
+ result = scaled_font.text_to_glyphs(0, 0, "abc")
148
+ expected = {
149
+ init_args: [
150
+ [Cairo::ScaledFont, Cairo::Context, Cairo::FontExtents],
151
+ ],
152
+ render_glyph_args: [
153
+ [Cairo::ScaledFont, codepoint("a"), Cairo::Context, Cairo::TextExtents],
154
+ [Cairo::ScaledFont, codepoint("b"), Cairo::Context, Cairo::TextExtents],
155
+ [Cairo::ScaledFont, codepoint("c"), Cairo::Context, Cairo::TextExtents],
156
+ ],
157
+ render_color_glyph_args: [],
158
+ text_to_glyphs_args: [
159
+ [Cairo::ScaledFont, "abc", Cairo::UserFontFace::TextToGlyphsData],
160
+ ],
161
+ unicode_to_glyph_args: [
162
+ [Cairo::ScaledFont, codepoint("a")],
163
+ [Cairo::ScaledFont, codepoint("b")],
164
+ [Cairo::ScaledFont, codepoint("c")],
165
+ ],
166
+ result: [[], [], Cairo::TextClusterFlag::BACKWARD],
167
+ }
168
+ actual = {
169
+ init_args: classify_cairo_object(init_args),
170
+ render_glyph_args: classify_cairo_object(render_glyph_args),
171
+ render_color_glyph_args: classify_cairo_object(render_color_glyph_args),
172
+ text_to_glyphs_args: classify_cairo_object(text_to_glyphs_args),
173
+ unicode_to_glyph_args: classify_cairo_object(unicode_to_glyph_args),
174
+ result: result,
175
+ }
176
+ if Cairo.satisfied_version?(1, 17, 6)
177
+ expected[:render_glyph_args],
178
+ expected[:render_color_glyph_args] =
179
+ expected[:render_color_glyph_args],
180
+ expected[:render_glyph_args]
181
+ end
182
+ assert_equal(expected, actual)
160
183
  end
161
184
 
162
185
  if Cairo.satisfied_version?(1, 7, 2)
163
186
  class CustomUserFontFace < Cairo::UserFontFace
164
- attr_reader :init_args, :render_glyph_args
165
- attr_reader :text_to_glyphs_args, :unicode_to_glyph_args
187
+ attr_reader :init_args
188
+ attr_reader :render_glyph_args
189
+ attr_reader :render_color_glyph_args
190
+ attr_reader :text_to_glyphs_args
191
+ attr_reader :unicode_to_glyph_args
166
192
  def initialize
167
193
  super
168
194
  @init_args = []
169
195
  @render_glyph_args = []
196
+ @render_color_glyph_args = []
170
197
  @text_to_glyphs_args = []
171
198
  @unicode_to_glyph_args = []
172
199
  end
@@ -179,6 +206,10 @@ class FontFaceTest < Test::Unit::TestCase
179
206
  @render_glyph_args << args
180
207
  end
181
208
 
209
+ def render_color_glyph(*args)
210
+ @render_color_glyph_args << args
211
+ end
212
+
182
213
  def text_to_glyphs(*args)
183
214
  @text_to_glyphs_args << args
184
215
  scaled_font, utf8, data = args
@@ -202,26 +233,54 @@ class FontFaceTest < Test::Unit::TestCase
202
233
  Cairo::Matrix.identity,
203
234
  Cairo::Matrix.identity,
204
235
  Cairo::FontOptions.new)
205
- result = scaled_font.text_to_glyphs(0, 0, "text")
206
- assert_equal([[[Cairo::ScaledFont, Cairo::Context, Cairo::FontExtents]],
207
- [[Cairo::ScaledFont, codepoint("t"),
208
- Cairo::Context, Cairo::TextExtents],
209
- [Cairo::ScaledFont, codepoint("e"),
210
- Cairo::Context, Cairo::TextExtents],
211
- [Cairo::ScaledFont, codepoint("x"),
212
- Cairo::Context, Cairo::TextExtents]],
213
- [[Cairo::ScaledFont, "text",
214
- Cairo::UserFontFace::TextToGlyphsData]],
215
- [[Cairo::ScaledFont, codepoint("t")],
216
- [Cairo::ScaledFont, codepoint("e")],
217
- [Cairo::ScaledFont, codepoint("x")],
218
- [Cairo::ScaledFont, codepoint("t")]],
219
- [[], [], Cairo::TextClusterFlag::BACKWARD]],
220
- [classify_cairo_object(face.init_args),
221
- classify_cairo_object(face.render_glyph_args),
222
- classify_cairo_object(face.text_to_glyphs_args),
223
- classify_cairo_object(face.unicode_to_glyph_args),
224
- result])
236
+ result = scaled_font.text_to_glyphs(0, 0, "abc")
237
+ expected = {
238
+ init_args: [
239
+ [Cairo::ScaledFont, Cairo::Context, Cairo::FontExtents]
240
+ ],
241
+ text_to_glyphs_args: [
242
+ [Cairo::ScaledFont, "abc", Cairo::UserFontFace::TextToGlyphsData],
243
+ ],
244
+ unicode_to_glyph_args: [
245
+ [Cairo::ScaledFont, codepoint("a")],
246
+ [Cairo::ScaledFont, codepoint("b")],
247
+ [Cairo::ScaledFont, codepoint("c")],
248
+ ],
249
+ result: [
250
+ [],
251
+ [],
252
+ Cairo::TextClusterFlag::BACKWARD,
253
+ ],
254
+ }
255
+ actual = {
256
+ init_args: classify_cairo_object(face.init_args),
257
+ text_to_glyphs_args:
258
+ classify_cairo_object(face.text_to_glyphs_args),
259
+ unicode_to_glyph_args:
260
+ classify_cairo_object(face.unicode_to_glyph_args),
261
+ result: result,
262
+ }
263
+ if Cairo.satisfied_version?(1, 17, 6)
264
+ expected[:render_color_glyph_args] = [
265
+ [Cairo::ScaledFont, codepoint("a"), Cairo::Context, Cairo::TextExtents],
266
+ [Cairo::ScaledFont, codepoint("b"), Cairo::Context, Cairo::TextExtents],
267
+ [Cairo::ScaledFont, codepoint("c"), Cairo::Context, Cairo::TextExtents],
268
+ ]
269
+ actual[:render_color_glyph_args] =
270
+ classify_cairo_object(face.render_color_glyph_args)
271
+ expected[:render_glyph_args] = []
272
+ actual[:render_glyph_args] =
273
+ classify_cairo_object(face.render_glyph_args)
274
+ else
275
+ expected[:render_glyph_args] = [
276
+ [Cairo::ScaledFont, codepoint("a"), Cairo::Context, Cairo::TextExtents],
277
+ [Cairo::ScaledFont, codepoint("b"), Cairo::Context, Cairo::TextExtents],
278
+ [Cairo::ScaledFont, codepoint("c"), Cairo::Context, Cairo::TextExtents],
279
+ ]
280
+ actual[:render_glyph_args] =
281
+ classify_cairo_object(face.render_glyph_args)
282
+ end
283
+ assert_equal(expected, actual)
225
284
  end
226
285
 
227
286
  def test_user_font_face_class_and_callback
@@ -239,6 +298,13 @@ class FontFaceTest < Test::Unit::TestCase
239
298
  render_glyph_args << args
240
299
  end
241
300
 
301
+ render_color_glyph_args = []
302
+ if face.respond_to?(:on_render_color_glyph)
303
+ face.on_render_color_glyph do |*args|
304
+ render_color_glyph_args << args
305
+ end
306
+ end
307
+
242
308
  text_to_glyphs_args = []
243
309
  face.on_text_to_glyphs do |*args|
244
310
  text_to_glyphs_args << args
@@ -257,34 +323,63 @@ class FontFaceTest < Test::Unit::TestCase
257
323
  Cairo::Matrix.identity,
258
324
  Cairo::Matrix.identity,
259
325
  Cairo::FontOptions.new)
260
- result = scaled_font.text_to_glyphs(0, 0, "text")
261
- assert_equal([[[Cairo::ScaledFont, Cairo::Context, Cairo::FontExtents]],
262
- [[Cairo::ScaledFont, codepoint("t"),
263
- Cairo::Context, Cairo::TextExtents],
264
- [Cairo::ScaledFont, codepoint("e"),
265
- Cairo::Context, Cairo::TextExtents],
266
- [Cairo::ScaledFont, codepoint("x"),
267
- Cairo::Context, Cairo::TextExtents]],
268
- [[Cairo::ScaledFont, "text",
269
- Cairo::UserFontFace::TextToGlyphsData]],
270
- [[Cairo::ScaledFont, codepoint("t")],
271
- [Cairo::ScaledFont, codepoint("e")],
272
- [Cairo::ScaledFont, codepoint("x")],
273
- [Cairo::ScaledFont, codepoint("t")]],
274
- [],
275
- [],
276
- [],
277
- [],
278
- [[], [], Cairo::TextClusterFlag::BACKWARD]],
279
- [classify_cairo_object(init_args),
280
- classify_cairo_object(render_glyph_args),
281
- classify_cairo_object(text_to_glyphs_args),
282
- classify_cairo_object(unicode_to_glyph_args),
283
- classify_cairo_object(face.init_args),
284
- classify_cairo_object(face.render_glyph_args),
285
- classify_cairo_object(face.text_to_glyphs_args),
286
- classify_cairo_object(face.unicode_to_glyph_args),
287
- result])
326
+ result = scaled_font.text_to_glyphs(0, 0, "abc")
327
+ expected = {
328
+ callback_init_args: [
329
+ [
330
+ Cairo::ScaledFont, Cairo::Context, Cairo::FontExtents,
331
+ ],
332
+ ],
333
+ callback_render_glyph_args: [
334
+ [Cairo::ScaledFont, codepoint("a"), Cairo::Context, Cairo::TextExtents],
335
+ [Cairo::ScaledFont, codepoint("b"), Cairo::Context, Cairo::TextExtents],
336
+ [Cairo::ScaledFont, codepoint("c"), Cairo::Context, Cairo::TextExtents],
337
+ ],
338
+ callback_render_color_glyph_args: [],
339
+ callback_text_to_glyphs_args: [
340
+ [Cairo::ScaledFont, "abc", Cairo::UserFontFace::TextToGlyphsData],
341
+ ],
342
+ callback_unicode_to_glyph_args: [
343
+ [Cairo::ScaledFont, codepoint("a")],
344
+ [Cairo::ScaledFont, codepoint("b")],
345
+ [Cairo::ScaledFont, codepoint("c")],
346
+ ],
347
+ object_init_args: [],
348
+ object_render_glyph_args: [],
349
+ object_render_color_glyph_args: [],
350
+ object_text_to_glyphs_args: [],
351
+ object_unicode_to_glyph_args: [],
352
+ result: [[], [], Cairo::TextClusterFlag::BACKWARD],
353
+ }
354
+ actual = {
355
+ callback_init_args: classify_cairo_object(init_args),
356
+ callback_render_glyph_args:
357
+ classify_cairo_object(render_glyph_args),
358
+ callback_render_color_glyph_args:
359
+ classify_cairo_object(render_color_glyph_args),
360
+ callback_text_to_glyphs_args:
361
+ classify_cairo_object(text_to_glyphs_args),
362
+ callback_unicode_to_glyph_args:
363
+ classify_cairo_object(unicode_to_glyph_args),
364
+ object_init_args:
365
+ classify_cairo_object(face.init_args),
366
+ object_render_glyph_args:
367
+ classify_cairo_object(face.render_glyph_args),
368
+ object_render_color_glyph_args:
369
+ classify_cairo_object(face.render_color_glyph_args),
370
+ object_text_to_glyphs_args:
371
+ classify_cairo_object(face.text_to_glyphs_args),
372
+ object_unicode_to_glyph_args:
373
+ classify_cairo_object(face.unicode_to_glyph_args),
374
+ result: result,
375
+ }
376
+ if Cairo.satisfied_version?(1, 17, 6)
377
+ expected[:callback_render_glyph_args],
378
+ expected[:callback_render_color_glyph_args] =
379
+ expected[:callback_render_color_glyph_args],
380
+ expected[:callback_render_glyph_args]
381
+ end
382
+ assert_equal(expected, actual)
288
383
  end
289
384
 
290
385
  def classify_cairo_object(object)
@@ -6,8 +6,10 @@ class QuartzImageSurfaceTest < Test::Unit::TestCase
6
6
  end
7
7
 
8
8
  def test_quartz_image_surface
9
- surface = Cairo::ImageSurface.new(100, 100)
10
- quartz_surface = Cairo::QuartzImageSurface.new(surface)
11
- assert_kind_of(Cairo::QuartzImageSurface, quartz_surface)
9
+ Cairo::ImageSurface.create(100, 100) do |surface|
10
+ Cairo::QuartzImageSurface.create(surface) do |quartz_surface|
11
+ assert_kind_of(Cairo::QuartzImageSurface, quartz_surface)
12
+ end
13
+ end
12
14
  end
13
15
  end
@@ -10,7 +10,11 @@ class SVGSurfaceTest < Test::Unit::TestCase
10
10
  only_cairo_version(1, 15, 10)
11
11
  output = StringIO.new
12
12
  surface = Cairo::SVGSurface.new(output, 10, 20)
13
- assert_equal(Cairo::SVGUnit::PT, surface.document_unit)
13
+ if Cairo.satisfied_version?(1, 17, 6)
14
+ assert_equal(Cairo::SVGUnit::USER, surface.document_unit)
15
+ else
16
+ assert_equal(Cairo::SVGUnit::PT, surface.document_unit)
17
+ end
14
18
  surface.document_unit = Cairo::SVGUnit::CM
15
19
  assert_equal(Cairo::SVGUnit::CM, surface.document_unit)
16
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cairo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.17.4
4
+ version: 1.17.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-16 00:00:00.000000000 Z
11
+ date: 2022-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: native-package-installer
@@ -235,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
235
235
  version: '0'
236
236
  requirements:
237
237
  - cairo >= 1.2.0
238
- rubygems_version: 3.3.0.dev
238
+ rubygems_version: 3.4.0.dev
239
239
  signing_key:
240
240
  specification_version: 4
241
241
  summary: Ruby bindings for cairo