|
@@ -37,12 +37,13 @@ namespace font
|
|
|
|
|
|
int w_newRasterizer(lua_State *L)
|
|
|
{
|
|
|
- if (lua_isnoneornil(L, 2))
|
|
|
+ if (lua_type(L, 1) == LUA_TNUMBER || lua_type(L, 2) == LUA_TNUMBER)
|
|
|
+ {
|
|
|
+ // First or second argument is a number: call newTrueTypeRasterizer.
|
|
|
+ return w_newTrueTypeRasterizer(L);
|
|
|
+ }
|
|
|
+ else if (lua_isnoneornil(L, 2))
|
|
|
{
|
|
|
- // Single number argument: use the default TrueType font.
|
|
|
- if (lua_type(L, 1) == LUA_TNUMBER)
|
|
|
- return w_newTrueTypeRasterizer(L);
|
|
|
-
|
|
|
// Single argument of another type: call Font::newRasterizer.
|
|
|
Rasterizer *t = nullptr;
|
|
|
filesystem::FileData *d = filesystem::luax_getfiledata(L, 1);
|
|
@@ -56,11 +57,6 @@ int w_newRasterizer(lua_State *L)
|
|
|
t->release();
|
|
|
return 1;
|
|
|
}
|
|
|
- else if (lua_type(L, 2) == LUA_TNUMBER)
|
|
|
- {
|
|
|
- // Second argument is a number: call newTrueTypeRasterizer.
|
|
|
- return w_newTrueTypeRasterizer(L);
|
|
|
- }
|
|
|
else
|
|
|
{
|
|
|
// Otherwise call newBMFontRasterizer.
|
|
@@ -71,12 +67,18 @@ int w_newRasterizer(lua_State *L)
|
|
|
int w_newTrueTypeRasterizer(lua_State *L)
|
|
|
{
|
|
|
Rasterizer *t = nullptr;
|
|
|
+ TrueTypeRasterizer::Hinting hinting = TrueTypeRasterizer::HINTING_NORMAL;
|
|
|
|
|
|
if (lua_type(L, 1) == LUA_TNUMBER)
|
|
|
{
|
|
|
// First argument is a number: use the default TrueType font.
|
|
|
int size = luaL_checkint(L, 1);
|
|
|
- luax_catchexcept(L, [&](){ t = instance()->newTrueTypeRasterizer(size); });
|
|
|
+
|
|
|
+ const char *hintstr = lua_isnoneornil(L, 2) ? nullptr : luaL_checkstring(L, 2);
|
|
|
+ if (hintstr && !TrueTypeRasterizer::getConstant(hintstr, hinting))
|
|
|
+ return luaL_error(L, "Invalid TrueType font hinting mode: %s", hintstr);
|
|
|
+
|
|
|
+ luax_catchexcept(L, [&](){ t = instance()->newTrueTypeRasterizer(size, hinting); });
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -89,8 +91,12 @@ int w_newTrueTypeRasterizer(lua_State *L)
|
|
|
|
|
|
int size = luaL_optint(L, 2, 12);
|
|
|
|
|
|
+ const char *hintstr = lua_isnoneornil(L, 3) ? nullptr : luaL_checkstring(L, 3);
|
|
|
+ if (hintstr && !TrueTypeRasterizer::getConstant(hintstr, hinting))
|
|
|
+ return luaL_error(L, "Invalid TrueType font hinting mode: %s", hintstr);
|
|
|
+
|
|
|
luax_catchexcept(L,
|
|
|
- [&]() { t = instance()->newTrueTypeRasterizer(d, size); },
|
|
|
+ [&]() { t = instance()->newTrueTypeRasterizer(d, size, hinting); },
|
|
|
[&]() { d->release(); }
|
|
|
);
|
|
|
}
|
|
@@ -102,7 +108,7 @@ int w_newTrueTypeRasterizer(lua_State *L)
|
|
|
|
|
|
static void convimagedata(lua_State *L, int idx)
|
|
|
{
|
|
|
- if (lua_isstring(L, idx) || luax_istype(L, idx, FILESYSTEM_FILE_ID) || luax_istype(L, idx, FILESYSTEM_FILE_DATA_ID))
|
|
|
+ if (lua_type(L, 1) == LUA_TSTRING || luax_istype(L, idx, FILESYSTEM_FILE_ID) || luax_istype(L, idx, FILESYSTEM_FILE_DATA_ID))
|
|
|
luax_convobj(L, idx, "image", "newImageData");
|
|
|
}
|
|
|
|