Added a text_length() function.

This commit is contained in:
lephe 2017-04-17 13:39:28 +02:00
parent a50ae4f38a
commit 8965590b12
3 changed files with 28 additions and 1 deletions

View file

@ -97,6 +97,12 @@ typedef struct Font Font;
*/
void text_configure(struct Font *font, color_t operator);
/*
text_length()
Computes the length of a string using the currently configured font.
*/
size_t text_length(const char *str);
/*
dtext()
Prints the given string, without any analysis.

21
src/tales/text_length.c Normal file
View file

@ -0,0 +1,21 @@
#include <internals/tales.h>
#include <tales.h>
/*
text_length()
Computes the length of a string using the currently configured font.
*/
size_t text_length(const char *str)
{
if(!str) return 0;
size_t len = 0;
while(*str)
{
int index = getCharacterIndex(*str);
len += font->glyphs[index] >> 24;
if(*++str) len++;
}
return len;
}

View file

@ -1 +1 @@
beta-0.9-303
beta-0.9-305