acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
lv_font.c (3347B)
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 a UNICODE character code 47 * @return pointer to the bitmap of the letter 48 */ 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 a 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 */ 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 68 LV_ASSERT_NULL(font_p); 69 LV_ASSERT_NULL(dsc_out); 70 71 const lv_font_t * placeholder_font = NULL; 72 const lv_font_t * f = font_p; 73 74 dsc_out->resolved_font = NULL; 75 76 while(f) { 77 bool found = f->get_glyph_dsc(f, dsc_out, letter, letter_next); 78 if(found) { 79 if(!dsc_out->is_placeholder) { 80 dsc_out->resolved_font = f; 81 return true; 82 } 83 else if(placeholder_font == NULL) { 84 placeholder_font = f; 85 } 86 } 87 f = f->fallback; 88 } 89 90 if(placeholder_font != NULL) { 91 placeholder_font->get_glyph_dsc(placeholder_font, dsc_out, letter, letter_next); 92 dsc_out->resolved_font = placeholder_font; 93 return true; 94 } 95 96 97 if(letter < 0x20 || 98 letter == 0xf8ff || /*LV_SYMBOL_DUMMY*/ 99 letter == 0x200c) { /*ZERO WIDTH NON-JOINER*/ 100 dsc_out->box_w = 0; 101 dsc_out->adv_w = 0; 102 } 103 else { 104 dsc_out->box_w = font_p->line_height / 2; 105 dsc_out->adv_w = dsc_out->box_w + 2; 106 } 107 108 dsc_out->resolved_font = NULL; 109 dsc_out->box_h = font_p->line_height; 110 dsc_out->ofs_x = 0; 111 dsc_out->ofs_y = 0; 112 dsc_out->bpp = 1; 113 dsc_out->is_placeholder = true; 114 115 return false; 116 } 117 118 /** 119 * Get the width of a glyph with kerning 120 * @param font pointer to a font 121 * @param letter a UNICODE letter 122 * @param letter_next the next letter after `letter`. Used for kerning 123 * @return the width of the glyph 124 */ 125 uint16_t lv_font_get_glyph_width(const lv_font_t * font, uint32_t letter, uint32_t letter_next) 126 { 127 LV_ASSERT_NULL(font); 128 lv_font_glyph_dsc_t g; 129 lv_font_get_glyph_dsc(font, &g, letter, letter_next); 130 return g.adv_w; 131 } 132 133 /********************** 134 * STATIC FUNCTIONS 135 **********************/