[cairo-commit] rcairo/packages/cairo/ext cairo.def, 1.2,
1.3 rb_cairo.c, 1.7, 1.8 rb_cairo.h, 1.8, 1.9 rb_cairo_path.c,
NONE, 1.1
Kouhei Sutou
commit at pdx.freedesktop.org
Sat Oct 8 07:01:44 PDT 2005
Committed by: kou
Update of /cvs/cairo/rcairo/packages/cairo/ext
In directory gabe:/tmp/cvs-serv23351/packages/cairo/ext
Modified Files:
cairo.def rb_cairo.c rb_cairo.h
Added Files:
rb_cairo_path.c
Log Message:
* packages/cairo/ext/rb_cairo_path.c: Implemented cairo_path_t.
* packages/cairo/ext/rb_cairo.c: ditto.
* packages/cairo/ext/rb_cairo.h: ditto.
* packages/cairo/ext/cairo.def: ditto.
Index: cairo.def
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/cairo.def,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- cairo.def 7 Oct 2005 15:11:26 -0000 1.2
+++ cairo.def 8 Oct 2005 14:01:42 -0000 1.3
@@ -2,6 +2,7 @@
Init_cairo
rb_mCairo DATA
rb_cCairo_Context DATA
+ rb_cCairo_Path DATA
rb_cCairo_Matrix DATA
rb_cCairo_Pattern DATA
rb_cCairo_FontFace DATA
@@ -12,6 +13,8 @@
rb_cCairo_Surface DATA
rb_cairo_context_from_ruby_object
rb_cairo_context_to_ruby_object
+ rb_cairo_path_from_ruby_object
+ rb_cairo_path_to_ruby_object
rb_cairo_matrix_from_ruby_object
rb_cairo_matrix_to_ruby_object
rb_cairo_pattern_from_ruby_object
Index: rb_cairo.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- rb_cairo.c 7 Oct 2005 15:11:26 -0000 1.7
+++ rb_cairo.c 8 Oct 2005 14:01:42 -0000 1.8
@@ -15,6 +15,7 @@
VALUE rb_mCairo;
extern void Init_cairo_context (void);
+extern void Init_cairo_path (void);
extern void Init_cairo_matrix (void);
extern void Init_cairo_surface (void);
extern void Init_cairo_constants (void);
@@ -32,6 +33,7 @@
rb_mCairo = rb_define_module ("Cairo");
Init_cairo_context ();
+ Init_cairo_path ();
Init_cairo_matrix ();
Init_cairo_surface ();
Init_cairo_constants ();
Index: rb_cairo.h
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- rb_cairo.h 7 Oct 2005 15:11:26 -0000 1.8
+++ rb_cairo.h 8 Oct 2005 14:01:42 -0000 1.9
@@ -29,6 +29,7 @@
RUBY_CAIRO_VAR VALUE rb_mCairo;
RUBY_CAIRO_VAR VALUE rb_cCairo_Context;
+RUBY_CAIRO_VAR VALUE rb_cCairo_Path;
RUBY_CAIRO_VAR VALUE rb_cCairo_Matrix;
RUBY_CAIRO_VAR VALUE rb_cCairo_Pattern;
RUBY_CAIRO_VAR VALUE rb_cCairo_FontFace;
@@ -41,6 +42,9 @@
#define RVAL2CRCONTEXT(obj) (rb_cairo_context_from_ruby_object(obj))
#define CRCONTEXT2RVAL(cr) (rb_cairo_context_to_ruby_object(cr))
+#define RVAL2CRPATH(obj) (rb_cairo_path_from_ruby_object(obj))
+#define CRPATH2RVAL(path) (rb_cairo_path_to_ruby_object(path))
+
#define RVAL2CRMATRIX(obj) (rb_cairo_matrix_from_ruby_object(obj))
#define CRMATRIX2RVAL(matrix) (rb_cairo_matrix_to_ruby_object(matrix))
@@ -68,6 +72,9 @@
cairo_t *rb_cairo_context_from_ruby_object (VALUE obj);
VALUE rb_cairo_context_to_ruby_object (cairo_t *cr);
+cairo_path_t *rb_cairo_path_from_ruby_object (VALUE obj);
+VALUE rb_cairo_path_to_ruby_object (cairo_path_t *path);
+
cairo_matrix_t *rb_cairo_matrix_from_ruby_object (VALUE obj);
VALUE rb_cairo_matrix_to_ruby_object (cairo_matrix_t *matrix);
--- NEW FILE: rb_cairo_path.c ---
/* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
/*
* Ruby Cairo Binding
*
* Copyright 2005 Kouhei Sutou <kou at cozmixng.org>
*
* This file is made available under the same terms as Ruby
*
*/
#include "rb_cairo.h"
#define _SELF(self) (RVAL2CRPATH (self))
VALUE rb_cCairo_Path;
cairo_path_t *
rb_cairo_path_from_ruby_object (VALUE obj)
{
cairo_path_t *path;
if (!RTEST (rb_obj_is_kind_of (obj, rb_cCairo_Path)))
{
rb_raise (rb_eTypeError, "not a cairo path");
}
Data_Get_Struct (obj, cairo_path_t, path);
return path;
}
static void
cr_path_free (void *ptr)
{
if (ptr)
{
cairo_path_destroy ((cairo_path_t *) ptr);
}
}
VALUE
rb_cairo_path_to_ruby_object (cairo_path_t *path)
{
if (path)
{
return Data_Wrap_Struct (rb_cCairo_Path, NULL, cr_path_free, path);
}
else
{
return Qnil;
}
}
static VALUE
cr_path_each (VALUE self)
{
cairo_path_t *path = _SELF(self);
int i, j;
for (i = 0; i < path->num_data; i += path->data[i].header.length)
{
cairo_path_data_t *data = &(path->data[i]);
VALUE points = rb_ary_new ();
for (j = 1; j < data->header.length; j++)
{
rb_ary_push (points, rb_ary_new3 (2,
rb_float_new (data[j].point.x),
rb_float_new (data[j].point.y)));
}
rb_yield_values (2, INT2NUM (data->header.type), points);
}
return self;
}
void
Init_cairo_path (void)
{
rb_cCairo_Path = rb_define_class_under (rb_mCairo, "Path", rb_cObject);
rb_include_module (rb_cCairo_Path, rb_mEnumerable);
rb_define_method (rb_cCairo_Path, "each", cr_path_each, 0);
}
More information about the cairo-commit
mailing list