From ccbb8f1c2c7dc3e182118b89e55031f8bfb6051b Mon Sep 17 00:00:00 2001 From: Allanis Date: Sat, 30 Mar 2013 20:58:52 +0000 Subject: [PATCH] [Add] gl_printHeight. --- src/font.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/font.h | 3 +++ 2 files changed, 48 insertions(+) diff --git a/src/font.c b/src/font.c index ce137c3..12a27b9 100644 --- a/src/font.c +++ b/src/font.c @@ -277,6 +277,51 @@ int gl_printWidth(const glFont* ft_font, const char* fmt, ...) { return n; } +int gl_printHeight(const glFont* ft_font, const int width, + const char* fmt, ...) { + + char txt[1024]; // Holds the string. + va_list ap; + int p, i, n, len, lastspace; + double x, y; + + if(ft_font == NULL) ft_font = &gl_defFont; + + if(fmt == NULL) return -1; + else { + // Convert the symbols to text. + va_start(ap, fmt); + vsprintf(txt, fmt, ap); + va_end(ap); + } + x = 0.; + y = 0.; + + len = (int) strlen(txt); + // Limit the size per line. + lastspace = -1; // Last ' ' or '\n' in the text. + n = 0; // Current width. + i = 0; // Current position. + p = -1; // Where we last drew up to. + + while(i < len+1) { + n += ft_font->w[(int)txt[i]]; + + if((txt[i] == ' ') || (txt[i] == '\n') || (txt[i] == '\0')) lastspace = i; + + if(((n > width) && (p != lastspace)) || + (txt[i] == '\n') || (txt[i] == '\0')) { + + p = lastspace; + n = 0; + i = lastspace; + y += 1.5*(double)ft_font->h; // Move position down. + } + i++; + } + return (int)y; +} + // ================ // FONT! // ================ diff --git a/src/font.h b/src/font.h index c4206f1..dceb7bb 100644 --- a/src/font.h +++ b/src/font.h @@ -36,3 +36,6 @@ int gl_printText(const glFont* ft_font, const int width, const int height, // Get the width of the text that you wish to print. int gl_printWidth(const glFont* ft_font, const char* fmt, ...); +int gl_printHeight(const glFont* ft_font, const int width, + const char* fmt, ...); +