Add Font:getAscent/getDescent/getBaseline (issue #445)

This commit is contained in:
Bart van Strien
2013-01-18 13:20:40 +01:00
parent 84b6eedf1f
commit 32684b674e
4 changed files with 49 additions and 2 deletions
+17 -2
View File
@@ -291,8 +291,7 @@ void Font::print(const std::string &text, float x, float y, float letter_spacing
// copy glyphquad (4 vertices) from original glyph to our current quad list
glyphquads.push_back(glyph->quad);
// 1.25 is magic line height for true type fonts
float lineheight = (type == FONT_TRUETYPE) ? floor(getHeight() / 1.25f + 0.5f) : 0.0f;
float lineheight = getBaseline();
// set proper relative position
for (int i = 0; i < 4; i++)
@@ -592,6 +591,22 @@ void Font::unloadVolatile()
textures.clear();
}
int Font::getAscent() const
{
return rasterizer->getAscent();
}
int Font::getDescent() const
{
return rasterizer->getDescent();
}
float Font::getBaseline() const
{
// 1.25 is magic line height for true type fonts
return (type == FONT_TRUETYPE) ? floor(getHeight() / 1.25f + 0.5f) : 0.0f;
}
} // opengl
} // graphics
} // love
+5
View File
@@ -136,6 +136,11 @@ public:
bool loadVolatile();
void unloadVolatile();
// Extra font metrics
int getAscent() const;
int getDescent() const;
float getBaseline() const;
private:
enum FontType
+24
View File
@@ -162,6 +162,27 @@ int w_Font_getMipmapSharpness(lua_State *L)
return 1;
}
int w_Font_getAscent(lua_State *L)
{
Font *t = luax_checkfont(L, 1);
lua_pushnumber(L, t->getAscent());
return 1;
}
int w_Font_getDescent(lua_State *L)
{
Font *t = luax_checkfont(L, 1);
lua_pushnumber(L, t->getDescent());
return 1;
}
int w_Font_getBaseline(lua_State *L)
{
Font *t = luax_checkfont(L, 1);
lua_pushnumber(L, t->getBaseline());
return 1;
}
static const luaL_Reg functions[] =
{
{ "getHeight", w_Font_getHeight },
@@ -173,6 +194,9 @@ static const luaL_Reg functions[] =
{ "getFilter", w_Font_getFilter },
{ "setMipmapSharpness", w_Font_setMipmapSharpness },
{ "getMipmapSharpness", w_Font_getMipmapSharpness },
{ "getAscent", w_Font_getAscent },
{ "getDescent", w_Font_getDescent },
{ "getBaseline", w_Font_getBaseline },
{ 0, 0 }
};
+3
View File
@@ -42,6 +42,9 @@ int w_Font_setFilter(lua_State *L);
int w_Font_getFilter(lua_State *L);
int w_Font_setMipmapSharpness(lua_State *L);
int w_Font_getMipmapSharpness(lua_State *L);
int w_Font_getAscent(lua_State *L);
int w_Font_getDescent(lua_State *L);
int w_Font_getBaseline(lua_State *L);
extern "C" int luaopen_font(lua_State *L);
} // opengl