#include "rays/ruby/font.h" #include #include "defs.h" using namespace Rucy; using Rays::coord; namespace Rays { static Class cFont; Class font_class () { return cFont; } }// Rays namespace Rucy { Value value (const Rays::Font& font) { return new_type( Rays::font_class(), new Rays::Font(font)); } }// Rucy #define this to(self) #define CHECK CHECK_OBJECT(self, Rays::Font, Rays::font_class()) static VALUE alloc(VALUE klass) { return new_type(klass, new Rays::Font); } static VALUE initialize(VALUE self) { CHECK_OBJ(self, Rays::Font, Rays::font_class()); if (argc < 0 || 2 < argc) arg_count_error("Font#initialize", argc, 0, 1, 2); const char* name = (argc >= 1) ? argv[0].c_str() : NULL; float size = (argc >= 2) ? to(argv[1]) : 0; *this = Rays::Font(name, size); return self; } static VALUE name(VALUE self) { CHECK; return value(this->name().c_str()); } static VALUE size(VALUE self) { CHECK; return value(this->size()); } static VALUE width(VALUE self, VALUE str) { CHECK; coord width = 0; if (!this->get_extent(&width, NULL, str.c_str())) error("Font#width(%s) failed.", str.inspect().c_str()); return value(width); } static VALUE height(VALUE self) { CHECK; coord height = 0; if (!this->get_extent(NULL, &height, NULL)) error("Font#height() failed."); return value(height); } void Init_font () { Module m = rb_define_module("Rays"); Class c = rb_define_class_under(m, "Font", rb_cObject); Rays::cFont = c; rb_define_alloc_func(c, alloc); rb_define_method(c, "initialize", RUBY_METHOD_FUNC(initialize), -1); rb_define_method(c, "name", RUBY_METHOD_FUNC(name), 0); rb_define_method(c, "size", RUBY_METHOD_FUNC(size), 0); rb_define_method(c, "width", RUBY_METHOD_FUNC(width), 1); rb_define_method(c, "height", RUBY_METHOD_FUNC(height), 0); }