Added a text_length() function.

This commit is contained in:
lephe 2017-04-17 13:39:28 +02:00
parent 34588147d8
commit 6c0ae34708
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