[cairo-commit] rcairo/src rb_cairo.h, 1.6, 1.7 rb_cairo_context.c, 1.15, 1.16 rb_cairo_pattern.c, 1.7, 1.8 rb_cairo_surface.c, 1.8, 1.9

Kouhei Sutou commit at pdx.freedesktop.org
Sun May 20 01:46:19 PDT 2007


Committed by: kou

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

Modified Files:
	rb_cairo.h rb_cairo_context.c rb_cairo_pattern.c 
	rb_cairo_surface.c 
Log Message:
* src/rb_cairo.h, src/rb_cairo_pattern.c, src/rb_cairo_surface.c:
  always detected surface and pattern type dynamically.
* src/rb_cairo_context.c: followed the above changes.


Index: rb_cairo.h
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- rb_cairo.h	20 May 2007 03:03:02 -0000	1.6
+++ rb_cairo.h	20 May 2007 08:46:06 -0000	1.7
@@ -113,7 +113,7 @@
 #define CRMATRIX2RVAL(matrix)   (rb_cairo_matrix_to_ruby_object(matrix))
 
 #define RVAL2CRPATTERN(obj)     (rb_cairo_pattern_from_ruby_object(obj))
-#define CRPATTERN2RVAL(pattern, klass) (rb_cairo_pattern_to_ruby_object(pattern, klass))
+#define CRPATTERN2RVAL(pattern) (rb_cairo_pattern_to_ruby_object(pattern))
 
 #define RVAL2CRFONTFACE(obj)    (rb_cairo_font_face_from_ruby_object(obj))
 #define CRFONTFACE2RVAL(face)   (rb_cairo_font_face_to_ruby_object(face))
@@ -146,7 +146,7 @@
 VALUE                 rb_cairo_matrix_to_ruby_object         (cairo_matrix_t *matrix);
 
 cairo_pattern_t      *rb_cairo_pattern_from_ruby_object      (VALUE obj);
-VALUE                 rb_cairo_pattern_to_ruby_object        (cairo_pattern_t *pat, VALUE klass);
+VALUE                 rb_cairo_pattern_to_ruby_object        (cairo_pattern_t *pat);
 
 cairo_font_face_t    *rb_cairo_font_face_from_ruby_object    (VALUE obj);
 VALUE                 rb_cairo_font_face_to_ruby_object      (cairo_font_face_t *face);

Index: rb_cairo_context.c
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_context.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- rb_cairo_context.c	18 May 2007 14:07:48 -0000	1.15
+++ rb_cairo_context.c	20 May 2007 08:46:07 -0000	1.16
@@ -17,7 +17,7 @@
 
 VALUE rb_cCairo_Context;
 
-static ID cr_id_surface, cr_id_source, cr_id_source_class;
+static ID cr_id_surface, cr_id_source;
 static ID cr_id_plus, cr_id_minus, cr_id_multi, cr_id_div;
 
 #define _SELF  (RVAL2CRCONTEXT(self))
@@ -129,7 +129,7 @@
 
   pattern = cairo_pop_group (_SELF);
   cr_check_status (_SELF);
-  return CRPATTERN2RVAL (pattern, rb_cCairo_SurfacePattern);
+  return CRPATTERN2RVAL (pattern);
 }
 
 static VALUE
@@ -137,7 +137,6 @@
 {
   cairo_pop_group_to_source (_SELF);
   cr_check_status (_SELF);
-  rb_ivar_set (self, cr_id_source_class, rb_cCairo_SurfacePattern);
   return Qnil;
 }
 
@@ -232,7 +231,6 @@
     }
   cr_check_status (_SELF);
   rb_ivar_set (self, cr_id_source, Qnil);
-  rb_ivar_set (self, cr_id_source_class, rb_cCairo_SolidPattern);
   return self;
 }
 
@@ -281,7 +279,6 @@
     }
   cr_check_status (_SELF);
   rb_ivar_set (self, cr_id_source, Qnil);
-  rb_ivar_set (self, cr_id_source_class, rb_cCairo_SolidPattern);
   return self;
 }
 
@@ -294,7 +291,6 @@
                             NUM2INT (height));
   cr_check_status (_SELF);
   rb_ivar_set (self, cr_id_source, Qnil);
