int w_newRasterizer(lua_State *L) { Rasterizer *t = NULL; try { if (luax_istype(L, 1, IMAGE_IMAGE_DATA_T)) { love::image::ImageData *d = luax_checktype<love::image::ImageData>(L, 1, "ImageData", IMAGE_IMAGE_DATA_T); const char *g = luaL_checkstring(L, 2); std::string glyphs(g); t = instance->newRasterizer(d, glyphs); } else if (luax_istype(L, 1, DATA_T)) { Data *d = luax_checkdata(L, 1); int size = luaL_checkint(L, 2); t = instance->newRasterizer(d, size); } } catch (love::Exception &e) { return luaL_error(L, "%s", e.what()); } luax_newtype(L, "Rasterizer", FONT_RASTERIZER_T, t); return 1; }
int w_newTrueTypeRasterizer(lua_State *L) { Rasterizer *t = nullptr; TrueTypeRasterizer::Hinting hinting = TrueTypeRasterizer::HINTING_NORMAL; if (lua_type(L, 1) == LUA_TNUMBER || lua_isnone(L, 1)) { // First argument is a number: use the default TrueType font. int size = (int) luaL_optnumber(L, 1, 12); 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 { love::Data *d = nullptr; if (luax_istype(L, 1, DATA_ID)) d = luax_checkdata(L, 1); else d = filesystem::luax_getfiledata(L, 1); int size = (int) luaL_optnumber(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, hinting); }, [&](bool) { d->release(); } ); } luax_pushtype(L, FONT_RASTERIZER_ID, t); t->release(); return 1; }
int w_Data_getPointer(lua_State *L) { Data *t = luax_checkdata(L, 1); lua_pushlightuserdata(L, t->getData()); return 1; }
int w_Data_getSize(lua_State *L) { Data *t = luax_checkdata(L, 1); lua_pushnumber(L, (lua_Number) t->getSize()); return 1; }
int w_Data_getString(lua_State *L) { Data *t = luax_checkdata(L, 1); lua_pushlstring(L, (const char *) t->getData(), t->getSize()); return 1; }