[cairo-commit] rcairo/src cairo.def, 1.5, 1.6 rb_cairo.h, 1.8, 1.9 rb_cairo_private.h, 1.5, 1.6 rb_cairo_surface.c, 1.13, 1.14

Kouhei Sutou commit at pdx.freedesktop.org
Fri Jan 11 00:03:41 PST 2008


Committed by: kou

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

Modified Files:
	cairo.def rb_cairo.h rb_cairo_private.h rb_cairo_surface.c 
Log Message:
* src/rb_cairo.h:
  - RUBY_XXX -> RB_XXX.
  - added extern "C" {}.
  - added rb_cCairo_QuartzSurface.

* src/cairo.def: rb_cCairo_QuartzSurface.

* src/rb_cairo_surface.c: supported Quartz backend.

* src/lib/cairo.rb: required 'osx/cocoa' if Cairo::QuartzSurface is available.


Index: cairo.def
===================================================================
RCS file: /cvs/cairo/rcairo/src/cairo.def,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- cairo.def	22 May 2007 11:25:39 -0000	1.5
+++ cairo.def	11 Jan 2008 08:03:39 -0000	1.6
@@ -27,6 +27,7 @@
     rb_cCairo_PSSurface       DATA
     rb_cCairo_SVGSurface      DATA
     rb_cCairo_WIN32Surface    DATA
+    rb_cCairo_QuartzSurface   DATA
 
     rb_mCairo_Operator        DATA
     rb_mCairo_Antialias       DATA

Index: rb_cairo.h
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- rb_cairo.h	22 May 2007 11:25:39 -0000	1.8
+++ rb_cairo.h	11 Jan 2008 08:03:39 -0000	1.9
@@ -36,6 +36,10 @@
 #  undef OpenFile
 #endif
 
