Class: Cairo::QuartzSurface

Inherits:
Surface
  • Object
show all
Defined in:
ext/cairo/rb_cairo_surface.c

Instance Method Summary collapse

Methods inherited from Surface

#clone, #content, #copy_page, #create_similar, #create_similar_image, #destroy, #device, #device_offset, #device_scale, #dup, #fallback_resolution, #finish, #flush, #font_options, #get_mime_data, gl_supported?, gl_texture_supported?, image_supported?, #map_to_image, #mark_dirty, pdf_supported?, ps_supported?, quartz_image_supported?, quartz_supported?, recording_supported?, script_supported?, #set_device_offset, #set_device_scale, #set_fallback_resolution, #set_mime_data, #show_page, #sub_rectangle_surface, supported?, #supported_mime_type?, svg_supported?, tee_supported?, #unmap_image, win32_printing_supported?, win32_supported?, #write_to_png, xml_supported?

Constructor Details

#initializeObject



1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
# File 'ext/cairo/rb_cairo_surface.c', line 1229

static VALUE
cr_quartz_surface_initialize (int argc, VALUE *argv, VALUE self)
{
  id objc_object = nil;
  CGContextRef context;
  unsigned int width, height;
  cairo_surface_t *surface = NULL;
  cairo_format_t format = CAIRO_FORMAT_ARGB32;
  VALUE arg1, arg2, arg3, rb_width, rb_height;
#  ifdef HAVE_RUBY_COCOA
  static VALUE rb_cOSXCGContextRef = Qnil;
#  endif

  rb_scan_args (argc, argv, "21", &arg1, &arg2, &arg3);

  if (argc == 2)
    {
      rb_width = arg1;
      rb_height = arg2;
    }
  else
    {
      switch (TYPE (arg1))
        {
        case T_NIL:
          break;
        case T_STRING:
        case T_SYMBOL:
        case T_FIXNUM:
          format = RVAL2CRFORMAT (arg1);
          break;
        default:
#  ifdef HAVE_RUBY_COCOA
          if (NIL_P (rb_cOSXCGContextRef))
            rb_cOSXCGContextRef =
              rb_const_get (rb_const_get (rb_cObject, rb_intern ("OSX")),
                            rb_intern ("CGContextRef"));
#  endif

#  ifdef HAVE_RUBY_COCOA
          if (RTEST (rb_obj_is_kind_of (arg1, rb_cOSXCGContextRef)))
            {
              rbobj_to_nsobj (arg1, &objc_object);
            }
          else
#  endif
            {
              if (!NIL_P (rb_cairo__cFFIPointer) &&
                  RTEST (rb_obj_is_kind_of (arg1, rb_cairo__cFFIPointer)))
                {
                  VALUE rb_objc_pointer;
                  rb_objc_pointer = rb_funcall (arg1,
                                                rb_intern ("address"),
                                                0);
                  objc_object = NUM2ULONG (rb_objc_pointer);
                }
              else
                {
                  rb_raise (rb_eArgError,
                            "invalid argument (expect "
                            "(width, height), "
                            "(format, width, height), "
                            "(cg_context, width, height) or "
                            "(ffi_pointer, width, height)): %s",
                            rb_cairo__inspect (rb_ary_new3 (3, arg1, arg2, arg3)));
                }
            }
          break;
        }

      rb_width = arg2;
      rb_height = arg3;
    }

  width = NUM2UINT (rb_width);
  height = NUM2UINT (rb_height);

  if (objc_object == nil)
    {
      surface = cairo_quartz_surface_create (format, width, height);
    }
  else
    {
      context = (CGContextRef)objc_object;
      surface =
        cairo_quartz_surface_create_for_cg_context (context, width, height);
    }

  cr_surface_check_status (surface);
  DATA_PTR (self) = surface;
  if (rb_block_given_p ())
    yield_and_finish (self);
  return Qnil;
}

Instance Method Details

#cg_contextObject



1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
# File 'ext/cairo/rb_cairo_surface.c', line 1324

static VALUE
cr_quartz_surface_get_cg_context (VALUE self)
{
#  ifdef HAVE_RUBY_COCOA
  CGContextRef context;
  id objc_object;

  context = cairo_quartz_surface_get_cg_context (_SELF);
  objc_object = (id)context;
  return ocid_to_rbobj (Qnil, objc_object);
#  else
  rb_raise (rb_eNotImpError,
            "%s#cg_context requires RubyCocoa",
            rb_obj_classname(self));
  return Qnil;
#  endif
}