mirror of
https://github.com/love2d/love.git
synced 2026-08-16 16:20:42 +02:00
Add Font:getAscent/getDescent/getBaseline (issue #445)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -136,6 +136,11 @@ public:
|
||||
bool loadVolatile();
|
||||
void unloadVolatile();
|
||||
|
||||
// Extra font metrics
|
||||
int getAscent() const;
|
||||
int getDescent() const;
|
||||
float getBaseline() const;
|
||||
|
||||
private:
|
||||
|
||||
enum FontType
|
||||
|
||||
@@ -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 }
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user