[cairo-commit] rcairo/src cairo.def, 1.1, 1.2 rb_cairo.h, 1.3, 1.4 rb_cairo_surface.c, 1.5, 1.6
Kouhei Sutou
commit at pdx.freedesktop.org
Fri May 18 17:25:54 PDT 2007
Committed by: kou
Update of /cvs/cairo/rcairo/src
In directory kemper:/tmp/cvs-serv16284/src
Modified Files:
cairo.def rb_cairo.h rb_cairo_surface.c
Log Message:
* src/rb_cairo.h, src/cairo.def, src/rb_cairo_surface.c:
supported win32 surface. Thanks to Yoshinao Muramatsu!!!
* README: added entry for Yoshinao Muramatsu.
Index: cairo.def
===================================================================
RCS file: /cvs/cairo/rcairo/src/cairo.def,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- cairo.def 6 Mar 2007 12:17:34 -0000 1.1
+++ cairo.def 19 May 2007 00:25:42 -0000 1.2
@@ -17,6 +17,13 @@
rb_cCairo_TextExtents DATA
rb_cCairo_Glyph DATA
rb_cCairo_Surface DATA
+ rb_cCairo_ImageSurface DATA
+ rb_cCairo_PDFSurface DATA
+ rb_cCairo_PSSurface DATA
+ rb_cCairo_SVGSurface DATA
+ rb_cCairo_WIN32Surface DATA
+ rb_mCairo_Color DATA
+ rb_cCairo_Color_Base DATA
rb_cairo_context_from_ruby_object
rb_cairo_context_to_ruby_object
rb_cairo_path_from_ruby_object
Index: rb_cairo.h
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- rb_cairo.h 3 May 2007 02:03:06 -0000 1.3
+++ rb_cairo.h 19 May 2007 00:25:42 -0000 1.4
@@ -30,6 +30,10 @@
# include <cairo-svg.h>
#endif
+#if CAIRO_HAS_WIN32_SURFACE
+# include <cairo-win32.h>
+#endif
+
#define CAIRO_CHECK_VERSION(major, minor, micro) \
(CAIRO_VERSION_MAJOR > (major) || \
(CAIRO_VERSION_MAJOR == (major) && CAIRO_VERSION_MINOR > (minor)) || \
@@ -67,7 +71,11 @@
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_Color;
RUBY_CAIRO_VAR VALUE rb_cCairo_Color_Base;
Index: rb_cairo_surface.c
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_surface.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- rb_cairo_surface.c 10 May 2007 05:16:19 -0000 1.5
+++ rb_cairo_surface.c 19 May 2007 00:25:42 -0000 1.6
@@ -29,6 +29,7 @@
VALUE rb_cCairo_PDFSurface;
VALUE rb_cCairo_PSSurface;
VALUE rb_cCairo_SVGSurface;
+VALUE rb_cCairo_WIN32Surface;
static ID cr_id_target;
static ID cr_id_read;
@@ -77,6 +78,9 @@
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;
@@ -536,6 +540,7 @@
"(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);
@@ -740,6 +745,101 @@
}
#endif
+#if CAIRO_HAS_WIN32_SURFACE
+/* WIN32-surface functions */
+static VALUE
+cr_win32_surface_initialize (int argc, VALUE *argv, VALUE self)
+{
+ const char[] invalid_argument_message =
+ "invalid argument (expect "
+ "(hdc), "
+ "(hdc, width, height), "
+ "(hdc, format, width, height), "
+ "(width, height) or "
+ "(format, width, height)";
+ cairo_surface_t *surface;
+ cairo_format_t cr_format;
+ VALUE hdc, format, width, height;
+
+ rb_scan_args (argc, argv, "13", &hdc, &format, &width, &height);
+
+ switch (argc)
+ {
+ case 1:
+ surface = cairo_win32_surface_create ((HDC) NUM2UINT (hdc));
+ break;
+ case 2:
+ surface = cairo_win32_surface_create_with_dib (CAIRO_FORMAT_RGB24,
+ NUM2INT (width),
+ NUM2INT (height));
+ break;
+ case 3:
+ if (NIL_P (hdc) ||
+ (rb_cairo__is_kind_of (hdc, rb_cNumeric) &&
+ NUM2INT (hdc) != CAIRO_FORMAT_RGB24))
+ {
+ HDC win32_hdc = NIL_P (hdc) ? NULL : (HDC) NUM2UINT (hdc);
+ surface = cairo_win32_surface_create_with_ddb (hdc,
+ CAIRO_FORMAT_ARGB32,
+ NUM2INT (width),
+ NUM2INT (height));
+ }
+ else
+ {
+ height = width;
+ width = format;
+ format = hdc;
+ surface = cairo_win32_surface_create_with_dib (RVAL2CRFORMAT (format),
+ NUM2INT (width),
+ NUM2INT (height));
+ }
+ break;
+ case 4:
+ {
+ HDC win32_hdc = NIL_P (hdc) ? NULL : (HDC) NUM2UINT (hdc);
+ surface = cairo_win32_surface_create_with_ddb (hdc,
+ CAIRO_FORMAT_ARGB32,
+ NUM2INT (width),
+ NUM2INT (height));
+ }
+ }
+
+ 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);
+ return Qnil;
+}
+
+static VALUE
+cr_win32_surface_get_hdc (VALUE self)
+{
+ HDC hdc;
+
+ hdc = cairo_win32_surface_get_dc (_SELF);
+ if (!hdc)
+ return Qnil;
+ else
+ return UINT2NUM ((unsigned int) hdc);
+}
+
+static VALUE
+cr_win32_surface_get_image (VALUE self)
+{
+ cairo_surface_t *surface;
+ VALUE rb_surface;
+
+ surface = cairo_win32_surface_get_image (_SELF);
+ if (!surface)
+ return Qnil;
+ rb_cairo_check_status (cairo_surface_status (surface));
+ return CRSURFACE2RVAL (surface);
+}
+#endif
+
void
Init_cairo_surface (void)
@@ -857,4 +957,19 @@
#else
rb_cCairo_SVGSurface = Qnil;
#endif
+
+#if CAIRO_HAS_WIN32_SURFACE
+ /* WIN32-surface */
+ rb_cCairo_WIN32Surface =
+ rb_define_class_under (rb_mCairo, "WIN32Surface", rb_cCairo_Surface);
+
+ rb_define_method (rb_cCairo_WIN32Surface, "initialize",
+ cr_win32_surface_initialize, -1);
+ rb_define_method (rb_cCairo_WIN32Surface, "hdc",
+ 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
}
More information about the cairo-commit
mailing list