[cairo-commit] rcairo/src rb_cairo_surface.c,1.18,1.19
Kouhei Sutou
commit at pdx.freedesktop.org
Thu Jan 17 21:04:27 PST 2008
Committed by: kou
Update of /cvs/cairo/rcairo/src
In directory kemper:/tmp/cvs-serv1096/src
Modified Files:
rb_cairo_surface.c
Log Message:
* src/rb_cairo_surface.c: used rbobj_to_nsobj() and
ocid_to_rbobj() instead of rbobj_get_ocid() and ocobj_s_new().
Suggested by kumura wataru. Thanks!!!
* README: added kumura wataru to Thanks list.
Index: rb_cairo_surface.c
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_surface.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- rb_cairo_surface.c 18 Jan 2008 04:57:20 -0000 1.18
+++ rb_cairo_surface.c 18 Jan 2008 05:04:25 -0000 1.19
@@ -851,14 +851,13 @@
}
#endif
-#if CAIRO_HAS_QUARTZ_SURFACE
+#if CAIRO_HAS_QUARTZ_SURFACE && defined(HAVE_RUBY_COCOA)
/* Quartz-surface functions */
#include <objc/objc-runtime.h>
-VALUE ocobj_s_new (id ocid);
-id rbobj_get_ocid (VALUE obj);
-
+BOOL rbobj_to_nsobj (VALUE obj, id* nsobj);
+VALUE ocid_to_rbobj (VALUE context_obj, id ocid);
static VALUE
cr_quartz_surface_initialize (int argc, VALUE *argv, VALUE self)
@@ -869,6 +868,7 @@
cairo_surface_t *surface = NULL;
cairo_format_t format = CAIRO_FORMAT_ARGB32;
VALUE arg1, arg2, arg3, rb_width, rb_height;
+ static VALUE rb_cOSXCGContextRef = Qnil;
rb_scan_args (argc, argv, "21", &arg1, &arg2, &arg3);
@@ -879,9 +879,32 @@
}
else
{
- objc_object = rbobj_get_ocid (arg1);
- if (objc_object == nil)
- format = RVAL2CRFORMAT (arg1);
+ switch (TYPE (arg1))
+ {
+ case T_NIL:
+ break;
+ case T_STRING:
+ case T_SYMBOL:
+ case T_FIXNUM:
+ format = RVAL2CRFORMAT (arg1);
+ break;
+ default:
+ if (NIL_P (rb_cOSXCGContextRef))
+ rb_cOSXCGContextRef =
+ rb_const_get (rb_const_get (rb_cObject, rb_intern ("OSX")),
+ rb_intern ("CGContextRef"));
+
+ if (RTEST (rb_obj_is_kind_of (arg1, rb_cOSXCGContextRef)))
+ rbobj_to_nsobj (arg1, &objc_object);
+ else
+ rb_raise (rb_eArgError,
+ "invalid argument (expect "
+ "(width, height), "
+ "(format, width, height) or "
+ "(cg_context, width, height)): %s",
+ inspect (rb_ary_new3 (3, arg1, arg2, arg3)));
+ break;
+ }
rb_width = arg2;
rb_height = arg3;
@@ -916,7 +939,7 @@
context = cairo_quartz_surface_get_cg_context (_SELF);
objc_object = (id)context;
- return ocobj_s_new (objc_object);
+ return ocid_to_rbobj (Qnil, objc_object);
}
#endif
More information about the cairo-commit
mailing list