diff --git a/src/font.c b/src/font.c index 909353b..616a955 100644 --- a/src/font.c +++ b/src/font.c @@ -34,7 +34,7 @@ static void glFontMakeDList(FT_Face face, char ch, GLuint list_base, GLuint* tex_base, int* width_base); static int font_limitSize(const glFont* ft_font, int* width, - char* text, const int max); + char* txt, const int max); /** * @brief Limits the text to max. @@ -70,7 +70,7 @@ static int font_limitSize(const glFont* ft_font, int* width, * @param width Width to match. * @return Number of characters that fit. */ -int gl_printWidthForText(const glFont* ft_font, char* text, +int gl_printWidthForText(const glFont* ft_font, char* txt, const int width) { int i, n, lastspace; @@ -81,30 +81,28 @@ int gl_printWidthForText(const glFont* ft_font, char* text, lastspace = 0; /* last ' ' or '\n' in the text. */ n = 0; /* Current width. */ i = 0; /* Current position. */ - while(1) { - /* Check if we found an EOL character. */ - if((text[i] == '\n') || (text[i] == '\0')) - return i; - + while((txt[i] != '\n') && (txt[i] != '\0')) { /* Characters we should ignore. */ - if(text[i] == '\t') + if(txt[i] == '\t') { + i++; continue; + } /* Increase size. */ - n += ft_font->w[(int)text[i]]; + n += ft_font->w[(int)txt[i]]; /* Save last space. */ - if(text[i] == ' ') + if(txt[i] == ' ') lastspace = i; /* Check if out of bounds. */ if(n > width) - break; + return lastspace; /* Check next character. */ i++; } - return lastspace; + return i; } /** @@ -314,7 +312,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(1) { + while(by - y < 0) { i = gl_printWidthForText(ft_font, &txt[p], width); glMatrixMode(GL_MODELVIEW); /* Using MODELVIEW, PROJECTION gets full fast. */ @@ -329,8 +327,6 @@ int gl_printText(const glFont* ft_font, const int width, const int height, break; p += i + 1; y -= 1.5*(double)ft_font->h; /* Move position down. */ - if(by - y > (double)height) - break; } glDisable(GL_TEXTURE_2D);