diff --git a/include/tales.h b/include/tales.h index 42249ef..81a2f59 100644 --- a/include/tales.h +++ b/include/tales.h @@ -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. diff --git a/src/tales/text_length.c b/src/tales/text_length.c new file mode 100644 index 0000000..2add43e --- /dev/null +++ b/src/tales/text_length.c @@ -0,0 +1,21 @@ +#include +#include + +/* + 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; +} diff --git a/version b/version index c06f383..1a72b1c 100644 --- a/version +++ b/version @@ -1 +1 @@ -beta-0.9-303 +beta-0.9-305