[cairo-commit] rcairo/packages/cairo/ext rb_cairo_context.c, 1.3, 1.4 rb_cairo_exception.c, 1.1, 1.2 rb_cairo_matrix.c, 1.2, 1.3 rb_cairo_surface.c, 1.1, 1.2

Oeyvind Kolaas commit at pdx.freedesktop.org
Thu Mar 17 08:02:59 PST 2005


Committed by: pippin

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

Modified Files:
	rb_cairo_context.c rb_cairo_exception.c rb_cairo_matrix.c 
	rb_cairo_surface.c 
Log Message:
adding surface.finish (for pdf)

Index: rb_cairo_context.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo_context.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- rb_cairo_context.c	15 Mar 2005 08:20:00 -0000	1.3
+++ rb_cairo_context.c	17 Mar 2005 16:02:57 -0000	1.4
@@ -48,7 +48,7 @@
   status = cairo_status (context);
   if (status)
     {
-      raise_cairo_exception (status, cairo_status_string (context));
+      rb_cairo_raise_exception (status, cairo_status_string (context));
     }
 }
 
@@ -732,7 +732,7 @@
       if (cairo_status (_SELF))
         {
           rb_free_font (xform);
-          raise_cairo_exception (cairo_status (_SELF),
+          rb_cairo_raise_exception (cairo_status (_SELF),
                                  cairo_status_string (_SELF));
         }
       return Data_Wrap_Struct (rb_cCairo_Font, NULL, rb_free_font, xform);
@@ -772,7 +772,7 @@
       if (cairo_status (_SELF))
         {
           rb_free_font (xform);
-          raise_cairo_exception (cairo_status (_SELF),
+          rb_cairo_raise_exception (cairo_status (_SELF),
                                  cairo_status_string (_SELF));
         }
       return Data_Wrap_Struct (rb_cCairo_TextExtents, NULL, rb_free_text_extents, xform);
@@ -818,7 +818,7 @@
       if (cairo_status (_SELF))
         {
           rb_free_font (xform);
-          raise_cairo_exception (cairo_status (_SELF),
+          rb_cairo_raise_exception (cairo_status (_SELF),
                                  cairo_status_string (_SELF));
         }
       free (glyphs);
@@ -985,7 +985,7 @@
       if (cairo_status (_SELF))
         {
           rb_free_matrix (matrix);
-          raise_cairo_exception (cairo_status (_SELF),
+          rb_cairo_raise_exception (cairo_status (_SELF),
                                  cairo_status_string (_SELF));
         }
       return rb_cairo_matrix_wrap (matrix);

Index: rb_cairo_exception.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo_exception.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rb_cairo_exception.c	8 Feb 2005 01:28:21 -0000	1.1
+++ rb_cairo_exception.c	17 Mar 2005 16:02:57 -0000	1.2
@@ -16,6 +16,8 @@
 static VALUE rb_eCairo_InvalidMatrixError;
 static VALUE rb_eCairo_NoTargetSurfaceError;
 static VALUE rb_eCairo_NullPointerError;
+static VALUE rb_eCairo_WriteError;
+static VALUE rb_eCairo_SurfaceFinishedError;
 
 void
 rb_cairo_raise_exception (cairo_status_t  status,
@@ -44,6 +46,11 @@
     case CAIRO_STATUS_NULL_POINTER:
       rb_raise (rb_eCairo_NullPointerError, string);
       break;
+    case CAIRO_STATUS_WRITE_ERROR:
+      rb_raise (rb_eCairo_WriteError, string);
+      break;
+    case CAIRO_STATUS_SURFACE_FINISHED:
+      rb_raise (rb_eCairo_SurfaceFinishedError, string);
     }
 }
 
@@ -60,10 +67,18 @@
     rb_define_class_under (rb_mCairo, "NoCurrentPointError",
                            rb_eRuntimeError);
   rb_eCairo_InvalidMatrixError =
-    rb_define_class_under (rb_mCairo, "InvalidMatrixError", rb_eArgError);
+    rb_define_class_under (rb_mCairo, "InvalidMatrixError",
+                           rb_eArgError);
   rb_eCairo_NoTargetSurfaceError =
     rb_define_class_under (rb_mCairo, "NoTargetSurfaceError",
                            rb_eRuntimeError);
   rb_eCairo_NullPointerError =
-    rb_define_class_under (rb_mCairo, "NullPointerError", rb_eTypeError);
+    rb_define_class_under (rb_mCairo, "NullPointerError",
+                           rb_eTypeError);
+  rb_eCairo_WriteError =
+    rb_define_class_under (rb_mCairo, "WriteError",
+                           rb_eRuntimeError);
+  rb_eCairo_SurfaceFinishedError =
+    rb_define_class_under (rb_mCairo, "SurfaceFinishedError",
+                           rb_eRuntimeError);
 }

Index: rb_cairo_matrix.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo_matrix.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- rb_cairo_matrix.c	14 Feb 2005 23:51:54 -0000	1.2
+++ rb_cairo_matrix.c	17 Mar 2005 16:02:57 -0000	1.3
@@ -82,7 +82,7 @@
                        rb_v_to_cairo_matrix_t (other));
   if (status)
     {
-      raise_cairo_exception (status, "error copying matrix");
+      rb_cairo_raise_exception (status, "error copying matrix");
     }
   return self;
 }
@@ -94,7 +94,7 @@
   status = cairo_matrix_set_identity (_SELF);
   if (status)
     {
-      raise_cairo_exception (status, "error resetting matrix");
+      rb_cairo_raise_exception (status, "error resetting matrix");
     }
   return self;
 }
@@ -112,7 +112,7 @@
                                     NUM2DBL (tx), NUM2DBL (ty));
   if (status)
     {
-      raise_cairo_exception (status, "error setting matrix components");
+      rb_cairo_raise_exception (status, "error setting matrix components");
     }
   return self;
 }
