[Change] gl_printText is much more strict on width, with more checking.
This commit is contained in:
parent
8c7a38686c
commit
ab0ecfdede
14
src/font.c
14
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;
|
||||
|
Loading…
Reference in New Issue
Block a user