static int font_width(lua_State *L) { font_t *font = checked_font(L, 1); const char *text = luaL_checkstring(L, 2); GLfloat size = luaL_checknumber(L, 3) / SCALE; lua_pushnumber(L, ftglGetFontAdvance(font->font, text) * size); return 1; }
static void cdgetfontdim(cdCtxCanvas *ctxcanvas, int *max_width, int *height, int *ascent, int *descent) { if(!ctxcanvas->font) return; if (max_width) *max_width = (int)ftglGetFontAdvance(ctxcanvas->font, "W"); if (height) *height = (int)ftglGetFontLineHeight(ctxcanvas->font); if (ascent) *ascent = (int)ftglGetFontAscender(ctxcanvas->font); if (descent) *descent = (int)ftglGetFontDescender(ctxcanvas->font); }
static int font_write(lua_State *L) { font_t *font = checked_font(L, 1); GLfloat x = luaL_checknumber(L, 2); GLfloat y = luaL_checknumber(L, 3); const char *text = luaL_checkstring(L, 4); // Protect FTGL if (!check_utf8(text)) return luaL_error(L, "invalid utf8"); GLfloat size = luaL_checknumber(L, 5) / SCALE; int type = lua_type(L, 6); if (type == LUA_TNUMBER) { GLfloat r = luaL_checknumber(L, 6); GLfloat g = luaL_checknumber(L, 7); GLfloat b = luaL_checknumber(L, 8); GLfloat a = luaL_optnumber(L, 9, 1.0); shader_set_gl_color(r, g, b, a); glBindTexture(GL_TEXTURE_2D, default_tex); } else if (type == LUA_TUSERDATA || type == LUA_TTABLE) { lua_pushliteral(L, "texid"); lua_gettable(L, 6); if (lua_type(L, -1) != LUA_TFUNCTION) return luaL_argerror(L, 6, "no texid() function"); lua_pushvalue(L, 6); lua_call(L, 1, 1); if (lua_type(L, -1) != LUA_TNUMBER) return luaL_argerror(L, 6, "texid() did not return number"); int tex_id = lua_tonumber(L, -1); lua_pop(L, 1); shader_set_gl_color(1.0, 1.0, 1.0, 1.0); glBindTexture(GL_TEXTURE_2D, tex_id); } else { return luaL_argerror(L, 6, "unsupported value. must be RGBA or texturelike"); } glPushMatrix(); glTranslatef(x, y, 0); glTranslatef(0, size * (SCALE * 0.8), 0); glScalef(size, -size, 1.0); ftglRenderFont(font->font, text, FTGL_RENDER_ALL); glPopMatrix(); lua_pushnumber(L, ftglGetFontAdvance(font->font, text) * size); return 1; }