-  rb_ivar_set (self, cr_id_source_class, rb_cCairo_SurfacePattern);
   return self;
 }
 
@@ -304,7 +300,6 @@
   cairo_set_source (_SELF, RVAL2CRPATTERN (pattern));
   cr_check_status (_SELF);
   rb_ivar_set (self, cr_id_source, pattern);
-  rb_ivar_set (self, cr_id_source_class, rb_obj_class (pattern));
   return self;
 }
 
@@ -1190,14 +1185,13 @@
   cairo_pattern_t *source;
   source = cairo_get_source (_SELF);
 
-  rb_source = rb_ivar_get (self, cr_id_source);
   if (source)
     {
       rb_cairo_check_status (cairo_pattern_status (source));
+      rb_source = rb_ivar_get (self, cr_id_source);
       if (NIL_P (rb_source) || RVAL2CRPATTERN (rb_source) != source)
         {
-          rb_source =
-            CRPATTERN2RVAL (source, rb_ivar_get (self, cr_id_source_class));
+          rb_source = CRPATTERN2RVAL (source);
           rb_ivar_set (self, cr_id_source, rb_source);
         }
     }
@@ -1357,7 +1351,6 @@
 {
   cr_id_surface = rb_intern ("surface");
   cr_id_source = rb_intern ("source");
-  cr_id_source_class = rb_intern ("source_class");
 
   cr_id_plus = rb_intern ("+");
   cr_id_minus = rb_intern ("-");

Index: rb_cairo_pattern.c
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_pattern.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- rb_cairo_pattern.c	3 May 2007 02:47:39 -0000	1.7
+++ rb_cairo_pattern.c	20 May 2007 08:46:07 -0000	1.8
@@ -38,6 +38,36 @@
   rb_cairo_check_status (cairo_pattern_status (pattern));
 }
 
+static VALUE
+cr_pattern_get_klass (cairo_pattern_t *pattern)
+{
+  VALUE klass;
+  cairo_pattern_type_t type;
+
+  type = cairo_pattern_get_type (pattern);
+  switch (type)
+    {
+    case CAIRO_PATTERN_TYPE_SOLID:
+      klass = rb_cCairo_SolidPattern;
+      break;
+    case CAIRO_PATTERN_TYPE_SURFACE:
+      klass = rb_cCairo_SurfacePattern;
+      break;
+    case CAIRO_PATTERN_TYPE_LINEAR:
+      klass = rb_cCairo_LinearPattern;
+      break;
+    case CAIRO_PATTERN_TYPE_RADIAL:
+      klass = rb_cCairo_RadialPattern;
+      break;
+    default:
+      rb_raise (rb_eArgError, "unknown pattern type: %d", type);
+      break;
+    }
+
+  return klass;
+}
+
+
 cairo_pattern_t *
 rb_cairo_pattern_from_ruby_object (VALUE obj)
 {
@@ -60,10 +90,12 @@
 }
 
 VALUE
-rb_cairo_pattern_to_ruby_object (cairo_pattern_t *pattern, VALUE klass)
+rb_cairo_pattern_to_ruby_object (cairo_pattern_t *pattern)
 {
   if (pattern)
     {
+      VALUE klass;
+      klass = cr_pattern_get_klass (pattern);
       cairo_pattern_reference (pattern);
       return Data_Wrap_Struct (klass, NULL, cr_pattern_free, pattern);
     }

Index: rb_cairo_surface.c
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_surface.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- rb_cairo_surface.c	20 May 2007 03:03:02 -0000	1.8
+++ rb_cairo_surface.c	20 May 2007 08:46:07 -0000	1.9
@@ -34,7 +34,6 @@
 static ID cr_id_target;
 static ID cr_id_read;
 static ID cr_id_write;
-static cairo_user_data_key_t cr_klass_key;
 static cairo_user_data_key_t cr_closure_key;
 
 #define _SELF  (RVAL2CRSURFACE(self))
@@ -45,46 +44,33 @@
   rb_cairo_check_status (cairo_surface_status (surface));
 }
 
