~ubuntu-branches/ubuntu/karmic/libcairo-ruby/karmic

« back to all changes in this revision

Viewing changes to src/rb_cairo_surface.c

  • Committer: Bazaar Package Importer
  • Author(s): Paul van Tilburg, Gunnar Wolf, Paul van Tilburg
  • Date: 2009-05-05 12:14:31 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090505121431-n803uyjz51je38l0
Tags: 1.8.0-1
[ Gunnar Wolf ]
* Changed section to Ruby as per ftp-masters' request

[ Paul van Tilburg ]
* New upstream release.
* debian/patches:
  - Dropped patch 01_fix-st.h-ruby1.9-paths: fixed by upstream. 
* debian/control:
  - Bumped standards version to 3.8.1; no changes required.
  - Added ${misc:Depends} to the depends of libcairo-ruby (binary).

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 * Ruby Cairo Binding
4
4
 *
5
5
 * $Author: kou $
6
 
 * $Date: 2008-06-20 02:01:53 $
 
6
 * $Date: 2008-08-16 12:52:17 $
7
7
 *
8
8
 * Copyright 2005 Øyvind Kolås <pippin@freedesktop.org>
9
9
 * Copyright 2004-2005 MenTaLguY <mental@rydia.com>
15
15
#include "rb_cairo.h"
16
16
#include "rb_cairo_private.h"
17
17
 
18
 
#include <st.h>
 
18
#ifdef HAVE_RUBY_ST_H
 
19
#  include <ruby/st.h>
 
20
#else
 
21
#  include <st.h>
 
22
#endif
19
23
 
20
24
#ifdef CAIRO_HAS_WIN32_SURFACE
21
25
#  define OpenFile OpenFile_win32
62
66
static ID cr_id_parse;
63
67
static ID cr_id_size;
64
68
static ID cr_id_set_unit;
65
 
static ID cr_id_instances;
66
 
static ID cr_id_dup;
67
69
static cairo_user_data_key_t cr_closure_key;
68
70
static cairo_user_data_key_t cr_object_holder_key;
69
71
static cairo_user_data_key_t cr_finished_key;
131
133
      break;
132
134
#endif
133
135
    default:
134
 
      rb_raise (rb_eArgError, "unknown source type: %d", type);
 
136
      klass = rb_cCairo_Surface;
135
137
      break;
136
138
    }
137
139
 
157
159
  unsigned int length;
158
160
} cr_io_callback_closure_t;
159
161
 
 
162
typedef struct cr_invoke_data {
 
163
  cr_callback_func_t func;
 
164
  VALUE data;
 
165
} cr_invoke_data_t;
 
166
 
160
167
#if HAS_CREATE_CR_CLOSURE_SURFACE
161
168
static cr_io_callback_closure_t *
162
169
cr_closure_new (VALUE target)
192
199
  return Qnil;
193
200
}
194
201
 
 
202
static VALUE
 
203
cr_surface_invoke_io_func (VALUE user_data)
 
204
{
 
205
  cr_invoke_data_t *data;
 
206
 
 
207
  data = (cr_invoke_data_t *)user_data;
 
208
  return rb_rescue2 (data->func, data->data,
 
209
                     cr_surface_io_func_rescue, data->data, rb_eException,
 
210
                     (VALUE)0);
 
211
}
 
212
 
195
213
/* write callback */
196
214
static VALUE
197
215
cr_surface_write_func_invoke (VALUE write_closure)
224
242
                       const unsigned char *data, unsigned int length)
