void label_draw(const struct rich_text *rich, struct pack_label * l, struct srt *srt, const struct sprite_trans *arg) { shader_texture(Tex, 0); uint32_t color = label_get_color(l, arg); const char *str = rich->text; char utf8[7]; int i; int ch = 0, w = 0, cy = 0, pre = 0, char_cnt = 0, idx = 0; for (i=0; str && str[i];) { int unicode; int len = unicode_len(str[i]); unicode = copystr(utf8, str+i, len); i+=len; w += draw_size(unicode, utf8, l->size, l->edge) + l->space_w; if (ch == 0) { ch = draw_height(unicode, utf8, l->size, l->edge) + l->space_h; } float space_scale=1.0; uint32_t lf = get_rich_filed_lf(rich, idx, &space_scale); if((l->auto_scale == 0 && lf) || unicode == '\n') { draw_line(rich, l, srt, arg, color, cy, w, pre, i, &char_cnt, space_scale); cy += ch; pre = i; w = 0; ch = 0; } idx++; } draw_line(rich, l, srt, arg, color, cy, w, pre, i, &char_cnt, 1.0); }
void label_draw(const char *str, struct pack_label * l, struct srt *srt, const struct sprite_trans *arg) { shader_texture(Tex); uint32_t color; if (arg->color == 0xffffffff) { color = l->color; } else if (l->color == 0xffffffff){ color = arg->color; } else { color = color_mul(l->color, arg->color); } char utf8[7]; int i; int ch = 0, w = 0, cy = 0, pre = 0; for (i=0; str[i];) { int unicode; uint8_t c = (uint8_t)str[i]; if ((c&0x80) == 0) { unicode = copystr(utf8,str+i,1); i+=1; } else if ((c&0xe0) == 0xc0) { unicode = copystr(utf8,str+i,2); i+=2; } else if ((c&0xf0) == 0xe0) { unicode = copystr(utf8,str+i,3); i+=3; } else if ((c&0xf8) == 0xf0) { unicode = copystr(utf8,str+i,4); i+=4; } else if ((c&0xfc) == 0xf8) { unicode = copystr(utf8,str+i,5); i+=5; } else { unicode = copystr(utf8,str+i,6); i+=6; } w += draw_size(unicode, utf8, l->size); if (ch == 0) { ch = draw_height(unicode, utf8, l->size); } if(w > l->width || unicode == '\n') { draw_line(str, l, srt, arg, color, cy, w, pre, i); cy += ch; pre = i; w = 0; ch = 0; } } draw_line(str, l, srt, arg, color, cy, w, pre, i); }