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 #ifdef LV_CONF_INCLUDE_SIMPLE
17 #include "lv_conf.h"
18 #else
19 #include "../../lv_conf.h"
20 #endif
21 
22 #include <stdint.h>
23 #include <stddef.h>
24 #include <stdbool.h>
25 
26 #include "lv_symbol_def.h"
27 
28 /*********************
29  *      DEFINES
30  *********************/
31 /*Number of fractional digits in the advanced width (`adv_w`) field of `lv_font_glyph_dsc_t`*/
32 #define LV_FONT_WIDTH_FRACT_DIGIT       4
33 
34 #define LV_FONT_KERN_POSITIVE        0
35 #define LV_FONT_KERN_NEGATIVE        1
36 
37 /**********************
38  *      TYPEDEFS
39  **********************/
40 
41 /*------------------
42  * General types
43  *-----------------*/
44 
45 /** Describes the properties of a glyph. */
46 typedef struct
47 {
48     uint16_t adv_w; /**< The glyph needs this space. Draw the next glyph after this width. 8 bit integer, 4 bit fractional */
49     uint8_t box_w;  /**< Width of the glyph's bounding box*/
50     uint8_t box_h;  /**< Height of the glyph's bounding box*/
51     int8_t ofs_x;   /**< x offset of the bounding box*/
52     int8_t ofs_y;  /**< y offset of the bounding box*/
53     uint8_t bpp;   /**< Bit-per-pixel: 1, 2, 4, 8*/
54 }lv_font_glyph_dsc_t;
55 
56 /*Describe the properties of a font*/
57 typedef struct _lv_font_struct
58 {
59     /** Get a glyph's  descriptor from a font*/
60     bool (*get_glyph_dsc)(const struct _lv_font_struct *, lv_font_glyph_dsc_t *, uint32_t letter, uint32_t letter_next);
61 
62     /** Get a glyph's bitmap from a font*/
63     const uint8_t * (*get_glyph_bitmap)(const struct _lv_font_struct *, uint32_t);
64 
65     /*Pointer to the font in a font pack (must have the same line height)*/
66     uint8_t line_height;      /**< The real line height where any text fits*/
67     uint8_t base_line;        /**< Base line measured from the top of the line_height*/
68     void * dsc;               /**< Store implementation specific data here*/
69 #if LV_USE_USER_DATA
70     lv_font_user_data_t user_data; /**< Custom user data for font. */
71 #endif
72 } lv_font_t;
73 
74 /**********************
75  * GLOBAL PROTOTYPES
76  **********************/
77 
78 /**
79  * Return with the bitmap of a font.
80  * @param font_p pointer to a font
81  * @param letter an UNICODE character code
82  * @return  pointer to the bitmap of the letter
83  */
84 const uint8_t * lv_font_get_glyph_bitmap(const lv_font_t * font_p, uint32_t letter);
85 
86 /**
87  * Get the descriptor of a glyph
88  * @param font_p pointer to font
89  * @param dsc_out store the result descriptor here
90  * @param letter an UNICODE letter code
91  * @return true: descriptor is successfully loaded into `dsc_out`.
92  *         false: the letter was not found, no data is loaded to `dsc_out`
93  */
94 bool lv_font_get_glyph_dsc(const lv_font_t * font_p, lv_font_glyph_dsc_t * dsc_out, uint32_t letter, uint32_t letter_next);
95 
96 /**
97  * Get the width of a glyph with kerning
98  * @param font pointer to a font
99  * @param letter an UNICODE letter
100  * @param letter_next the next letter after `letter`. Used for kerning
101  * @return the width of the glyph
102  */
103 uint16_t lv_font_get_glyph_width(const lv_font_t * font, uint32_t letter, uint32_t letter_next);
104 
105 /**
106  * Get the line height of a font. All characters fit into this height
107  * @param font_p pointer to a font
108  * @return the height of a font
109  */
lv_font_get_line_height(const lv_font_t * font_p)110 static inline uint8_t lv_font_get_line_height(const lv_font_t * font_p)
111 {
112     return font_p->line_height;
113 }
114 
115 /**********************
116  *      MACROS
117  **********************/
118 
119 #define LV_FONT_DECLARE(font_name) extern lv_font_t font_name;
120 
121 #if LV_FONT_ROBOTO_12
122 LV_FONT_DECLARE(lv_font_roboto_12)
123 #endif
124 
125 #if LV_FONT_ROBOTO_16
126 LV_FONT_DECLARE(lv_font_roboto_16)
127 #endif
128 
129 #if LV_FONT_ROBOTO_22
130 LV_FONT_DECLARE(lv_font_roboto_22)
131 #endif
132 
133 #if LV_FONT_ROBOTO_28
134 LV_FONT_DECLARE(lv_font_roboto_28)
135 #endif
136 
137 #if LV_FONT_UNSCII_8
138 LV_FONT_DECLARE(lv_font_unscii_8)
139 #endif
140 
141 /*Declare the custom (user defined) fonts*/
142 #ifdef LV_FONT_CUSTOM_DECLARE
143 LV_FONT_CUSTOM_DECLARE
144 #endif
145 
146 #ifdef __cplusplus
147 } /* extern "C" */
148 #endif
149 
150 #endif /*USE_FONT*/
151