static int ldfont_flush(lua_State *L) { struct dfont *df = get_dfont(L); if (!df) { return luaL_error(L, "invalid dfont table"); } dfont_flush(df); return 0; }
static const struct dfont_rect * gen_char(int unicode, const char * utf8, int size, int edge) { // todo : use large size when size is large struct font_context ctx; font_create(FONT_SIZE, &ctx); if (ctx.font == NULL) { return NULL; } font_size(utf8, unicode, &ctx); const struct dfont_rect * rect = dfont_insert(Dfont, unicode, FONT_SIZE, ctx.w+1, ctx.h+1, edge); if (rect == NULL) { dfont_flush(Dfont); rect = dfont_insert(Dfont, unicode, FONT_SIZE, ctx.w+1, ctx.h+1, edge); if (rect == NULL) { font_release(&ctx); return NULL; } } ctx.w = rect->w ; ctx.h = rect->h ; int buffer_sz = ctx.w * ctx.h; ARRAY(uint8_t, buffer, buffer_sz); #ifdef FONT_EDGE_HASH if (edge) { ARRAY(uint8_t, tmp, buffer_sz); memset(tmp,0,buffer_sz); font_glyph(utf8, unicode, tmp, &ctx); gen_outline(ctx.w, ctx.h, tmp, buffer); } else { memset(buffer,0,buffer_sz); font_glyph(utf8, unicode, buffer, &ctx); } #else ARRAY(uint8_t, tmp, buffer_sz); memset(tmp,0,buffer_sz); font_glyph(utf8, unicode, tmp, &ctx); gen_outline(ctx.w, ctx.h, tmp, buffer); #endif // write_pgm(unicode, ctx.w, ctx.h, buffer); font_release(&ctx); render_texture_subupdate(R, Tex, buffer, rect->x, rect->y, rect->w, rect->h); return rect; }
static void test(struct dfont *df) { int i,j; for (i=0;i<20;i++) { for (j=0;j<4;j++) { dfont_insert(df, i, j, 12+i/2+j , 16+j); } } dfont_dump(df); dfont_flush(df); for (i=0;i<10;i++) { dfont_insert(df, 100+i, i%4, 12+i+j , 16+i%4); } dfont_dump(df); }
void label_flush() { if (Dfont) { dfont_flush(Dfont); } }