µGFX  2.9
version 2.9
mf_font.c
1 /*
2  * This file is subject to the terms of the GFX License. If a copy of
3  * the license was not distributed with this file, you can obtain one at:
4  *
5  * http://ugfx.io/license.html
6  */
7 
8 #include "mf_config.h"
9 
10 #ifndef MF_NO_COMPILE
11 
12 #define MF_BWFONT_INTERNALS
13 #define MF_RLEFONT_INTERNALS
14 #define MF_SCALEDFONT_INTERNALS
15 #include "mf_font.h"
16 #include "mf_rlefont.h"
17 #include "mf_bwfont.h"
18 #include "mf_scaledfont.h"
19 
20 #include <stdbool.h>
21 
22 /* This will be made into a list of included fonts using macro magic. */
23 #define MF_INCLUDED_FONTS 0
24 
25 /* Included fonts begin here */
26 #include MF_FONT_FILE_NAME
27 /* Include fonts end here */
28 
29 gU8 mf_render_character(const struct mf_font_s *font,
30  gI16 x0, gI16 y0,
31  mf_char character,
32  mf_pixel_callback_t callback,
33  void *state)
34 {
35  gU8 width;
36  width = font->render_character(font, x0, y0, MFCHAR2UINT16(character), callback, state);
37 
38  if (!width)
39  {
40  width = font->render_character(font, x0, y0, font->fallback_character,
41  callback, state);
42  }
43 
44  return width;
45 }
46 
47 gU8 mf_character_width(const struct mf_font_s *font,
48  mf_char character)
49 {
50  gU8 width;
51  width = font->character_width(font, MFCHAR2UINT16(character));
52 
53  if (!width)
54  {
55  width = font->character_width(font, font->fallback_character);
56  }
57 
58  return width;
59 }
60 
61 /* Avoids a dependency on libc */
62 static bool strequals(const char *a, const char *b)
63 {
64  while (*a)
65  {
66  if (*a++ != *b++)
67  return false;
68  }
69  return (!*b);
70 }
71 
72 const struct mf_font_s *mf_find_font(const char *name)
73 {
74  const struct mf_font_list_s *f;
75  f = MF_INCLUDED_FONTS;
76 
77  while (f)
78  {
79  if (strequals(f->font->full_name, name) ||
80  strequals(f->font->short_name, name))
81  {
82  return f->font;
83  }
84 
85  f = f->next;
86  }
87 
88  return 0;
89 }
90 
91 const struct mf_font_list_s *mf_get_font_list()
92 {
93  return MF_INCLUDED_FONTS;
94 }
95 
96 #endif //MF_NO_COMPILE
97