#include "rays/ruby/font.h" #include #include "rays.h" using namespace Rucy; using Rays::coord; namespace Rays { Class font_class () { static Class c = rays_module().define_class("Font"); return c; } }// 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 () { Rays::font_class() .define_alloc_func(alloc) .define_method("initialize", initialize) .define_method("name", name) .define_method("size", size) .define_method("width", width) .define_method("height", height); }