ext/rays/font.cpp in rays-0.1.47 vs ext/rays/font.cpp in rays-0.1.48
- old
+ new
@@ -29,18 +29,37 @@
return self;
}
RUCY_END
static
+RUCY_DEF1(initialize_copy, obj)
+{
+ RUCY_CHECK_OBJ(Rays::Font, self);
+
+ *THIS = to<Rays::Font&>(obj).dup();
+ return self;
+}
+RUCY_END
+
+static
RUCY_DEF0(name)
{
CHECK;
return value(THIS->name().c_str());
}
RUCY_END
static
+RUCY_DEF1(set_size, size)
+{
+ CHECK;
+ THIS->set_size(to<coord>(size));
+ return size;
+}
+RUCY_END
+
+static
RUCY_DEF0(size)
{
CHECK;
return value(THIS->size());
}
@@ -90,28 +109,61 @@
THIS->get_height(NULL, NULL, &leading);
return value(leading);
}
RUCY_END
+static
+RUCY_DEF0(families)
+{
+ Hash hash;
+ for (const auto& family : Rays::get_font_families())
+ {
+ std::vector<Value> members;
+ for (const auto& member : family.second)
+ members.emplace_back(member.c_str());
+ hash.set(family.first.c_str(), value(members.size(), &members[0]));
+ }
+ return hash;
+}
+RUCY_END
+static
+RUCY_DEFN(load)
+{
+ check_arg_count(__FILE__, __LINE__, "Font.load", argc, 1, 2);
+
+ const char* path = argv[0].c_str();
+
+ if (argc >= 2)
+ return value(Rays::load_font(path, to<Rays::coord>(argv[1])));
+ else
+ return value(Rays::load_font(path));
+}
+RUCY_END
+
+
static Class cFont;
void
Init_rays_font ()
{
Module mRays = define_module("Rays");
cFont = mRays.define_class("Font");
cFont.define_alloc_func(alloc);
- cFont.define_private_method("initialize", initialize);
+ cFont.define_private_method("initialize", initialize);
+ cFont.define_private_method("initialize_copy", initialize_copy);
cFont.define_method("name", name);
- cFont.define_method("size", size);
+ cFont.define_method("size=", set_size);
+ cFont.define_method("size", size);
cFont.define_method("width", width);
cFont.define_method("height", height);
cFont.define_method("ascent", ascent);
cFont.define_method("descent", descent);
cFont.define_method("leading", leading);
+ cFont.define_module_function("families", families);
+ cFont.define_module_function("load", load);
}
namespace Rucy
{
@@ -129,12 +181,12 @@
assert(argc == 0 || (argc > 0 && argv));
if (convert)
{
if (argc == 0)
- return Rays::default_font();
+ return Rays::get_default_font();
- coord size = argc >= 2 ? to<coord>(argv[1]) : 0;
+ coord size = argc >= 2 ? to<coord>(argv[1]) : Rays::Font::DEFAULT_SIZE;
if (argv->is_nil())
return Rays::Font(NULL, size);
else if (argv->is_s() || argv->is_sym())
return Rays::Font(argv[0].c_str(), size);
}