diff --git a/examples/widgets/textarea/lv_example_textarea_1.c b/examples/widgets/textarea/lv_example_textarea_1.c index 7ced95953..353144061 100644 --- a/examples/widgets/textarea/lv_example_textarea_1.c +++ b/examples/widgets/textarea/lv_example_textarea_1.c @@ -18,7 +18,7 @@ static void btnm_event_handler(lv_obj_t * obj, lv_event_t event) void lv_example_textarea_1(void) { 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_add_state(ta, LV_STATE_FOCUSED); /*To be sure the cursor is visible*/ diff --git a/src/lv_font/lv_font.h b/src/lv_font/lv_font.h index 0376c58b4..a9bfba1ac 100644 --- a/src/lv_font/lv_font.h +++ b/src/lv_font/lv_font.h @@ -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_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 void * user_data; /**< Custom user data for font. */ #endif @@ -137,7 +137,7 @@ LV_FONT_DECLARE(lv_font_montserrat_12) #endif #if LV_FONT_MONTSERRAT_14 -LV_FONT_DECLARE(lv_font_montserrat_14) +LV_FONT_DECLARE(const lv_font_montserrat_14) #endif #if LV_FONT_MONTSERRAT_16 diff --git a/src/lv_font/lv_font_fmt_txt.c b/src/lv_font/lv_font_fmt_txt.c index 64fb35d25..2502a3875 100644 --- a/src/lv_font/lv_font_fmt_txt.c +++ b/src/lv_font/lv_font_fmt_txt.c @@ -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; /*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; 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*/ - fdsc->last_letter = letter; - fdsc->last_glyph_id = glyph_id; + if(fdsc->cache) { + fdsc->cache->last_letter = letter; + fdsc->cache->last_glyph_id = glyph_id; + } return glyph_id; } - fdsc->last_letter = letter; - fdsc->last_glyph_id = 0; + if(fdsc->cache) { + fdsc->cache->last_letter = letter; + fdsc->cache->last_glyph_id = 0; + } return 0; } diff --git a/src/lv_font/lv_font_fmt_txt.h b/src/lv_font/lv_font_fmt_txt.h index 1660dc1a2..76056841c 100644 --- a/src/lv_font/lv_font_fmt_txt.h +++ b/src/lv_font/lv_font_fmt_txt.h @@ -150,6 +150,11 @@ typedef enum { LV_FONT_FMT_TXT_COMPRESSED_NO_PREFILTER = 1, } 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 */ typedef struct { /*The bitmaps of all glyphs*/ @@ -187,9 +192,7 @@ typedef struct { uint16_t bitmap_format : 2; /*Cache the last letter and is glyph id*/ - uint32_t last_letter; - uint32_t last_glyph_id; - + lv_font_fmt_txt_glyph_cache_t * cache; } lv_font_fmt_txt_dsc_t; /********************** diff --git a/src/lv_font/lv_font_montserrat_14.c b/src/lv_font/lv_font_montserrat_14.c index 095073323..4ad95b217 100644 --- a/src/lv_font/lv_font_montserrat_14.c +++ b/src/lv_font/lv_font_montserrat_14.c @@ -2106,9 +2106,13 @@ static const lv_font_fmt_txt_kern_classes_t kern_classes = /*-------------------- * ALL CUSTOM DATA *--------------------*/ - +#if LV_VERSION_CHECK(8, 0, 0) /*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 = { +#endif .glyph_bitmap = gylph_bitmap, .glyph_dsc = glyph_dsc, .cmaps = cmaps, @@ -2117,7 +2121,10 @@ static lv_font_fmt_txt_dsc_t font_dsc = { .cmap_num = 2, .bpp = 4, .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*/ +#if LV_VERSION_CHECK(8, 0, 0) +const lv_font_t lv_font_montserrat_14 = { +#else 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_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*/