Kouhei Sutou
kous****@users*****
2006年 11月 22日 (水) 11:20:36 JST
Index: tomoe/ext/ruby/tomoe-rb-handwrite.c diff -u tomoe/ext/ruby/tomoe-rb-handwrite.c:1.1 tomoe/ext/ruby/tomoe-rb-handwrite.c:1.2 --- tomoe/ext/ruby/tomoe-rb-handwrite.c:1.1 Wed Nov 22 10:59:09 2006 +++ tomoe/ext/ruby/tomoe-rb-handwrite.c Wed Nov 22 11:20:36 2006 @@ -70,6 +70,31 @@ return Qnil; } +static VALUE +tg_each(VALUE self) +{ + int i, j; + guint number_of_strokes, number_of_points; + TomoeGlyph *glyph; + + glyph = _SELF(self); + number_of_strokes = tomoe_glyph_get_number_of_strokes(glyph); + for (i = 0; i < number_of_strokes; i++) { + VALUE points; + number_of_points = tomoe_glyph_get_number_of_points(glyph, i); + + points = rb_ary_new2(number_of_points); + for (j = 0; j < number_of_points; j++) { + gint x, y; + if (tomoe_glyph_get_point(glyph, i, j, &x, &y)) + rb_ary_push(points, rb_ary_new3(2, INT2NUM(x), INT2NUM(y))); + } + rb_yield(points); + } + + return Qnil; +} + void Init_tomoe_handwrite(VALUE mTomoe) { @@ -77,6 +102,8 @@ cTomoeGlyph = G_DEF_CLASS(TOMOE_TYPE_GLYPH, "Glyph", mTomoe); + rb_include_module(cTomoeGlyph, rb_mEnumerable); + rb_define_method(cTomoeGlyph, "move_to", tg_move_to, 2); rb_define_method(cTomoeGlyph, "line_to", tg_line_to, 2); rb_define_method(cTomoeGlyph, "clear", tg_clear, 0); @@ -88,4 +115,6 @@ rb_define_method(cTomoeGlyph, "last_point", tg_get_last_point, 0); rb_define_method(cTomoeGlyph, "remove_last_stroke", tg_remove_last_stroke, 0); + + rb_define_method(cTomoeGlyph, "each", tg_each, 0); }