From a1295dca545c58fcdfc4dfae84bf838c1c06ada0 Mon Sep 17 00:00:00 2001 From: divverent Date: Thu, 24 Dec 2009 11:48:32 +0000 Subject: [PATCH] fix text width function git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9666 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_draw.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/gl_draw.c b/gl_draw.c index a891e89e..0bd87d9b 100644 --- a/gl_draw.c +++ b/gl_draw.c @@ -1125,7 +1125,7 @@ float DrawQ_TextWidth_Font_UntilWidth_TrackColors_Size(const char *text, float w for (i = 0;((bytes_left = *maxlen - (text - text_start)) > 0) && *text;) { nextch = ch = u8_getnchar(text, &text, bytes_left); - //i = text - text_start; + i = text - text_start; if (!ch) break; if (snap) @@ -1135,12 +1135,11 @@ float DrawQ_TextWidth_Font_UntilWidth_TrackColors_Size(const char *text, float w if(x + fnt->width_of[(int) ' '] * w > maxwidth) break; // oops, can't draw this x += fnt->width_of[(int) ' '] * w; - ++i; continue; } - if (ch == STRING_COLOR_TAG && !ignorecolorcodes && i + 1 < *maxlen) + // i points to the char after ^ + if (ch == STRING_COLOR_TAG && !ignorecolorcodes && i < *maxlen) { - ++i; ch = *text; // colors are ascii, so no u8_ needed if (ch <= '9' && ch >= '0') // ^[0-9] found { @@ -1149,6 +1148,9 @@ float DrawQ_TextWidth_Font_UntilWidth_TrackColors_Size(const char *text, float w ++i; continue; } + // i points to the char after ^... + // i+3 points to 3 in ^x123 + // i+3 == *maxlen would mean that char is missing else if (ch == STRING_COLOR_RGB_TAG_CHAR && i + 3 < *maxlen ) // ^x found { // building colorindex... @@ -1188,7 +1190,6 @@ float DrawQ_TextWidth_Font_UntilWidth_TrackColors_Size(const char *text, float w i--; } ch = nextch; - ++i; if (!fontmap || (ch <= 0xFF && fontmap->glyphs[ch].image) || (ch >= 0xE000 && ch <= 0xE0FF)) { -- 2.39.2