1 /**
2 * @file lv_font.c
3 *
4 */
5
6 /*********************
7 * INCLUDES
8 *********************/
9
10 #include "lv_font.h"
11 #include "../misc/lv_utils.h"
12 #include "../misc/lv_log.h"
13 #include "../misc/lv_assert.h"
14
15 /*********************
16 * DEFINES
17 *********************/
18
19 /**********************
20 * TYPEDEFS
21 **********************/
22
23 /**********************
24 * STATIC PROTOTYPES
25 **********************/
26
27 /**********************
28 * STATIC VARIABLES
29 **********************/
30
31 /**********************
32 * GLOBAL PROTOTYPES
33 **********************/
34
35 /**********************
36 * MACROS
37 **********************/
38
39 /**********************
40 * GLOBAL FUNCTIONS
41 **********************/
42
43 /**
44 * Return with the bitmap of a font.
45 * @param font_p pointer to a font
46 * @param letter an UNICODE character code
47 * @return pointer to the bitmap of the letter
48 */
lv_font_get_glyph_bitmap(const lv_font_t * font_p,uint32_t letter)49 const uint8_t * lv_font_get_glyph_bitmap(const lv_font_t * font_p, uint32_t letter)
50 {
51 LV_ASSERT_NULL(font_p);
52 return font_p->get_glyph_bitmap(font_p, letter);
53 }
54
55 /**
56 * Get the descriptor of a glyph
57 * @param font_p pointer to font
58 * @param dsc_out store the result descriptor here
59 * @param letter an UNICODE letter code
60 * @param letter_next the next letter after `letter`. Used for kerning
61 * @return true: descriptor is successfully loaded into `dsc_out`.
62 * false: the letter was not found, no data is loaded to `dsc_out`
63 */
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)64 bool lv_font_get_glyph_dsc(const lv_font_t * font_p, lv_font_glyph_dsc_t * dsc_out, uint32_t letter,
65 uint32_t letter_next)
66 {
67 LV_ASSERT_NULL(font_p);
68 LV_ASSERT_NULL(dsc_out);
69 dsc_out->resolved_font = NULL;
70 const lv_font_t * f = font_p;
71 bool found = false;
72 while(f) {
73 found = f->get_glyph_dsc(f, dsc_out, letter, letter_next);
74 if(found && !dsc_out->is_placeholder) {
75 dsc_out->resolved_font = f;
76 break;
77 }
78 f = f->fallback;
79 }
80 return found;
81 }
82
83 /**
84 * Get the width of a glyph with kerning
85 * @param font pointer to a font
86 * @param letter an UNICODE letter
87 * @param letter_next the next letter after `letter`. Used for kerning
88 * @return the width of the glyph
89 */
lv_font_get_glyph_width(const lv_font_t * font,uint32_t letter,uint32_t letter_next)90 uint16_t lv_font_get_glyph_width(const lv_font_t * font, uint32_t letter, uint32_t letter_next)
91 {
92 LV_ASSERT_NULL(font);
93 lv_font_glyph_dsc_t g;
94 bool ret;
95 ret = lv_font_get_glyph_dsc(font, &g, letter, letter_next);
96 if(ret) return g.adv_w;
97 else return 0;
98 }
99
100 /**********************
101 * STATIC FUNCTIONS
102 **********************/
103