class Cairo::QuartzSurface - cairo-1.12.9 Documentation

# class Cairo::QuartzSurface

Quartz surface

### Public Class Methods

new(*args) click to toggle source

    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
      static VALUE rb_cFFIPointer = Qnil;

      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

              if (NIL_P (rb_cFFIPointer))
                rb_cFFIPointer =
                  rb_const_get (rb_const_get (rb_cObject, rb_intern ("FFI")),
                                rb_intern ("Pointer"));

    #ifdef HAVE_RUBY_COCOA
              if (RTEST (rb_obj_is_kind_of (arg1, rb_cOSXCGContextRef)))
                {
                  rbobj_to_nsobj (arg1, &objc_object);
                }
              else
    #endif
                {
                  if (RTEST (rb_obj_is_kind_of (arg1, rb_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;
    }

### Public Instance Methods

cg_context() click to toggle source

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

      context = cairo_quartz_surface_get_cg_context (_SELF);
      objc_object = (id)context;
      return ocid_to_rbobj (Qnil, objc_object);
    }