1.1 --- a/include/font.h Mon Nov 12 17:55:53 2018 +0100
1.2 +++ b/include/font.h Tue Nov 13 00:02:15 2018 +0100
1.3 @@ -57,4 +57,7 @@
1.4 int write_char(display_config_t *cfg, font_config_t *fcfg, char c,
1.5 int x, int y, uint8_t colour);
1.6
1.7 +void write_string(display_config_t *cfg, font_config_t *fcfg, const char *s,
1.8 + int *x, int *y, uint8_t colour);
1.9 +
1.10 #endif /* __FONT_H__ */
2.1 --- a/lib/font.c Mon Nov 12 17:55:53 2018 +0100
2.2 +++ b/lib/font.c Tue Nov 13 00:02:15 2018 +0100
2.3 @@ -24,6 +24,14 @@
2.4
2.5
2.6
2.7 +/* Space is a special case. */
2.8 +
2.9 +static char_definition_t space = {
2.10 + .width = 3, .height = 9, .data = {0, 0, 0, 0, 0, 0, 0, 0, 0}
2.11 + };
2.12 +
2.13 +
2.14 +
2.15 /* Initialise a font configuration. */
2.16
2.17 void init_font(font_config_t *cfg, uint8_t *chars, uint32_t *table,
2.18 @@ -47,7 +55,7 @@
2.19 if ((c >= fcfg->base) && (c < fcfg->limit))
2.20 return (char_definition_t *) ((uint8_t *) fcfg->chars + fcfg->table[c - fcfg->base]);
2.21 else
2.22 - return NULL;
2.23 + return &space;
2.24 }
2.25
2.26 /* Write a character to the screen, returning the next character position. */
2.27 @@ -61,11 +69,6 @@
2.28 *displayline = cfg->screen_start + y * cfg->line_length,
2.29 bitmap, mask;
2.30
2.31 - /* Space is a special case. */
2.32 -
2.33 - if (c == ' ')
2.34 - return x + 3;
2.35 -
2.36 for (sy = 0, dy = y; (sy < chardef->height) && (dy < cfg->line_count); sy++, dy++)
2.37 {
2.38 if (displayline >= cfg->screen_limit)
2.39 @@ -85,3 +88,26 @@
2.40
2.41 return x + chardef->width;
2.42 }
2.43 +
2.44 +/* Write a string to the screen, updating the coordinates to indicate the next
2.45 + character position. */
2.46 +
2.47 +void write_string(display_config_t *cfg, font_config_t *fcfg, const char *s,
2.48 + int *x, int *y, uint8_t colour)
2.49 +{
2.50 + const int line_height = 9;
2.51 +
2.52 + while (*s)
2.53 + {
2.54 + if (*x + get_char_definition(fcfg, *s)->width > cfg->line_length)
2.55 + {
2.56 + *x = 0; *y += line_height;
2.57 + }
2.58 +
2.59 + if (*y + line_height >= cfg->line_count)
2.60 + break;
2.61 +
2.62 + *x = write_char(cfg, fcfg, *s, *x, *y, colour);
2.63 + s++;
2.64 + }
2.65 +}