#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 RUBY_DEF_ALLOC(alloc, klass) { return new_type(klass, new Rays::Font); } RUBY_END static RUBY_DEFN(initialize) { 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; } RUBY_END static RUBY_DEF0(name) { CHECK; return value(this->name().c_str()); } RUBY_END static RUBY_DEF0(size) { CHECK; return value(this->size()); } RUBY_END static RUBY_DEF1(width, 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); } RUBY_END static RUBY_DEF0(height) { CHECK; coord height = 0; if (!this->get_extent(NULL, &height, NULL)) error("Font#height() failed."); return value(height); } RUBY_END void Init_font () { Module m = define_module("Rays"); Class c = m.define_class("Font"); Rays::cFont = c; c.define_alloc_func(alloc); c.define_method("initialize", initialize); c.define_method("name", name); c.define_method("size", size); c.define_method("width", width); c.define_method("height", height); }