aboutsummaryrefslogtreecommitdiffstats
path: root/src/gdisp/mcufont/mf_font.c
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_font.c
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_font.c')
-rw-r--r--src/gdisp/mcufont/mf_font.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/gdisp/mcufont/mf_font.c b/src/gdisp/mcufont/mf_font.c
new file mode 100644
index 00000000..698a3d8e
--- /dev/null
+++ b/src/gdisp/mcufont/mf_font.c
@@ -0,0 +1,77 @@
+#include "mf_font.h"
+#include <stdbool.h>
+
+/* This will be made into a list of included fonts using macro magic. */
+#define MF_INCLUDED_FONTS 0
+
+/* Included fonts begin here */
+#include MF_FONT_FILE_NAME
+/* Include fonts end here */
+
+uint8_t mf_render_character(const struct mf_font_s *font,
+ int16_t x0, int16_t y0,
+ mf_char character,
+ mf_pixel_callback_t callback,
+ void *state)
+{
+ uint8_t width;
+ width = font->render_character(font, x0, y0, character, callback, state);
+
+ if (!width)
+ {
+ width = font->render_character(font, x0, y0, font->fallback_character,
+ callback, state);
+ }
+
+ return width;
+}
+
+uint8_t mf_character_width(const struct mf_font_s *font,
+ mf_char character)
+{
+ uint8_t width;
+ width = font->character_width(font, character);
+
+ if (!width)
+ {
+ width = font->character_width(font, font->fallback_character);
+ }
+
+ return width;
+}
+
+/* Avoids a dependency on libc */
+static bool strequals(const char *a, const char *b)
+{
+ while (*a)
+ {
+ if (*a++ != *b++)
+ return false;
+ }
+ return (!*b);
+}
+
+const struct mf_font_s *mf_find_font(const char *name)
+{
+ const struct mf_font_list_s *f;
+ f = MF_INCLUDED_FONTS;
+
+ while (f)
+ {
+ if (strequals(f->font->full_name, name) ||
+ strequals(f->font->short_name, name))
+ {
+ return f->font;
+ }
+
+ f = f->next;
+ }
+
+ return 0;
+}
+
+const struct mf_font_list_s *mf_get_font_list()
+{
+ return MF_INCLUDED_FONTS;
+}
+