[cairo-commit] rcairo/src rb_cairo_pattern.c,1.2,1.3

Kouhei Sutou commit at pdx.freedesktop.org
Mon Apr 16 00:31:53 PDT 2007


Committed by: kou

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

Modified Files:
	rb_cairo_pattern.c 
Log Message:
* src/lib/cairo/color.rb, src/lib/cairo/pattern.rb,
  src/lib/cairo/context/color.rb, src/rb_cairo_pattern.c: improved
  Cairo::Color interface.

* sample/: used Cairo::Color.


Index: rb_cairo_pattern.c
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_pattern.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- rb_cairo_pattern.c	16 Apr 2007 03:12:49 -0000	1.2
+++ rb_cairo_pattern.c	16 Apr 2007 07:31:43 -0000	1.3
@@ -21,8 +21,9 @@
 VALUE rb_cCairo_LinearPattern;
 VALUE rb_cCairo_RadialPattern;
 
+static VALUE rb_mCairo_Color = 0;
 static VALUE rb_cCairo_Color_Base = 0;
-static ID id_Color, id_Base, id_to_rgb, id_to_a, id_inspect;
+static ID id_Color, id_Base, id_parse, id_to_rgb, id_to_a, id_inspect;
 
 #define _SELF(self)  (RVAL2CRPATTERN(self))
 
@@ -103,12 +104,21 @@
 
   n = rb_scan_args (argc, argv, "13", &red, &green, &blue, &alpha);
 
-  if (!rb_cCairo_Color_Base)
-    rb_cCairo_Color_Base = rb_const_get (rb_const_get (rb_mCairo, id_Color),
-                                         id_Base);
+  if (!rb_mCairo_Color)
+    rb_mCairo_Color = rb_const_get (rb_mCairo, id_Color);
 
-  if (n == 1 && rb_obj_is_kind_of (red, rb_cCairo_Color_Base))
-    red = rb_funcall (rb_funcall (red, id_to_rgb, 0), id_to_a, 0);
+  if (n == 1)
+    {
+      VALUE parsed;
+
+      parsed = rb_funcall (rb_mCairo_Color, id_parse, 1, red);
+
+      if (!rb_cCairo_Color_Base)
+        rb_cCairo_Color_Base = rb_const_get (rb_mCairo_Color, id_Base);
+
+      if (rb_obj_is_kind_of (parsed, rb_cCairo_Color_Base))
+        red = rb_funcall (rb_funcall (parsed, id_to_rgb, 0), id_to_a, 0);
+    }
 
   if (n == 1 && rb_obj_is_kind_of (red, rb_cArray) &&
       (RARRAY (red)->len == 3 || RARRAY (red)->len == 4))
@@ -158,6 +168,8 @@
 
       rb_raise (rb_eArgError,
                 "invalid argument (expect "
+                "(color_name), "
+                "(color_hex_triplet), "
                 "(Cairo::Color::RGB), "
                 "(Cairo::Color::CMYK), "
                 "(red, green, blue), "
@@ -431,6 +443,7 @@
 {
   id_Color = rb_intern ("Color");
   id_Base = rb_intern ("Base");
+  id_parse = rb_intern ("parse");
   id_to_rgb = rb_intern ("to_rgb");
   id_to_a = rb_intern ("to_a");
   id_inspect = rb_intern ("inspect");



More information about the cairo-commit mailing list