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  *      INCLUDES
15  *********************/
16 #include "../lv_conf_internal.h"
17 #include <stdint.h>
18 #include <stddef.h>
19 #include <stdbool.h>
20 
21 #include "lv_symbol_def.h"
22 #include "../lv_misc/lv_area.h"
23 
24 /*********************
25  *      DEFINES
26  *********************/
27 /*Number of fractional digits in the advanced width (`adv_w`) field of `lv_font_glyph_dsc_t`*/
28 #define LV_FONT_WIDTH_FRACT_DIGIT       4
29 
30 #define LV_FONT_KERN_POSITIVE        0
31 #define LV_FONT_KERN_NEGATIVE        1
32 
33 /**********************
34  *      TYPEDEFS
35  **********************/
36 
37 /*------------------
38  * General types
39  *-----------------*/
40 
41 /** Describes the properties of a glyph. */
42 typedef struct {
43     uint16_t adv_w; /**< The glyph needs this space. Draw the next glyph after this width. 8 bit integer, 4 bit fractional */
44     uint16_t box_w;  /**< Width of the glyph's bounding box*/
45     uint16_t box_h;  /**< Height of the glyph's bounding box*/
46     int16_t ofs_x;   /**< x offset of the bounding box*/
47     int16_t ofs_y;  /**< y offset of the bounding box*/
48     uint8_t bpp;   /**< Bit-per-pixel: 1, 2, 4, 8*/
49 } lv_font_glyph_dsc_t;
50 
51 
52 /** The bitmaps might be upscaled by 3 to achieve subpixel rendering. */
53 enum {
54     LV_FONT_SUBPX_NONE,
55     LV_FONT_SUBPX_HOR,
56     LV_FONT_SUBPX_VER,
57     LV_FONT_SUBPX_BOTH,
58 };
59 
60 typedef uint8_t lv_font_subpx_t;
61 
62 /** Describe the properties of a font*/
63 typedef struct _lv_font_struct {
64     /** Get a glyph's  descriptor from a font*/
65     bool (*get_glyph_dsc)(const struct _lv_font_struct *, lv_font_glyph_dsc_t *, uint32_t letter, uint32_t letter_next);
66 
67     /** Get a glyph's bitmap from a font*/
68     const uint8_t * (*get_glyph_bitmap)(const struct _lv_font_struct *, uint32_t);
69 
70     /*Pointer to the font in a font pack (must have the same line height)*/
71     lv_coord_t line_height;         /**< The real line height where any text fits*/
72     lv_coord_t base_line;           /**< Base line measured from the top of the line_height*/
73     uint8_t subpx  : 2;             /**< An element of `lv_font_subpx_t`*/
74 
75     int8_t underline_position;      /**< Distance between the top of the underline and base line (< 0 means below the base line)*/
76     int8_t  underline_thickness;     /**< Thickness of the underline*/
77 
78     void * dsc;                     /**< Store implementation specific or run_time data or caching here*/
79 #if LV_USE_USER_DATA
80     lv_font_user_data_t user_data;  /**< Custom user data for font. */
81 #endif
82 
83 
84 } lv_font_t;
85 
86 /**********************
87  * GLOBAL PROTOTYPES
88  **********************/
89 
90 /**
91  * Return with the bitmap of a font.
92  * @param font_p pointer to a font
93  * @param letter an UNICODE character code
94  * @return  pointer to the bitmap of the letter
95  */
96 const uint8_t * lv_font_get_glyph_bitmap(const lv_font_t * font_p, uint32_t letter);
97 
98 /**
99  * Get the descriptor of a glyph
100  * @param font_p pointer to font
101  * @param dsc_out store the result descriptor here
102  * @param letter an UNICODE letter code
103  * @return true: descriptor is successfully loaded into `dsc_out`.
104  *         false: the letter was not found, no data is loaded to `dsc_out`
105  */
106 bool lv_font_get_glyph_dsc(const lv_font_t * font_p, lv_font_glyph_dsc_t * dsc_out, uint32_t letter,
107                            uint32_t letter_next);
108 
109 /**
110  * Get the width of a glyph with kerning
111  * @param font pointer to a font
112  * @param letter an UNICODE letter
113  * @param letter_next the next letter after `letter`. Used for kerning
114  * @return the width of the glyph
115  */
116 uint16_t lv_font_get_glyph_width(const lv_font_t * font, uint32_t letter, uint32_t letter_next);
117 
118 /**
119  * Get the line height of a font. All characters fit into this height
120  * @param font_p pointer to a font
121  * @return the height of a font
122  */
lv_font_get_line_height(const lv_font_t * font_p)123 static inline lv_coord_t lv_font_get_line_height(const lv_font_t * font_p)
124 {
125     return font_p->line_height;
126 }
127 
128 /**********************
129  *      MACROS
130  **********************/
131 
132 #define LV_FONT_DECLARE(font_name) extern lv_font_t font_name;
133 
134 #if LV_FONT_MONTSERRAT_8
135 LV_FONT_DECLARE(lv_font_montserrat_8)
136 #endif
137 
138 #if LV_FONT_MONTSERRAT_10
139 LV_FONT_DECLARE(lv_font_montserrat_10)
140 #endif
141 
142 #if LV_FONT_MONTSERRAT_12
143 LV_FONT_DECLARE(lv_font_montserrat_12)
144 #endif
145 
146 #if LV_FONT_MONTSERRAT_14
147 LV_FONT_DECLARE(lv_font_montserrat_14)
148 #endif
149 
150 #if LV_FONT_MONTSERRAT_16
151 LV_FONT_DECLARE(lv_font_montserrat_16)
152 #endif
153 
154 #if LV_FONT_MONTSERRAT_18
155 LV_FONT_DECLARE(lv_font_montserrat_18)
156 #endif
157 
158 #if LV_FONT_MONTSERRAT_20
159 LV_FONT_DECLARE(lv_font_montserrat_20)
160 #endif
161 
162 #if LV_FONT_MONTSERRAT_22
163 LV_FONT_DECLARE(lv_font_montserrat_22)
164 #endif
165 
166 #if LV_FONT_MONTSERRAT_24
167 LV_FONT_DECLARE(lv_font_montserrat_24)
168 #endif
169 
170 #if LV_FONT_MONTSERRAT_26
171 LV_FONT_DECLARE(lv_font_montserrat_26)
172 #endif
173 
174 #if LV_FONT_MONTSERRAT_28
175 LV_FONT_DECLARE(lv_font_montserrat_28)
176 #endif
177 
178 #if LV_FONT_MONTSERRAT_30
179 LV_FONT_DECLARE(lv_font_montserrat_30)
180 #endif
181 
182 #if LV_FONT_MONTSERRAT_32
183 LV_FONT_DECLARE(lv_font_montserrat_32)
184 #endif
185 
186 #if LV_FONT_MONTSERRAT_34
187 LV_FONT_DECLARE(lv_font_montserrat_34)
188 #endif
189 
190 #if LV_FONT_MONTSERRAT_36
191 LV_FONT_DECLARE(lv_font_montserrat_36)
192 #endif
193 
194 #if LV_FONT_MONTSERRAT_38
195 LV_FONT_DECLARE(lv_font_montserrat_38)
196 #endif
197 
198 #if LV_FONT_MONTSERRAT_40
199 LV_FONT_DECLARE(lv_font_montserrat_40)
200 #endif
201 
202 #if LV_FONT_MONTSERRAT_42
203 LV_FONT_DECLARE(lv_font_montserrat_42)
204 #endif
205 
206 #if LV_FONT_MONTSERRAT_44
207 LV_FONT_DECLARE(lv_font_montserrat_44)
208 #endif
209 
210 #if LV_FONT_MONTSERRAT_46
211 LV_FONT_DECLARE(lv_font_montserrat_46)
212 #endif
213 
214 #if LV_FONT_MONTSERRAT_48
215 LV_FONT_DECLARE(lv_font_montserrat_48)
216 #endif
217 
218 #if LV_FONT_MONTSERRAT_28_COMPRESSED
219 LV_FONT_DECLARE(lv_font_montserrat_28_compressed)
220 #endif
221 
222 #if LV_FONT_MONTSERRAT_12_SUBPX
223 LV_FONT_DECLARE(lv_font_montserrat_12_subpx)
224 #endif
225 
226 #if LV_FONT_UNSCII_8
227 LV_FONT_DECLARE(lv_font_unscii_8)
228 #endif
229 
230 #if LV_FONT_DEJAVU_16_PERSIAN_HEBREW
231 LV_FONT_DECLARE(lv_font_dejavu_16_persian_hebrew)
232 #endif
233 
234 #if LV_FONT_SIMSUN_16_CJK
235 LV_FONT_DECLARE(lv_font_simsun_16_cjk)
236 #endif
237 
238 /*Declare the custom (user defined) fonts*/
239 #ifdef LV_FONT_CUSTOM_DECLARE
240 LV_FONT_CUSTOM_DECLARE
241 #endif
242 
243 #ifdef __cplusplus
244 } /* extern "C" */
245 #endif
246 
247 #endif /*USE_FONT*/
248