[cairo-commit] rcairo/packages/cairo/ext rb_cairo.c, 1.1, 1.2 rb_cairo_constants.c, 1.1, 1.2 rb_cairo_context.c, 1.1, 1.2 rb_cairo_matrix.c, 1.1, 1.2 rb_cairo_matrix.h, 1.1, 1.2 rb_cairo_pattern.c, 1.1, 1.2 rb_cairo_pattern.h, 1.1, 1.2

Oeyvind Kolaas commit at pdx.freedesktop.org
Mon Feb 14 15:51:56 PST 2005


Committed by: pippin

Update of /cvs/cairo/rcairo/packages/cairo/ext
In directory gabe:/tmp/cvs-serv13901/packages/cairo/ext

Modified Files:
	rb_cairo.c rb_cairo_constants.c rb_cairo_context.c 
	rb_cairo_matrix.c rb_cairo_matrix.h rb_cairo_pattern.c 
	rb_cairo_pattern.h 
Log Message:
adding pattern class

Index: rb_cairo.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rb_cairo.c	8 Feb 2005 01:28:21 -0000	1.1
+++ rb_cairo.c	14 Feb 2005 23:51:54 -0000	1.2
@@ -26,6 +26,7 @@
   Init_cairo_font ();
   Init_cairo_text_extents ();
   Init_cairo_font_extents ();
+  Init_cairo_pattern ();
   Init_cairo_glyph ();
 
 }

Index: rb_cairo_constants.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo_constants.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rb_cairo_constants.c	8 Feb 2005 01:28:21 -0000	1.1
+++ rb_cairo_constants.c	14 Feb 2005 23:51:54 -0000	1.2
@@ -81,4 +81,24 @@
                    INT2FIX (CAIRO_OPERATOR_ADD));
   rb_define_const (rb_mCairo,    "OPERATOR_SATURATE",
                    INT2FIX (CAIRO_OPERATOR_SATURATE));
+
+  rb_define_const (rb_mCairo,    "FILTER_FAST",
+                   INT2FIX (CAIRO_FILTER_FAST));
+  rb_define_const (rb_mCairo,    "FILTER_GOOD",
+                   INT2FIX (CAIRO_FILTER_GOOD));
+  rb_define_const (rb_mCairo,    "FILTER_BEST",
+                   INT2FIX (CAIRO_FILTER_BEST));
+  rb_define_const (rb_mCairo,    "FILTER_NEAREST",
+                   INT2FIX (CAIRO_FILTER_NEAREST));
+  rb_define_const (rb_mCairo,    "FILTER_BILINEAR",
+                   INT2FIX (CAIRO_FILTER_BILINEAR));
+  rb_define_const (rb_mCairo,    "FILTER_GAUSSIAN",
+                   INT2FIX (CAIRO_FILTER_GAUSSIAN));
+
+  rb_define_const (rb_mCairo,    "EXTEND_NONE",
+                   INT2FIX (CAIRO_EXTEND_NONE));
+  rb_define_const (rb_mCairo,    "EXTEND_REPEAT",
+                   INT2FIX (CAIRO_EXTEND_REPEAT));
+  rb_define_const (rb_mCairo,    "EXTEND_REFLECT",
+                   INT2FIX (CAIRO_EXTEND_REFLECT));
 }

Index: rb_cairo_context.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo_context.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rb_cairo_context.c	8 Feb 2005 01:28:21 -0000	1.1
+++ rb_cairo_context.c	14 Feb 2005 23:51:54 -0000	1.2
@@ -906,6 +906,12 @@
 }
 
 static    VALUE
