>>>>> In [ruby-list : No.32143] 
>>>>>	ohai / kmc.kyoto-u.ac.jp (Ippei Obayashi) wrote:
> 私が作っているRuby/SDLの新しいバージョン、Ruby/SDL 0.7 を公開しました。

SDL_ttf-2.0.4になってフォントまわりの
関数を追加してもらうことができたので, 
それに対応するパッチを書きました. 

# 大林に前にお送りしたものと同じものです. 
# どこかに出しておかないとなくしてしまいそう(^_^;)なので
# ここにも流しておきます.

-- 
 やまだ あきら <URL:http://arika.org/ruby/>
 (akira / arika.org, akira / ruby-lang.org, 
  akira / debian.org or akira / linux.or.jp)

diff -ruN rubysdl-0.7.orig/extconf.rb rubysdl-0.7/extconf.rb --- rubysdl-0.7.orig/extconf.rb Tue Oct 30 18:23:30 2001 +++ rubysdl-0.7/extconf.rb Fri Nov 2 09:48:15 2001 @@ -5,6 +5,12 @@ $CFLAGS += ' ' + `#{sdl_config} --cflags`.chomp $LDFLAGS += ' ' + `#{sdl_config} --libs`.chomp +have_func("TTF_OpenFontIndex","SDL_ttf.h") +have_func("TTF_FontFaces","SDL_ttf.h") +have_func("TTF_FontFaceIsFixedWidth","SDL_ttf.h") +have_func("TTF_FontFaceFamilyName","SDL_ttf.h") +have_func("TTF_FontFaceStyleName","SDL_ttf.h") + if enable_config("event2",true) then $CFLAGS+= " -D DEF_EVENT2" end diff -ruN rubysdl-0.7.orig/rubysdl_ttf.c rubysdl-0.7/rubysdl_ttf.c --- rubysdl-0.7.orig/rubysdl_ttf.c Tue Oct 30 18:23:30 2001 +++ rubysdl-0.7/rubysdl_ttf.c Fri Nov 2 09:52:05 2001 @@ -32,10 +32,20 @@ ttf_initialized=1; return Qnil; } -static VALUE sdl_ttf_open(VALUE class,VALUE filename,VALUE size) +static VALUE sdl_ttf_open(int argc, VALUE *argv, VALUE class) { TTF_Font *font; - font=TTF_OpenFont( STR2CSTR(filename),NUM2INT(size) ); + VALUE filename, size, index; + rb_scan_args( argc, argv, "21", &filename, &size, &index ); + if( NIL_P(index) ) + font=TTF_OpenFont( STR2CSTR(filename),NUM2INT(size) ); + else +#ifdef HAVE_TTF_OPENFONTINDEX + font=TTF_OpenFontIndex( STR2CSTR(filename),NUM2INT(size),NUM2INT(index) ); +#else + if( index != 0) + rb_raise(rb_eRuntimeError,"Not supported for selecting indivisual font face by SDL_ttf. The feature is in SDL_ttf 2.0.4 or later."); +#endif if( font==NULL ) rb_raise(eSDLError,"Couldn't open font %s: %s",STR2CSTR(filename), TTF_GetError()); @@ -54,6 +64,49 @@ TTF_SetFontStyle(font,NUM2UINT(style)); return Qnil; } +static VALUE sdl_ttf_getFontFaces(VALUE obj) +{ +#ifdef TTF_FONTFACES + TTF_Font *font; + Data_Get_Struct(obj,TTF_Font,font); + return UINT2NUM( TTF_FontFaces(font) ); +#else + rb_raise(rb_eRuntimeError,"Not supported. The feature is in SDL_ttf 2.0.4 or later."); +#endif +} +static VALUE sdl_ttf_FontFaceIsFixedWidth(VALUE obj) +{ +#ifdef TTF_FONTISFIXEDWIDTH + TTF_Font *font; + Data_Get_Struct(obj,TTF_Font,font); + if( TTF_FontFaceIsFixedWidth(font) ) + return Qtrue; + else + return Qfalse; +#else + rb_raise(rb_eRuntimeError,"Not supported. The feature is in SDL_ttf 2.0.4 or later."); +#endif +} +static VALUE sdl_ttf_FontFaceFamilyName(VALUE obj) +{ +#ifdef TTF_FONTFACEFAMILYNAME + TTF_Font *font; + Data_Get_Struct(obj,TTF_Font,font); + return rb_str_new2( (const char *)TTF_FontFaceFamilyName(font) ); +#else + rb_raise(rb_eRuntimeError,"Not supported. The feature is in SDL_ttf 2.0.4 or later."); +#endif +} +static VALUE sdl_ttf_FontFaceStyleName(VALUE obj) +{ +#ifdef TTF_FONTFACESTYLENAME + TTF_Font *font; + Data_Get_Struct(obj,TTF_Font,font); + return rb_str_new2( (const char *)TTF_FontFaceStyleName(font) ); +#else + rb_raise(rb_eRuntimeError,"Not supported. The feature is in SDL_ttf 2.0.4 or later."); +#endif +} static VALUE sdl_ttf_sizeText(VALUE obj,VALUE text) { TTF_Font *font; @@ -115,11 +168,15 @@ { cTTF=rb_define_class_under(mSDL,"TTF",rb_cObject); rb_define_singleton_method(cTTF,"init",sdl_ttf_init,0); - rb_define_singleton_method(cTTF,"open",sdl_ttf_open,2); + rb_define_singleton_method(cTTF,"open",sdl_ttf_open,-1); rb_define_method(cTTF,"style",sdl_ttf_getFontStyle,0); rb_define_method(cTTF,"style=",sdl_ttf_setFontStyle,1); rb_define_method(cTTF,"textSize",sdl_ttf_sizeText,1); + rb_define_method(cTTF,"faces",sdl_ttf_getFontFaces,0); + rb_define_method(cTTF,"fixed_width?",sdl_ttf_FontFaceIsFixedWidth,0); + rb_define_method(cTTF,"family_name",sdl_ttf_FontFaceFamilyName,0); + rb_define_method(cTTF,"style_name",sdl_ttf_FontFaceStyleName,0); rb_define_method(cTTF,"drawSolidUTF8",sdl_ttf_drawSolidUTF8,7); rb_define_method(cTTF,"drawBlendedUTF8",sdl_ttf_drawBlendedUTF8,7);