Rasterizer:getBoundingBox;

For the global bounding box
This commit is contained in:
bjorn 2022-06-18 17:40:14 -07:00
parent 717f95f6bd
commit 0d7fed1fa7
3 changed files with 22 additions and 0 deletions

View File

@ -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 },

View File

@ -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;
}

View File

@ -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);