[cairo] [rcairo] cleanup codes to more rubyish
Kouhei Sutou
kou at cozmixng.org
Sun Sep 11 19:42:45 PDT 2005
Hi,
This patch cleanup codes to more rubyish:
* packages/cairo/ext:
- add (or rename) internal (static) functions to 'cr_XXX' prefix.
- XXX_v -> rb_XXX
- get_XXX -> XXX
- remove needless RUBY_METHOD_FUNC cast.
- call rb_obj_call_init() in new method.
* packages/cairo/ext/rb_cairo_font_face.c
(rb_cairo_font_extents, rb_cairo_font_glyph_extents):
move to ...
* packages/cairo/ext/rb_cairo_context.c:
- ... here.
- add some status checks.
* packages/cairo/ext/rb_cairo_context.c,
packages/cairo/ext/rb_cairo.h:
- rb_cairo_{from,to}_ruby_object ->
rb_cairo_context_{from,to}_ruby_object
* packages/cairo/lib/cairo.rb: auto-generate XXX=.
(Cairo::Context#save: move to the C-side.
Thanks,
--
kou
-------------- next part --------------
Index: packages/cairo/ext/rb_cairo.h
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo.h,v
retrieving revision 1.4
diff -u -p -r1.4 rb_cairo.h
--- packages/cairo/ext/rb_cairo.h 10 Sep 2005 18:29:03 -0000 1.4
+++ packages/cairo/ext/rb_cairo.h 12 Sep 2005 02:42:07 -0000
@@ -27,8 +27,8 @@ extern VALUE rb_cCairo_TextExtents;
extern VALUE rb_cCairo_Glyph;
extern VALUE rb_cCairo_Surface;
-#define RVAL2CRCONTEXT(obj) (rb_cairo_from_ruby_object(obj))
-#define CRCONTEXT2RVAL(cr) (rb_cairo_to_ruby_object(cr))
+#define RVAL2CRCONTEXT(obj) (rb_cairo_context_from_ruby_object(obj))
+#define CRCONTEXT2RVAL(cr) (rb_cairo_context_to_ruby_object(cr))
#define RVAL2CRMATRIX(obj) (rb_cairo_matrix_from_ruby_object(obj))
#define CRMATRIX2RVAL(matrix) (rb_cairo_matrix_to_ruby_object(matrix))
@@ -51,8 +51,8 @@ extern VALUE rb_cCairo_Surface;
#define RVAL2CRSURFACE(obj) (rb_cairo_surface_from_ruby_object(obj))
#define CRSURFACE2RVAL(surface) (rb_cairo_surface_to_ruby_object(surface))
-cairo_t *rb_cairo_from_ruby_object (VALUE obj);
-VALUE rb_cairo_to_ruby_object (cairo_t *cr);
+cairo_t *rb_cairo_context_from_ruby_object (VALUE obj);
+VALUE rb_cairo_context_to_ruby_object (cairo_t *cr);
cairo_matrix_t *rb_cairo_matrix_from_ruby_object (VALUE obj);
VALUE rb_cairo_matrix_to_ruby_object (cairo_matrix_t *matrix);
Index: packages/cairo/ext/rb_cairo_context.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo_context.c,v
retrieving revision 1.9
diff -u -p -r1.9 rb_cairo_context.c
--- packages/cairo/ext/rb_cairo_context.c 10 Sep 2005 18:29:03 -0000 1.9
+++ packages/cairo/ext/rb_cairo_context.c 12 Sep 2005 02:42:08 -0000
@@ -15,7 +15,7 @@ VALUE rb_cCairo_Context;
#define _SELF (RVAL2CRCONTEXT(self))
cairo_t *
-rb_cairo_from_ruby_object (VALUE obj)
+rb_cairo_context_from_ruby_object (VALUE obj)
{
cairo_t *context;
if (!RTEST (rb_obj_is_kind_of (obj, rb_cCairo_Context)))
@@ -41,8 +41,27 @@ float_array (double *values,
return result;
}
+static void
+glyphs_to_array (VALUE rb_array, cairo_glyph_t **glyphs, int *length)
+{
+ int i;
+
+ *length = RARRAY(rb_array)->len;
+ *glyphs = ALLOCA_N (cairo_glyph_t, *length);
+
+ if (!*glyphs)
+ rb_cairo_raise_exception (CAIRO_STATUS_NO_MEMORY);
+
+ for (i = 0; i < *length; i++)
+ {
+ memcpy ( (char *) &(*glyphs)[i],
+ (char *) RVAL2CRGLYPH (rb_ary_entry (rb_array, i)),
+ sizeof (cairo_glyph_t));
+ }
+}
+
static inline void
-check_context_status (cairo_t *context)
+cr_check_status (cairo_t *context)
{
cairo_status_t status;
status = cairo_status (context);
@@ -53,7 +72,7 @@ check_context_status (cairo_t *context)
}
static void
-rb_free_context (void *ptr)
+cr_context_free (void *ptr)
{
if (ptr)
{
@@ -62,205 +81,247 @@ rb_free_context (void *ptr)
}
VALUE
-rb_cairo_to_ruby_object (cairo_t *cr)
+rb_cairo_context_to_ruby_object (cairo_t *cr)
{
- cairo_reference (cr);
- return Data_Wrap_Struct (rb_cCairo_Context, NULL, rb_free_context, cr);
-}
-
-static VALUE
-rb_cairo_new (VALUE klass,
- VALUE target_v)
-{
- cairo_surface_t *target;
- cairo_t *cr;
-
- target = RVAL2CRSURFACE (target_v);
- cr = cairo_create (target);
-
if (cr)
{
- VALUE rb_cr = CRCONTEXT2RVAL (cr);
- cairo_destroy (cr);
- return rb_cr;
+ cairo_reference (cr);
+ return Data_Wrap_Struct (rb_cCairo_Context, NULL, cr_context_free, cr);
}
else
{
- rb_raise (rb_eNoMemError, "unable to allocate cairo context");
- return Qundef;
+ return Qnil;
}
}
static VALUE
-rb_cairo_save (VALUE self)
+cr_allocate (VALUE klass)
{
- cairo_save (_SELF);
- check_context_status (_SELF);
- return self;
+ return Data_Wrap_Struct (rb_cCairo_Context, NULL, cr_context_free, NULL);
+}
+
+static VALUE
+cr_initialize (VALUE self, VALUE rb_target)
+{
+ cairo_t *cr;
+
+ cr = cairo_create (RVAL2CRSURFACE (rb_target));
+
+ if (!cr)
+ rb_cairo_raise_exception (CAIRO_STATUS_NO_MEMORY);
+
+ DATA_PTR(self) = cr;
+ return Qnil;
}
static VALUE
-rb_cairo_restore (VALUE self)
+cr_restore (VALUE self)
{
cairo_restore (_SELF);
- check_context_status (_SELF);
- return self;
+ cr_check_status (_SELF);
+ return Qnil;
}
-#if 0
-NYI
-rb_cairo_set_target_image (VALUE self,
-#endif
+static VALUE
+cr_save (VALUE self)
+{
+ VALUE result = Qnil;
+ cairo_save (_SELF);
+ cr_check_status (_SELF);
+ if (rb_block_given_p ())
+ {
+ result = rb_ensure (rb_yield, self, cr_restore, self);
+ }
+ return result;
+}
static VALUE
-rb_cairo_set_operator (VALUE self,
- VALUE op_v)
+cr_set_operator (VALUE self,
+ VALUE rb_op)
{
int op;
- Check_Type (op_v, T_FIXNUM);
- op = FIX2INT (op_v);
+ Check_Type (rb_op, T_FIXNUM);
+ op = FIX2INT (rb_op);
if (op < CAIRO_OPERATOR_CLEAR || op > CAIRO_OPERATOR_SATURATE)
{
rb_raise (rb_eArgError, "invalid composition operator");
}
cairo_set_operator (_SELF, (cairo_operator_t) op);
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_set_source_rgb (VALUE self,
- VALUE red,
- VALUE green,
- VALUE blue)
+cr_set_source_rgb (int argc, VALUE *argv, VALUE self)
{
+ VALUE red, green, blue;
+ int n;
+
+ n = rb_scan_args(argc, argv, "12", &red, &green, &blue);
+
+ if (n == 1 && RTEST (rb_obj_is_kind_of (red, rb_cArray)))
+ {
+ VALUE ary = red;
+ n = RARRAY (ary)->len;
+ if (n >= 3)
+ {
+ red = rb_ary_entry (ary, 0);
+ green = rb_ary_entry (ary, 1);
+ blue = rb_ary_entry (ary, 2);
+ }
+ }
+
+ if (n < 3)
+ {
+ rb_raise (rb_eArgError, "invalid RGB");
+ }
+
cairo_set_source_rgb (_SELF,
NUM2DBL (red),
NUM2DBL (green),
NUM2DBL (blue));
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_set_source_rgba (VALUE self,
- VALUE red_v,
- VALUE green_v,
- VALUE blue_v,
- VALUE alpha_v)
+cr_set_source_rgba (int argc, VALUE *argv, VALUE self)
{
- cairo_set_source_rgba (_SELF,
- NUM2DBL (red_v),
- NUM2DBL (green_v),
- NUM2DBL (blue_v),
- NUM2DBL (alpha_v));
- return self;
+ VALUE red, green, blue, alpha;
+ int n;
+
+ n = rb_scan_args(argc, argv, "13", &red, &green, &blue, &alpha);
+
+ if (n == 1 && RTEST (rb_obj_is_kind_of (red, rb_cArray)))
+ {
+ VALUE ary = red;
+ n = RARRAY (ary)->len;
+ if (n >= 4)
+ {
+ red = rb_ary_entry (ary, 0);
+ green = rb_ary_entry (ary, 1);
+ blue = rb_ary_entry (ary, 2);
+ alpha = rb_ary_entry (ary, 3);
+ }
+ }
+
+ if (n < 4)
+ {
+ return cr_set_source_rgb (argc, argv, self);
+ }
+ else
+ {
+ cairo_set_source_rgba (_SELF,
+ NUM2DBL (red),
+ NUM2DBL (green),
+ NUM2DBL (blue),
+ NUM2DBL (alpha));
+ cr_check_status (_SELF);
+ return self;
+ }
}
static VALUE
-rb_cairo_set_source_surface (VALUE self,
- VALUE surface_v,
- VALUE width_v,
- VALUE height_v)
+cr_set_source_surface (VALUE self,
+ VALUE rb_surface,
+ VALUE rb_width,
+ VALUE rb_height)
{
- cairo_surface_t *surface = RVAL2CRSURFACE (surface_v);
- int width = NUM2INT (width_v);
- int height = NUM2INT (height_v);
- cairo_set_source_surface (_SELF, surface, width, height);
- check_context_status (_SELF);
+ cairo_set_source_surface (_SELF,
+ RVAL2CRSURFACE (rb_surface),
+ NUM2INT (rb_width),
+ NUM2INT (rb_height));
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_set_source (VALUE self,
- VALUE pattern_v)
+cr_set_source (VALUE self,
+ VALUE rb_pattern)
{
- cairo_pattern_t *pattern;
- pattern = RVAL2CRPATTERN (pattern_v);
-
- cairo_set_source (_SELF, pattern);
- check_context_status (_SELF);
+ cairo_set_source (_SELF, RVAL2CRPATTERN (rb_pattern));
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_get_source (VALUE self)
+cr_get_source (VALUE self)
{
return CRPATTERN2RVAL (cairo_get_source (_SELF));
}
static VALUE
-rb_cairo_set_tolerance (VALUE self,
- VALUE tolerance)
+cr_set_tolerance (VALUE self,
+ VALUE tolerance)
{
cairo_set_tolerance (_SELF, NUM2DBL (tolerance));
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_set_fill_rule (VALUE self,
- VALUE rule_v)
+cr_set_fill_rule (VALUE self,
+ VALUE rb_rule)
{
int rule;
- Check_Type (rule_v, T_FIXNUM);
- rule = FIX2INT (rule_v);
+ Check_Type (rb_rule, T_FIXNUM);
+ rule = FIX2INT (rb_rule);
if (rule < CAIRO_FILL_RULE_WINDING || rule > CAIRO_FILL_RULE_EVEN_ODD)
{
rb_raise (rb_eArgError, "invalid fill rule");
}
cairo_set_fill_rule (_SELF, (cairo_fill_rule_t) rule);
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_set_line_width (VALUE self,
+cr_set_line_width (VALUE self,
VALUE width)
{
cairo_set_line_width (_SELF, NUM2DBL (width));
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_set_line_cap (VALUE self,
- VALUE cap_v)
+cr_set_line_cap (VALUE self,
+ VALUE rb_cap)
{
int cap;
- Check_Type (cap_v, T_FIXNUM);
- cap = FIX2INT (cap_v);
+ Check_Type (rb_cap, T_FIXNUM);
+ cap = FIX2INT (rb_cap);
if (cap < CAIRO_LINE_CAP_BUTT || cap > CAIRO_LINE_CAP_SQUARE)
{
rb_raise (rb_eArgError, "invalid line cap type");
}
cairo_set_line_cap (_SELF, (cairo_line_cap_t) cap);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_set_line_join (VALUE self,
- VALUE join_v)
+cr_set_line_join (VALUE self,
+ VALUE rb_join)
{
int join;
- Check_Type (join_v, T_FIXNUM);
- join = FIX2INT (join_v);
+ Check_Type (rb_join, T_FIXNUM);
+ join = FIX2INT (rb_join);
if (join < CAIRO_LINE_JOIN_MITER || join > CAIRO_LINE_JOIN_BEVEL)
{
rb_raise (rb_eArgError, "invalid line join type");
}
cairo_set_line_join (_SELF, (cairo_line_join_t) join);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_set_dash (VALUE self,
- VALUE dash_array,
- VALUE offset)
+cr_set_dash (VALUE self,
+ VALUE dash_array,
+ VALUE offset)
{
- int length;
- double *values;
-
if (!NIL_P (dash_array))
{
Check_Type (dash_array, T_ARRAY);
@@ -268,351 +329,358 @@ rb_cairo_set_dash (VALUE self,
if (NIL_P (dash_array) || RARRAY (dash_array)->len == 0)
{
- length = 0;
- values = NULL;
+ cairo_set_dash (_SELF, NULL, 0, NUM2DBL (offset));
}
else
{
+ int length;
+ double *values;
int i;
length = RARRAY (dash_array)->len;
- values = (double *) malloc (sizeof (double) * length);
+ values = ALLOCA_N (double, length);
if (!values)
{
- rb_raise (rb_eNoMemError, "out of memory");
+ rb_cairo_raise_exception (CAIRO_STATUS_NO_MEMORY);
}
for (i = 0; i < length; i++)
{
- // TODO: handle memory leak if NUM2DBL throws an exception
values[i] = NUM2DBL (RARRAY (dash_array)->ptr[i]);
}
+ cairo_set_dash (_SELF, values, length, NUM2DBL (offset));
}
- cairo_set_dash (_SELF, values, length, NUM2DBL (offset));
- free (values);
-
return self;
}
static VALUE
-rb_cairo_set_miter_limit (VALUE self,
- VALUE limit)
+cr_set_miter_limit (VALUE self,
+ VALUE limit)
{
cairo_set_miter_limit (_SELF, NUM2DBL (limit));
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_translate (VALUE self,
- VALUE tx,
- VALUE ty)
+cr_translate (VALUE self,
+ VALUE tx,
+ VALUE ty)
{
cairo_translate (_SELF, NUM2DBL (tx), NUM2DBL (ty));
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_scale (VALUE self,
- VALUE sx,
- VALUE sy)
+cr_scale (VALUE self,
+ VALUE sx,
+ VALUE sy)
{
cairo_scale (_SELF, NUM2DBL (sx), NUM2DBL (sy));
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_rotate (VALUE self,
- VALUE radians)
+cr_rotate (VALUE self,
+ VALUE radians)
{
cairo_rotate (_SELF, NUM2DBL (radians));
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_transform (VALUE self,
- VALUE xform)
+cr_transform (VALUE self,
+ VALUE xform)
{
cairo_transform (_SELF, RVAL2CRMATRIX (xform));
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_set_matrix (VALUE self,
- VALUE xform)
+cr_set_matrix (VALUE self,
+ VALUE xform)
{
cairo_set_matrix (_SELF, RVAL2CRMATRIX (xform));
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_identity_matrix (VALUE self)
+cr_identity_matrix (VALUE self)
{
cairo_identity_matrix (_SELF);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_user_to_device (VALUE self,
- VALUE x, VALUE y)
+cr_user_to_device (VALUE self,
+ VALUE x, VALUE y)
{
double pair[2];
pair[0] = NUM2DBL (x);
pair[1] = NUM2DBL (y);
cairo_user_to_device (_SELF, pair, pair + 1);
+ cr_check_status (_SELF);
return float_array (pair, 2);
}
static VALUE
-rb_cairo_user_to_device_distance (VALUE self,
- VALUE dx, VALUE dy)
+cr_user_to_device_distance (VALUE self,
+ VALUE dx, VALUE dy)
{
double pair[2];
pair[0] = NUM2DBL (dx);
pair[1] = NUM2DBL (dy);
cairo_user_to_device_distance (_SELF, pair, pair + 1);
+ cr_check_status (_SELF);
return float_array (pair, 2);
}
static VALUE
-rb_cairo_device_to_user (VALUE self,
- VALUE x, VALUE y)
+cr_device_to_user (VALUE self,
+ VALUE x, VALUE y)
{
double pair[2];
pair[0] = NUM2DBL (x);
pair[1] = NUM2DBL (y);
cairo_device_to_user (_SELF, pair, pair + 1);
+ cr_check_status (_SELF);
return float_array (pair, 2);
}
static VALUE
-rb_cairo_device_to_user_distance (VALUE self,
- VALUE dx, VALUE dy)
+cr_device_to_user_distance (VALUE self,
+ VALUE dx, VALUE dy)
{
double pair[2];
pair[0] = NUM2DBL (dx);
pair[1] = NUM2DBL (dy);
cairo_device_to_user_distance (_SELF, pair, pair + 1);
+ cr_check_status (_SELF);
return float_array (pair, 2);
}
/* Path creation functions */
static VALUE
-rb_cairo_new_path (VALUE self)
+cr_new_path (VALUE self)
{
cairo_new_path (_SELF);
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_move_to (VALUE self,
- VALUE x, VALUE y)
+cr_move_to (VALUE self,
+ VALUE x, VALUE y)
{
cairo_move_to (_SELF, NUM2DBL (x), NUM2DBL (y));
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_line_to (VALUE self,
- VALUE x, VALUE y)
+cr_line_to (VALUE self,
+ VALUE x, VALUE y)
{
cairo_line_to (_SELF, NUM2DBL (x), NUM2DBL (y));
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_curve_to (VALUE self,
- VALUE x1, VALUE y1,
- VALUE x2, VALUE y2,
- VALUE x3, VALUE y3)
+cr_curve_to (VALUE self,
+ VALUE x1, VALUE y1,
+ VALUE x2, VALUE y2,
+ VALUE x3, VALUE y3)
{
cairo_curve_to (_SELF, NUM2DBL (x1), NUM2DBL (y1),
NUM2DBL (x2), NUM2DBL (y2), NUM2DBL (x3), NUM2DBL (y3));
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_arc (VALUE self,
- VALUE cx, VALUE cy,
- VALUE radius,
- VALUE angle1,
- VALUE angle2)
+cr_arc (VALUE self,
+ VALUE cx, VALUE cy,
+ VALUE radius,
+ VALUE angle1,
+ VALUE angle2)
{
cairo_arc (_SELF, NUM2DBL (cx), NUM2DBL (cy), NUM2DBL (radius),
NUM2DBL (angle1), NUM2DBL (angle2));
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_arc_negative (VALUE self,
- VALUE cx, VALUE cy,
- VALUE radius,
- VALUE angle1,
- VALUE angle2)
+cr_arc_negative (VALUE self,
+ VALUE cx, VALUE cy,
+ VALUE radius,
+ VALUE angle1,
+ VALUE angle2)
{
cairo_arc_negative (_SELF, NUM2DBL (cx), NUM2DBL (cy), NUM2DBL (radius),
NUM2DBL (angle1), NUM2DBL (angle2));
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_rel_move_to (VALUE self,
- VALUE x, VALUE y)
+cr_rel_move_to (VALUE self,
+ VALUE x, VALUE y)
{
cairo_rel_move_to (_SELF, NUM2DBL (x), NUM2DBL (y));
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_rel_line_to (VALUE self,
- VALUE x, VALUE y)
+cr_rel_line_to (VALUE self,
+ VALUE x, VALUE y)
{
cairo_rel_line_to (_SELF, NUM2DBL (x), NUM2DBL (y));
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_rel_curve_to (VALUE self,
- VALUE x1, VALUE y1,
- VALUE x2, VALUE y2,
- VALUE x3, VALUE y3)
+cr_rel_curve_to (VALUE self,
+ VALUE x1, VALUE y1,
+ VALUE x2, VALUE y2,
+ VALUE x3, VALUE y3)
{
cairo_rel_curve_to (_SELF, NUM2DBL (x1), NUM2DBL (y1),
NUM2DBL (x2), NUM2DBL (y2), NUM2DBL (x3), NUM2DBL (y3));
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_rectangle (VALUE self,
- VALUE x, VALUE y,
- VALUE width, VALUE height)
+cr_rectangle (VALUE self,
+ VALUE x, VALUE y,
+ VALUE width, VALUE height)
{
cairo_rectangle (_SELF, NUM2DBL (x), NUM2DBL (y),
NUM2DBL (width), NUM2DBL (height));
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_close_path (VALUE self)
+cr_close_path (VALUE self)
{
cairo_close_path (_SELF);
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_stroke (VALUE self)
+cr_stroke (VALUE self)
{
if (rb_block_given_p ())
{
- cairo_new_path (_SELF);
- rb_yield (Qnil);
+ cr_new_path (self);
+ rb_yield (self);
}
cairo_stroke (_SELF);
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_stroke_preserve (VALUE self)
+cr_stroke_preserve (VALUE self)
{
if (rb_block_given_p ())
{
- cairo_new_path (_SELF);
- rb_yield (Qnil);
+ cr_new_path (self);
+ rb_yield (self);
}
cairo_stroke_preserve (_SELF);
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_fill (VALUE self)
+cr_fill (VALUE self)
{
if (rb_block_given_p ())
{
- cairo_new_path (_SELF);
- rb_yield (Qnil);
+ cr_new_path (self);
+ rb_yield (self);
}
cairo_fill (_SELF);
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_fill_preserve (VALUE self)
+cr_fill_preserve (VALUE self)
{
if (rb_block_given_p ())
{
- cairo_new_path (_SELF);
- rb_yield (Qnil);
+ cr_new_path (self);
+ rb_yield (self);
}
cairo_fill_preserve (_SELF);
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_paint (VALUE self)
+cr_paint (VALUE self)
{
cairo_paint (_SELF);
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_copy_page (VALUE self)
+cr_copy_page (VALUE self)
{
cairo_copy_page (_SELF);
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_show_page (VALUE self)
+cr_show_page (VALUE self)
{
cairo_show_page (_SELF);
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
/* Insideness testing */
static VALUE
-rb_cairo_in_fill (VALUE self,
- VALUE x, VALUE y)
+cr_in_fill (VALUE self,
+ VALUE x, VALUE y)
{
if (rb_block_given_p ())
{
- cairo_new_path (_SELF);
- rb_yield (Qnil);
+ cr_new_path (self);
+ rb_yield (self);
}
return cairo_in_fill (_SELF, NUM2DBL (x), NUM2DBL (y))
? Qtrue : Qfalse;
}
static VALUE
-rb_cairo_in_stroke (VALUE self,
- VALUE x, VALUE y)
+cr_in_stroke (VALUE self,
+ VALUE x, VALUE y)
{
if (rb_block_given_p ())
{
- cairo_new_path (_SELF);
- rb_yield (Qnil);
+ cr_new_path (self);
+ rb_yield (self);
}
return cairo_in_stroke (_SELF, NUM2DBL (x), NUM2DBL (y))
? Qtrue : Qfalse;
@@ -621,13 +689,13 @@ rb_cairo_in_stroke (VALUE self,
/* Rectangular extents */
static VALUE
-rb_cairo_stroke_extents (VALUE self)
+cr_stroke_extents (VALUE self)
{
double extents[4];
if (rb_block_given_p ())
{
- cairo_new_path (_SELF);
- rb_yield (Qnil);
+ cr_new_path (self);
+ rb_yield (self);
}
cairo_stroke_extents (_SELF,
extents, extents + 1,
@@ -636,13 +704,13 @@ rb_cairo_stroke_extents (VALUE self)
}
static VALUE
-rb_cairo_fill_extents (VALUE self)
+cr_fill_extents (VALUE self)
{
double extents[4];
if (rb_block_given_p ())
{
- cairo_new_path (_SELF);
- rb_yield (Qnil);
+ cr_new_path (self);
+ rb_yield (self);
}
cairo_fill_extents (_SELF,
extents, extents + 1,
@@ -653,18 +721,18 @@ rb_cairo_fill_extents (VALUE self)
/* Clipping */
static VALUE
-rb_cairo_reset_clip (VALUE self)
+cr_reset_clip (VALUE self)
{
cairo_reset_clip (_SELF);
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_clip (VALUE self)
+cr_clip (VALUE self)
{
cairo_clip (_SELF);
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
@@ -673,13 +741,13 @@ rb_cairo_clip (VALUE self)
/* The "toy" text api */
static VALUE
-rb_cairo_select_font_face (VALUE self,
- VALUE family,
- VALUE slant_v,
- VALUE weight_v)
+cr_select_font_face (VALUE self,
+ VALUE family,
+ VALUE rb_slant,
+ VALUE rb_weight)
{
- int slant = NUM2INT (slant_v);
- int weight = NUM2INT (weight_v);
+ int slant = NUM2INT (rb_slant);
+ int weight = NUM2INT (rb_weight);
if (slant < CAIRO_FONT_SLANT_NORMAL ||
slant > CAIRO_FONT_SLANT_OBLIQUE)
@@ -698,136 +766,123 @@ rb_cairo_select_font_face (VALUE self,
STR2CSTR (family),
slant,
weight);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_set_font_size (VALUE self,
- VALUE scale)
+cr_set_font_size (VALUE self,
+ VALUE scale)
{
cairo_set_font_size (_SELF,
NUM2DBL (scale));
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_set_font_matrix (VALUE self,
- VALUE matrix)
+cr_set_font_matrix (VALUE self,
+ VALUE matrix)
{
cairo_set_font_matrix (_SELF,
RVAL2CRMATRIX (matrix));
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_show_text (VALUE self,
- VALUE utf8)
+cr_show_text (VALUE self,
+ VALUE utf8)
{
cairo_show_text (_SELF,
STR2CSTR (utf8));
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_show_glyphs (VALUE self,
- VALUE glyphs_v)
+cr_show_glyphs (VALUE self,
+ VALUE rb_glyphs)
{
int i;
int count;
cairo_glyph_t *glyphs;
- if (!rb_obj_is_kind_of (glyphs_v, rb_cArray))
+ if (!rb_obj_is_kind_of (rb_glyphs, rb_cArray))
rb_raise (rb_eTypeError, "expected array");
- count = RARRAY(glyphs_v)->len;
- glyphs = malloc (sizeof (cairo_glyph_t) * count);
+ count = RARRAY(rb_glyphs)->len;
+ glyphs = ALLOCA_N (cairo_glyph_t, count);
if (!glyphs)
- rb_raise (rb_eNoMemError, "unable to allocate memory for text extents");
+ rb_cairo_raise_exception (CAIRO_STATUS_NO_MEMORY);
- for (i=0; i< count; i++)
+ for (i = 0; i < count; i++)
{
memcpy ( (char *) &glyphs[i],
- (char *) RVAL2CRGLYPH (rb_ary_entry (glyphs_v, i)),
+ (char *) RVAL2CRGLYPH (rb_ary_entry (rb_glyphs, i)),
sizeof (cairo_glyph_t));
}
cairo_show_glyphs (_SELF, glyphs, count);
-
- free (glyphs);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_get_font_face (VALUE self)
+cr_get_font_face (VALUE self)
{
cairo_font_face_t *xform;
+ VALUE rb_xform;
+
xform = cairo_get_font_face (_SELF);
- if (xform)
- {
- VALUE rb_xform = CRFONTFACE2RVAL (xform);
- if (cairo_status (_SELF))
- {
- rb_cairo_raise_exception (cairo_status (_SELF));
- }
- return rb_xform;
- }
- else
+
+ if (!xform)
{
- rb_raise (rb_eNoMemError, "unable to get current font face");
- return Qundef;
+ rb_cairo_raise_exception (CAIRO_STATUS_NO_MEMORY);
}
+
+ rb_xform = CRFONTFACE2RVAL (xform);
+ cr_check_status (_SELF);
+ return rb_xform;
}
static VALUE
-rb_cairo_set_font_face (VALUE self,
- VALUE xform)
+cr_set_font_face (VALUE self,
+ VALUE xform)
{
cairo_set_font_face (_SELF,
RVAL2CRFONTFACE (xform));
- check_context_status (_SELF);
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_text_path (VALUE self,
- VALUE utf8)
+cr_text_path (VALUE self,
+ VALUE utf8)
{
cairo_text_path (_SELF,
STR2CSTR (utf8));
+ cr_check_status (_SELF);
return self;
}
static VALUE
-rb_cairo_glyph_path (VALUE self,
- VALUE glyphs_v)
+cr_glyph_path (VALUE self,
+ VALUE rb_glyphs)
{
- int i;
int count;
cairo_glyph_t *glyphs;
- if (!rb_obj_is_kind_of (glyphs_v, rb_cArray))
+ if (!rb_obj_is_kind_of (rb_glyphs, rb_cArray))
rb_raise (rb_eTypeError, "expected array");
-
-
- count = RARRAY(glyphs_v)->len;
- glyphs = malloc (sizeof (cairo_glyph_t) * count);
-
- if (!glyphs)
- rb_raise (rb_eNoMemError, "unable to allocate memory for text extents");
-
- for (i=0; i< count; i++)
- {
- memcpy ( (char *) &glyphs[i],
- (char *) RVAL2CRGLYPH (rb_ary_entry (glyphs_v, i)),
- sizeof (cairo_glyph_t));
- }
+ glyphs_to_array (rb_glyphs, &glyphs, &count);
cairo_glyph_path (_SELF, glyphs, count);
-
- free (glyphs);
+ cr_check_status (_SELF);
+
return self;
}
@@ -835,24 +890,20 @@ rb_cairo_glyph_path (VALUE self,
/* Query functions */
static VALUE
-rb_cairo_get_operator (VALUE self)
+cr_get_operator (VALUE self)
{
- cairo_operator_t op;
- op = cairo_get_operator (_SELF);
- return INT2FIX (op);
+ return INT2FIX (cairo_get_operator (_SELF));
}
static VALUE
-rb_cairo_get_tolerance (VALUE self)
+cr_get_tolerance (VALUE self)
{
- double tolerance;
- tolerance = cairo_get_tolerance (_SELF);
- return rb_float_new (tolerance);
+ return rb_float_new (cairo_get_tolerance (_SELF));
}
static VALUE
-rb_cairo_get_current_point (VALUE self)
+cr_get_current_point (VALUE self)
{
double point[2];
cairo_get_current_point (_SELF, point, point + 1);
@@ -860,223 +911,238 @@ rb_cairo_get_current_point (VALUE self)
}
static VALUE
-rb_cairo_get_fill_rule (VALUE self)
+cr_get_fill_rule (VALUE self)
{
- cairo_fill_rule_t rule;
- rule = cairo_get_fill_rule (_SELF);
- return INT2FIX (rule);
+ return INT2FIX (cairo_get_fill_rule (_SELF));
}
static VALUE
-rb_cairo_get_line_width (VALUE self)
+cr_get_line_width (VALUE self)
{
- double line_width;
- line_width = cairo_get_line_width (_SELF);
- return rb_float_new (line_width);
+ return rb_float_new (cairo_get_line_width (_SELF));
}
static VALUE
-rb_cairo_get_line_cap (VALUE self)
+cr_get_line_cap (VALUE self)
{
- cairo_line_cap_t cap;
- cap = cairo_get_line_cap (_SELF);
- return INT2FIX (cap);
+ return INT2FIX (cairo_get_line_cap (_SELF));
}
static VALUE
-rb_cairo_get_line_join (VALUE self)
+cr_get_line_join (VALUE self)
{
- cairo_line_join_t join;
- join = cairo_get_line_join (_SELF);
- return INT2FIX (join);
+ return INT2FIX (cairo_get_line_join (_SELF));
}
static VALUE
-rb_cairo_get_miter_limit (VALUE self)
+cr_get_miter_limit (VALUE self)
{
- double miter_limit;
- miter_limit = cairo_get_miter_limit (_SELF);
- return rb_float_new (miter_limit);
+ return rb_float_new (cairo_get_miter_limit (_SELF));
}
static VALUE
-rb_cairo_get_matrix (VALUE self)
+cr_get_matrix (VALUE self)
{
cairo_matrix_t matrix;
cairo_get_matrix (_SELF, &matrix);
- if (cairo_status (_SELF))
- {
- rb_cairo_raise_exception (cairo_status (_SELF));
- }
+ cr_check_status (_SELF);
return CRMATRIX2RVAL (&matrix);
}
static VALUE
-rb_cairo_get_target (VALUE self)
+cr_get_target (VALUE self)
{
return CRSURFACE2RVAL (cairo_get_target (_SELF));
}
+
+static VALUE
+cr_font_extents (VALUE self)
+{
+ cairo_font_extents_t extents;
+ cairo_font_extents (_SELF, &extents);
+ cr_check_status (_SELF);
+ return CRFONTEXTENTS2RVAL (&extents);
+}
+
+static VALUE
+cr_glyph_extents (VALUE self, VALUE rb_glyphs)
+{
+ cairo_text_extents_t extents;
+ cairo_glyph_t *glyphs;
+ int length;
+
+ glyphs_to_array (rb_glyphs, &glyphs, &length);
+ cairo_glyph_extents (_SELF, glyphs, length, &extents);
+ cr_check_status (_SELF);
+ return CRTEXTEXTENTS2RVAL (&extents);
+}
+
+
void
Init_cairo_context (void)
{
rb_cCairo_Context =
rb_define_class_under (rb_mCairo, "Context", rb_cObject);
- rb_define_singleton_method (rb_cCairo_Context, "new",
- RUBY_METHOD_FUNC (rb_cairo_new), 1);
+ rb_define_alloc_func (rb_cCairo_Context, cr_allocate);
+
+ rb_define_method (rb_cCairo_Context, "initialize",
+ cr_initialize, 1);
rb_define_method (rb_cCairo_Context, "save",
- RUBY_METHOD_FUNC (rb_cairo_save), 0);
+ cr_save, 0);
rb_define_method (rb_cCairo_Context, "restore",
- RUBY_METHOD_FUNC (rb_cairo_restore), 0);
+ cr_restore, 0);
rb_define_method (rb_cCairo_Context, "set_operator",
- RUBY_METHOD_FUNC (rb_cairo_set_operator), 1);
+ cr_set_operator, 1);
rb_define_method (rb_cCairo_Context, "set_source_rgb",
- RUBY_METHOD_FUNC (rb_cairo_set_source_rgb), 3);
+ cr_set_source_rgb, -1);
rb_define_method (rb_cCairo_Context, "set_source_rgba",
- RUBY_METHOD_FUNC (rb_cairo_set_source_rgba), 4);
+ cr_set_source_rgba, -1);
rb_define_method (rb_cCairo_Context, "set_source",
- RUBY_METHOD_FUNC (rb_cairo_set_source), 1);
+ cr_set_source, 1);
rb_define_method (rb_cCairo_Context, "set_source_surface",
- RUBY_METHOD_FUNC (rb_cairo_set_source_surface), 3);
+ cr_set_source_surface, 3);
rb_define_method (rb_cCairo_Context, "set_tolerance",
- RUBY_METHOD_FUNC (rb_cairo_set_tolerance), 1);
+ cr_set_tolerance, 1);
rb_define_method (rb_cCairo_Context, "set_fill_rule",
- RUBY_METHOD_FUNC (rb_cairo_set_fill_rule), 1);
+ cr_set_fill_rule, 1);
rb_define_method (rb_cCairo_Context, "set_line_width",
- RUBY_METHOD_FUNC (rb_cairo_set_line_width), 1);
+ cr_set_line_width, 1);
rb_define_method (rb_cCairo_Context, "set_line_cap",
- RUBY_METHOD_FUNC (rb_cairo_set_line_cap), 1);
+ cr_set_line_cap, 1);
rb_define_method (rb_cCairo_Context, "set_line_join",
- RUBY_METHOD_FUNC (rb_cairo_set_line_join), 1);
+ cr_set_line_join, 1);
rb_define_method (rb_cCairo_Context, "set_dash",
- RUBY_METHOD_FUNC (rb_cairo_set_dash), 2);
+ cr_set_dash, 2);
rb_define_method (rb_cCairo_Context, "set_miter_limit",
- RUBY_METHOD_FUNC (rb_cairo_set_miter_limit), 1);
+ cr_set_miter_limit, 1);
rb_define_method (rb_cCairo_Context, "translate",
- RUBY_METHOD_FUNC (rb_cairo_translate), 2);
+ cr_translate, 2);
rb_define_method (rb_cCairo_Context, "scale",
- RUBY_METHOD_FUNC (rb_cairo_scale), 2);
+ cr_scale, 2);
rb_define_method (rb_cCairo_Context, "rotate",
- RUBY_METHOD_FUNC (rb_cairo_rotate), 1);
+ cr_rotate, 1);
rb_define_method (rb_cCairo_Context, "transform",
- RUBY_METHOD_FUNC (rb_cairo_transform), 1);
+ cr_transform, 1);
rb_define_method (rb_cCairo_Context, "set_matrix",
- RUBY_METHOD_FUNC (rb_cairo_set_matrix), 1);
+ cr_set_matrix, 1);
rb_define_method (rb_cCairo_Context, "identity_matrix",
- RUBY_METHOD_FUNC (rb_cairo_identity_matrix), 1);
+ cr_identity_matrix, 1);
rb_define_method (rb_cCairo_Context, "user_to_device",
- RUBY_METHOD_FUNC (rb_cairo_user_to_device), 2);
+ cr_user_to_device, 2);
rb_define_method (rb_cCairo_Context, "user_to_device_distance",
- RUBY_METHOD_FUNC (rb_cairo_user_to_device_distance), 2);
+ cr_user_to_device_distance, 2);
rb_define_method (rb_cCairo_Context, "device_to_user",
- RUBY_METHOD_FUNC (rb_cairo_device_to_user), 2);
+ cr_device_to_user, 2);
rb_define_method (rb_cCairo_Context, "device_to_user_distance",
- RUBY_METHOD_FUNC (rb_cairo_device_to_user_distance), 2);
+ cr_device_to_user_distance, 2);
/* path creation functions */
rb_define_method (rb_cCairo_Context, "new_path",
- RUBY_METHOD_FUNC (rb_cairo_new_path), 0);
+ cr_new_path, 0);
rb_define_method (rb_cCairo_Context, "move_to",
- RUBY_METHOD_FUNC (rb_cairo_move_to), 2);
+ cr_move_to, 2);
rb_define_method (rb_cCairo_Context, "line_to",
- RUBY_METHOD_FUNC (rb_cairo_line_to), 2);
+ cr_line_to, 2);
rb_define_method (rb_cCairo_Context, "curve_to",
- RUBY_METHOD_FUNC (rb_cairo_curve_to), 6);
- rb_define_method (rb_cCairo_Context, "arc", RUBY_METHOD_FUNC (rb_cairo_arc),
+ cr_curve_to, 6);
+ rb_define_method (rb_cCairo_Context, "arc", cr_arc,
5);
rb_define_method (rb_cCairo_Context, "arc_negative",
- RUBY_METHOD_FUNC (rb_cairo_arc_negative), 5);
+ cr_arc_negative, 5);
rb_define_method (rb_cCairo_Context, "rel_move_to",
- RUBY_METHOD_FUNC (rb_cairo_rel_move_to), 2);
+ cr_rel_move_to, 2);
rb_define_method (rb_cCairo_Context, "rel_line_to",
- RUBY_METHOD_FUNC (rb_cairo_rel_line_to), 2);
+ cr_rel_line_to, 2);
rb_define_method (rb_cCairo_Context, "rel_curve_to",
- RUBY_METHOD_FUNC (rb_cairo_rel_curve_to), 6);
+ cr_rel_curve_to, 6);
rb_define_method (rb_cCairo_Context, "rectangle",
- RUBY_METHOD_FUNC (rb_cairo_rectangle), 4);
+ cr_rectangle, 4);
rb_define_method (rb_cCairo_Context, "close_path",
- RUBY_METHOD_FUNC (rb_cairo_close_path), 0);
+ cr_close_path, 0);
rb_define_method (rb_cCairo_Context, "paint",
- RUBY_METHOD_FUNC (rb_cairo_paint), 0);
+ cr_paint, 0);
rb_define_method (rb_cCairo_Context, "stroke",
- RUBY_METHOD_FUNC (rb_cairo_stroke), 0);
+ cr_stroke, 0);
rb_define_method (rb_cCairo_Context, "fill",
- RUBY_METHOD_FUNC (rb_cairo_fill), 0);
+ cr_fill, 0);
rb_define_method (rb_cCairo_Context, "stroke_preserve",
- RUBY_METHOD_FUNC (rb_cairo_stroke_preserve), 0);
+ cr_stroke_preserve, 0);
rb_define_method (rb_cCairo_Context, "fill_preserve",
- RUBY_METHOD_FUNC (rb_cairo_fill_preserve), 0);
+ cr_fill_preserve, 0);
rb_define_method (rb_cCairo_Context, "copy_page",
- RUBY_METHOD_FUNC (rb_cairo_copy_page), 0);
+ cr_copy_page, 0);
rb_define_method (rb_cCairo_Context, "show_page",
- RUBY_METHOD_FUNC (rb_cairo_show_page), 0);
- rb_define_method (rb_cCairo_Context, "in_fill",
- RUBY_METHOD_FUNC (rb_cairo_in_fill), 2);
- rb_define_method (rb_cCairo_Context, "in_stroke",
- RUBY_METHOD_FUNC (rb_cairo_in_stroke), 2);
+ cr_show_page, 0);
+ rb_define_method (rb_cCairo_Context, "in_fill?",
+ cr_in_fill, 2);
+ rb_define_method (rb_cCairo_Context, "in_stroke?",
+ cr_in_stroke, 2);
rb_define_method (rb_cCairo_Context, "fill_extents",
- RUBY_METHOD_FUNC (rb_cairo_fill_extents), 0);
+ cr_fill_extents, 0);
rb_define_method (rb_cCairo_Context, "stroke_extents",
- RUBY_METHOD_FUNC (rb_cairo_stroke_extents), 0);
+ cr_stroke_extents, 0);
rb_define_method (rb_cCairo_Context, "reset_clip",
- RUBY_METHOD_FUNC (rb_cairo_reset_clip), 0);
+ cr_reset_clip, 0);
rb_define_method (rb_cCairo_Context, "clip",
- RUBY_METHOD_FUNC (rb_cairo_clip), 0);
+ cr_clip, 0);
- rb_define_method (rb_cCairo_Context, "get_operator",
- RUBY_METHOD_FUNC (rb_cairo_get_operator), 0);
- rb_define_method (rb_cCairo_Context, "get_source",
- RUBY_METHOD_FUNC (rb_cairo_get_source), 0);
- rb_define_method (rb_cCairo_Context, "get_tolerance",
- RUBY_METHOD_FUNC (rb_cairo_get_tolerance), 0);
- rb_define_method (rb_cCairo_Context, "get_current_point",
- RUBY_METHOD_FUNC (rb_cairo_get_current_point), 0);
- rb_define_method (rb_cCairo_Context, "get_fill_rule",
- RUBY_METHOD_FUNC (rb_cairo_get_fill_rule), 0);
- rb_define_method (rb_cCairo_Context, "get_line_width",
- RUBY_METHOD_FUNC (rb_cairo_get_line_width), 0);
- rb_define_method (rb_cCairo_Context, "get_line_cap",
- RUBY_METHOD_FUNC (rb_cairo_get_line_cap), 0);
- rb_define_method (rb_cCairo_Context, "get_line_join",
- RUBY_METHOD_FUNC (rb_cairo_get_line_join), 0);
- rb_define_method (rb_cCairo_Context, "get_miter_limit",
- RUBY_METHOD_FUNC (rb_cairo_get_miter_limit), 0);
- rb_define_method (rb_cCairo_Context, "get_matrix",
- RUBY_METHOD_FUNC (rb_cairo_get_matrix), 0);
+ rb_define_method (rb_cCairo_Context, "operator",
+ cr_get_operator, 0);
+ rb_define_method (rb_cCairo_Context, "source",
+ cr_get_source, 0);
+ rb_define_method (rb_cCairo_Context, "tolerance",
+ cr_get_tolerance, 0);
+ rb_define_method (rb_cCairo_Context, "current_point",
+ cr_get_current_point, 0);
+ rb_define_method (rb_cCairo_Context, "fill_rule",
+ cr_get_fill_rule, 0);
+ rb_define_method (rb_cCairo_Context, "line_width",
+ cr_get_line_width, 0);
+ rb_define_method (rb_cCairo_Context, "line_cap",
+ cr_get_line_cap, 0);
+ rb_define_method (rb_cCairo_Context, "line_join",
+ cr_get_line_join, 0);
+ rb_define_method (rb_cCairo_Context, "miter_limit",
+ cr_get_miter_limit, 0);
+ rb_define_method (rb_cCairo_Context, "matrix",
+ cr_get_matrix, 0);
- rb_define_method (rb_cCairo_Context, "get_font_face",
- RUBY_METHOD_FUNC (rb_cairo_get_font_face), 0);
+ rb_define_method (rb_cCairo_Context, "font_face",
+ cr_get_font_face, 0);
rb_define_method (rb_cCairo_Context, "select_font_face",
- RUBY_METHOD_FUNC (rb_cairo_select_font_face), 3);
+ cr_select_font_face, 3);
rb_define_method (rb_cCairo_Context, "set_font_face",
- RUBY_METHOD_FUNC (rb_cairo_set_font_face), 1);
+ cr_set_font_face, 1);
rb_define_method (rb_cCairo_Context, "set_font_size",
- RUBY_METHOD_FUNC (rb_cairo_set_font_size), 1);
+ cr_set_font_size, 1);
rb_define_method (rb_cCairo_Context, "set_font_matrix",
- RUBY_METHOD_FUNC (rb_cairo_set_font_matrix), 1);
+ cr_set_font_matrix, 1);
rb_define_method (rb_cCairo_Context, "show_text",
- RUBY_METHOD_FUNC (rb_cairo_show_text), 1);
+ cr_show_text, 1);
rb_define_method (rb_cCairo_Context, "show_glyphs",
- RUBY_METHOD_FUNC (rb_cairo_show_glyphs), 1);
+ cr_show_glyphs, 1);
rb_define_method (rb_cCairo_Context, "text_path",
- RUBY_METHOD_FUNC (rb_cairo_text_path), 1);
+ cr_text_path, 1);
rb_define_method (rb_cCairo_Context, "glyph_path",
- RUBY_METHOD_FUNC (rb_cairo_glyph_path), 1);
- rb_define_method (rb_cCairo_Context, "get_target",
- RUBY_METHOD_FUNC (rb_cairo_get_target), 0);
+ cr_glyph_path, 1);
+ rb_define_method (rb_cCairo_Context, "target",
+ cr_get_target, 0);
+ rb_define_method (rb_cCairo_Context, "font_extents",
+ cr_font_extents, 0);
+ rb_define_method (rb_cCairo_Context, "glyph_extents",
+ cr_glyph_extents, 0);
}
-
-
Index: packages/cairo/ext/rb_cairo_exception.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo_exception.c,v
retrieving revision 1.4
diff -u -p -r1.4 rb_cairo_exception.c
--- packages/cairo/ext/rb_cairo_exception.c 8 Sep 2005 09:16:59 -0000 1.4
+++ packages/cairo/ext/rb_cairo_exception.c 12 Sep 2005 02:42:08 -0000
@@ -36,6 +36,8 @@ rb_cairo_raise_exception (cairo_status_t
switch (status)
{
+ case CAIRO_STATUS_SUCCESS:
+ break;
case CAIRO_STATUS_NO_MEMORY:
rb_raise (rb_eNoMemError, string);
break;
@@ -93,8 +95,6 @@ rb_cairo_raise_exception (cairo_status_t
case CAIRO_STATUS_INVALID_DASH:
rb_raise (rb_eCairo_InvalidDashError, string);
break;
- case CAIRO_STATUS_SUCCESS:
- break;
}
}
Index: packages/cairo/ext/rb_cairo_font_extents.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo_font_extents.c,v
retrieving revision 1.3
diff -u -p -r1.3 rb_cairo_font_extents.c
--- packages/cairo/ext/rb_cairo_font_extents.c 10 Sep 2005 18:29:03 -0000 1.3
+++ packages/cairo/ext/rb_cairo_font_extents.c 12 Sep 2005 02:42:08 -0000
@@ -43,9 +43,10 @@ rb_cairo_font_extents_to_ruby_object (ca
}
static VALUE
-rb_cairo_font_extents_new (VALUE klass)
+cr_font_extents_new (int argc, VALUE *argv, VALUE klass)
{
cairo_font_extents_t font_extents;
+ VALUE self;
font_extents.ascent = 0.0;
font_extents.descent = 0.0;
@@ -53,35 +54,37 @@ rb_cairo_font_extents_new (VALUE klass)
font_extents.max_x_advance = 0.0;
font_extents.max_y_advance = 0.0;
- return CRFONTEXTENTS2RVAL (&font_extents);
+ self = CRFONTEXTENTS2RVAL (&font_extents);
+ rb_obj_call_init (self, argc, argv);
+ return self;
}
static VALUE
-rb_cairo_font_extents_ascent (VALUE self)
+cr_font_extents_ascent (VALUE self)
{
return rb_float_new (_SELF->ascent);
}
static VALUE
-rb_cairo_font_extents_descent (VALUE self)
+cr_font_extents_descent (VALUE self)
{
return rb_float_new (_SELF->descent);
}
static VALUE
-rb_cairo_font_extents_height (VALUE self)
+cr_font_extents_height (VALUE self)
{
return rb_float_new (_SELF->height);
}
static VALUE
-rb_cairo_font_extents_max_x_advance (VALUE self)
+cr_font_extents_max_x_advance (VALUE self)
{
return rb_float_new (_SELF->max_x_advance);
}
static VALUE
-rb_cairo_font_extents_max_y_advance (VALUE self)
+cr_font_extents_max_y_advance (VALUE self)
{
return rb_float_new (_SELF->max_y_advance);
}
@@ -92,15 +95,15 @@ Init_cairo_font_extents (void)
rb_cCairo_FontExtents =
rb_define_class_under (rb_mCairo, "FontExtents", rb_cObject);
rb_define_singleton_method (rb_cCairo_FontExtents, "new",
- RUBY_METHOD_FUNC (rb_cairo_font_extents_new), 0);
+ cr_font_extents_new, -1);
rb_define_method (rb_cCairo_FontExtents, "ascent",
- RUBY_METHOD_FUNC (rb_cairo_font_extents_ascent), 0);
+ cr_font_extents_ascent, 0);
rb_define_method (rb_cCairo_FontExtents, "descent",
- RUBY_METHOD_FUNC (rb_cairo_font_extents_descent), 0);
+ cr_font_extents_descent, 0);
rb_define_method (rb_cCairo_FontExtents, "height",
- RUBY_METHOD_FUNC (rb_cairo_font_extents_height), 0);
+ cr_font_extents_height, 0);
rb_define_method (rb_cCairo_FontExtents, "max_x_advance",
- RUBY_METHOD_FUNC (rb_cairo_font_extents_max_x_advance), 0);
+ cr_font_extents_max_x_advance, 0);
rb_define_method (rb_cCairo_FontExtents, "max_y_advance",
- RUBY_METHOD_FUNC (rb_cairo_font_extents_max_y_advance), 0);
+ cr_font_extents_max_y_advance, 0);
}
Index: packages/cairo/ext/rb_cairo_font_face.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo_font_face.c,v
retrieving revision 1.3
diff -u -p -r1.3 rb_cairo_font_face.c
--- packages/cairo/ext/rb_cairo_font_face.c 10 Sep 2005 18:29:03 -0000 1.3
+++ packages/cairo/ext/rb_cairo_font_face.c 12 Sep 2005 02:42:08 -0000
@@ -43,51 +43,9 @@ rb_cairo_font_face_to_ruby_object (cairo
}
-#if 0
-static VALUE
-rb_cairo_font_extents (VALUE self,
- VALUE font_matrix_v)
-{
- cairo_matrix_t *font_matrix = RVAL2CRAMTRIX (font_matrix_v);
- cairo_font_extents_t extents;
- cairo_status_t status;
-
- status = cairo_font_extents (_SELF, font_matrix, &extents);
- if (status)
- {
- rb_cairo_raise_exception (status);
- }
- else
- {
- return CRFONTEXTENTS2RVAL (&extents);
- }
-}
-
-static VALUE
-rb_cairo_font_glyph_extents (VALUE self,
- VALUE font_matrix_v,
- VALUE glyphs_v)
-{
- cairo_matrix_t *font_matrix = RVAL2CRMATRIX (font_matrix_v);
- cairo_text_extents_t extents;
- cairo_status_t status;
-
- /* XXX: unwrap glyph array */
- cairo_font_glyph_extents (_SELF, font_matrix, NULL, 0, &extents);
- return CRTEXTEXTENTS2RVAL (&extents);
-}
-#endif
-
-
void
Init_cairo_font (void)
{
rb_cCairo_FontFace =
rb_define_class_under (rb_mCairo, "FontFace", rb_cObject);
- /*
- rb_define_method (rb_cCairo_Font, "extents",
- RUBY_METHOD_FUNC (rb_cairo_font_extents), 1);
- rb_define_method (rb_cCairo_Font, "glyph_extents",
- RUBY_METHOD_FUNC (rb_cairo_font_extents), 2);
- */
}
Index: packages/cairo/ext/rb_cairo_glyph.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo_glyph.c,v
retrieving revision 1.3
diff -u -p -r1.3 rb_cairo_glyph.c
--- packages/cairo/ext/rb_cairo_glyph.c 10 Sep 2005 18:29:03 -0000 1.3
+++ packages/cairo/ext/rb_cairo_glyph.c 12 Sep 2005 02:42:08 -0000
@@ -43,56 +43,59 @@ rb_cairo_glyph_to_ruby_object (cairo_gly
}
static VALUE
-rb_cairo_glyph_new (VALUE klass)
+cr_glyph_new (int argc, VALUE *argv, VALUE klass)
{
cairo_glyph_t glyph;
+ VALUE rb_glyph;
glyph.index = 0;
glyph.x = 0.0;
glyph.y = 0.0;
- return CRGLYPH2RVAL (&glyph);
+ rb_glyph = CRGLYPH2RVAL (&glyph);
+ rb_obj_call_init (rb_glyph, argc, argv);
+ return rb_glyph;
}
static VALUE
-rb_cairo_glyph_index (VALUE self)
+cr_glyph_index (VALUE self)
{
return INT2NUM(_SELF->index);
}
static VALUE
-rb_cairo_glyph_x (VALUE self)
+cr_glyph_x (VALUE self)
{
return rb_float_new (_SELF->x);
}
static VALUE
-rb_cairo_glyph_y (VALUE self)
+cr_glyph_y (VALUE self)
{
return rb_float_new (_SELF->y);
}
static VALUE
-rb_cairo_glyph_set_index (VALUE self,
- VALUE index_v)
+cr_glyph_set_index (VALUE self,
+ VALUE rb_index)
{
- _SELF->index = NUM2ULONG (index_v);
+ _SELF->index = NUM2ULONG (rb_index);
return self;
}
static VALUE
-rb_cairo_glyph_set_x (VALUE self,
- VALUE x_v)
+cr_glyph_set_x (VALUE self,
+ VALUE rb_x)
{
- _SELF->x = NUM2DBL (x_v);
+ _SELF->x = NUM2DBL (rb_x);
return self;
}
static VALUE
-rb_cairo_glyph_set_y (VALUE self,
- VALUE y_v)
+cr_glyph_set_y (VALUE self,
+ VALUE rb_y)
{
- _SELF->y = NUM2DBL (y_v);
+ _SELF->y = NUM2DBL (rb_y);
return self;
}
@@ -104,17 +107,17 @@ Init_cairo_glyph (void)
rb_cCairo_Glyph =
rb_define_class_under (rb_mCairo, "Glyph", rb_cObject);
rb_define_singleton_method (rb_cCairo_Glyph, "new",
- RUBY_METHOD_FUNC (rb_cairo_glyph_new), 0);
+ cr_glyph_new, -1);
rb_define_method (rb_cCairo_Glyph, "index",
- RUBY_METHOD_FUNC (rb_cairo_glyph_index), 0);
+ cr_glyph_index, 0);
rb_define_method (rb_cCairo_Glyph, "x",
- RUBY_METHOD_FUNC (rb_cairo_glyph_x), 0);
+ cr_glyph_x, 0);
rb_define_method (rb_cCairo_Glyph, "y",
- RUBY_METHOD_FUNC (rb_cairo_glyph_y), 0);
- rb_define_method (rb_cCairo_Glyph, "index=",
- RUBY_METHOD_FUNC (rb_cairo_glyph_set_index), 1);
- rb_define_method (rb_cCairo_Glyph, "x=",
- RUBY_METHOD_FUNC (rb_cairo_glyph_set_x), 1);
- rb_define_method (rb_cCairo_Glyph, "y=",
- RUBY_METHOD_FUNC (rb_cairo_glyph_set_y), 1);
+ cr_glyph_y, 0);
+ rb_define_method (rb_cCairo_Glyph, "set_index",
+ cr_glyph_set_index, 1);
+ rb_define_method (rb_cCairo_Glyph, "set_x",
+ cr_glyph_set_x, 1);
+ rb_define_method (rb_cCairo_Glyph, "set_y",
+ cr_glyph_set_y, 1);
}
Index: packages/cairo/ext/rb_cairo_matrix.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo_matrix.c,v
retrieving revision 1.7
diff -u -p -r1.7 rb_cairo_matrix.c
--- packages/cairo/ext/rb_cairo_matrix.c 10 Sep 2005 18:29:03 -0000 1.7
+++ packages/cairo/ext/rb_cairo_matrix.c 12 Sep 2005 02:42:08 -0000
@@ -66,16 +66,19 @@ float_array (double *values,
static VALUE
-rb_cairo_matrix_new (VALUE klass)
+cr_matrix_new (VALUE klass)
{
cairo_matrix_t matrix;
+ VALUE rb_matrix;
cairo_matrix_init_identity (&matrix);
- return CRMATRIX2RVAL (&matrix);
+ rb_matrix = CRMATRIX2RVAL (&matrix);
+ rb_obj_call_init (rb_matrix, 0, NULL);
+ return rb_matrix;
}
static VALUE
-rb_cairo_matrix_copy (VALUE self, VALUE other)
+cr_matrix_copy (VALUE self, VALUE other)
{
cairo_matrix_t *matrix = RVAL2CRMATRIX (other);
@@ -87,17 +90,17 @@ rb_cairo_matrix_copy (VALUE self, VALUE
}
static VALUE
-rb_cairo_matrix_init_identity (VALUE self)
+cr_matrix_init_identity (VALUE self)
{
cairo_matrix_init_identity (_SELF);
return self;
}
static VALUE
-rb_cairo_matrix_set (VALUE self,
- VALUE a, VALUE b,
- VALUE c, VALUE d,
- VALUE tx, VALUE ty)
+cr_matrix_set (VALUE self,
+ VALUE a, VALUE b,
+ VALUE c, VALUE d,
+ VALUE tx, VALUE ty)
{
cairo_matrix_init (_SELF,
NUM2DBL (a), NUM2DBL (b),
@@ -107,7 +110,7 @@ rb_cairo_matrix_set (VALUE self,
}
static VALUE
-rb_cairo_matrix_get (VALUE self)
+cr_matrix_get (VALUE self)
{
cairo_matrix_t *matrix = _SELF;
double affine[6];
@@ -121,8 +124,8 @@ rb_cairo_matrix_get (VALUE self)
}
static VALUE
-rb_cairo_matrix_translate (VALUE self,
- VALUE tx, VALUE ty)
+cr_matrix_translate (VALUE self,
+ VALUE tx, VALUE ty)
{
cairo_matrix_translate (_SELF,
NUM2DBL (tx), NUM2DBL (ty));
@@ -130,8 +133,8 @@ rb_cairo_matrix_translate (VALUE self,
}
static VALUE
-rb_cairo_matrix_scale (VALUE self,
- VALUE sx, VALUE sy)
+cr_matrix_scale (VALUE self,
+ VALUE sx, VALUE sy)
{
cairo_matrix_scale (_SELF,
NUM2DBL (sx), NUM2DBL (sy));
@@ -139,8 +142,8 @@ rb_cairo_matrix_scale (VALUE self,
}
static VALUE
-rb_cairo_matrix_rotate (VALUE self,
- VALUE radians)
+cr_matrix_rotate (VALUE self,
+ VALUE radians)
{
cairo_matrix_rotate (_SELF,
NUM2DBL (radians));
@@ -148,7 +151,7 @@ rb_cairo_matrix_rotate (VALUE self,
}
static VALUE
-rb_cairo_matrix_invert (VALUE self)
+cr_matrix_invert (VALUE self)
{
cairo_status_t status;
status = cairo_matrix_invert (_SELF);
@@ -161,9 +164,9 @@ rb_cairo_matrix_invert (VALUE self)
}
static VALUE
-rb_cairo_matrix_multiply (VALUE self,
- VALUE a,
- VALUE b)
+cr_matrix_multiply (VALUE self,
+ VALUE a,
+ VALUE b)
{
cairo_matrix_multiply (_SELF,
RVAL2CRMATRIX (a),
@@ -172,8 +175,8 @@ rb_cairo_matrix_multiply (VALUE self,
}
static VALUE
-rb_cairo_matrix_transform_distance (VALUE self,
- VALUE dx, VALUE dy)
+cr_matrix_transform_distance (VALUE self,
+ VALUE dx, VALUE dy)
{
double pair[2];
pair[0] = NUM2DBL (dx);
@@ -184,8 +187,8 @@ rb_cairo_matrix_transform_distance (VALU
}
static VALUE
-rb_cairo_matrix_transform_point (VALUE self,
- VALUE x, VALUE y)
+cr_matrix_transform_point (VALUE self,
+ VALUE x, VALUE y)
{
double pair[2];
pair[0] = NUM2DBL (x);
@@ -202,27 +205,27 @@ Init_cairo_matrix (void)
rb_cCairo_Matrix =
rb_define_class_under (rb_mCairo, "Matrix", rb_cObject);
rb_define_singleton_method (rb_cCairo_Matrix, "new",
- RUBY_METHOD_FUNC (rb_cairo_matrix_new), 0);
+ cr_matrix_new, 0);
rb_define_method (rb_cCairo_Matrix, "copy",
- RUBY_METHOD_FUNC (rb_cairo_matrix_copy), 1);
+ cr_matrix_copy, 1);
rb_define_method (rb_cCairo_Matrix, "set",
- RUBY_METHOD_FUNC (rb_cairo_matrix_set), 6);
- rb_define_method (rb_cCairo_Matrix, "get",
- RUBY_METHOD_FUNC (rb_cairo_matrix_get), 0);
+ cr_matrix_set, 6);
+ rb_define_method (rb_cCairo_Matrix, "to_a",
+ cr_matrix_get, 0);
rb_define_method (rb_cCairo_Matrix, "init_identity",
- RUBY_METHOD_FUNC (rb_cairo_matrix_init_identity), 1);
+ cr_matrix_init_identity, 1);
rb_define_method (rb_cCairo_Matrix, "translate!",
- RUBY_METHOD_FUNC (rb_cairo_matrix_translate), 2);
+ cr_matrix_translate, 2);
rb_define_method (rb_cCairo_Matrix, "scale!",
- RUBY_METHOD_FUNC (rb_cairo_matrix_scale), 2);
+ cr_matrix_scale, 2);
rb_define_method (rb_cCairo_Matrix, "rotate!",
- RUBY_METHOD_FUNC (rb_cairo_matrix_rotate), 2);
+ cr_matrix_rotate, 2);
rb_define_method (rb_cCairo_Matrix, "invert!",
- RUBY_METHOD_FUNC (rb_cairo_matrix_invert), 0);
+ cr_matrix_invert, 0);
rb_define_method (rb_cCairo_Matrix, "multiply!",
- RUBY_METHOD_FUNC (rb_cairo_matrix_multiply), 3);
+ cr_matrix_multiply, 3);
rb_define_method (rb_cCairo_Matrix, "transform_point",
- RUBY_METHOD_FUNC (rb_cairo_matrix_transform_point), 2);
+ cr_matrix_transform_point, 2);
rb_define_method (rb_cCairo_Matrix, "matrix_distance",
- RUBY_METHOD_FUNC (rb_cairo_matrix_transform_distance), 2);
+ cr_matrix_transform_distance, 2);
}
Index: packages/cairo/ext/rb_cairo_pattern.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo_pattern.c,v
retrieving revision 1.5
diff -u -p -r1.5 rb_cairo_pattern.c
--- packages/cairo/ext/rb_cairo_pattern.c 10 Sep 2005 18:29:03 -0000 1.5
+++ packages/cairo/ext/rb_cairo_pattern.c 12 Sep 2005 02:42:08 -0000
@@ -27,7 +27,7 @@ rb_cairo_pattern_from_ruby_object (VALUE
}
static void
-rb_free_pattern (void *ptr)
+cr_pattern_free (void *ptr)
{
if (ptr)
{
@@ -41,7 +41,7 @@ rb_cairo_pattern_to_ruby_object (cairo_p
if (pat)
{
cairo_pattern_reference (pat);
- return Data_Wrap_Struct (rb_cCairo_Pattern, NULL, rb_free_pattern, pat);
+ return Data_Wrap_Struct (rb_cCairo_Pattern, NULL, cr_pattern_free, pat);
}
else
{
Index: packages/cairo/ext/rb_cairo_surface.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo_surface.c,v
retrieving revision 1.5
diff -u -p -r1.5 rb_cairo_surface.c
--- packages/cairo/ext/rb_cairo_surface.c 10 Sep 2005 18:29:03 -0000 1.5
+++ packages/cairo/ext/rb_cairo_surface.c 12 Sep 2005 02:42:08 -0000
@@ -64,7 +64,7 @@ rb_cairo_surface_from_ruby_object (VALUE
}
static void
-rb_free_surface (void *ptr)
+cr_surface_free (void *ptr)
{
if (ptr)
{
@@ -78,7 +78,7 @@ rb_cairo_surface_to_ruby_object (cairo_s
if (surface)
{
cairo_surface_reference (surface);
- return Data_Wrap_Struct (rb_cCairo_Surface, NULL, rb_free_surface, surface);
+ return Data_Wrap_Struct (rb_cCairo_Surface, NULL, cr_surface_free, surface);
}
else
{
Index: packages/cairo/ext/rb_cairo_text_extents.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo_text_extents.c,v
retrieving revision 1.3
diff -u -p -r1.3 rb_cairo_text_extents.c
--- packages/cairo/ext/rb_cairo_text_extents.c 10 Sep 2005 18:29:03 -0000 1.3
+++ packages/cairo/ext/rb_cairo_text_extents.c 12 Sep 2005 02:42:08 -0000
@@ -42,7 +42,7 @@ rb_cairo_text_extents_to_ruby_object (ca
}
static VALUE
-rb_cairo_text_extents_new (VALUE klass)
+cr_text_extents_new (VALUE klass)
{
cairo_text_extents_t text_extents;
@@ -57,37 +57,37 @@ rb_cairo_text_extents_new (VALUE klass)
}
static VALUE
-rb_cairo_text_extents_x_bearing (VALUE self)
+cr_text_extents_x_bearing (VALUE self)
{
return rb_float_new (_SELF->x_bearing);
}
static VALUE
-rb_cairo_text_extents_y_bearing (VALUE self)
+cr_text_extents_y_bearing (VALUE self)
{
return rb_float_new (_SELF->y_bearing);
}
static VALUE
-rb_cairo_text_extents_width (VALUE self)
+cr_text_extents_width (VALUE self)
{
return rb_float_new (_SELF->width);
}
static VALUE
-rb_cairo_text_extents_height (VALUE self)
+cr_text_extents_height (VALUE self)
{
return rb_float_new (_SELF->height);
}
static VALUE
-rb_cairo_text_extents_x_advance (VALUE self)
+cr_text_extents_x_advance (VALUE self)
{
return rb_float_new (_SELF->x_advance);
}
static VALUE
-rb_cairo_text_extents_y_advance (VALUE self)
+cr_text_extents_y_advance (VALUE self)
{
return rb_float_new (_SELF->y_advance);
}
@@ -98,17 +98,17 @@ Init_cairo_text_extents (void)
rb_cCairo_TextExtents =
rb_define_class_under (rb_mCairo, "TextExtents", rb_cObject);
rb_define_singleton_method (rb_cCairo_TextExtents, "new",
- RUBY_METHOD_FUNC (rb_cairo_text_extents_new), 0);
+ cr_text_extents_new, 0);
rb_define_method (rb_cCairo_TextExtents, "x_bearing",
- RUBY_METHOD_FUNC (rb_cairo_text_extents_x_bearing), 0);
+ cr_text_extents_x_bearing, 0);
rb_define_method (rb_cCairo_TextExtents, "y_bearing",
- RUBY_METHOD_FUNC (rb_cairo_text_extents_y_bearing), 0);
+ cr_text_extents_y_bearing, 0);
rb_define_method (rb_cCairo_TextExtents, "width",
- RUBY_METHOD_FUNC (rb_cairo_text_extents_width), 0);
+ cr_text_extents_width, 0);
rb_define_method (rb_cCairo_TextExtents, "height",
- RUBY_METHOD_FUNC (rb_cairo_text_extents_height), 0);
+ cr_text_extents_height, 0);
rb_define_method (rb_cCairo_TextExtents, "x_advance",
- RUBY_METHOD_FUNC (rb_cairo_text_extents_x_advance), 0);
+ cr_text_extents_x_advance, 0);
rb_define_method (rb_cCairo_TextExtents, "y_advance",
- RUBY_METHOD_FUNC (rb_cairo_text_extents_y_advance), 0);
+ cr_text_extents_y_advance, 0);
}
Index: packages/cairo/lib/cairo.rb
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/lib/cairo.rb,v
retrieving revision 1.8
diff -u -p -r1.8 cairo.rb
--- packages/cairo/lib/cairo.rb 23 Jun 2005 09:30:48 -0000 1.8
+++ packages/cairo/lib/cairo.rb 12 Sep 2005 02:42:08 -0000
@@ -4,7 +4,21 @@ require 'cairo.so'
module Cairo
+ module_function
+ def __add_one_arg_setter(klass)
+ names = klass.instance_methods(false)
+ names.each do |name|
+ if /^set_(.*)/ =~ name and
+ not names.include? "#{$1}=" and
+ klass.instance_method(name).arity == 1
+ klass.module_eval("def #{$1}=(val); set_#{$1}(val); val; end")
+ end
+ end
+ end
+
class Context
+ Cairo.__add_one_arg_setter(self)
+
def dup
copy = Context.new
copy.copy(self)
@@ -41,55 +55,10 @@ class Context
( x0, y0 ) = get_point
quad_to(x1 + x0, y1 + y0, x2 + x0, y2 + x0)
end
+end
- def rgb_color=(*args)
- args = args[0] if args[0].is_a? Array
- self.set_rgb_color(*args)
- end
-
- alias save_internal save
- private :save_internal
- def save
- if block_given?
- save_internal
- begin
- yield
- ensure
- restore
- end
- else
- save_internal
- end
- end
-
- alias operator= set_operator
- alias operator get_operator
- alias tolerance= set_tolerance
- alias tolerance get_tolerance
- alias fill_rule= set_fill_rule
- alias fill_rule get_fill_rule
- alias line_width= set_line_width
- alias line_width get_line_width
- alias line_cap= set_line_cap
- alias line_cap get_line_cap
- alias line_join= set_line_join
- alias line_join get_line_join
- alias miter_limit= set_miter_limit
- alias miter_limit get_miter_limit
- alias matrix= set_matrix
- alias matrix get_matrix
- alias source get_source
- alias source= set_source
- alias set_transform set_matrix
- alias get_transform get_matrix
- alias transform= set_transform
- alias transform get_transform
- alias target get_target
- alias font_face get_font_face
- alias font_face= set_font_face
-
- alias in_fill? in_fill
- alias in_stroke? in_stroke
+class Glyph
+ Cairo.__add_one_arg_setter(self)
end
class Surface
More information about the cairo
mailing list