-static void
-cr_surface_set_klass (cairo_surface_t *surface, VALUE klass)
-{
-  cairo_status_t status;
-  status = cairo_surface_set_user_data (surface, &cr_klass_key,
-                                        (void *)klass, NULL);
-  rb_cairo_check_status (status);
-}
-
 static VALUE
 cr_surface_get_klass (cairo_surface_t *surface)
 {
   VALUE klass;
-  void *data = cairo_surface_get_user_data (surface, &cr_klass_key);
+  cairo_surface_type_t type;
 
-  if (data)
-    klass = (VALUE) data;
-  else
+  type = cairo_surface_get_type (surface);
+  switch (type)
     {
-      switch (cairo_surface_get_type (surface))
-        {
-        case CAIRO_SURFACE_TYPE_IMAGE:
-          klass = rb_cCairo_ImageSurface;
-          break;
-        case CAIRO_SURFACE_TYPE_PDF:
-          klass = rb_cCairo_PDFSurface;
-          break;
-        case CAIRO_SURFACE_TYPE_PS:
-          klass = rb_cCairo_PSSurface;
-          break;
-        case CAIRO_SURFACE_TYPE_SVG:
-          klass = rb_cCairo_SVGSurface;
-          break;
-        case CAIRO_SURFACE_TYPE_WIN32:
-          klass = rb_cCairo_WIN32Surface;
-          break;
-        default:
-          klass = rb_cCairo_Surface;
-          break;
-        }
+    case CAIRO_SURFACE_TYPE_IMAGE:
+      klass = rb_cCairo_ImageSurface;
+      break;
+    case CAIRO_SURFACE_TYPE_PDF:
+      klass = rb_cCairo_PDFSurface;
+      break;
+    case CAIRO_SURFACE_TYPE_PS:
+      klass = rb_cCairo_PSSurface;
+      break;
+    case CAIRO_SURFACE_TYPE_SVG:
+      klass = rb_cCairo_SVGSurface;
+      break;
+    case CAIRO_SURFACE_TYPE_WIN32:
+      klass = rb_cCairo_WIN32Surface;
+      break;
+    default:
+      rb_raise (rb_eArgError, "unknown source type: %d", type);
+      break;
     }
 
   return klass;
@@ -233,7 +219,6 @@
       rb_raise (rb_eTypeError, "not a cairo surface");
     }
   Data_Get_Struct (obj, cairo_surface_t, surface);
-  cr_surface_set_klass (surface, rb_obj_class (obj));
   return surface;
 }
 
@@ -251,7 +236,8 @@
 {
   if (surface)
     {
-      VALUE klass = cr_surface_get_klass (surface);
+      VALUE klass;
+      klass = cr_surface_get_klass (surface);
       cairo_surface_reference (surface);
       return Data_Wrap_Struct (klass, NULL, cr_surface_free, surface);
     }
@@ -297,7 +283,6 @@
                                           RVAL2CRCONTENT (content),
                                           NUM2INT (width), NUM2INT (height));
   cr_surface_check_status (surface);
-  cr_surface_set_klass (surface, cr_surface_get_klass (surface));
   return CRSURFACE2RVAL (surface);
 }
 
@@ -483,7 +468,6 @@
     surface = cr_image_surface_create_from_png (target);
 
   cr_surface_check_status (surface);
-  cr_surface_set_klass (surface, klass);
   rb_surface = cr_surface_allocate (klass);
   DATA_PTR (rb_surface) = surface;
   return rb_surface;
@@ -540,7 +524,6 @@
               "(data, format, width, height, stride))");
 
   cr_surface_check_status (surface);
-  cr_surface_set_klass (surface, cr_surface_get_klass (surface));
   DATA_PTR (self) = surface;
   if (rb_block_given_p ())
     yield_and_finish (self);
@@ -813,7 +796,6 @@
   if (!surface)
     rb_cairo_check_status (CAIRO_STATUS_INVALID_FORMAT);
   cr_surface_check_status (surface);
-  cr_surface_set_klass (surface, cr_surface_get_klass (surface));
   DATA_PTR (self) = surface;
   if (rb_block_given_p ())
     yield_and_finish (self);



More information about the cairo-commit mailing list