[cairo-commit] rcairo/src rb_cairo_context.c, 1.5,
1.6 rb_cairo_pattern.c, 1.1, 1.2
Kouhei Sutou
commit at pdx.freedesktop.org
Sun Apr 15 20:12:58 PDT 2007
Committed by: kou
Update of /cvs/cairo/rcairo/src
In directory kemper:/tmp/cvs-serv27775/src
Modified Files:
rb_cairo_context.c rb_cairo_pattern.c
Log Message:
* src/lib/cairo/color.rb: added high-level color class including
CMYK support.
* src/rb_cairo_pattern.c, src/lib/cairo.rb,
src/lib/cairo/context.rb, src/lib/cairo/pattern.rb: supported
Cairo::Color.
Index: rb_cairo_context.c
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_context.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- rb_cairo_context.c 15 Apr 2007 06:45:25 -0000 1.5
+++ rb_cairo_context.c 16 Apr 2007 03:12:49 -0000 1.6
@@ -414,7 +414,7 @@
}
cairo_set_dash (_SELF, values, length, NUM2DBL (offset));
}
-
+
cr_check_status (_SELF);
return self;
}
@@ -1000,7 +1000,7 @@
if (!rb_obj_is_kind_of (rb_glyphs, rb_cArray))
rb_raise (rb_eTypeError, "expected array");
-
+
rb_cairo__glyphs_to_array (rb_glyphs, &glyphs, &count);
cairo_show_glyphs (_SELF, glyphs, count);
cr_check_status (_SELF);
@@ -1011,7 +1011,7 @@
cr_get_font_face (VALUE self)
{
cairo_font_face_t *face;
-
+
face = cairo_get_font_face (_SELF);
cr_check_status (_SELF);
return CRFONTFACE2RVAL (face);
@@ -1073,7 +1073,7 @@
rb_cairo__glyphs_to_array (rb_glyphs, &glyphs, &count);
cairo_glyph_path (_SELF, glyphs, count);
cr_check_status (_SELF);
-
+
return self;
}
@@ -1275,7 +1275,7 @@
rb_define_class_under (rb_mCairo, "Context", rb_cObject);
rb_define_alloc_func (rb_cCairo_Context, cr_allocate);
-
+
/* Functions for manipulating state objects */
rb_define_method (rb_cCairo_Context, "initialize", cr_initialize, 1);
@@ -1302,12 +1302,12 @@
rb_define_method (rb_cCairo_Context, "set_dash", cr_set_dash, 2);
rb_define_method (rb_cCairo_Context, "set_miter_limit",
cr_set_miter_limit, 1);
-
+
rb_define_method (rb_cCairo_Context, "translate", cr_translate, 2);
rb_define_method (rb_cCairo_Context, "scale", cr_scale, 2);
rb_define_method (rb_cCairo_Context, "rotate", cr_rotate, 1);
rb_define_method (rb_cCairo_Context, "transform", cr_transform, 1);
-
+
rb_define_method (rb_cCairo_Context, "set_matrix", cr_set_matrix, 1);
rb_define_method (rb_cCairo_Context, "identity_matrix",
cr_identity_matrix, 0);
@@ -1346,11 +1346,11 @@
/* Insideness testing */
rb_define_method (rb_cCairo_Context, "in_stroke?", cr_in_stroke, 2);
rb_define_method (rb_cCairo_Context, "in_fill?", cr_in_fill, 2);
-
+
/* Rectangular extents */
rb_define_method (rb_cCairo_Context, "stroke_extents", cr_stroke_extents, 0);
rb_define_method (rb_cCairo_Context, "fill_extents", cr_fill_extents, 0);
-
+
/* Clipping */
rb_define_method (rb_cCairo_Context, "reset_clip", cr_reset_clip, 0);
rb_define_method (rb_cCairo_Context, "clip", cr_clip, 0);
Index: rb_cairo_pattern.c
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_pattern.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rb_cairo_pattern.c 6 Mar 2007 12:17:34 -0000 1.1
+++ rb_cairo_pattern.c 16 Apr 2007 03:12:49 -0000 1.2
@@ -21,8 +21,19 @@
VALUE rb_cCairo_LinearPattern;
VALUE rb_cCairo_RadialPattern;
+static VALUE rb_cCairo_Color_Base = 0;
+static ID id_Color, id_Base, id_to_rgb, id_to_a, id_inspect;
+
#define _SELF(self) (RVAL2CRPATTERN(self))
+static const char *
+cr_inspect (VALUE object)
+{
+ VALUE inspected;
+ inspected = rb_funcall (object, id_inspect, 0);
+ return StringValueCStr (inspected);
+}
+
static inline void
cr_pattern_check_status (cairo_pattern_t *pattern)
{
@@ -91,13 +102,20 @@
cairo_pattern_t *pattern;
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 (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 && rb_obj_is_kind_of (red, rb_cArray) &&
(RARRAY (red)->len == 3 || RARRAY (red)->len == 4))
{
VALUE ary = red;
n = RARRAY (ary)->len;
-
+
red = rb_ary_entry (ary, 0);
green = rb_ary_entry (ary, 1);
blue = rb_ary_entry (ary, 2);
@@ -119,15 +137,36 @@
}
else
{
+ const char *inspected;
+
+ if (argc == 1)
+ {
+ inspected = cr_inspect (red);
+ }
+ else
+ {
+ int i;
+ VALUE tmp_args;
+
+ tmp_args = rb_ary_new();
+ for (i = 0; i < argc; i++)
+ {
+ rb_ary_push (tmp_args, argv[i]);
+ }
+ inspected = cr_inspect (tmp_args);
+ }
+
rb_raise (rb_eArgError,
"invalid argument (expect "
+ "(Cairo::Color::RGB), "
+ "(Cairo::Color::CMYK), "
"(red, green, blue), "
"([red, green, blue]), "
"(red, green, blue, alpha) or "
"([red, green, blue, alpha])"
- ")");
+ "): %s", inspected);
}
-
+
cr_pattern_check_status (pattern);
DATA_PTR (self) = pattern;
return Qnil;
@@ -178,14 +217,14 @@
{
VALUE offset, red, green, blue;
int n;
-
+
n = rb_scan_args (argc, argv, "22", &offset, &red, &green, &blue);
if (n == 2 && rb_obj_is_kind_of (red, rb_cArray))
{
VALUE ary = red;
n = RARRAY (ary)->len + 1;
-
+
red = rb_ary_entry (ary, 0);
green = rb_ary_entry (ary, 1);
blue = rb_ary_entry (ary, 2);
@@ -217,14 +256,14 @@
{
VALUE offset, red, green, blue, alpha;
int n;
-
+
n = rb_scan_args (argc, argv, "23", &offset, &red, &green, &blue, &alpha);
if (n == 2 && rb_obj_is_kind_of (red, rb_cArray))
{
VALUE ary = red;
n = RARRAY (ary)->len + 1;
-
+
red = rb_ary_entry (ary, 0);
green = rb_ary_entry (ary, 1);
blue = rb_ary_entry (ary, 2);
@@ -390,6 +429,12 @@
void
Init_cairo_pattern (void)
{
+ id_Color = rb_intern ("Color");
+ id_Base = rb_intern ("Base");
+ id_to_rgb = rb_intern ("to_rgb");
+ id_to_a = rb_intern ("to_a");
+ id_inspect = rb_intern ("inspect");
+
rb_cCairo_Pattern =
rb_define_class_under (rb_mCairo, "Pattern", rb_cObject);
@@ -444,8 +489,6 @@
#if CAIRO_CHECK_VERSION(1, 3, 0)
rb_define_method (rb_cCairo_GradientPattern, "get_color_stop_rgba",
cr_gradient_pattern_get_color_stop_rgba, 1);
- rb_define_alias (rb_cCairo_GradientPattern,
- "get_color_stop", "get_color_stop_rgba");
rb_define_method (rb_cCairo_GradientPattern, "color_stop_count",
cr_gradient_pattern_get_color_stop_count, 0);
#endif
More information about the cairo-commit
mailing list