]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
fix text width function
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 24 Dec 2009 11:48:32 +0000 (11:48 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 24 Dec 2009 11:48:32 +0000 (11:48 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9666 d7cf8633-e32d-0410-b094-e92efae38249

gl_draw.c

index a891e89e35fc9e86c56dd174b93f9c082f4093ca..0bd87d9b18f4ea9288883ae36d87a94d64ddcc0b 100644 (file)
--- 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))
                {