From ab0ecfdede679a07791183d4c081c99b462715a2 Mon Sep 17 00:00:00 2001 From: Allanis Date: Fri, 22 Mar 2013 19:12:37 +0000 Subject: [PATCH] [Change] gl_printText is much more strict on width, with more checking. --- src/font.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/font.c b/src/font.c index 8d60586..17a5a71 100644 --- a/src/font.c +++ b/src/font.c @@ -184,7 +184,7 @@ int gl_printText(const glFont* ft_font, const int width, const int height, char txt[1024]; char buf[128]; va_list ap; - int p, i, j, n, len, ret, lastspace; + int p, i, j, n, m, len, ret, lastspace; double x, y; ret = 0; // Default return value. @@ -222,10 +222,16 @@ int gl_printText(const glFont* ft_font, const int width, const int height, if((txt[i] == ' ') || (txt[i] == '\n') || (txt[i] == '\0')) lastspace = i; - if((n > width) || (txt[i] == '\n') || (txt[i] == '\0')) { + if(((n > width) && ((p != lastspace) && (p != -1))) + || (txt[i] == '\n') || (txt[i] == '\0')) { + // Time to draw the line. - for(j = 0; j < (lastspace-p-1); j++) + m = 0; + for(j = 0; j < (lastspace-p-1); j++) { + m += ft_font->w[(int)buf[j]]; + if(m > width) break; buf[j] = txt[p+j+1]; + } // No need for null termination. glMatrixMode(GL_MODELVIEW); // using modelview, projection gets full fast. @@ -233,7 +239,7 @@ int gl_printText(const glFont* ft_font, const int width, const int height, glTranslated(x, y, 0); // This is what we are displaying. - glCallLists(lastspace-p-1, GL_UNSIGNED_BYTE, &buf); + glCallLists(j, GL_UNSIGNED_BYTE, &buf); glPopMatrix(); // Translation matrix. p = lastspace;