diff --git a/Kconfig b/Kconfig index 6221326e8f..64417f623d 100644 --- a/Kconfig +++ b/Kconfig @@ -718,7 +718,7 @@ menu "LVGL configuration" config LV_FONT_FMT_TXT_LARGE bool "Enable it if you have fonts with a lot of characters." help - The limit depends on the font size, font face and bpp + The limit depends on the font size, font face and format but with > 10,000 characters if you see issues probably you need to enable it. diff --git a/docs/overview/font.rst b/docs/overview/font.rst index 921a504641..f75caad3d6 100644 --- a/docs/overview/font.rst +++ b/docs/overview/font.rst @@ -13,15 +13,18 @@ For example: lv_style_set_text_font(&my_style, &lv_font_montserrat_28); /*Set a larger font*/ -Fonts have a **bpp (bits per pixel)** property. It shows how many bits -are used to describe a pixel in a font. The value stored for a pixel -determines the pixel's opacity. This way, with higher *bpp*, the edges -of the letter can be smoother. The possible *bpp* values are 1, 2, 4 and -8 (higher values mean better quality). +Fonts have a **format** property. It describes how the glyph draw data is stored. +It has *2* categories: `Legacy simple format` and `Advanced format`. +In the legacy simple format, the font is stored in a simple array of bitmaps. +In the advanced format, the font is stored in a different way like `Vector`, `SVG`, etc. -The *bpp* property also affects the amount of memory needed to store a -font. For example, *bpp = 4* makes a font nearly four times larger -compared to *bpp = 1*. +In the legacy simple format, the value stored for a pixel determines the pixel's opacity. +This way, with higher *bpp (bit per pixel)*, the edges of the letter can be smoother. +The possible *bpp* values are 1, 2, 4 and 8 (higher values mean better quality). + +The *format* property also affects the amount of memory needed to store a +font. For example, *format = LV_FONT_GLYPH_FORMAT_A4* makes a font nearly four times larger +compared to *format = LV_FONT_GLYPH_FORMAT_A1*. Unicode support *************** @@ -382,7 +385,7 @@ To do this, a custom :cpp:type:`lv_font_t` variable needs to be created: dsc_out->box_w = 6; /*Width of the bitmap in [px]*/ dsc_out->ofs_x = 0; /*X offset of the bitmap in [pf]*/ dsc_out->ofs_y = 3; /*Y offset of the bitmap measured from the as line*/ - dsc_out->bpp = 2; /*Bits per pixel: 1/2/4/8*/ + dsc_out->format= LV_FONT_GLYPH_FORMAT_A2; return true; /*true: glyph found; false: glyph was not found*/ } diff --git a/src/draw/lv_draw_label.c b/src/draw/lv_draw_label.c index dfb0640f5a..8f99b2ac2b 100644 --- a/src/draw/lv_draw_label.c +++ b/src/draw/lv_draw_label.c @@ -406,7 +406,7 @@ static void draw_letter(lv_draw_unit_t * draw_unit, lv_draw_glyph_dsc_t * dsc, if(g.resolved_font) { lv_draw_buf_t * draw_buf = NULL; - if(g.bpp < LV_IMGFONT_BPP) { + if(g.format < LV_FONT_GLYPH_FORMAT_IMAGE) { /*Only check draw buf for bitmap glyph*/ draw_buf = lv_draw_buf_reshape(dsc->_draw_buf, 0, g.box_w, g.box_h, LV_STRIDE_AUTO); if(draw_buf == NULL) { @@ -425,10 +425,10 @@ static void draw_letter(lv_draw_unit_t * draw_unit, lv_draw_glyph_dsc_t * dsc, if(dsc->glyph_data == NULL) { dsc->format = LV_DRAW_LETTER_BITMAP_FORMAT_INVALID; } - else if(g.bpp == LV_IMGFONT_BPP) { + else if(g.format == LV_FONT_GLYPH_FORMAT_IMAGE) { dsc->format = LV_DRAW_LETTER_BITMAP_FORMAT_IMAGE; } - else if(g.bpp == LV_VECFONT_BPP) { + else if(g.format == LV_FONT_GLYPH_FORMAT_VECTOR) { dsc->format = LV_DRAW_LETTER_VECTOR_FORMAT; } else { diff --git a/src/font/lv_font.c b/src/font/lv_font.c index 6cbd8e0d1f..6484889f60 100644 --- a/src/font/lv_font.c +++ b/src/font/lv_font.c @@ -102,7 +102,7 @@ bool lv_font_get_glyph_dsc(const lv_font_t * font_p, lv_font_glyph_dsc_t * dsc_o dsc_out->box_h = font_p->line_height; dsc_out->ofs_x = 0; dsc_out->ofs_y = 0; - dsc_out->bpp = 1; + dsc_out->format = LV_FONT_GLYPH_FORMAT_A1; dsc_out->is_placeholder = true; return false; diff --git a/src/font/lv_font.h b/src/font/lv_font.h index 77feee4147..005b1a6bec 100644 --- a/src/font/lv_font.h +++ b/src/font/lv_font.h @@ -40,6 +40,30 @@ extern "C" { * General types *-----------------*/ +/** The font format.*/ +enum _lv_font_glyph_format_t { + LV_FONT_GLYPH_FORMAT_NONE = 0, /**< Maybe not visible*/ + + /**< Legacy simple formats*/ + LV_FONT_GLYPH_FORMAT_A1 = 0x01, /**< 1 bit per pixel*/ + LV_FONT_GLYPH_FORMAT_A2 = 0x02, /**< 2 bit per pixel*/ + LV_FONT_GLYPH_FORMAT_A4 = 0x04, /**< 4 bit per pixel*/ + LV_FONT_GLYPH_FORMAT_A8 = 0x08, /**< 8 bit per pixel*/ + + LV_FONT_GLYPH_FORMAT_IMAGE = 0x09, /**< Image format*/ + + /**< Advanced formats*/ + LV_FONT_GLYPH_FORMAT_VECTOR = 0x0A, /**< Vectorial format*/ + LV_FONT_GLYPH_FORMAT_SVG = 0x0B, /**< SVG format*/ + LV_FONT_GLYPH_FORMAT_CUSTOM = 0xFF, /**< Custom format*/ +}; + +#ifdef DOXYGEN +typedef _lv_font_glyph_format_t lv_font_glyph_format_t; +#else +typedef uint8_t lv_font_glyph_format_t; +#endif /*DOXYGEN*/ + /** Describes the properties of a glyph.*/ typedef struct { const lv_font_t * @@ -49,8 +73,8 @@ typedef struct { uint16_t box_h; /**< Height of the glyph's bounding box*/ int16_t ofs_x; /**< x offset of the bounding box*/ int16_t ofs_y; /**< y offset of the bounding box*/ - uint8_t bpp: 4; /**< Bit-per-pixel: 1, 2, 4, 8*/ - uint8_t is_placeholder: 1; /** Glyph is missing. But placeholder will still be displayed */ + lv_font_glyph_format_t format; /**< Font format of the glyph see @lv_font_glyph_format_t*/ + uint8_t is_placeholder: 1; /**< Glyph is missing. But placeholder will still be displayed*/ uint32_t glyph_index; /**< The index of the glyph in the font file. Used by the font cache*/ lv_cache_entry_t * entry; /**< The cache entry of the glyph draw data. Used by the font cache*/ diff --git a/src/font/lv_font_fmt_txt.c b/src/font/lv_font_fmt_txt.c index c9097949b9..9a168bb9c7 100644 --- a/src/font/lv_font_fmt_txt.c +++ b/src/font/lv_font_fmt_txt.c @@ -204,7 +204,7 @@ bool lv_font_get_glyph_dsc_fmt_txt(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out->box_w = gdsc->box_w; dsc_out->ofs_x = gdsc->ofs_x; dsc_out->ofs_y = gdsc->ofs_y; - dsc_out->bpp = (uint8_t)fdsc->bpp; + dsc_out->format = (uint8_t)fdsc->bpp; dsc_out->is_placeholder = false; if(is_tab) dsc_out->box_w = dsc_out->box_w * 2; diff --git a/src/libs/freetype/lv_freetype_glyph.c b/src/libs/freetype/lv_freetype_glyph.c index 8e93394170..9b48c805d8 100644 --- a/src/libs/freetype/lv_freetype_glyph.c +++ b/src/libs/freetype/lv_freetype_glyph.c @@ -80,12 +80,12 @@ static bool freetype_get_glyph_dsc_cb(const lv_font_t * font, lv_font_glyph_dsc_ LV_ASSERT_NULL(g_dsc); if(unicode_letter < 0x20) { - g_dsc->adv_w = 0; - g_dsc->box_h = 0; - g_dsc->box_w = 0; - g_dsc->ofs_x = 0; - g_dsc->ofs_y = 0; - g_dsc->bpp = 0; + g_dsc->adv_w = 0; + g_dsc->box_h = 0; + g_dsc->box_w = 0; + g_dsc->ofs_x = 0; + g_dsc->ofs_y = 0; + g_dsc->format = LV_FONT_GLYPH_FORMAT_NONE; return true; } @@ -149,7 +149,7 @@ static bool freetype_glyph_create_cb(lv_freetype_glyph_cache_data_t * data, void dsc_out->ofs_x = FT_F26DOT6_TO_INT(glyph->metrics.horiBearingX); /*X offset of the bitmap in [pf]*/ dsc_out->ofs_y = FT_F26DOT6_TO_INT(glyph->metrics.horiBearingY - glyph->metrics.height); /*Y offset of the bitmap measured from the as line*/ - dsc_out->bpp = LV_VECFONT_BPP; /*Bit per pixel: 1/2/4/8*/ + dsc_out->format = LV_FONT_GLYPH_FORMAT_VECTOR; } else if(dsc->render_mode == LV_FREETYPE_FONT_RENDER_MODE_BITMAP) { FT_Bitmap * glyph_bitmap = &face->glyph->bitmap; @@ -160,7 +160,7 @@ static bool freetype_glyph_create_cb(lv_freetype_glyph_cache_data_t * data, void dsc_out->ofs_x = glyph->bitmap_left; /*X offset of the bitmap in [pf]*/ dsc_out->ofs_y = glyph->bitmap_top - dsc_out->box_h; /*Y offset of the bitmap measured from the as line*/ - dsc_out->bpp = 8; /*Bit per pixel: 1/2/4/8*/ + dsc_out->format = LV_FONT_GLYPH_FORMAT_A8; } dsc_out->is_placeholder = glyph_index == 0; diff --git a/src/libs/tiny_ttf/lv_tiny_ttf.c b/src/libs/tiny_ttf/lv_tiny_ttf.c index 7852202735..40e71cf273 100644 --- a/src/libs/tiny_ttf/lv_tiny_ttf.c +++ b/src/libs/tiny_ttf/lv_tiny_ttf.c @@ -194,7 +194,7 @@ static bool ttf_get_glyph_dsc_cb(const lv_font_t * font, lv_font_glyph_dsc_t * d dsc_out->box_h = 0; /*height of the bitmap in [px]*/ dsc_out->ofs_x = 0; /*X offset of the bitmap in [pf]*/ dsc_out->ofs_y = 0; /*Y offset of the bitmap in [pf]*/ - dsc_out->bpp = 0; + dsc_out->format = LV_FONT_GLYPH_FORMAT_NONE; dsc_out->is_placeholder = false; return true; } @@ -220,7 +220,7 @@ static bool ttf_get_glyph_dsc_cb(const lv_font_t * font, lv_font_glyph_dsc_t * d dsc_out->box_h = (y2 - y1 + 1); /*height of the bitmap in [px]*/ dsc_out->ofs_x = x1; /*X offset of the bitmap in [pf]*/ dsc_out->ofs_y = -y2; /*Y offset of the bitmap measured from the as line*/ - dsc_out->bpp = 8; /*Bits per pixel: 1/2/4/8*/ + dsc_out->format = LV_FONT_GLYPH_FORMAT_A8; dsc_out->is_placeholder = false; return true; /*true: glyph found; false: glyph was not found*/ } diff --git a/src/others/imgfont/lv_imgfont.c b/src/others/imgfont/lv_imgfont.c index 5a617ad803..b5bf858ef7 100644 --- a/src/others/imgfont/lv_imgfont.c +++ b/src/others/imgfont/lv_imgfont.c @@ -112,12 +112,12 @@ static bool imgfont_get_glyph_dsc(const lv_font_t * font, lv_font_glyph_dsc_t * } dsc_out->is_placeholder = 0; - dsc_out->adv_w = header.w; - dsc_out->box_w = header.w; - dsc_out->box_h = header.h; - dsc_out->bpp = LV_IMGFONT_BPP; /* is image identifier */ - dsc_out->ofs_x = 0; - dsc_out->ofs_y = offset_y; + dsc_out->adv_w = header.w; + dsc_out->box_w = header.w; + dsc_out->box_h = header.h; + dsc_out->ofs_x = 0; + dsc_out->ofs_y = offset_y; + dsc_out->format = LV_FONT_GLYPH_FORMAT_IMAGE; /* is image identifier */ return true; }