From 3977ee687ffff23e49dcac0ea9a7c3e8652248f0 Mon Sep 17 00:00:00 2001 From: inmarket Date: Sun, 28 Jul 2013 17:08:45 +1000 Subject: First cut - beautiful new font handling by PetteriAimonen --- src/gdisp/mcufont/mf_encoding.h | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/gdisp/mcufont/mf_encoding.h (limited to 'src/gdisp/mcufont/mf_encoding.h') diff --git a/src/gdisp/mcufont/mf_encoding.h b/src/gdisp/mcufont/mf_encoding.h new file mode 100644 index 00000000..e96718b7 --- /dev/null +++ b/src/gdisp/mcufont/mf_encoding.h @@ -0,0 +1,53 @@ +/* Simple UTF-8 decoder. Also implements the much simpler ASCII and UTF16 + * input encodings. + */ + +#ifndef _MF_ENCODING_H_ +#define _MF_ENCODING_H_ + +#include "mf_config.h" +#include + +/* Type used to represent characters internally. */ +#if MF_ENCODING == MF_ENCODING_ASCII +typedef char mf_char; +#else +typedef uint16_t mf_char; +#endif + +/* Type used to represent input strings. */ +#if MF_ENCODING == MF_ENCODING_ASCII +typedef const char * mf_str; +#elif MF_ENCODING == MF_ENCODING_UTF8 +typedef const char * mf_str; +#elif MF_ENCODING == MF_ENCODING_UTF16 +typedef const uint16_t * mf_str; +#elif MF_ENCODING == MF_ENCODING_WCHAR +#include +typedef const wchar_t * mf_str; +#endif + +/* Returns the next character in the string and advances the pointer. + * When the string ends, returns 0 and leaves the pointer at the 0 byte. + * + * str: Pointer to variable holding current location in string. + * Initialize it to the start of the string. + * + * Returns: The next character, as unicode codepoint. + */ +#if MF_ENCODING == MF_ENCODING_UTF8 +MF_EXTERN mf_char mf_getchar(mf_str *str); +#else +static mf_char mf_getchar(mf_str *str) { return *(*str)++; } +#endif + +/* Moves back the pointer to the beginning of the previous character. + * Be careful not to go beyond the start of the string. + */ +#if MF_ENCODING == MF_ENCODING_UTF8 +MF_EXTERN void mf_rewind(mf_str *str); +#else +static void mf_rewind(mf_str *str) { (*str)--; } +#endif + +#endif -- cgit v1.2.3