Removed font renderer.
This commit is contained in:
+103
-33
@@ -2,6 +2,92 @@
|
||||
#include "renderer.h"
|
||||
#include "rencache.h"
|
||||
|
||||
static int f_font_load(lua_State *L) {
|
||||
const char *filename = luaL_checkstring(L, 1);
|
||||
float size = luaL_checknumber(L, 2);
|
||||
unsigned int font_hinting = FONT_HINTING_SLIGHT;
|
||||
bool subpixel = true;
|
||||
if (lua_gettop(L) > 2 && lua_istable(L, 3)) {
|
||||
lua_getfield(L, 3, "antialiasing");
|
||||
if (lua_isstring(L, -1)) {
|
||||
const char *antialiasing = lua_tostring(L, -1);
|
||||
if (antialiasing) {
|
||||
if (strcmp(antialiasing, "grayscale") == 0) {
|
||||
subpixel = false;
|
||||
} else if (strcmp(antialiasing, "subpixel") == 0) {
|
||||
subpixel = true;
|
||||
} else {
|
||||
return luaL_error(L, "error in renderer.font.load, unknown antialiasing option: \"%s\"", antialiasing);
|
||||
}
|
||||
}
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
lua_getfield(L, 3, "hinting");
|
||||
if (lua_isstring(L, -1)) {
|
||||
const char *hinting = lua_tostring(L, -1);
|
||||
if (hinting) {
|
||||
if (strcmp(hinting, "slight") == 0) {
|
||||
font_hinting = FONT_HINTING_SLIGHT;
|
||||
} else if (strcmp(hinting, "none") == 0) {
|
||||
font_hinting = FONT_HINTING_NONE;
|
||||
} else if (strcmp(hinting, "full") == 0) {
|
||||
font_hinting = FONT_HINTING_FULL;
|
||||
} else {
|
||||
return luaL_error(L, "error in renderer.font.load, unknown hinting option: \"%s\"", hinting);
|
||||
}
|
||||
}
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
RenFont** font = lua_newuserdata(L, sizeof(RenFont*));
|
||||
*font = ren_font_load(filename, size, subpixel, font_hinting);
|
||||
if (!*font)
|
||||
return luaL_error(L, "failed to load font");
|
||||
luaL_setmetatable(L, API_TYPE_FONT);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int f_font_copy(lua_State *L) {
|
||||
RenFont** self = luaL_checkudata(L, 1, API_TYPE_FONT);
|
||||
float size = lua_gettop(L) >= 2 ? luaL_checknumber(L, 2) : ren_font_get_height(*self);
|
||||
RenFont** font = lua_newuserdata(L, sizeof(RenFont*));
|
||||
*font = ren_font_copy(*self, size);
|
||||
if (!*font)
|
||||
return luaL_error(L, "failed to copy font");
|
||||
luaL_setmetatable(L, API_TYPE_FONT);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int f_font_set_tab_size(lua_State *L) {
|
||||
RenFont** self = luaL_checkudata(L, 1, API_TYPE_FONT);
|
||||
int n = luaL_checknumber(L, 2);
|
||||
ren_font_set_tab_size(*self, n);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int f_font_gc(lua_State *L) {
|
||||
RenFont** self = luaL_checkudata(L, 1, API_TYPE_FONT);
|
||||
ren_font_free(*self);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int f_font_get_width(lua_State *L) {
|
||||
RenFont** self = luaL_checkudata(L, 1, API_TYPE_FONT);
|
||||
lua_pushnumber(L, ren_font_get_width(*self, luaL_checkstring(L, 2)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int f_font_get_height(lua_State *L) {
|
||||
RenFont** self = luaL_checkudata(L, 1, API_TYPE_FONT);
|
||||
lua_pushnumber(L, ren_font_get_height(*self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int f_font_get_size(lua_State *L) {
|
||||
RenFont** self = luaL_checkudata(L, 1, API_TYPE_FONT);
|
||||
lua_pushnumber(L, ren_font_get_size(*self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static RenColor checkcolor(lua_State *L, int idx, int def) {
|
||||
RenColor color;
|
||||
@@ -71,40 +157,17 @@ static int f_draw_rect(lua_State *L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int draw_text_subpixel_impl(lua_State *L, bool draw_subpixel) {
|
||||
FontDesc *font_desc = luaL_checkudata(L, 1, API_TYPE_FONT);
|
||||
static int f_draw_text(lua_State *L) {
|
||||
RenFont** font = luaL_checkudata(L, 1, API_TYPE_FONT);
|
||||
const char *text = luaL_checkstring(L, 2);
|
||||
/* The coordinate below will be in subpixel iff draw_subpixel is true.
|
||||
Otherwise it will be in pixels. */
|
||||
int x_subpixel = luaL_checknumber(L, 3);
|
||||
int y = luaL_checknumber(L, 4);
|
||||
RenColor color = checkcolor(L, 5, 255);
|
||||
|
||||
CPReplaceTable *rep_table;
|
||||
RenColor replace_color;
|
||||
if (lua_gettop(L) >= 7) {
|
||||
rep_table = luaL_checkudata(L, 6, API_TYPE_REPLACE);
|
||||
replace_color = checkcolor(L, 7, 255);
|
||||
} else {
|
||||
rep_table = NULL;
|
||||
replace_color = (RenColor) {0};
|
||||
}
|
||||
|
||||
x_subpixel = rencache_draw_text(L, font_desc, 1, text, x_subpixel, y, color, draw_subpixel, rep_table, replace_color);
|
||||
x_subpixel = rencache_draw_text(L, *font, text, x_subpixel, y, color);
|
||||
lua_pushnumber(L, x_subpixel);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int f_draw_text(lua_State *L) {
|
||||
return draw_text_subpixel_impl(L, false);
|
||||
}
|
||||
|
||||
|
||||
static int f_draw_text_subpixel(lua_State *L) {
|
||||
return draw_text_subpixel_impl(L, true);
|
||||
}
|
||||
|
||||
|
||||
static const luaL_Reg lib[] = {
|
||||
{ "show_debug", f_show_debug },
|
||||
{ "get_size", f_get_size },
|
||||
@@ -113,19 +176,26 @@ static const luaL_Reg lib[] = {
|
||||
{ "set_clip_rect", f_set_clip_rect },
|
||||
{ "draw_rect", f_draw_rect },
|
||||
{ "draw_text", f_draw_text },
|
||||
{ "draw_text_subpixel", f_draw_text_subpixel },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
||||
int luaopen_renderer_font(lua_State *L);
|
||||
int luaopen_renderer_replacements(lua_State *L);
|
||||
static const luaL_Reg fontLib[] = {
|
||||
{ "__gc", f_font_gc },
|
||||
{ "load", f_font_load },
|
||||
{ "copy", f_font_copy },
|
||||
{ "set_tab_size", f_font_set_tab_size },
|
||||
{ "get_width", f_font_get_width },
|
||||
{ "get_height", f_font_get_height },
|
||||
{ "get_size", f_font_get_size },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
int luaopen_renderer(lua_State *L) {
|
||||
luaL_newlib(L, lib);
|
||||
luaopen_renderer_font(L);
|
||||
luaL_newmetatable(L, API_TYPE_FONT);
|
||||
luaL_setfuncs(L, fontLib, 0);
|
||||
lua_pushvalue(L, -1);
|
||||
lua_setfield(L, -2, "__index");
|
||||
lua_setfield(L, -2, "font");
|
||||
luaopen_renderer_replacements(L);
|
||||
lua_setfield(L, -2, "replacements");
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user