diff --git a/src/api/l_data_rasterizer.c b/src/api/l_data_rasterizer.c index 9cd1d946..d05139b8 100644 --- a/src/api/l_data_rasterizer.c +++ b/src/api/l_data_rasterizer.c @@ -11,6 +11,17 @@ static int l_lovrRasterizerGetFontSize(lua_State* L) { return 1; } +static int l_lovrRasterizerGetBoundingBox(lua_State* L) { + Rasterizer* rasterizer = luax_checktype(L, 1, Rasterizer); + float box[4]; + lovrRasterizerGetBoundingBox(rasterizer, box); + lua_pushnumber(L, box[0]); + lua_pushnumber(L, box[1]); + lua_pushnumber(L, box[2]); + lua_pushnumber(L, box[3]); + return 4; +} + static int l_lovrRasterizerGetGlyphCount(lua_State* L) { Rasterizer* rasterizer = luax_checktype(L, 1, Rasterizer); uint32_t count = lovrRasterizerGetGlyphCount(rasterizer); @@ -187,6 +198,7 @@ static int l_lovrRasterizerGetGlyphCurves(lua_State* L) { const luaL_Reg lovrRasterizer[] = { { "getFontSize", l_lovrRasterizerGetFontSize }, + { "getBoundingBox", l_lovrRasterizerGetBoundingBox }, { "getGlyphCount", l_lovrRasterizerGetGlyphCount }, { "hasGlyphs", l_lovrRasterizerHasGlyphs }, { "getAscent", l_lovrRasterizerGetAscent }, diff --git a/src/modules/data/rasterizer.c b/src/modules/data/rasterizer.c index 264f924b..37d34712 100644 --- a/src/modules/data/rasterizer.c +++ b/src/modules/data/rasterizer.c @@ -54,6 +54,15 @@ float lovrRasterizerGetFontSize(Rasterizer* rasterizer) { return rasterizer->size; } +void lovrRasterizerGetBoundingBox(Rasterizer* rasterizer, float box[4]) { + int x0, y0, x1, y1; + stbtt_GetFontBoundingBox(&rasterizer->font, &x0, &y0, &x1, &y1); + box[0] = x0 * rasterizer->scale; + box[1] = y0 * rasterizer->scale; + box[2] = x1 * rasterizer->scale; + box[3] = y1 * rasterizer->scale; +} + uint32_t lovrRasterizerGetGlyphCount(Rasterizer* rasterizer) { return rasterizer->font.numGlyphs; } diff --git a/src/modules/data/rasterizer.h b/src/modules/data/rasterizer.h index cdf7bf88..ab1d4a7e 100644 --- a/src/modules/data/rasterizer.h +++ b/src/modules/data/rasterizer.h @@ -11,6 +11,7 @@ typedef struct Rasterizer Rasterizer; Rasterizer* lovrRasterizerCreate(struct Blob* blob, float size); void lovrRasterizerDestroy(void* ref); float lovrRasterizerGetFontSize(Rasterizer* rasterizer); +void lovrRasterizerGetBoundingBox(Rasterizer* rasterizer, float box[4]); uint32_t lovrRasterizerGetGlyphCount(Rasterizer* rasterizer); bool lovrRasterizerHasGlyph(Rasterizer* rasterizer, uint32_t codepoint); bool lovrRasterizerHasGlyphs(Rasterizer* rasterizer, const char* str, size_t length);