|
@@ -86,9 +86,16 @@ int w_Font_getHeight(lua_State *L)
|
|
|
int w_Font_getWidth(lua_State *L)
|
|
|
{
|
|
|
Font *t = luax_checkfont(L, 1);
|
|
|
- const char *str = luaL_checkstring(L, 2);
|
|
|
-
|
|
|
- luax_catchexcept(L, [&](){ lua_pushinteger(L, t->getWidth(str)); });
|
|
|
+ if (lua_type(L, 2) == LUA_TSTRING)
|
|
|
+ {
|
|
|
+ const char *str = luaL_checkstring(L, 2);
|
|
|
+ luax_catchexcept(L, [&](){ lua_pushinteger(L, t->getWidth(str)); });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ uint32 glyph = (uint32) luaL_checknumber(L, 2);
|
|
|
+ luax_catchexcept(L, [&](){ lua_pushinteger(L, t->getWidth(glyph)); });
|
|
|
+ }
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
@@ -214,6 +221,30 @@ int w_Font_hasGlyphs(lua_State *L)
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
+int w_Font_getKerning(lua_State *L)
|
|
|
+{
|
|
|
+ Font *t = luax_checkfont(L, 1);
|
|
|
+ float kerning = 0.0f;
|
|
|
+
|
|
|
+ luax_catchexcept(L, [&]() {
|
|
|
+ if (lua_type(L, 2) == LUA_TSTRING)
|
|
|
+ {
|
|
|
+ std::string left = luax_checkstring(L, 2);
|
|
|
+ std::string right = luax_checkstring(L, 3);
|
|
|
+ kerning = t->getKerning(left, right);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ uint32 left = (uint32) luaL_checknumber(L, 2);
|
|
|
+ uint32 right = (uint32) luaL_checknumber(L, 3);
|
|
|
+ kerning = t->getKerning(left, right);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ lua_pushnumber(L, kerning);
|
|
|
+ return 1;
|
|
|
+}
|
|
|
+
|
|
|
int w_Font_setFallbacks(lua_State *L)
|
|
|
{
|
|
|
Font *t = luax_checkfont(L, 1);
|
|
@@ -246,6 +277,7 @@ static const luaL_Reg w_Font_functions[] =
|
|
|
{ "getDescent", w_Font_getDescent },
|
|
|
{ "getBaseline", w_Font_getBaseline },
|
|
|
{ "hasGlyphs", w_Font_hasGlyphs },
|
|
|
+ { "getKerning", w_Font_getKerning },
|
|
|
{ "setFallbacks", w_Font_setFallbacks },
|
|
|
{ "getDPIScale", w_Font_getDPIScale },
|
|
|
{ 0, 0 }
|