MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / GetTextLength

Function GetTextLength

LibLemon/src/gfx/text.cpp:213–249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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);

Callers 9

mainFunction · 0.85
mainFunction · 0.85
CalculateSizesMethod · 0.85
OnMouseDownMethod · 0.85
DisplayMessageBoxFunction · 0.85
ButtonMethod · 0.85
PaintMethod · 0.85
PaintMethod · 0.85
OnTaskbarPaintFunction · 0.85

Calls 2

InitializeFontsFunction · 0.85
strlenFunction · 0.85

Tested by

no test coverage detected