Changeset 1995 for libcaca/trunk


Ignore:
Timestamp:
Nov 16, 2007, 11:24:35 PM (13 years ago)
Author:
Pascal Terjan
Message:
  • Add Cucul::Font
Location:
libcaca/trunk/ruby
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/ruby/Makefile.am

    r1983 r1995  
    88
    99cucul_la_CPPFLAGS = -I$(top_srcdir)/cucul -I$(RUBY_ARCHDIR)
    10 cucul_la_SOURCES = cucul.c cucul-canvas.c
     10cucul_la_SOURCES = cucul.c cucul-canvas.c cucul-font.c
    1111cucul_la_LDFLAGS = -module -avoid-version -shared -L$(RUBY_LIBDIR) -l$(RUBY_SO_NAME)
    1212cucul_la_LIBADD = ../cucul/libcucul.la
    1313
    1414EXTRA_DIST = cucul-canvas.h \
     15             cucul-canvas.h \
     16             common.h \
    1517             test.rb \
    1618             t/tc_frame.rb \
  • libcaca/trunk/ruby/cucul-canvas.c

    r1964 r1995  
    1313#include <cucul.h>
    1414#include <errno.h>
    15 #include "cucul-canvas.h"
    16 
    17 #define _SELF  (DATA_PTR(self))
     15#include "cucul-font.h"
     16#include "common.h"
     17
     18VALUE cCanvas;
    1819
    1920#define simple_func(x)                                  \
     
    202203    Check_Type(x, T_FIXNUM);
    203204    Check_Type(y, T_FIXNUM);
     205    //FIXME rather check that class is cCanvas
    204206    Check_Type(src, TYPE(self));
    205207    Data_Get_Struct(src, cucul_canvas_t, csrc);
    206208    if(!NIL_P(mask))
    207209    {
     210        //FIXME rather check that class is cCanvas
    208211        Check_Type(mask, TYPE(self));
    209212        Data_Get_Struct(mask, cucul_canvas_t, cmask);
     
    485488/****/
    486489
     490static VALUE render_canvas(VALUE self, VALUE font, VALUE width, VALUE height, VALUE pitch)
     491{
     492    void *buf;
     493    cucul_font_t *f;
     494    VALUE b;
     495
     496    //FIXME rather check that class is cFont
     497    Check_Type(font, TYPE(self));
     498
     499    buf = malloc(width*height*4);
     500    if(buf == NULL)
     501    {
     502        rb_raise(rb_eNoMemError, "Out of memory");
     503    }
     504
     505    f = DATA_PTR(font);
     506    cucul_render_canvas(_SELF, f, buf, NUM2UINT(width), NUM2UINT(height), NUM2UINT(pitch));
     507
     508    b = rb_str_new(buf, width*height*4);
     509    free(buf);
     510    return b;
     511}
     512
    487513static VALUE import_memory(VALUE self, VALUE data, VALUE format)
    488514{
     
    566592void Init_cucul_canvas(VALUE mCucul)
    567593{
    568     VALUE cCanvas = rb_define_class_under(mCucul, "Canvas", rb_cObject);
     594    cCanvas = rb_define_class_under(mCucul, "Canvas", rb_cObject);
    569595    rb_define_alloc_func(cCanvas, canvas_alloc);
    570596
     
    635661    rb_define_method(cCanvas, "free_frame", free_frame, 1);
    636662
     663    rb_define_method(cCanvas, "render", render_canvas, 4);
    637664    rb_define_method(cCanvas, "import_memory", import_memory, 2);
    638665    rb_define_method(cCanvas, "import_file", import_file, 2);
  • libcaca/trunk/ruby/cucul-canvas.h

    r1961 r1995  
    22#define __CUCUL_CANVAS_H__
    33
     4#include <ruby.h>
     5
     6extern VALUE cCanvas;
    47extern void Init_cucul_canvas(VALUE);
    58
  • libcaca/trunk/ruby/cucul.c

    r1961 r1995  
    1414
    1515#include "cucul-canvas.h"
    16 
    17 static VALUE mCucul;
     16#include "cucul-font.h"
    1817
    1918void Init_cucul()
    2019{
    21     mCucul = rb_define_module("Cucul");
     20    VALUE mCucul = rb_define_module("Cucul");
    2221
    2322    rb_define_const(mCucul, "BLACK", INT2FIX(CUCUL_BLACK));
     
    4645
    4746    Init_cucul_canvas(mCucul);
     47    Init_cucul_font(mCucul);
    4848}
  • libcaca/trunk/ruby/t/tc_canvas.rb

    r1966 r1995  
    4545        assert_equal(42, @c.get_char(1,1))
    4646    end
     47    def test_render
     48        c = Cucul::Canvas.new(4,4)
     49        c.put_str(0,0,"plop")
     50        f = Cucul::Font.new(Cucul::Font.list[0])
     51        assert_not_nil(c.render(f, c.width*f.width, c.height*f.height, c.width*f.width*4))
     52    end
    4753end
Note: See TracChangeset for help on using the changeset viewer.