Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/libs/lvgl/lv_misc/lv_font.h
1476 views
1
/**
2
* @file lv_font.h
3
*
4
*/
5
6
#ifndef LV_FONT_H
7
#define LV_FONT_H
8
9
#ifdef __cplusplus
10
extern "C" {
11
#endif
12
13
14
/*********************
15
* INCLUDES
16
*********************/
17
#ifdef LV_CONF_INCLUDE_SIMPLE
18
#include "lv_conf.h"
19
#else
20
#include "../../lv_conf.h"
21
#endif
22
23
#include <stdint.h>
24
#include <stddef.h>
25
26
#include "lv_symbol_def.h"
27
28
/*********************
29
* DEFINES
30
*********************/
31
32
/**********************
33
* TYPEDEFS
34
**********************/
35
36
typedef struct
37
{
38
uint32_t w_px :8;
39
uint32_t glyph_index :24;
40
} lv_font_glyph_dsc_t;
41
42
typedef struct
43
{
44
uint32_t unicode :21;
45
uint32_t glyph_dsc_index :11;
46
} lv_font_unicode_map_t;
47
48
typedef struct _lv_font_struct
49
{
50
uint32_t unicode_first;
51
uint32_t unicode_last;
52
const uint8_t * glyph_bitmap;
53
const lv_font_glyph_dsc_t * glyph_dsc;
54
const uint32_t * unicode_list;
55
const uint8_t * (*get_bitmap)(const struct _lv_font_struct *,uint32_t); /*Get a glyph's bitmap from a font*/
56
int16_t (*get_width)(const struct _lv_font_struct *,uint32_t); /*Get a glyph's with with a given font*/
57
struct _lv_font_struct * next_page; /*Pointer to a font extension*/
58
uint32_t h_px :8;
59
uint32_t bpp :4; /*Bit per pixel: 1, 2 or 4*/
60
uint32_t monospace :8; /*Fix width (0: normal width)*/
61
uint16_t glyph_cnt; /*Number of glyphs (letters) in the font*/
62
} lv_font_t;
63
64
/**********************
65
* GLOBAL PROTOTYPES
66
**********************/
67
68
/**
69
* Initialize the fonts
70
*/
71
void lv_font_init(void);
72
73
/**
74
* Add a font to an other to extend the character set.
75
* @param child the font to add
76
* @param parent this font will be extended. Using it later will contain the characters from `child`
77
*/
78
void lv_font_add(lv_font_t *child, lv_font_t *parent);
79
80
/**
81
* Remove a font from a character set.
82
* @param child the font to remove
83
* @param parent remove `child` from here
84
*/
85
void lv_font_remove(lv_font_t * child, lv_font_t * parent);
86
87
/**
88
* Tells if font which contains `letter` is monospace or not
89
* @param font_p point to font
90
* @param letter an UNICODE character code
91
* @return true: the letter is monospace; false not monospace
92
*/
93
bool lv_font_is_monospace(const lv_font_t * font_p, uint32_t letter);
94
95
/**
96
* Return with the bitmap of a font.
97
* @param font_p pointer to a font
98
* @param letter an UNICODE character code
99
* @return pointer to the bitmap of the letter
100
*/
101
const uint8_t * lv_font_get_bitmap(const lv_font_t * font_p, uint32_t letter);
102
103
/**
104
* Get the width of a letter in a font. If `monospace` is set then return with it.
105
* @param font_p pointer to a font
106
* @param letter an UNICODE character code
107
* @return the width of a letter
108
*/
109
uint8_t lv_font_get_width(const lv_font_t * font_p, uint32_t letter);
110
111
112
/**
113
* Get the width of the letter without overwriting it with the `monospace` attribute
114
* @param font_p pointer to a font
115
* @param letter an UNICODE character code
116
* @return the width of a letter
117
*/
118
uint8_t lv_font_get_real_width(const lv_font_t * font_p, uint32_t letter);
119
120
/**
121
* Get the height of a font
122
* @param font_p pointer to a font
123
* @return the height of a font
124
*/
125
static inline uint8_t lv_font_get_height(const lv_font_t * font_p)
126
{
127
return font_p->h_px;
128
}
129
130
/**
131
* Get the bit-per-pixel of font
132
* @param font pointer to font
133
* @param letter a letter from font (font extensions can have different bpp)
134
* @return bpp of the font (or font extension)
135
*/
136
uint8_t lv_font_get_bpp(const lv_font_t * font, uint32_t letter);
137
138
/**
139
* Generic bitmap get function used in 'font->get_bitmap' when the font contains all characters in the range
140
* @param font pointer to font
141
* @param unicode_letter an unicode letter which bitmap should be get
142
* @return pointer to the bitmap or NULL if not found
143
*/
144
const uint8_t * lv_font_get_bitmap_continuous(const lv_font_t * font, uint32_t unicode_letter);
145
146
/**
147
* Generic bitmap get function used in 'font->get_bitmap' when the font NOT contains all characters in the range (sparse)
148
* @param font pointer to font
149
* @param unicode_letter an unicode letter which bitmap should be get
150
* @return pointer to the bitmap or NULL if not found
151
*/
152
const uint8_t * lv_font_get_bitmap_sparse(const lv_font_t * font, uint32_t unicode_letter);
153
/**
154
* Generic glyph width get function used in 'font->get_width' when the font contains all characters in the range
155
* @param font pointer to font
156
* @param unicode_letter an unicode letter which width should be get
157
* @return width of the gylph or -1 if not found
158
*/
159
int16_t lv_font_get_width_continuous(const lv_font_t * font, uint32_t unicode_letter);
160
161
/**
162
* Generic glyph width get function used in 'font->get_bitmap' when the font NOT contains all characters in the range (sparse)
163
* @param font pointer to font
164
* @param unicode_letter an unicode letter which width should be get
165
* @return width of the glyph or -1 if not found
166
*/
167
int16_t lv_font_get_width_sparse(const lv_font_t * font, uint32_t unicode_letter);
168
169
/**********************
170
* MACROS
171
**********************/
172
173
#define LV_FONT_DECLARE(font_name) extern lv_font_t font_name;
174
175
176
/**********************
177
* ADD BUILT IN FONTS
178
**********************/
179
#include "../lv_fonts/lv_font_builtin.h"
180
181
/*Declare the custom (user defined) fonts*/
182
#ifdef LV_FONT_CUSTOM_DECLARE
183
LV_FONT_CUSTOM_DECLARE
184
#endif
185
186
#ifdef __cplusplus
187
} /* extern "C" */
188
#endif
189
190
#endif /*USE_FONT*/
191
192
193