|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- /*
- * libcucul Ruby bindings
- * Copyright (c) 2007 Pascal Terjan <pterjan@linuxfr.org>
- *
- * This library is free software. It comes without any warranty, to
- * the extent permitted by applicable law. You can redistribute it
- * and/or modify it under the terms of the Do What The Fuck You Want
- * To Public License, Version 2, as published by Sam Hocevar. See
- * http://sam.zoy.org/wtfpl/COPYING for more details.
- */
-
- #include <ruby.h>
- #include <cucul.h>
- #include <errno.h>
- #include "common.h"
-
- VALUE cFont;
-
- void font_free(void *font)
- {
- cucul_free_font((cucul_font_t *)font);
- }
-
- static VALUE font_alloc(VALUE klass)
- {
- VALUE obj;
- obj = Data_Wrap_Struct(klass, 0, font_free, NULL);
- return obj;
- }
-
- static VALUE font_initialize(VALUE self, VALUE name)
- {
- cucul_font_t *font;
-
- font = cucul_load_font(StringValuePtr(name), 0);
- if(font == NULL)
- {
- rb_raise(rb_eRuntimeError, strerror(errno));
- }
- _SELF = font;
- return self;
- }
-
- static VALUE font_list(void)
- {
- VALUE ary;
- char const* const* list;
-
- list = cucul_get_font_list();
-
- ary = rb_ary_new();
- while (*list != NULL)
- {
- rb_ary_push(ary, rb_str_new2(*list));
- list++;
- }
-
- return ary;
- }
-
- static VALUE get_font_width(VALUE self)
- {
- return UINT2NUM(cucul_get_font_width(_SELF));
- }
-
- static VALUE get_font_height(VALUE self)
- {
- return UINT2NUM(cucul_get_font_height(_SELF));
- }
-
- static VALUE get_font_blocks(VALUE self)
- {
- VALUE ary;
- unsigned long int const *list;
-
- list = cucul_get_font_blocks(_SELF);
-
- ary = rb_ary_new();
- while (*list != 0L)
- {
- rb_ary_push(ary, ULONG2NUM(*list));
- list++;
- }
-
- return ary;
- }
-
- void Init_cucul_font(VALUE mCucul)
- {
- cFont = rb_define_class_under(mCucul, "Font", rb_cObject);
- rb_define_alloc_func(cFont, font_alloc);
-
- rb_define_method(cFont, "initialize", font_initialize, 1);
- rb_define_method(cFont, "width", get_font_width, 0);
- rb_define_method(cFont, "height", get_font_height, 0);
- rb_define_method(cFont, "blocks", get_font_blocks, 0);
- rb_define_singleton_method(cFont, "list", font_list, 0);
- }
-
|