2 Copyright (c)2006-2007 - Brett Lajzer
4 See LICENSE for license information.
11 #include "SDL/SDL_ttf.h"
12 #include "funcs_font.h"
14 //loads a font and returns a pointer to it
15 int l_load_font(lua_State
*L
){
17 font
= TTF_OpenFont(luaL_checkstring(L
,1), (int)lua_tonumber(L
,2));
19 lua_pushlightuserdata(L
,font
);
24 int l_close_font(lua_State
*L
){
25 TTF_CloseFont((TTF_Font
*)lua_touserdata(L
,1));
30 //gets dimensions of a string as rendered with a font
31 int l_font_string_metrics(lua_State
*L
){
33 TTF_SizeUTF8((TTF_Font
*)lua_touserdata(L
,1), luaL_checkstring(L
,2), &w
, &h
);
35 lua_pushinteger(L
, w
);
36 lua_pushinteger(L
, h
);
41 //render a string in a font
42 int l_render_string(lua_State
*L
){
46 color
.r
= (int)lua_tonumber(L
,3);
47 color
.g
= (int)lua_tonumber(L
,4);
48 color
.b
= (int)lua_tonumber(L
,5);
50 temp
= TTF_RenderUTF8_Blended((TTF_Font
*)lua_touserdata(L
,1),luaL_checkstring(L
,2), color
);
52 lua_pushlightuserdata(L
,temp
);
53 lua_pushinteger(L
, temp
->w
);
54 lua_pushinteger(L
, temp
->h
);