+rb_cairo_current_pattern (VALUE self)
+{
+  return rb_cairo_pattern_wrap (cairo_current_pattern (_SELF));
+}
+
+static    VALUE
 rb_cairo_current_alpha (VALUE self)
 {
   double    alpha;
@@ -972,19 +978,17 @@
 static    VALUE
 rb_cairo_current_matrix (VALUE self)
 {
-  cairo_matrix_t *xform;
-
-  xform = cairo_matrix_create ();
-  if (xform)
+  cairo_matrix_t *matrix = cairo_matrix_create ();
+  if (matrix)
     {
-      cairo_current_matrix (_SELF, xform);
+      cairo_current_matrix (_SELF, matrix);
       if (cairo_status (_SELF))
         {
-          rb_free_matrix (xform);
+          rb_free_matrix (matrix);
           raise_cairo_exception (cairo_status (_SELF),
                                  cairo_status_string (_SELF));
         }
-      return Data_Wrap_Struct (rb_cCairo_Matrix, NULL, rb_free_matrix, xform);
+      return rb_cairo_matrix_wrap (matrix);
     }
   else
     {
@@ -1119,6 +1123,8 @@
                     RUBY_METHOD_FUNC (rb_cairo_set_operator), 1);
   rb_define_method (rb_cCairo_Context, "set_rgb_color",
                     RUBY_METHOD_FUNC (rb_cairo_set_rgb_color), 3);
+  rb_define_method (rb_cCairo_Context, "set_pattern",
+                    RUBY_METHOD_FUNC (rb_cairo_set_pattern), 1);
   rb_define_method (rb_cCairo_Context, "set_alpha",
                     RUBY_METHOD_FUNC (rb_cairo_set_alpha), 1);
   rb_define_method (rb_cCairo_Context, "set_tolerance",
@@ -1217,6 +1223,8 @@
                     RUBY_METHOD_FUNC (rb_cairo_current_operator), 0);
   rb_define_method (rb_cCairo_Context, "current_rgb_color",
                     RUBY_METHOD_FUNC (rb_cairo_current_rgb_color), 0);
+  rb_define_method (rb_cCairo_Context, "current_pattern",
+                    RUBY_METHOD_FUNC (rb_cairo_current_pattern), 0);
   rb_define_method (rb_cCairo_Context, "current_alpha",
                     RUBY_METHOD_FUNC (rb_cairo_current_alpha), 0);
   rb_define_method (rb_cCairo_Context, "current_tolerance",

Index: rb_cairo_matrix.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo_matrix.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rb_cairo_matrix.c	8 Feb 2005 01:28:21 -0000	1.1
+++ rb_cairo_matrix.c	14 Feb 2005 23:51:54 -0000	1.2
@@ -37,18 +37,34 @@
 }
 
 
+VALUE
+rb_cairo_matrix_wrap (cairo_matrix_t *matrix)
+{
+  if (matrix)
+    {
+      return Data_Wrap_Struct (rb_cCairo_Matrix, NULL, rb_free_matrix, matrix);
+    }
+  else
+    {
+      rb_raise (rb_eNoMemError, "unable to wrap matrix");
+      return Qundef;
+    }
+}  
+
+
 /*
  * methods
  */
 
+
+
 static    VALUE
 rb_cairo_matrix_new (VALUE klass)
 {
-  cairo_matrix_t *xform;
-  xform = cairo_matrix_create ();
-  if (xform)
+  cairo_matrix_t *matrix = cairo_matrix_create ();
+  if (matrix)
     {
-      return Data_Wrap_Struct (rb_cCairo_Matrix, NULL, rb_free_matrix, xform);
+      return rb_cairo_matrix_wrap (matrix);
     }
   else
     {

Index: rb_cairo_matrix.h
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo_matrix.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rb_cairo_matrix.h	8 Feb 2005 01:28:21 -0000	1.1
+++ rb_cairo_matrix.h	14 Feb 2005 23:51:54 -0000	1.2
@@ -17,6 +17,7 @@
 
 void            Init_cairo_matrix      (void);
 cairo_matrix_t *rb_v_to_cairo_matrix_t (VALUE value);
+VALUE           rb_cairo_matrix_wrap   (cairo_matrix_t *matrix);
 void            rb_free_matrix         (void *ptr);
 
 

Index: rb_cairo_pattern.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo_pattern.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rb_cairo_pattern.c	8 Feb 2005 01:28:21 -0000	1.1
+++ rb_cairo_pattern.c	14 Feb 2005 23:51:54 -0000	1.2
@@ -35,9 +35,169 @@
     }
 }
 
+VALUE
+rb_cairo_pattern_wrap (cairo_pattern_t *pat)
+{
+  if (pat)
+    {
+      cairo_pattern_reference (pat);
+      return Data_Wrap_Struct (rb_cCairo_Pattern, NULL, rb_free_pattern, pat);
+    }
+  else
+    {
+      rb_raise (rb_eNoMemError, "unable to wrap pattern");
+      return Qundef;
+    }
+}  
+
+VALUE
+rb_cairo_pattern_create_linear (VALUE klass,
+                                VALUE x0_v, VALUE y0_v,
+                                VALUE x1_v, VALUE y1_v)
+{
+  double x0 = NUM2DBL (x0_v);
+  double y0 = NUM2DBL (y0_v);
+  double x1 = NUM2DBL (x1_v);
+  double y1 = NUM2DBL (y1_v);
+
+  return rb_cairo_pattern_wrap (
+    cairo_pattern_create_linear (x0, y0, x1, y1));
+}
+
+VALUE
+rb_cairo_pattern_create_radial (VALUE klass,
+                                VALUE cx0_v, VALUE cy0_v, VALUE radius0_v,
+                                VALUE cx1_v, VALUE cy1_v, VALUE radius1_v)
+{
+  double cx0     = NUM2DBL (cx0_v);
+  double cy0     = NUM2DBL (cy0_v);
+  double radius0 = NUM2DBL (radius0_v);
+  double cx1     = NUM2DBL (cx1_v);
+  double cy1     = NUM2DBL (cy1_v);
+  double radius1 = NUM2DBL (radius1_v);
+
+  return rb_cairo_pattern_wrap (
+    cairo_pattern_create_radial (cx0, cy0, radius0,
+                                 cx1, cy1, radius1));
+}
+
+VALUE
+rb_cairo_pattern_create_for_surface (VALUE klass,
+                                     VALUE surface_v)
+{
+
+
+  return rb_cairo_pattern_wrap (
+     cairo_pattern_create_for_surface (rb_v_to_cairo_surface_t (surface_v)));
+}
+
+
+VALUE
+rb_cairo_pattern_add_color_stop (VALUE self,
+                                 VALUE offset_v,
+                                 VALUE red_v,
+                                 VALUE green_v,
+                                 VALUE blue_v,
+                                 VALUE alpha_v)
+{
+  double offset = NUM2DBL (offset_v);
+  double red    = NUM2DBL (red_v);
+  double green  = NUM2DBL (green_v);
+  double blue   = NUM2DBL (blue_v);
+  double alpha  = NUM2DBL (alpha_v);
+
+  cairo_pattern_add_color_stop (_SELF, offset, red, green, blue, alpha);
+  return self;
+}
+
+VALUE
+rb_cairo_pattern_set_matrix (VALUE self,
+                             VALUE matrix_v)
+{
+  cairo_pattern_set_matrix (_SELF, rb_v_to_cairo_matrix_t (matrix_v));
+  return self;
+}
+
+VALUE
+rb_cairo_pattern_get_matrix (VALUE self)
+{
+  cairo_matrix_t *matrix = cairo_matrix_create ();
+
+  if (matrix)
+    {
+      cairo_pattern_get_matrix (_SELF, matrix);
+      return rb_cairo_matrix_wrap (matrix);
+    }
+  else
+    {
+      rb_raise (rb_eNoMemError, "matrix problem");
+    }
+}
+
+static VALUE
+rb_cairo_pattern_set_extend (VALUE self,
+                             VALUE extend_v)
+{
+  cairo_extend_t extend = FIX2INT (extend_v);
+  if (extend < CAIRO_EXTEND_NONE || extend > CAIRO_EXTEND_REFLECT)
+    rb_raise (rb_eArgError, "invalide pattern extend type");
+  cairo_pattern_set_extend (_SELF, extend);
+  return self; 
+}
+
+static VALUE
+rb_cairo_pattern_get_extend (VALUE self)
+{
+  cairo_extend_t extend = cairo_pattern_get_extend (_SELF);
+  return INT2FIX (extend);
+}
+
+static VALUE
+rb_cairo_pattern_set_filter (VALUE self,
+                             VALUE filter_v)
+{
+  cairo_filter_t filter = FIX2INT (filter_v);
+  if (filter < CAIRO_FILTER_FAST || filter > CAIRO_FILTER_GAUSSIAN)
+    rb_raise (rb_eArgError, "invalide pattern filter type");
+  cairo_pattern_set_filter (_SELF, filter);
+  return self; 
+}
+
+static VALUE
+rb_cairo_pattern_get_filter (VALUE self)
+{
+  cairo_filter_t filter = cairo_pattern_get_filter (_SELF);
+  return INT2FIX (filter);
+}
+
+
+
 void
 Init_cairo_pattern (void)
 {
   rb_cCairo_Pattern =
     rb_define_class_under (rb_mCairo, "Pattern", rb_cObject);
+  
+  rb_define_singleton_method (rb_cCairo_Pattern, "create_linear",
+    RUBY_METHOD_FUNC (rb_cairo_pattern_create_linear), 4);
+  rb_define_singleton_method (rb_cCairo_Pattern, "create_radial",
+    RUBY_METHOD_FUNC (rb_cairo_pattern_create_radial), 6);
+ 
+  rb_define_method (rb_cCairo_Pattern, "add_color_stop",
+    RUBY_METHOD_FUNC (rb_cairo_pattern_add_color_stop), 5);
+
+  rb_define_method (rb_cCairo_Pattern, "set_matrix",
+    RUBY_METHOD_FUNC (rb_cairo_pattern_set_matrix), 1);
+  rb_define_method (rb_cCairo_Pattern, "get_matrix",
+    RUBY_METHOD_FUNC (rb_cairo_pattern_get_matrix), 0);
+    
+  rb_define_method (rb_cCairo_Pattern, "set_extend",
+    RUBY_METHOD_FUNC (rb_cairo_pattern_set_extend), 1);
+  rb_define_method (rb_cCairo_Pattern, "get_extend",
+    RUBY_METHOD_FUNC (rb_cairo_pattern_get_extend), 0);
+
+  rb_define_method (rb_cCairo_Pattern, "set_filter",
+    RUBY_METHOD_FUNC (rb_cairo_pattern_set_filter), 1);
+  rb_define_method (rb_cCairo_Pattern, "get_filter",
+    RUBY_METHOD_FUNC (rb_cairo_pattern_get_filter), 0);
 }

Index: rb_cairo_pattern.h
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo_pattern.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rb_cairo_pattern.h	8 Feb 2005 01:28:21 -0000	1.1
+++ rb_cairo_pattern.h	14 Feb 2005 23:51:54 -0000	1.2
@@ -17,6 +17,7 @@
 extern VALUE rb_cCairo_Pattern;
 
 void             Init_cairo_pattern      (void);
+VALUE            rb_cairo_pattern_wrap   (cairo_pattern_t *pat);
 cairo_pattern_t *rb_v_to_cairo_pattern_t (VALUE value);
 void             rb_free_pattern         (void *ptr);
 




More information about the cairo-commit mailing list