+#if CAIRO_HAS_QUARTZ_SURFACE
+#  include <cairo-quartz.h>
+#endif
+
 #define CAIRO_CHECK_VERSION(major, minor, micro)    \
     (CAIRO_VERSION_MAJOR > (major) || \
      (CAIRO_VERSION_MAJOR == (major) && CAIRO_VERSION_MINOR > (minor)) || \
@@ -44,67 +48,85 @@
 
 #include "ruby.h"
 
-#if defined(RUBY_CAIRO_PLATFORM_WIN32) && !defined(RUBY_CAIRO_STATIC_COMPILATION)
-#  ifdef RUBY_CAIRO_COMPILATION
-#    define RUBY_CAIRO_VAR __declspec(dllexport)
+#if defined(__cplusplus)
+#  define RB_CAIRO_BEGIN_DECLS extern "C" {
+#  define RB_CAIRO_END_DECLS }
+#else
+#  define RB_CAIRO_BEGIN_DECLS
+#  define RB_CAIRO_END_DECLS
+#endif
+
+RB_CAIRO_BEGIN_DECLS
+
+#if defined(RUBY_CAIRO_PLATFORM_WIN32) && !defined(RB_CAIRO_PLATFORM_WIN32)
+#  define RB_CAIRO_PLATFORM_WIN32 RUBY_CAIRO_PLATFORM_WIN32
+#endif
+
+#if defined(RUBY_CAIRO_STATIC_COMPILATION) && !defined(RB_CAIRO_STATIC_COMPILATION)
+#  define RB_CAIRO_STATIC_COMPILATION RUBY_CAIRO_STATIC_COMPILATION
+#endif
+
+#if defined(RB_CAIRO_PLATFORM_WIN32) && !defined(RB_CAIRO_STATIC_COMPILATION)
+#  ifdef RB_CAIRO_COMPILATION
+#    define RB_CAIRO_VAR __declspec(dllexport)
 #  else
-#    define RUBY_CAIRO_VAR extern __declspec(dllimport)
+#    define RB_CAIRO_VAR extern __declspec(dllimport)
 #  endif
 #else
-#  define RUBY_CAIRO_VAR extern
+#  define RB_CAIRO_VAR extern
 #endif
 
-RUBY_CAIRO_VAR VALUE rb_mCairo;
-RUBY_CAIRO_VAR VALUE rb_cCairo_Context;
-RUBY_CAIRO_VAR VALUE rb_cCairo_Point;
-RUBY_CAIRO_VAR VALUE rb_cCairo_Path;
-RUBY_CAIRO_VAR VALUE rb_cCairo_PathData;
-RUBY_CAIRO_VAR VALUE rb_cCairo_PathMoveTo;
-RUBY_CAIRO_VAR VALUE rb_cCairo_PathLineTo;
-RUBY_CAIRO_VAR VALUE rb_cCairo_PathCurveTo;
-RUBY_CAIRO_VAR VALUE rb_cCairo_PathClosePath;
-RUBY_CAIRO_VAR VALUE rb_cCairo_Matrix;
-RUBY_CAIRO_VAR VALUE rb_cCairo_Pattern;
-RUBY_CAIRO_VAR VALUE rb_cCairo_SolidPattern;
-RUBY_CAIRO_VAR VALUE rb_cCairo_SurfacePattern;
-RUBY_CAIRO_VAR VALUE rb_cCairo_GradientPattern;
-RUBY_CAIRO_VAR VALUE rb_cCairo_LinearPattern;
-RUBY_CAIRO_VAR VALUE rb_cCairo_RadialPattern;
-RUBY_CAIRO_VAR VALUE rb_cCairo_FontFace;
-RUBY_CAIRO_VAR VALUE rb_cCairo_FontExtents;
-RUBY_CAIRO_VAR VALUE rb_cCairo_FontOptions;
-RUBY_CAIRO_VAR VALUE rb_cCairo_ScaledFont;
-RUBY_CAIRO_VAR VALUE rb_cCairo_TextExtents;
-RUBY_CAIRO_VAR VALUE rb_cCairo_Glyph;
-RUBY_CAIRO_VAR VALUE rb_cCairo_Surface;
-RUBY_CAIRO_VAR VALUE rb_cCairo_ImageSurface;
-RUBY_CAIRO_VAR VALUE rb_cCairo_PDFSurface;
-RUBY_CAIRO_VAR VALUE rb_cCairo_PSSurface;
-RUBY_CAIRO_VAR VALUE rb_cCairo_SVGSurface;
-RUBY_CAIRO_VAR VALUE rb_cCairo_WIN32Surface;
-
-RUBY_CAIRO_VAR VALUE rb_mCairo_Operator;
-RUBY_CAIRO_VAR VALUE rb_mCairo_Antialias;
-RUBY_CAIRO_VAR VALUE rb_mCairo_FillRule;
-RUBY_CAIRO_VAR VALUE rb_mCairo_LineCap;
-RUBY_CAIRO_VAR VALUE rb_mCairo_LineJoin;
-RUBY_CAIRO_VAR VALUE rb_mCairo_FontSlant;
-RUBY_CAIRO_VAR VALUE rb_mCairo_FontWeight;
-RUBY_CAIRO_VAR VALUE rb_mCairo_SubpixelOrder;
-RUBY_CAIRO_VAR VALUE rb_mCairo_HintStyle;
-RUBY_CAIRO_VAR VALUE rb_mCairo_HintMetrics;
-RUBY_CAIRO_VAR VALUE rb_mCairo_FontType;
-RUBY_CAIRO_VAR VALUE rb_mCairo_PathDataType;
-RUBY_CAIRO_VAR VALUE rb_mCairo_Content;
-RUBY_CAIRO_VAR VALUE rb_mCairo_SurfaceType;
-RUBY_CAIRO_VAR VALUE rb_mCairo_Format;
-RUBY_CAIRO_VAR VALUE rb_mCairo_PatternType;
-RUBY_CAIRO_VAR VALUE rb_mCairo_Extend;
-RUBY_CAIRO_VAR VALUE rb_mCairo_Filter;
-RUBY_CAIRO_VAR VALUE rb_mCairo_SVGVersion;
+RB_CAIRO_VAR VALUE rb_mCairo;
+RB_CAIRO_VAR VALUE rb_cCairo_Context;
+RB_CAIRO_VAR VALUE rb_cCairo_Point;
+RB_CAIRO_VAR VALUE rb_cCairo_Path;
+RB_CAIRO_VAR VALUE rb_cCairo_PathData;
+RB_CAIRO_VAR VALUE rb_cCairo_PathMoveTo;
+RB_CAIRO_VAR VALUE rb_cCairo_PathLineTo;
+RB_CAIRO_VAR VALUE rb_cCairo_PathCurveTo;
+RB_CAIRO_VAR VALUE rb_cCairo_PathClosePath;
+RB_CAIRO_VAR VALUE rb_cCairo_Matrix;
+RB_CAIRO_VAR VALUE rb_cCairo_Pattern;
+RB_CAIRO_VAR VALUE rb_cCairo_SolidPattern;
+RB_CAIRO_VAR VALUE rb_cCairo_SurfacePattern;
+RB_CAIRO_VAR VALUE rb_cCairo_GradientPattern;
+RB_CAIRO_VAR VALUE rb_cCairo_LinearPattern;
+RB_CAIRO_VAR VALUE rb_cCairo_RadialPattern;
+RB_CAIRO_VAR VALUE rb_cCairo_FontFace;
+RB_CAIRO_VAR VALUE rb_cCairo_FontExtents;
+RB_CAIRO_VAR VALUE rb_cCairo_FontOptions;
+RB_CAIRO_VAR VALUE rb_cCairo_ScaledFont;
+RB_CAIRO_VAR VALUE rb_cCairo_TextExtents;
+RB_CAIRO_VAR VALUE rb_cCairo_Glyph;
+RB_CAIRO_VAR VALUE rb_cCairo_Surface;
+RB_CAIRO_VAR VALUE rb_cCairo_ImageSurface;
+RB_CAIRO_VAR VALUE rb_cCairo_PDFSurface;
+RB_CAIRO_VAR VALUE rb_cCairo_PSSurface;
+RB_CAIRO_VAR VALUE rb_cCairo_SVGSurface;
+RB_CAIRO_VAR VALUE rb_cCairo_WIN32Surface;
+RB_CAIRO_VAR VALUE rb_cCairo_QuartzSurface;
 
-RUBY_CAIRO_VAR VALUE rb_mCairo_Color;
-RUBY_CAIRO_VAR VALUE rb_cCairo_Color_Base;
+RB_CAIRO_VAR VALUE rb_mCairo_Operator;
+RB_CAIRO_VAR VALUE rb_mCairo_Antialias;
+RB_CAIRO_VAR VALUE rb_mCairo_FillRule;
+RB_CAIRO_VAR VALUE rb_mCairo_LineCap;
+RB_CAIRO_VAR VALUE rb_mCairo_LineJoin;
+RB_CAIRO_VAR VALUE rb_mCairo_FontSlant;
+RB_CAIRO_VAR VALUE rb_mCairo_FontWeight;
+RB_CAIRO_VAR VALUE rb_mCairo_SubpixelOrder;
+RB_CAIRO_VAR VALUE rb_mCairo_HintStyle;
+RB_CAIRO_VAR VALUE rb_mCairo_HintMetrics;
+RB_CAIRO_VAR VALUE rb_mCairo_FontType;
+RB_CAIRO_VAR VALUE rb_mCairo_PathDataType;
+RB_CAIRO_VAR VALUE rb_mCairo_Content;
+RB_CAIRO_VAR VALUE rb_mCairo_SurfaceType;
+RB_CAIRO_VAR VALUE rb_mCairo_Format;
+RB_CAIRO_VAR VALUE rb_mCairo_PatternType;
+RB_CAIRO_VAR VALUE rb_mCairo_Extend;
+RB_CAIRO_VAR VALUE rb_mCairo_Filter;
+RB_CAIRO_VAR VALUE rb_mCairo_SVGVersion;
+RB_CAIRO_VAR VALUE rb_mCairo_Color;
+RB_CAIRO_VAR VALUE rb_cCairo_Color_Base;
 
 
 #define RVAL2CRCONTEXT(obj)     (rb_cairo_context_from_ruby_object(obj))
@@ -218,4 +240,6 @@
 #define RB_CAIRO_DEF_SETTERS(klass) rb_cairo_def_setters(klass);
 void rb_cairo_def_setters (VALUE klass);
 
+RB_CAIRO_END_DECLS
+
 #endif

Index: rb_cairo_private.h
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_private.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- rb_cairo_private.h	14 Jun 2007 12:23:45 -0000	1.5
+++ rb_cairo_private.h	11 Jan 2008 08:03:39 -0000	1.6
@@ -40,6 +40,7 @@
 extern void Init_cairo_path (void);
 extern void Init_cairo_matrix (void);
 extern void Init_cairo_surface (void);
+extern void Init_cairo_quartz_surface (void);
 extern void Init_cairo_exception (void);
 extern void Init_cairo_font (void);
 extern void Init_cairo_font_extents (void);

Index: rb_cairo_surface.c
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_surface.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- rb_cairo_surface.c	14 Jun 2007 12:23:45 -0000	1.13
+++ rb_cairo_surface.c	11 Jan 2008 08:03:39 -0000	1.14
@@ -26,10 +26,11 @@
 
 VALUE rb_cCairo_Surface;
 VALUE rb_cCairo_ImageSurface;
-VALUE rb_cCairo_PDFSurface;
-VALUE rb_cCairo_PSSurface;
-VALUE rb_cCairo_SVGSurface;
-VALUE rb_cCairo_WIN32Surface;
+VALUE rb_cCairo_PDFSurface = Qnil;
+VALUE rb_cCairo_PSSurface = Qnil;
+VALUE rb_cCairo_SVGSurface = Qnil;
+VALUE rb_cCairo_WIN32Surface = Qnil;
+VALUE rb_cCairo_QuartzSurface = Qnil;
 
 static ID cr_id_target;
 static ID cr_id_read;
@@ -830,6 +831,75 @@
 }
 #endif
 