@@ -128,7 +128,7 @@
                                     affine + 4, affine + 5);
   if (status)
     {
-      raise_cairo_exception (status, "error getting matrix components");
+      rb_cairo_raise_exception (status, "error getting matrix components");
     }
   return float_array (affine, 6);
 }
@@ -142,7 +142,7 @@
                                    NUM2DBL (tx), NUM2DBL (ty));
   if (status)
     {
-      raise_cairo_exception (status, "error translating matrix");
+      rb_cairo_raise_exception (status, "error translating matrix");
     }
   return self;
 }
@@ -156,7 +156,7 @@
                                NUM2DBL (sx), NUM2DBL (sy));
   if (status)
     {
-      raise_cairo_exception (status, "error scaling matrix");
+      rb_cairo_raise_exception (status, "error scaling matrix");
     }
   return self;
 }
@@ -170,7 +170,7 @@
                                 NUM2DBL (radians));
   if (status)
     {
-      raise_cairo_exception (status, "error rotating matrix");
+      rb_cairo_raise_exception (status, "error rotating matrix");
     }
   return self;
 }
@@ -182,7 +182,7 @@
   status = cairo_matrix_invert (_SELF);
   if (status)
     {
-      raise_cairo_exception (status, "error inverting matrix");
+      rb_cairo_raise_exception (status, "error inverting matrix");
     }
   return self;
 }
@@ -197,7 +197,7 @@
                                   rb_v_to_cairo_matrix_t (a), rb_v_to_cairo_matrix_t (b));
   if (status)
     {
-      raise_cairo_exception (status, "error multiplying matrices");
+      rb_cairo_raise_exception (status, "error multiplying matrices");
     }
   return self;
 }
@@ -214,7 +214,7 @@
                                             pair, pair + 1);
   if (status)
     {
-      raise_cairo_exception (status, "error transforming distance");
+      rb_cairo_raise_exception (status, "error transforming distance");
     }
   return float_array (pair, 2);
 }
@@ -231,7 +231,7 @@
                                          pair, pair + 1);
   if (status)
     {
-      raise_cairo_exception (status, "error transforming point");
+      rb_cairo_raise_exception (status, "error transforming point");
     }
   return float_array (pair, 2);
 }

Index: rb_cairo_surface.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo_surface.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rb_cairo_surface.c	8 Feb 2005 01:28:21 -0000	1.1
+++ rb_cairo_surface.c	17 Mar 2005 16:02:57 -0000	1.2
@@ -25,6 +25,31 @@
 
 #define _SELF  (DATA_PTR(self))
 
+static cairo_status_t
+rfile_write (void         *closure,
+             const char   *data,
+             unsigned int  length)
+{
+  OpenFile *fptr;
+  FILE     *fp;
+  
+  fptr = closure;
+  fp   = GetWriteFile (fptr);
+
+  if (rb_io_fwrite (data, length, fp) == length)
+    return CAIRO_STATUS_SUCCESS;
+  return CAIRO_STATUS_WRITE_ERROR;
+}
+
+static void
+rfile_destroy_closure (void *closure)
+{
+  OpenFile *fptr;
+ 
+  fptr = closure;
+}
+
+
 VALUE rb_cCairo_Surface;
 
 cairo_surface_t *
@@ -118,10 +143,17 @@
     {
       rb_raise (rb_eArgError, "height_inches must be positive");
     }
-
-  surface = cairo_pdf_surface_create (GetWriteFile (RFILE (port)->fptr),
+#if 1
+  surface = cairo_pdf_surface_create (rfile_write, rfile_destroy_closure, RFILE (port)->fptr,
                                       width_inches, height_inches,
                                       x_pixels_per_inch, y_pixels_per_inch);
+#endif
+#if 0
+  surface = cairo_pdf_surface_create_for_file (GetWriteFile(RFILE (port)->fptr),
+        width_inches, height_inches,
+        x_pixels_per_inch, y_pixels_per_inch);
+#endif
+  
   if (surface)
     {
       return Data_Wrap_Struct (rb_cCairo_Surface, NULL, rb_free_surface,
@@ -135,6 +167,13 @@
 }
 #endif
 
+static    VALUE
+rb_cairo_surface_finish (VALUE self)
+{
+  cairo_surface_finish (_SELF);
+  return Qnil;
+}
+
 #ifdef CAIRO_HAS_PNG_SURFACE
 static    VALUE
 rb_cairo_surface_new_png (VALUE klass,
@@ -229,7 +268,6 @@
 }
 #endif
 
-
 void
 Init_cairo_surface (void)
 {
@@ -238,6 +276,9 @@
   rb_define_singleton_method (rb_cCairo_Surface, "new",
                               RUBY_METHOD_FUNC (rb_cairo_surface_new), 3);
 
+  rb_define_method (rb_cCairo_Surface, "finish",
+                              RUBY_METHOD_FUNC (rb_cairo_surface_finish), 0);
+
 #ifdef CAIRO_HAS_PDF_SURFACE
   rb_define_singleton_method (rb_cCairo_Surface, "new_pdf",
                               RUBY_METHOD_FUNC (rb_cairo_surface_new_pdf), 5);
@@ -248,7 +289,7 @@
                               RUBY_METHOD_FUNC (rb_cairo_surface_new_png), 4);
 #endif
 
-#ifdef CAIRO_HAS_PDF_SURFACE
+#ifdef CAIRO_HAS_PS_SURFACE
   rb_define_singleton_method (rb_cCairo_Surface, "new_ps",
                               RUBY_METHOD_FUNC (rb_cairo_surface_new_ps), 5);
 #endif




More information about the cairo-commit mailing list