Beispiel #1
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;
}
Beispiel #2
0
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);
}
Beispiel #3
0
static const struct dfont_rect *
gen_char(int unicode, const char * utf8, int size) {
	// 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);
	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);
	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);
//	write_pgm(unicode, ctx.w, ctx.h, buffer);
	font_release(&ctx);

	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	glTexSubImage2D(GL_TEXTURE_2D, 0, rect->x, rect->y, rect->w, rect->h, TEX_FMT, GL_UNSIGNED_BYTE, buffer);

	return rect;
}
Beispiel #4
0
static int
ldfont_insert(lua_State *L) {
	struct dfont *df = get_dfont(L);
	if (!df) {
		return luaL_error(L, "invalid dfont table");
	}
	
	lua_getfield(L, 1, "texture");
	int tid = luaL_checkinteger(L, -1);
	lua_pop(L, 1);
	RID tex = texture_glid(tid);
	
	int id = luaL_checkinteger(L, 2);
	int rect_size = luaL_checkinteger(L, 3);
	int w = luaL_checkinteger(L, 4);
	int h = luaL_checkinteger(L, 5);
	void* buff = lua_touserdata(L, 6);
	
	const struct dfont_rect * rect = dfont_lookup(df, id, rect_size, 0);
	if (rect==NULL) {
		rect = dfont_insert(df, id, rect_size, w, h, 0);
		if (rect) {
			render_texture_subupdate(R, tex, buff, rect->x, rect->y, rect->w, rect->h);
		}
	}
	
	if (rect) {
		lua_pushinteger(L, rect->x);
		lua_pushinteger(L, rect->y);
		lua_pushinteger(L, rect->w);
		lua_pushinteger(L, rect->h);
		return 4;
	} else {
		return 0;
	}
}