aboutsummaryrefslogtreecommitdiffstats
path: root/src/gdisp/mcufont/mf_encoding.h
diff options
context:
space:
mode:
authorinmarket <andrewh@inmarket.com.au>2013-07-28 17:08:45 +1000
committerinmarket <andrewh@inmarket.com.au>2013-07-28 17:08:45 +1000
commit3977ee687ffff23e49dcac0ea9a7c3e8652248f0 (patch)
treec5be0359998987d29b6be213413c896fe4d6b07f /src/gdisp/mcufont/mf_encoding.h
parentf84bc2a3f6b82b0f05319fd7c609f8b30929d788 (diff)
downloaduGFX-3977ee687ffff23e49dcac0ea9a7c3e8652248f0.tar.gz
uGFX-3977ee687ffff23e49dcac0ea9a7c3e8652248f0.tar.bz2
uGFX-3977ee687ffff23e49dcac0ea9a7c3e8652248f0.zip
First cut - beautiful new font handling by PetteriAimonen
Diffstat (limited to 'src/gdisp/mcufont/mf_encoding.h')
-rw-r--r--src/gdisp/mcufont/mf_encoding.h53
1 files changed, 53 insertions, 0 deletions
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 <stdint.h>
+
+/* 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 <stddef.h>
+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