Skip to content

Commit

Permalink
Added better handling for unicode in demo's renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
rxi committed May 29, 2019
1 parent d488b48 commit 808b46f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions demo/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ void r_draw_rect(mu_Rect rect, mu_Color color) {
void r_draw_text(const char *text, mu_Vec2 pos, mu_Color color) {
mu_Rect dst = { pos.x, pos.y, 0, 0 };
for (const char *p = text; *p; p++) {
mu_Rect src = atlas[ATLAS_FONT + (unsigned char) *p];
if ((*p & 0xc0) == 0x80) { continue; }
int chr = mu_min((unsigned char) *p, 127);
mu_Rect src = atlas[ATLAS_FONT + chr];
dst.w = src.w;
dst.h = src.h;
push_quad(dst, src, color);
Expand All @@ -151,7 +153,9 @@ void r_draw_icon(int id, mu_Rect rect, mu_Color color) {
int r_get_text_width(const char *text, int len) {
int res = 0;
for (const char *p = text; *p && len--; p++) {
res += atlas[ATLAS_FONT + (unsigned char) *p].w;
if ((*p & 0xc0) == 0x80) { continue; }
int chr = mu_min((unsigned char) *p, 127);
res += atlas[ATLAS_FONT + chr].w;
}
return res;
}
Expand Down

0 comments on commit 808b46f

Please sign in to comment.