font cache test

This commit is contained in:
Gabor Kiss-Vamosi
2021-03-03 09:22:34 +01:00
parent 122f6c12be
commit 586542ddce
5 changed files with 25 additions and 15 deletions

View File

@@ -18,14 +18,14 @@ static void btnm_event_handler(lv_obj_t * obj, lv_event_t event)
void lv_example_textarea_1(void) void lv_example_textarea_1(void)
{ {
lv_obj_t * ta = lv_textarea_create(lv_scr_act(), NULL); lv_obj_t * ta = lv_textarea_create(lv_scr_act(), NULL);
lv_textarea_set_one_line(ta, true); // lv_textarea_set_one_line(ta, true);
lv_obj_align(ta, NULL, LV_ALIGN_IN_TOP_MID, 0, 10); lv_obj_align(ta, NULL, LV_ALIGN_IN_TOP_MID, 0, 10);
lv_obj_add_state(ta, LV_STATE_FOCUSED); /*To be sure the cursor is visible*/ lv_obj_add_state(ta, LV_STATE_FOCUSED); /*To be sure the cursor is visible*/
static const char * btnm_map[] = {"1", "2", "3", "\n", static const char * btnm_map[] = {"1", "2", "3", "\n",
"4", "5", "6", "\n", "4", "5", "6", "\n",
"7", "8", "9", "\n", "7", "8", "9", "\n",
LV_SYMBOL_BACKSPACE, "0", LV_SYMBOL_NEW_LINE}; LV_SYMBOL_BACKSPACE, "0", LV_SYMBOL_NEW_LINE, ""};
lv_obj_t * btnm = lv_btnmatrix_create(lv_scr_act(), NULL); lv_obj_t * btnm = lv_btnmatrix_create(lv_scr_act(), NULL);
lv_obj_set_size(btnm, 200, 150); lv_obj_set_size(btnm, 200, 150);

View File

@@ -69,7 +69,7 @@ typedef struct _lv_font_struct {
int8_t underline_position; /**< Distance between the top of the underline and base line (< 0 means below the base line)*/ int8_t underline_position; /**< Distance between the top of the underline and base line (< 0 means below the base line)*/
int8_t underline_thickness; /**< Thickness of the underline*/ int8_t underline_thickness; /**< Thickness of the underline*/
void * dsc; /**< Store implementation specific or run_time data or caching here*/ const void * dsc; /**< Store implementation specific or run_time data or caching here*/
#if LV_USE_USER_DATA #if LV_USE_USER_DATA
void * user_data; /**< Custom user data for font. */ void * user_data; /**< Custom user data for font. */
#endif #endif
@@ -137,7 +137,7 @@ LV_FONT_DECLARE(lv_font_montserrat_12)
#endif #endif
#if LV_FONT_MONTSERRAT_14 #if LV_FONT_MONTSERRAT_14
LV_FONT_DECLARE(lv_font_montserrat_14) LV_FONT_DECLARE(const lv_font_montserrat_14)
#endif #endif
#if LV_FONT_MONTSERRAT_16 #if LV_FONT_MONTSERRAT_16

View File

@@ -207,7 +207,7 @@ static uint32_t get_glyph_dsc_id(const lv_font_t * font, uint32_t letter)
lv_font_fmt_txt_dsc_t * fdsc = (lv_font_fmt_txt_dsc_t *) font->dsc; lv_font_fmt_txt_dsc_t * fdsc = (lv_font_fmt_txt_dsc_t *) font->dsc;
/*Check the cache first*/ /*Check the cache first*/
if(letter == fdsc->last_letter) return fdsc->last_glyph_id; if(fdsc->cache && letter == fdsc->cache->last_letter) return fdsc->cache->last_glyph_id;
uint16_t i; uint16_t i;
for(i = 0; i < fdsc->cmap_num; i++) { for(i = 0; i < fdsc->cmap_num; i++) {
@@ -246,13 +246,17 @@ static uint32_t get_glyph_dsc_id(const lv_font_t * font, uint32_t letter)
} }
/*Update the cache*/ /*Update the cache*/
fdsc->last_letter = letter; if(fdsc->cache) {
fdsc->last_glyph_id = glyph_id; fdsc->cache->last_letter = letter;
fdsc->cache->last_glyph_id = glyph_id;
}
return glyph_id; return glyph_id;
} }
fdsc->last_letter = letter; if(fdsc->cache) {
fdsc->last_glyph_id = 0; fdsc->cache->last_letter = letter;
fdsc->cache->last_glyph_id = 0;
}
return 0; return 0;
} }