225
243
{
226
244
  cr_io_callback_closure_t *closure;
 
245
  cr_invoke_data_t invoke_data;
227
246
 
228
247
  closure = (cr_io_callback_closure_t *)write_closure;
229
248
  closure->data = (unsigned char *)data;
230
249
  closure->length = length;
231
 
  
232
 
  rb_rescue2 (cr_surface_write_func_invoke, (VALUE) closure,
233
 
              cr_surface_io_func_rescue, (VALUE) closure, rb_eException,
234
 
              (VALUE)0);
235
 
  
 
250
 
 
251
  invoke_data.func = cr_surface_write_func_invoke;
 
252
  invoke_data.data = (VALUE)closure;
 
253
  rb_cairo__invoke_callback (cr_surface_invoke_io_func, (VALUE)&invoke_data);
 
254
 
236
255
  if (NIL_P (closure->error))
237
256
    return CAIRO_STATUS_SUCCESS;
238
257
  else
268
287
                      unsigned char *data, unsigned int length)
269
288
{
270
289
  cr_io_callback_closure_t *closure;
 
290
  cr_invoke_data_t invoke_data;
271
291
 
272
292
  closure = (cr_io_callback_closure_t *)read_closure;
273
293
  closure->data = data;
274
294
  closure->length = length;
275
 
  rb_rescue2 (cr_surface_read_func_invoke, (VALUE) closure,
276
 
              cr_surface_io_func_rescue, (VALUE) closure, rb_eException,
277
 
              (VALUE)0);
278
 
  
 
295
 
 
296
  invoke_data.func = cr_surface_read_func_invoke;
 
297
  invoke_data.data = (VALUE)closure;
 
298
  rb_cairo__invoke_callback (cr_surface_invoke_io_func, (VALUE)&invoke_data);
 
299
 
279
300
  if (NIL_P (closure->error))
280
301
    return CAIRO_STATUS_SUCCESS;
281
302
  else
292
313
      rb_raise (rb_eTypeError, "not a cairo surface");
293
314
    }
294
315
  Data_Get_Struct (obj, cairo_surface_t, surface);
 
316
  if (!surface)
 
317
    rb_cairo_check_status (CAIRO_STATUS_NULL_POINTER);
295
318
  return surface;
296
319
}
297
320
 
298
 
static void
299
 
add_gc_guard (VALUE self)
300
 
{
301
 
  rb_hash_aset (rb_ivar_get (rb_cCairo_Surface, cr_id_instances),
302
 
                self, Qnil);
303
 
}
304
 
 
305
 
static void
306
 
remove_gc_guard (VALUE self)
307
 
{
308
 
  rb_hash_delete (rb_ivar_get (rb_cCairo_Surface, cr_id_instances),
309
 
                  self);
310
 
}
311
 
 
312
 
typedef struct cr_object_holder {
313
 
  VALUE object;
314
 
} cr_object_holder_t;
315
 
 
316
 
static cr_object_holder_t *
 
321
static rb_cairo__object_holder_t *
317
322
cr_object_holder_new (VALUE object)
318
323
{
319
 
  cr_object_holder_t *holder;
320
 
 
321
 
  holder = ALLOC(cr_object_holder_t);
322
 
  add_gc_guard (object);
323
 
  holder->object = object;
324
 
  return holder;
 
324
  return rb_cairo__object_holder_new (rb_cCairo_Surface, object);
325
325
}
326
326
 
327
327
static void
328
328
cr_object_holder_free (void *ptr)
329
329
{
330
 
  cr_object_holder_t *holder = ptr;
331
 
 
332
 
  if (!NIL_P (holder->object))
333
 
    remove_gc_guard (holder->object);
334
 
 
335
 
  xfree (holder);
 
330
  rb_cairo__object_holder_free (rb_cCairo_Surface, ptr);
336
331
}
337
332
 
338
333
static void
380
375
 
381
376
/* Surface manipulation */
382
377
static VALUE
 
378
cr_surface_destroy (VALUE self)
 
379
{
 
380
  cairo_surface_t *surface;
 
381
 
 
382
  surface = _SELF;
 
383
  cairo_surface_destroy (surface);
 
384
  DATA_PTR (self) = NULL;
 
385
 
 
386
  return self;
 
387
}
 
