| 211 | } |
| 212 | |
| 213 | int GetTextLength(const char* str, size_t n, Font* font){ |
| 214 | if(fontState != 1 && fontState != -1) InitializeFonts(); |
| 215 | if(fontState == -1){ |
| 216 | return strlen(str) * 8; |
| 217 | } |
| 218 | |
| 219 | size_t len = 0; |
| 220 | size_t i = 0; |
| 221 | while (*str && i++ < n) { |
| 222 | if(*str == '\n'){ |
| 223 | break; |
| 224 | } else if (*str == ' ') { |
| 225 | len += font->width; |
| 226 | str++; |
| 227 | continue; |
| 228 | } else if (*str == '\t') { |
| 229 | len += font->tabWidth * font->width; |
| 230 | str++; |
| 231 | continue; |
| 232 | } else if (!isprint(*str)) { |
| 233 | str++; |
| 234 | continue; |
| 235 | } |
| 236 | |
| 237 | if(int err = FT_Load_Char(font->face, *str, FT_LOAD_ADVANCE_ONLY)) { |
| 238 | printf("Freetype Error (%d)\n", err); |
| 239 | throw new FontException(FontException::FontRenderError, err); |
| 240 | fontState = 0; |
| 241 | return 0; |
| 242 | } |
| 243 | |
| 244 | len += font->face->glyph->advance.x >> 6; |
| 245 | str++; |
| 246 | } |
| 247 | |
| 248 | return len; |
| 249 | } |
| 250 | |
| 251 | int GetTextLength(const char* str, Font* font){ |
| 252 | return GetTextLength(str, strlen(str), font); |
no test coverage detected