diff --git a/src/font.c b/src/font.c index 616a955..6b4f492 100644 --- a/src/font.c +++ b/src/font.c @@ -75,7 +75,8 @@ int gl_printWidthForText(const glFont* ft_font, char* txt, int i, n, lastspace; - if(ft_font == NULL) ft_font = &gl_defFont; + if(ft_font == NULL) + ft_font = &gl_defFont; /* Limit size per line. */ lastspace = 0; /* last ' ' or '\n' in the text. */ @@ -312,7 +313,7 @@ int gl_printText(const glFont* ft_font, const int width, const int height, else COLOUR(*c); p = 0; /* Where we last drew up to. */ - while(by - y < 0) { + while(y - by > -1e-5) { i = gl_printWidthForText(ft_font, &txt[p], width); glMatrixMode(GL_MODELVIEW); /* Using MODELVIEW, PROJECTION gets full fast. */ @@ -395,17 +396,21 @@ int gl_printHeight(const glFont* ft_font, const int width, vsprintf(txt, fmt, ap); va_end(ap); } + + if(txt[0] == '\0') + return 0; + y = 0.; p = 0; - while(1) { + do { i = gl_printWidthForText(ft_font, &txt[p], width); if(txt[p+i] == '\0') break; p += i + 1; y += 1.5*(double)ft_font->h; /* Move position down. */ - } + } while(txt[p-1] != '\0'); return (int)(y - 0.5*(double)ft_font->h); }