388
 
 
389
static VALUE
383
390
cr_surface_finish (VALUE self)
384
391
{
385
392
  cairo_surface_t *surface;
556
563
  return self;
557
564
}
558
565
 
 
566
#if CAIRO_CHECK_VERSION(1, 7, 2)
 
567
static VALUE
 
568
cr_surface_get_fallback_resolution (VALUE self)
 
569
{
 
570
  double x_pixels_per_inch, y_pixels_per_inch;
 
571
 
 
572
  cairo_surface_get_fallback_resolution (_SELF,
 
573
                                         &x_pixels_per_inch,
 
574
                                         &y_pixels_per_inch);
 
575
  cr_surface_check_status (_SELF);
 
576
  return rb_ary_new3 (2,
 
577
                      rb_float_new (x_pixels_per_inch),
 
578
                      rb_float_new (y_pixels_per_inch));
 
579
}
 
580
#endif
 
581
 
 
582
 
559
583
#if CAIRO_CHECK_VERSION(1, 5, 2)
560
584
static VALUE
561
585
cr_surface_copy_page (VALUE self)
1161
1185
static void
1162
1186
cr_finish_all_guarded_surfaces_at_end (VALUE data)
1163
1187
{
1164
 
  rb_hash_foreach (rb_funcall (rb_ivar_get (rb_cCairo_Surface, cr_id_instances),
1165
 
                               cr_id_dup, 0),
 
1188
  rb_hash_foreach (rb_cairo__gc_guarded_objects (rb_cCairo_Surface),
1166
1189
                   cr_finish_all_guarded_surfaces_at_end_iter,
1167
1190
                   Qnil);
1168
1191
}
1177
1200
  cr_id_parse = rb_intern ("parse");
1178
1201
  cr_id_size = rb_intern ("size");
1179
1202
  cr_id_set_unit = rb_intern ("unit=");
1180
 
  cr_id_instances = rb_intern ("instances");
1181
 
  cr_id_dup = rb_intern ("dup");
1182
 
 
1183
 
  rb_set_end_proc(cr_finish_all_guarded_surfaces_at_end, Qnil);
1184
1203
 
1185
1204
  rb_cCairo_Surface =
1186
1205
    rb_define_class_under (rb_mCairo, "Surface", rb_cObject);
1187
1206
  rb_define_alloc_func (rb_cCairo_Surface, cr_surface_allocate);
1188
1207
 
1189
 
  rb_ivar_set (rb_cCairo_Surface, cr_id_instances, rb_hash_new ());
 
1208
  rb_cairo__initialize_gc_guard_holder_class (rb_cCairo_Surface);
 
1209
  rb_set_end_proc(cr_finish_all_guarded_surfaces_at_end, Qnil);
1190
1210
 
1191
1211
 
1192
1212
  rb_define_method (rb_cCairo_Surface, "create_similar",
1193
1213
                    cr_surface_create_similar, 3);
 
1214
  rb_define_method (rb_cCairo_Surface, "destroy", cr_surface_destroy, 0);
1194
1215
  rb_define_method (rb_cCairo_Surface, "finish", cr_surface_finish, 0);
1195
1216
  rb_define_method (rb_cCairo_Surface, "content", cr_surface_get_content, 0);
1196
1217
 
1204
1225
                    cr_surface_get_device_offset, 0);
1205
1226
  rb_define_method (rb_cCairo_Surface, "set_fallback_resolution",
1206
1227
                    cr_surface_set_fallback_resolution, 2);
 
1228
#if CAIRO_CHECK_VERSION(1, 7, 2)
 
1229
  rb_define_method (rb_cCairo_Surface, "fallback_resolution",
 
1230
                    cr_surface_get_fallback_resolution, 0);
 
1231
#endif
1207
1232
#if CAIRO_CHECK_VERSION(1, 5, 2)
1208
1233
  rb_define_method (rb_cCairo_Surface, "copy_page",
1209
1234
                    cr_surface_copy_page, 2);