Skip to content

Commit

Permalink
label gen outline configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
rainfiel committed Apr 16, 2014
1 parent 0d4bed6 commit 4b8517d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/label.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

static GLuint Tex;
static struct dfont * Dfont = NULL;
static int Outline = 1;

void
label_load() {
Expand Down Expand Up @@ -53,6 +54,11 @@ label_flush() {
}
}

void
label_gen_outline(int outline) {
Outline = outline;
}

static inline int
copystr(char *utf8, const char *str, int n) {
int i;
Expand Down Expand Up @@ -152,7 +158,7 @@ write_pgm(int unicode, int w, int h, const uint8_t * buffer) {
*/

static const struct dfont_rect *
gen_char(int unicode, const char * utf8, int size, int edge) {
gen_char(int unicode, const char * utf8, int size, int outline) {
// todo : use large size when size is large
struct font_context ctx;
font_create(FONT_SIZE, &ctx);
Expand All @@ -172,7 +178,7 @@ gen_char(int unicode, const char * utf8, int size, int edge) {

ARRAY(uint8_t, buffer, buffer_sz);

if (edge) {
if (outline) {
ARRAY(uint8_t, tmp, buffer_sz);
memset(tmp,0,buffer_sz);
font_glyph(utf8, unicode, tmp, &ctx);
Expand Down Expand Up @@ -217,10 +223,10 @@ draw_rect(const struct dfont_rect *rect, int size, struct matrix *mat, uint32_t
}

static int
draw_size(int unicode, const char *utf8, int size, int edge) {
draw_size(int unicode, const char *utf8, int size) {
const struct dfont_rect * rect = dfont_lookup(Dfont,unicode,FONT_SIZE);
if (rect == NULL) {
rect = gen_char(unicode,utf8,size,edge);
rect = gen_char(unicode,utf8,size,Outline);
}
if (rect) {
return (rect->w -1) * size / FONT_SIZE;
Expand All @@ -229,10 +235,10 @@ draw_size(int unicode, const char *utf8, int size, int edge) {
}

static int
draw_height(int unicode, const char *utf8, int size, int edge) {
draw_height(int unicode, const char *utf8, int size) {
const struct dfont_rect * rect = dfont_lookup(Dfont,unicode,FONT_SIZE);
if (rect == NULL) {
rect = gen_char(unicode,utf8,size,edge);
rect = gen_char(unicode,utf8,size,Outline);
}
if (rect) {
return rect->h * size / FONT_SIZE;
Expand Down Expand Up @@ -364,9 +370,9 @@ label_draw(const char *str, struct pack_label * l, struct srt *srt, const struct
unicode = copystr(utf8,str+i,6);
i+=6;
}
w += draw_size(unicode, utf8, l->size, l->edge);
w += draw_size(unicode, utf8, l->size);
if (ch == 0) {
ch = draw_height(unicode, utf8, l->size, l->edge);
ch = draw_height(unicode, utf8, l->size);
}

if(w > l->width || unicode == '\n') {
Expand Down
1 change: 1 addition & 0 deletions lib/label.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ void label_unload();
void label_flush();

void label_draw(const char * str, struct pack_label * l, struct srt *srt, const struct sprite_trans *arg);
void label_gen_outline(int outline);

struct font_context {
int w;
Expand Down
7 changes: 7 additions & 0 deletions lib/lsprite.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ lnewlabel(lua_State *L) {
return 1;
}

static int
lgenoutline(lua_State *L) {
label_gen_outline(lua_toboolean(L, 1));
return 0;
}

static const char * srt_key[] = {
"x",
"y",
Expand Down Expand Up @@ -872,6 +878,7 @@ ejoy2d_sprite(lua_State *L) {
luaL_Reg l[] ={
{ "new", lnew },
{ "label", lnewlabel },
{ "label_gen_outline", lgenoutline },
{ NULL, NULL },
};
luaL_newlib(L,l);
Expand Down

0 comments on commit 4b8517d

Please sign in to comment.