+#if CAIRO_HAS_QUARTZ_SURFACE
+/* Quartz-surface functions */
+
+#include <objc/objc-runtime.h>
+
+VALUE ocobj_s_new (id ocid);
+id rbobj_get_ocid (VALUE obj);
+
+
+static VALUE
+cr_quartz_surface_initialize (int argc, VALUE *argv, VALUE self)
+{
+  id objc_object = nil;
+  CGContextRef context;
+  unsigned int width, height;
+  cairo_surface_t *surface = NULL;
+  cairo_format_t format = CAIRO_FORMAT_ARGB32;
+  VALUE arg1, arg2, arg3, rb_width, rb_height;
+
+  rb_scan_args (argc, argv, "21", &arg1, &arg2, &arg3);
+
+  if (argc == 2)
+    {
+      rb_width = arg1;
+      rb_height = arg2;
+    }
+  else
+    {
+      objc_object = rbobj_get_ocid (arg1);
+      if (objc_object == nil)
+        format = RVAL2CRFORMAT (arg1);
+
+      rb_width = arg2;
+      rb_height = arg3;
+    }
+
+  width = NUM2UINT (rb_width);
+  height = NUM2UINT (rb_height);
+
+  if (objc_object != nil)
+    {
+      context = (CGContextRef)objc_object;
+      surface = cairo_quartz_surface_create_for_cg_context (context,
+                                                            width, height);
+    }
+  else
+    {
+      surface = cairo_quartz_surface_create (format, width, height);
+    }
+
+  cr_surface_check_status (surface);
+  DATA_PTR (self) = surface;
+  if (rb_block_given_p ())
+    yield_and_finish (self);
+  return Qnil;
+}
+
+static VALUE
+cr_quartz_surface_get_cg_context (VALUE self)
+{
+  CGContextRef context;
+  id objc_object;
+
+  context = cairo_quartz_surface_get_cg_context (_SELF);
+  objc_object = (id)context;
+  return ocobj_s_new (objc_object);
+}
+#endif
+
 
 void
 Init_cairo_surface (void)