View File

@@ -150,6 +150,11 @@ typedef enum {
LV_FONT_FMT_TXT_COMPRESSED_NO_PREFILTER = 1, LV_FONT_FMT_TXT_COMPRESSED_NO_PREFILTER = 1,
} lv_font_fmt_txt_bitmap_format_t; } lv_font_fmt_txt_bitmap_format_t;
typedef struct {
uint32_t last_letter;
uint32_t last_glyph_id;
}lv_font_fmt_txt_glyph_cache_t;
/*Describe store additional data for fonts */ /*Describe store additional data for fonts */
typedef struct { typedef struct {
/*The bitmaps of all glyphs*/ /*The bitmaps of all glyphs*/
@@ -187,9 +192,7 @@ typedef struct {
uint16_t bitmap_format : 2; uint16_t bitmap_format : 2;
/*Cache the last letter and is glyph id*/ /*Cache the last letter and is glyph id*/
uint32_t last_letter; lv_font_fmt_txt_glyph_cache_t * cache;
uint32_t last_glyph_id;
} lv_font_fmt_txt_dsc_t; } lv_font_fmt_txt_dsc_t;
/********************** /**********************

View File

@@ -2107,8 +2107,10 @@ static const lv_font_fmt_txt_kern_classes_t kern_classes =
* ALL CUSTOM DATA * ALL CUSTOM DATA
*--------------------*/ *--------------------*/
static lv_font_fmt_txt_glyph_cache_t cache;
/*Store all the custom data of the font*/ /*Store all the custom data of the font*/
static lv_font_fmt_txt_dsc_t font_dsc = { static const lv_font_fmt_txt_dsc_t font_dsc = {
.glyph_bitmap = gylph_bitmap, .glyph_bitmap = gylph_bitmap,
.glyph_dsc = glyph_dsc, .glyph_dsc = glyph_dsc,
.cmaps = cmaps, .cmaps = cmaps,
@@ -2117,7 +2119,8 @@ static lv_font_fmt_txt_dsc_t font_dsc = {
.cmap_num = 2, .cmap_num = 2,
.bpp = 4, .bpp = 4,
.kern_classes = 1, .kern_classes = 1,
.bitmap_format = 0 .bitmap_format = 0,
.cache = &cache
}; };
/*----------------- /*-----------------
@@ -2125,7 +2128,7 @@ static lv_font_fmt_txt_dsc_t font_dsc = {
*----------------*/ *----------------*/
/*Initialize a public general font descriptor*/ /*Initialize a public general font descriptor*/
lv_font_t lv_font_montserrat_14 = { const lv_font_t lv_font_montserrat_14 = {
.get_glyph_dsc = lv_font_get_glyph_dsc_fmt_txt, /*Function pointer to get glyph's data*/ .get_glyph_dsc = lv_font_get_glyph_dsc_fmt_txt, /*Function pointer to get glyph's data*/
.get_glyph_bitmap = lv_font_get_bitmap_fmt_txt, /*Function pointer to get glyph's bitmap*/ .get_glyph_bitmap = lv_font_get_bitmap_fmt_txt, /*Function pointer to get glyph's bitmap*/
.line_height = 16, /*The maximum line height required by the font*/ .line_height = 16, /*The maximum line height required by the font*/