[cairo-commit] rcairo/src rb_cairo_text_extents.c,1.2,1.3

Kouhei Sutou commit at pdx.freedesktop.org
Sat Aug 16 22:41:30 PDT 2008


Committed by: kou

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

Modified Files:
	rb_cairo_text_extents.c 
Log Message:
        * src/rb_cairo_text_extents.c: add Cairo::TextExtents#initialize
        and setters.

        * test/test_text_extents.rb: add.


Index: rb_cairo_text_extents.c
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_text_extents.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- rb_cairo_text_extents.c	3 May 2007 02:47:39 -0000	1.2
+++ rb_cairo_text_extents.c	17 Aug 2008 05:41:28 -0000	1.3
@@ -46,6 +46,29 @@
     }
 }
 
+static VALUE
+cr_text_extents_allocate (VALUE klass)
+{
+  return Data_Wrap_Struct (klass, NULL, -1, NULL);
+}
+
+static VALUE
+cr_text_extents_initialize (VALUE self)
+{
+  cairo_text_extents_t *extents;
+
+  extents = ALLOC (cairo_text_extents_t);
+  extents->x_bearing = 0.0;
+  extents->y_bearing = -1.0;
+  extents->width = 0.0;
+  extents->height = 1.0;
+  extents->x_advance = 1.0;
+  extents->y_advance = 0.0;
+
+  DATA_PTR (self) = extents;
+
+  return Qnil;
+}
 
 static VALUE
 cr_text_extents_x_bearing (VALUE self)
@@ -54,36 +77,78 @@
 }
 
 static VALUE
+cr_text_extents_set_x_bearing (VALUE self, VALUE x_bearing)
+{
+  _SELF(self)->x_bearing = NUM2DBL (x_bearing);
+  return Qnil;
+}
+
+static VALUE
 cr_text_extents_y_bearing (VALUE self)
 {
   return rb_float_new (_SELF(self)->y_bearing);
 }
 
 static VALUE
+cr_text_extents_set_y_bearing (VALUE self, VALUE y_bearing)
+{
+  _SELF(self)->y_bearing = NUM2DBL (y_bearing);
+  return Qnil;
+}
+
+static VALUE
 cr_text_extents_width (VALUE self)
 {
   return rb_float_new (_SELF(self)->width);
 }
 
 static VALUE
+cr_text_extents_set_width (VALUE self, VALUE width)
+{
+  _SELF(self)->width = NUM2DBL (width);
+  return Qnil;
+}
+
+static VALUE
 cr_text_extents_height (VALUE self)
 {
   return rb_float_new (_SELF(self)->height);
 }
 
 static VALUE
+cr_text_extents_set_height (VALUE self, VALUE height)
+{
+  _SELF(self)->height = NUM2DBL (height);
+  return Qnil;
+}
+
+static VALUE
 cr_text_extents_x_advance (VALUE self)
 {
   return rb_float_new (_SELF(self)->x_advance);
 }
 
 static VALUE
+cr_text_extents_set_x_advance (VALUE self, VALUE x_advance)
+{
+  _SELF(self)->x_advance = NUM2DBL (x_advance);
+  return Qnil;
+}
+
+static VALUE
 cr_text_extents_y_advance (VALUE self)
 {
   return rb_float_new (_SELF(self)->y_advance);
 }
 
 static VALUE
+cr_text_extents_set_y_advance (VALUE self, VALUE y_advance)
+{
+  _SELF(self)->y_advance = NUM2DBL (y_advance);
+  return Qnil;
+}
+
+static VALUE
 cr_text_extents_to_s (VALUE self)
 {
   VALUE ret;
@@ -109,7 +174,7 @@
   rb_str_cat2 (ret, "y_advance=");
   rb_str_concat (ret, rb_inspect (cr_text_extents_y_advance (self)));
   rb_str_cat2 (ret, ">");
-                 
+
   return ret;
 }
 
@@ -119,20 +184,38 @@
 {
   rb_cCairo_TextExtents =
     rb_define_class_under (rb_mCairo, "TextExtents", rb_cObject);
+  rb_define_alloc_func (rb_cCairo_TextExtents, cr_text_extents_allocate);
+
+  rb_define_method (rb_cCairo_TextExtents, "initialize",
+                    cr_text_extents_initialize, 0);
 
   rb_define_method (rb_cCairo_TextExtents, "x_bearing",
                     cr_text_extents_x_bearing, 0);
+  rb_define_method (rb_cCairo_TextExtents, "set_x_bearing",
+                    cr_text_extents_set_x_bearing, 1);
   rb_define_method (rb_cCairo_TextExtents, "y_bearing",
                     cr_text_extents_y_bearing, 0);
+  rb_define_method (rb_cCairo_TextExtents, "set_y_bearing",
+                    cr_text_extents_set_y_bearing, 1);
   rb_define_method (rb_cCairo_TextExtents, "width",
                     cr_text_extents_width, 0);
+  rb_define_method (rb_cCairo_TextExtents, "set_width",
+                    cr_text_extents_set_width, 1);
   rb_define_method (rb_cCairo_TextExtents, "height",
                     cr_text_extents_height, 0);
+  rb_define_method (rb_cCairo_TextExtents, "set_height",
+                    cr_text_extents_set_height, 1);
   rb_define_method (rb_cCairo_TextExtents, "x_advance",
                     cr_text_extents_x_advance, 0);
+  rb_define_method (rb_cCairo_TextExtents, "set_x_advance",
+                    cr_text_extents_set_x_advance, 1);
   rb_define_method (rb_cCairo_TextExtents, "y_advance",
                     cr_text_extents_y_advance, 0);
+  rb_define_method (rb_cCairo_TextExtents, "set_y_advance",
+                    cr_text_extents_set_y_advance, 1);
 
   rb_define_method (rb_cCairo_TextExtents, "to_s",
                     cr_text_extents_to_s, 0);
+
+  RB_CAIRO_DEF_SETTERS (rb_cCairo_TextExtents);
 }



More information about the cairo-commit mailing list