From 112d7756352108cf2b80a12a0f65ee3e071aabbf Mon Sep 17 00:00:00 2001 From: bjorn Date: Sun, 11 Nov 2018 17:29:41 -0800 Subject: [PATCH] Font:hasGlyphs; --- src/api/types/font.c | 16 ++++++++++++++++ src/graphics/font.c | 4 ++++ src/graphics/font.h | 1 + 3 files changed, 21 insertions(+) diff --git a/src/api/types/font.c b/src/api/types/font.c index 82841148..7d9997d3 100644 --- a/src/api/types/font.c +++ b/src/api/types/font.c @@ -59,6 +59,21 @@ int l_lovrFontSetPixelDensity(lua_State* L) { return 0; } +int l_lovrFontHasGlyphs(lua_State* L) { + Font* font = luax_checktype(L, 1, Font); + Rasterizer* rasterizer = lovrFontGetRasterizer(font); + bool hasGlyphs = true; + for (int i = 2; i <= lua_gettop(L); i++) { + if (lua_type(L, i) == LUA_TSTRING) { + hasGlyphs &= lovrRasterizerHasGlyphs(rasterizer, lua_tostring(L, i)); + } else { + hasGlyphs &= lovrRasterizerHasGlyph(rasterizer, luaL_checkinteger(L, i)); + } + } + lua_pushboolean(L, hasGlyphs); + return 1; +} + const luaL_Reg lovrFont[] = { { "getWidth", l_lovrFontGetWidth }, { "getHeight", l_lovrFontGetHeight }, @@ -69,5 +84,6 @@ const luaL_Reg lovrFont[] = { { "setLineHeight", l_lovrFontSetLineHeight }, { "getPixelDensity", l_lovrFontGetPixelDensity }, { "setPixelDensity", l_lovrFontSetPixelDensity }, + { "hasGlyphs", l_lovrFontHasGlyphs }, { NULL, NULL } }; diff --git a/src/graphics/font.c b/src/graphics/font.c index eccfa07b..80b21a26 100644 --- a/src/graphics/font.c +++ b/src/graphics/font.c @@ -68,6 +68,10 @@ void lovrFontDestroy(void* ref) { free(font); } +Rasterizer* lovrFontGetRasterizer(Font* font) { + return font->rasterizer; +} + void lovrFontRender(Font* font, const char* str, float wrap, HorizontalAlign halign, VerticalAlign valign, VertexPointer vertices, float* offsety, uint32_t* vertexCount) { FontAtlas* atlas = &font->atlas; diff --git a/src/graphics/font.h b/src/graphics/font.h index c86e1ce0..bd9abeae 100644 --- a/src/graphics/font.h +++ b/src/graphics/font.h @@ -41,6 +41,7 @@ typedef struct { Font* lovrFontCreate(Rasterizer* rasterizer); void lovrFontDestroy(void* ref); +Rasterizer* lovrFontGetRasterizer(Font* font); void lovrFontRender(Font* font, const char* str, float wrap, HorizontalAlign halign, VerticalAlign valign, VertexPointer vertices, float* offsety, uint32_t* vertexCount); float lovrFontGetWidth(Font* font, const char* string, float wrap); float lovrFontGetHeight(Font* font);