Ignore:
Timestamp:
Nov 16, 2007, 11:24:35 PM (12 years ago)
Author:
Pascal Terjan
Message:
  • Add Cucul::Font
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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);
Note: See TracChangeset for help on using the changeset viewer.