paul@78 | 1 | /* |
paul@78 | 2 | * Common font-related functions. |
paul@78 | 3 | * |
paul@78 | 4 | * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk> |
paul@78 | 5 | * |
paul@78 | 6 | * This program is free software: you can redistribute it and/or modify |
paul@78 | 7 | * it under the terms of the GNU General Public License as published by |
paul@78 | 8 | * the Free Software Foundation, either version 3 of the License, or |
paul@78 | 9 | * (at your option) any later version. |
paul@78 | 10 | * |
paul@78 | 11 | * This program is distributed in the hope that it will be useful, |
paul@78 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@78 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@78 | 14 | * GNU General Public License for more details. |
paul@78 | 15 | * |
paul@78 | 16 | * You should have received a copy of the GNU General Public License |
paul@78 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
paul@78 | 18 | */ |
paul@78 | 19 | |
paul@78 | 20 | #ifndef __FONT_H__ |
paul@78 | 21 | #define __FONT_H__ |
paul@78 | 22 | |
paul@78 | 23 | #include <stdint.h> |
paul@78 | 24 | |
paul@78 | 25 | |
paul@78 | 26 | |
paul@78 | 27 | /* Character definition structure. */ |
paul@78 | 28 | |
paul@78 | 29 | typedef struct |
paul@78 | 30 | { |
paul@78 | 31 | uint8_t width; |
paul@78 | 32 | uint8_t height; |
paul@78 | 33 | uint8_t data[]; |
paul@78 | 34 | |
paul@78 | 35 | } char_definition_t; |
paul@78 | 36 | |
paul@135 | 37 | typedef struct |
paul@135 | 38 | { |
paul@135 | 39 | uint32_t base; |
paul@135 | 40 | uint32_t limit; |
paul@135 | 41 | uint32_t table[]; |
paul@135 | 42 | |
paul@135 | 43 | } font_range_t; |
paul@135 | 44 | |
paul@78 | 45 | /* Font configuration type. */ |
paul@78 | 46 | |
paul@78 | 47 | typedef struct |
paul@78 | 48 | { |
paul@78 | 49 | char_definition_t *chars; |
paul@135 | 50 | font_range_t *range; |
paul@78 | 51 | |
paul@78 | 52 | } font_config_t; |
paul@78 | 53 | |
paul@78 | 54 | |
paul@78 | 55 | |
paul@135 | 56 | /* Initialise a font. |
paul@135 | 57 | |
paul@135 | 58 | Font(<name>, uint8_t *chars, font_range_t *range) |
paul@135 | 59 | */ |
paul@78 | 60 | |
paul@135 | 61 | #define Font(NAME, CHARS, RANGE) \ |
paul@135 | 62 | font_config_t NAME = { \ |
paul@135 | 63 | .chars = (char_definition_t *) (CHARS), \ |
paul@135 | 64 | .range = RANGE}; |
paul@135 | 65 | |
paul@135 | 66 | /* Access functions. */ |
paul@110 | 67 | |
paul@78 | 68 | char_definition_t *get_char_definition(font_config_t *cfg, char c); |
paul@78 | 69 | |
paul@78 | 70 | int write_char(display_config_t *cfg, font_config_t *fcfg, char c, |
paul@78 | 71 | int x, int y, uint8_t colour); |
paul@78 | 72 | |
paul@132 | 73 | void write_string(display_config_t *cfg, font_config_t *fcfg, const char *s, |
paul@132 | 74 | int *x, int *y, uint8_t colour); |
paul@132 | 75 | |
paul@78 | 76 | #endif /* __FONT_H__ */ |