Fix width for getWrap and catch utf8 decoding errors in getWrap and getSize (issues #230 and #244)

This commit is contained in:
Bart van Strien
2011-09-03 16:22:21 +02:00
parent 190e11d016
commit 6e630e8987
2 changed files with 37 additions and 13 deletions
+19 -4
View File
@@ -43,7 +43,14 @@ namespace opengl
{
Font * t = luax_checkfont(L, 1);
const char * str = luaL_checkstring(L, 2);
lua_pushinteger(L, t->getWidth(str));
try
{
lua_pushinteger(L, t->getWidth(str));
}
catch (love::Exception & e)
{
return luaL_error(L, e.what());
}
return 1;
}
@@ -52,10 +59,18 @@ namespace opengl
Font * t = luax_checkfont(L, 1);
const char * str = luaL_checkstring(L, 2);
float wrap = (float) luaL_checknumber(L, 3);
int max_width = 0;
std::vector<std::string> lines = t->getWrap(str, wrap, &max_width);
int max_width = 0, numlines = 0;
try
{
std::vector<std::string> lines = t->getWrap(str, wrap, &max_width);
numlines = lines.size();
}
catch (love::Exception & e)
{
return luaL_error(L, e.what());
}
lua_pushinteger(L, max_width);
lua_pushinteger(L, lines.size());
lua_pushinteger(L, numlines);
return 2;
}