[Change] gl_printText is much more strict on width, with more checking.

This commit is contained in:
Allanis 2013-03-22 19:12:37 +00:00
parent 8c7a38686c
commit ab0ecfdede

View File

@ -184,7 +184,7 @@ int gl_printText(const glFont* ft_font, const int width, const int height,
char txt[1024]; char txt[1024];
char buf[128]; char buf[128];
va_list ap; va_list ap;
int p, i, j, n, len, ret, lastspace; int p, i, j, n, m, len, ret, lastspace;
double x, y; double x, y;
ret = 0; // Default return value. 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((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. // 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]; buf[j] = txt[p+j+1];
}
// No need for null termination. // No need for null termination.
glMatrixMode(GL_MODELVIEW); // using modelview, projection gets full fast. 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); glTranslated(x, y, 0);
// This is what we are displaying. // This is what we are displaying.
glCallLists(lastspace-p-1, GL_UNSIGNED_BYTE, &buf); glCallLists(j, GL_UNSIGNED_BYTE, &buf);
glPopMatrix(); // Translation matrix. glPopMatrix(); // Translation matrix.
p = lastspace; p = lastspace;