mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Exposed the internal Rasterizer and GlyphData object methods to Lua. Also added Font:hasGlyph.
This commit is contained in:
@@ -339,7 +339,7 @@ void Font::print(const std::string &text, float x, float y, float letter_spacing
|
||||
catch (utf8::exception &e)
|
||||
{
|
||||
glPopMatrix();
|
||||
throw love::Exception("%s", e.what());
|
||||
throw love::Exception("Decoding error: %s", e.what());
|
||||
}
|
||||
|
||||
if (quadindex > 0 && glyphinfolist.size() > 0)
|
||||
@@ -399,7 +399,7 @@ int Font::getWidth(const std::string &str)
|
||||
}
|
||||
catch(utf8::exception &e)
|
||||
{
|
||||
throw love::Exception("%s", e.what());
|
||||
throw love::Exception("Decoding error: %s", e.what());
|
||||
}
|
||||
|
||||
if (width > max_width)
|
||||
@@ -559,6 +559,16 @@ float Font::getBaseline() const
|
||||
return (type == FONT_TRUETYPE) ? floor(getHeight() / 1.25f + 0.5f) : 0.0f;
|
||||
}
|
||||
|
||||
bool Font::hasGlyph(unsigned int glyph) const
|
||||
{
|
||||
return rasterizer->hasGlyph(glyph);
|
||||
}
|
||||
|
||||
bool Font::hasGlyph(const std::string &text) const
|
||||
{
|
||||
return rasterizer->hasGlyph(text);
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -138,6 +138,9 @@ public:
|
||||
int getDescent() const;
|
||||
float getBaseline() const;
|
||||
|
||||
bool hasGlyph(unsigned int glyph) const;
|
||||
bool hasGlyph(const std::string &text) const;
|
||||
|
||||
private:
|
||||
|
||||
enum FontType
|
||||
|
||||
@@ -152,6 +152,27 @@ int w_Font_getBaseline(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Font_hasGlyph(lua_State *L)
|
||||
{
|
||||
Font *t = luax_checkfont(L, 1);
|
||||
bool hasglyph = false;
|
||||
|
||||
try
|
||||
{
|
||||
if (lua_type(L, 2) == LUA_TSTRING)
|
||||
hasglyph = t->hasGlyph(luax_checkstring(L, 2));
|
||||
else
|
||||
hasglyph = t->hasGlyph((unsigned int) luaL_checknumber(L, 2));
|
||||
}
|
||||
catch (love::Exception &e)
|
||||
{
|
||||
return luaL_error(L, "%s", e.what());
|
||||
}
|
||||
|
||||
luax_pushboolean(L, hasglyph);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getHeight", w_Font_getHeight },
|
||||
@@ -164,6 +185,7 @@ static const luaL_Reg functions[] =
|
||||
{ "getAscent", w_Font_getAscent },
|
||||
{ "getDescent", w_Font_getDescent },
|
||||
{ "getBaseline", w_Font_getBaseline },
|
||||
{ "hasGlyph", w_Font_hasGlyph },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ int w_Font_getFilter(lua_State *L);
|
||||
int w_Font_getAscent(lua_State *L);
|
||||
int w_Font_getDescent(lua_State *L);
|
||||
int w_Font_getBaseline(lua_State *L);
|
||||
int w_Font_hasGlyph(lua_State *L);
|
||||
extern "C" int luaopen_font(lua_State *L);
|
||||
|
||||
} // opengl
|
||||
|
||||
@@ -1150,9 +1150,9 @@ int w_print(lua_State *L)
|
||||
{
|
||||
instance->print(str, x, y, angle, sx, sy, ox, oy, kx,ky);
|
||||
}
|
||||
catch(love::Exception e)
|
||||
catch(love::Exception &e)
|
||||
{
|
||||
return luaL_error(L, "Decoding error: %s", e.what());
|
||||
return luaL_error(L, "%s", e.what());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1193,9 +1193,9 @@ int w_printf(lua_State *L)
|
||||
{
|
||||
instance->printf(str, x, y, wrap, align, angle, sx, sy, ox, oy, kx, ky);
|
||||
}
|
||||
catch(love::Exception e)
|
||||
catch(love::Exception &e)
|
||||
{
|
||||
return luaL_error(L, "Decoding error: %s", e.what());
|
||||
return luaL_error(L, "%s", e.what());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user