@@ -909,8 +979,6 @@
                     cr_ps_surface_dsc_begin_page_setup, 0);
 
   RB_CAIRO_DEF_SETTERS (rb_cCairo_PSSurface);
-#else
-  rb_cCairo_PSSurface = Qnil;
 #endif
 
 #if CAIRO_HAS_PDF_SURFACE
@@ -921,8 +989,6 @@
                     cr_pdf_surface_set_size, 2);
 
   RB_CAIRO_DEF_SETTERS (rb_cCairo_PDFSurface);
-#else
-  rb_cCairo_PDFSurface = Qnil;
 #endif
 
 #if CAIRO_HAS_SVG_SURFACE
@@ -938,8 +1004,6 @@
                     cr_svg_surface_restrict_to_version, 1);
 
   RB_CAIRO_DEF_SETTERS (rb_cCairo_SVGSurface);
-#else
-  rb_cCairo_SVGSurface = Qnil;
 #endif
 
 #if CAIRO_HAS_WIN32_SURFACE
@@ -953,7 +1017,17 @@
                     cr_win32_surface_get_hdc, 0);
   rb_define_method (rb_cCairo_WIN32Surface, "image",
                     cr_win32_surface_get_image, 0);
-#else
-  rb_cCairo_WIN32Surface = Qnil;
+#endif
+
+#if CAIRO_HAS_QUARTZ_SURFACE
+  /* Quartz-surface */
+
+  rb_cCairo_QuartzSurface =
+    rb_define_class_under (rb_mCairo, "QuartzSurface", rb_cCairo_Surface);
+
+  rb_define_method (rb_cCairo_QuartzSurface, "initialize",
+                    cr_quartz_surface_initialize, -1);
+  rb_define_method (rb_cCairo_QuartzSurface, "cg_context",
+                    cr_quartz_surface_get_cg_context, 0);
 #endif
 }



More information about the cairo-commit mailing list