Merge branch 'feat/font-cache' into dev
This commit is contained in:
@@ -18,7 +18,7 @@ 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*/
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
|
|||||||
@@ -2106,9 +2106,13 @@ static const lv_font_fmt_txt_kern_classes_t kern_classes =
|
|||||||
/*--------------------
|
/*--------------------
|
||||||
* ALL CUSTOM DATA
|
* ALL CUSTOM DATA
|
||||||
*--------------------*/
|
*--------------------*/
|
||||||
|
#if LV_VERSION_CHECK(8, 0, 0)
|
||||||
/*Store all the custom data of the font*/
|
/*Store all the custom data of the font*/
|
||||||
|
static lv_font_fmt_txt_glyph_cache_t cache;
|
||||||
|
static const lv_font_fmt_txt_dsc_t font_dsc = {
|
||||||
|
#else
|
||||||
static lv_font_fmt_txt_dsc_t font_dsc = {
|
static lv_font_fmt_txt_dsc_t font_dsc = {
|
||||||
|
#endif
|
||||||
.glyph_bitmap = gylph_bitmap,
|
.glyph_bitmap = gylph_bitmap,
|
||||||
.glyph_dsc = glyph_dsc,
|
.glyph_dsc = glyph_dsc,
|
||||||
.cmaps = cmaps,
|
.cmaps = cmaps,
|
||||||
@@ -2117,7 +2121,10 @@ 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,
|
||||||
|
#if LV_VERSION_CHECK(8, 0, 0)
|
||||||
|
.cache = &cache
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/*-----------------
|
/*-----------------
|
||||||
@@ -2125,7 +2132,11 @@ static lv_font_fmt_txt_dsc_t font_dsc = {
|
|||||||
*----------------*/
|
*----------------*/
|
||||||
|
|
||||||
/*Initialize a public general font descriptor*/
|
/*Initialize a public general font descriptor*/
|
||||||
|
#if LV_VERSION_CHECK(8, 0, 0)
|
||||||
|
const lv_font_t lv_font_montserrat_14 = {
|
||||||
|
#else
|
||||||
lv_font_t lv_font_montserrat_14 = {
|
lv_font_t lv_font_montserrat_14 = {
|
||||||
|
#endif
|
||||||
.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*/
|
||||||
|
|||||||
Reference in New Issue
Block a user