[cairo-commit] rcairo/src rb_cairo_context.c,1.13,1.14

Kouhei Sutou commit at pdx.freedesktop.org
Fri May 18 05:25:10 PDT 2007


Committed by: kou

Update of /cvs/cairo/rcairo/src
In directory kemper:/tmp/cvs-serv23330/src

Modified Files:
	rb_cairo_context.c 
Log Message:
* src/rb_cairo_context.c (cr_set_dash):
  - made offset optional.
  - accepted a number for dash_array.

* src/rb_cairo_context.c (cr_get_group_target): added NULL check.


Index: rb_cairo_context.c
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_context.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- rb_cairo_context.c	15 May 2007 12:09:28 -0000	1.13
+++ rb_cairo_context.c	18 May 2007 12:24:59 -0000	1.14
@@ -390,16 +390,34 @@
 }
 
 static VALUE
-cr_set_dash (VALUE self, VALUE dash_array, VALUE offset)
+cr_set_dash (int argc, VALUE *argv, VALUE self)
 {
-  if (!NIL_P (dash_array))
+  VALUE dash_array, rb_offset;
+  double offset;
+  cairo_bool_t is_num;
+
+  rb_scan_args(argc, argv, "11", &dash_array, &rb_offset);
+
+  is_num = rb_cairo__is_kind_of (dash_array, rb_cNumeric));
+  if (!(NIL_P (dash_array) || is_num))
     {
       Check_Type (dash_array, T_ARRAY);
     }
 
-  if (NIL_P (dash_array) || RARRAY (dash_array)->len == 0)
+  if (NIL_P (rb_offset))
+    offset = 0.0;
+  else
+    offset = NUM2DBL (rb_offset);
+
+  if (is_num)
     {
-      cairo_set_dash (_SELF, NULL, 0, NUM2DBL (offset));
+      double values[1];
+      values[0] = NUM2DBL (dash_array);
+      cairo_set_dash (_SELF, values, 1, offset);
+    }
+  else if (NIL_P (dash_array) || RARRAY (dash_array)->len == 0)
+    {
+      cairo_set_dash (_SELF, NULL, 0, offset);
     }
   else
     {
@@ -415,7 +433,7 @@
         {
           values[i] = NUM2DBL (RARRAY (dash_array)->ptr[i]);
         }
-      cairo_set_dash (_SELF, values, length, NUM2DBL (offset));
+      cairo_set_dash (_SELF, values, length, offset);
     }
 
   cr_check_status (_SELF);
@@ -1302,6 +1320,8 @@
   cairo_surface_t *surface;
 
   surface = cairo_get_group_target (_SELF);
+  if (!surface)
+    return Qnil;
   rb_cairo_check_status (cairo_surface_status (surface));
   return CRSURFACE2RVAL (surface);
 }
@@ -1392,7 +1412,7 @@
   rb_define_method (rb_cCairo_Context, "set_line_width", cr_set_line_width, 1);
   rb_define_method (rb_cCairo_Context, "set_line_cap", cr_set_line_cap, 1);
   rb_define_method (rb_cCairo_Context, "set_line_join", cr_set_line_join, 1);
-  rb_define_method (rb_cCairo_Context, "set_dash", cr_set_dash, 2);
+  rb_define_method (rb_cCairo_Context, "set_dash", cr_set_dash, -1);
   rb_define_method (rb_cCairo_Context, "set_miter_limit",
                     cr_set_miter_limit, 1);
 



More information about the cairo-commit mailing list