1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

Revert "feat(font_glyph_format): refactor draw and font format into lv_font_glyph_format_t" (#5550)

Need to merge the commits separately.
This commit is contained in:
_VIFEXTech 2024-02-01 11:38:51 +08:00 committed by GitHub
parent 84917689da
commit 71e7bd816e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 197 additions and 228 deletions

View File

@ -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 format
The limit depends on the font size, font face and bpp
but with > 10,000 characters if you see issues probably you
need to enable it.

View File

@ -13,18 +13,15 @@ For example:
lv_style_set_text_font(&my_style, &lv_font_montserrat_28); /*Set a larger font*/
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.
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).
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*.
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*.
Unicode support
***************
@ -385,7 +382,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->format= LV_FONT_GLYPH_FORMAT_A2;
dsc_out->bpp = 2; /*Bits per pixel: 1/2/4/8*/
return true; /*true: glyph found; false: glyph was not found*/
}

View File

@ -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(LV_FONT_GLYPH_FORMAT_NONE < g.format && g.format < LV_FONT_GLYPH_FORMAT_IMAGE) {
if(g.bpp < LV_IMGFONT_BPP) {
/*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) {
@ -422,10 +422,21 @@ static void draw_letter(lv_draw_unit_t * draw_unit, lv_draw_glyph_dsc_t * dsc,
}
dsc->glyph_data = (void *)lv_font_get_glyph_bitmap(&g, letter, draw_buf);
dsc->format = dsc->glyph_data ? g.format : LV_FONT_GLYPH_FORMAT_NONE;
if(dsc->glyph_data == NULL) {
dsc->format = LV_DRAW_LETTER_BITMAP_FORMAT_INVALID;
}
else if(g.bpp == LV_IMGFONT_BPP) {
dsc->format = LV_DRAW_LETTER_BITMAP_FORMAT_IMAGE;
}
else if(g.bpp == LV_VECFONT_BPP) {
dsc->format = LV_DRAW_LETTER_VECTOR_FORMAT;
}
else {
dsc->format = LV_FONT_GLYPH_FORMAT_NONE;
dsc->format = LV_DRAW_LETTER_BITMAP_FORMAT_A8;
}
}
else {
dsc->format = LV_DRAW_LETTER_BITMAP_FORMAT_INVALID;
}
dsc->letter_coords = &letter_coords;

View File

@ -72,9 +72,16 @@ typedef struct {
lv_draw_label_hint_t * hint;
} lv_draw_label_dsc_t;
typedef enum {
LV_DRAW_LETTER_BITMAP_FORMAT_INVALID,
LV_DRAW_LETTER_BITMAP_FORMAT_A8,
LV_DRAW_LETTER_BITMAP_FORMAT_IMAGE,
LV_DRAW_LETTER_VECTOR_FORMAT,
} lv_draw_glyph_bitmap_format_t;
typedef struct {
void * glyph_data; /*Depends on `format` field, it could be image source or draw buf of bitmap or vector data.*/
lv_font_glyph_format_t format;
lv_draw_glyph_bitmap_format_t format;
const lv_area_t * letter_coords;
const lv_area_t * bg_coords;
const lv_font_glyph_dsc_t * g;

View File

@ -79,9 +79,7 @@ static void _draw_vglite_letter(lv_draw_unit_t * draw_unit, lv_draw_glyph_dsc_t
lv_draw_fill_dsc_t * fill_draw_dsc, const lv_area_t * fill_area)
{
if(glyph_draw_dsc) {
switch(glyph_draw_dsc->format) {
case LV_FONT_GLYPH_FORMAT_NONE: {
if(glyph_draw_dsc->format == LV_DRAW_LETTER_BITMAP_FORMAT_INVALID) {
#if LV_USE_FONT_PLACEHOLDER
/* Draw a placeholder rectangle*/
lv_draw_border_dsc_t border_draw_dsc;
@ -92,8 +90,7 @@ static void _draw_vglite_letter(lv_draw_unit_t * draw_unit, lv_draw_glyph_dsc_t
lv_draw_vglite_border(draw_unit, &border_draw_dsc, glyph_draw_dsc->bg_coords);
#endif
}
break;
case LV_FONT_GLYPH_FORMAT_A1 ... LV_FONT_GLYPH_FORMAT_A8: {
else if(glyph_draw_dsc->format == LV_DRAW_LETTER_BITMAP_FORMAT_A8) {
/*Do not draw transparent things*/
if(glyph_draw_dsc->opa <= LV_OPA_MIN)
return;
@ -139,8 +136,7 @@ static void _draw_vglite_letter(lv_draw_unit_t * draw_unit, lv_draw_glyph_dsc_t
_vglite_draw_letter(&mask_area, glyph_draw_dsc->color, glyph_draw_dsc->opa);
}
}
break;
case LV_FONT_GLYPH_FORMAT_IMAGE: {
else if(glyph_draw_dsc->format == LV_DRAW_LETTER_BITMAP_FORMAT_IMAGE) {
#if LV_USE_IMGFONT
lv_draw_img_dsc_t img_dsc;
lv_draw_img_dsc_init(&img_dsc);
@ -151,10 +147,6 @@ static void _draw_vglite_letter(lv_draw_unit_t * draw_unit, lv_draw_glyph_dsc_t
lv_draw_vglite_img(draw_unit, &img_dsc, glyph_draw_dsc->letter_coords);
#endif
}
break;
default:
break;
}
}
if(fill_draw_dsc && fill_area) {

View File

@ -63,8 +63,7 @@ static void lv_draw_dave2d_draw_letter_cb(lv_draw_unit_t * u, lv_draw_glyph_dsc_
(d2_border)clip_area.y2);
if(glyph_draw_dsc) {
switch(glyph_draw_dsc->format) {
case LV_FONT_GLYPH_FORMAT_NONE: {
if(glyph_draw_dsc->format == LV_DRAW_LETTER_BITMAP_FORMAT_INVALID) {
#if LV_USE_FONT_PLACEHOLDER
/* Draw a placeholder rectangle*/
lv_draw_border_dsc_t border_draw_dsc;
@ -76,8 +75,7 @@ static void lv_draw_dave2d_draw_letter_cb(lv_draw_unit_t * u, lv_draw_glyph_dsc_
lv_draw_dave2d_border(unit, &border_draw_dsc, glyph_draw_dsc->bg_coords);
#endif
}
break;
case LV_FONT_GLYPH_FORMAT_A1 ... LV_FONT_GLYPH_FORMAT_A8: {
else if(glyph_draw_dsc->format == LV_DRAW_LETTER_BITMAP_FORMAT_A8) {
lv_area_t mask_area = letter_coords;
mask_area.x2 = mask_area.x1 + lv_draw_buf_width_to_stride(lv_area_get_width(&mask_area), LV_COLOR_FORMAT_A8) - 1;
// lv_draw_sw_blend_dsc_t blend_dsc;
@ -121,8 +119,7 @@ static void lv_draw_dave2d_draw_letter_cb(lv_draw_unit_t * u, lv_draw_glyph_dsc_
d2_setfillmode(unit->d2_handle, current_fillmode);
}
break;
case LV_FONT_GLYPH_FORMAT_IMAGE: {
else if(glyph_draw_dsc->format == LV_DRAW_LETTER_BITMAP_FORMAT_IMAGE) {
#if LV_USE_IMGFONT
lv_draw_image_dsc_t img_dsc;
lv_draw_image_dsc_init(&img_dsc);
@ -134,10 +131,6 @@ static void lv_draw_dave2d_draw_letter_cb(lv_draw_unit_t * u, lv_draw_glyph_dsc_
//lv_draw_sw_image(draw_unit, &img_dsc, glyph_draw_dsc->letter_coords);
#endif
}
break;
default:
break;
}
}
//

View File

@ -66,8 +66,7 @@ static void LV_ATTRIBUTE_FAST_MEM draw_letter_cb(lv_draw_unit_t * draw_unit, lv_
lv_draw_fill_dsc_t * fill_draw_dsc, const lv_area_t * fill_area)
{
if(glyph_draw_dsc) {
switch(glyph_draw_dsc->format) {
case LV_FONT_GLYPH_FORMAT_NONE: {
if(glyph_draw_dsc->format == LV_DRAW_LETTER_BITMAP_FORMAT_INVALID) {
#if LV_USE_FONT_PLACEHOLDER
/* Draw a placeholder rectangle*/
lv_draw_border_dsc_t border_draw_dsc;
@ -78,8 +77,7 @@ static void LV_ATTRIBUTE_FAST_MEM draw_letter_cb(lv_draw_unit_t * draw_unit, lv_
lv_draw_sw_border(draw_unit, &border_draw_dsc, glyph_draw_dsc->bg_coords);
#endif
}
break;
case LV_FONT_GLYPH_FORMAT_A1 ... LV_FONT_GLYPH_FORMAT_A8: {
else if(glyph_draw_dsc->format == LV_DRAW_LETTER_BITMAP_FORMAT_A8) {
lv_area_t mask_area = *glyph_draw_dsc->letter_coords;
mask_area.x2 = mask_area.x1 + lv_draw_buf_width_to_stride(lv_area_get_width(&mask_area), LV_COLOR_FORMAT_A8) - 1;
lv_draw_sw_blend_dsc_t blend_dsc;
@ -95,8 +93,7 @@ static void LV_ATTRIBUTE_FAST_MEM draw_letter_cb(lv_draw_unit_t * draw_unit, lv_
lv_draw_sw_blend(draw_unit, &blend_dsc);
}
break;
case LV_FONT_GLYPH_FORMAT_IMAGE: {
else if(glyph_draw_dsc->format == LV_DRAW_LETTER_BITMAP_FORMAT_IMAGE) {
#if LV_USE_IMGFONT
lv_draw_image_dsc_t img_dsc;
lv_draw_image_dsc_init(&img_dsc);
@ -108,11 +105,6 @@ static void LV_ATTRIBUTE_FAST_MEM draw_letter_cb(lv_draw_unit_t * draw_unit, lv_
lv_draw_sw_image(draw_unit, &img_dsc, glyph_draw_dsc->letter_coords);
#endif
}
break;
default:
break;
}
}
if(fill_draw_dsc && fill_area) {

View File

@ -88,14 +88,15 @@ static void draw_letter_cb(lv_draw_unit_t * draw_unit, lv_draw_glyph_dsc_t * gly
{
lv_draw_vg_lite_unit_t * u = (lv_draw_vg_lite_unit_t *)draw_unit;
if(glyph_draw_dsc) {
switch(glyph_draw_dsc->format) {
case LV_FONT_GLYPH_FORMAT_A1 ... LV_FONT_GLYPH_FORMAT_A8: {
case LV_DRAW_LETTER_BITMAP_FORMAT_A8: {
draw_letter_bitmap(u, glyph_draw_dsc);
}
break;
#if LV_USE_FREETYPE
case LV_FONT_GLYPH_FORMAT_VECTOR: {
case LV_DRAW_LETTER_VECTOR_FORMAT: {
if(lv_freetype_is_outline_font(glyph_draw_dsc->g->resolved_font)) {
draw_letter_outline(u, glyph_draw_dsc);
}
@ -103,7 +104,7 @@ static void draw_letter_cb(lv_draw_unit_t * draw_unit, lv_draw_glyph_dsc_t * gly
break;
#endif /* LV_USE_FREETYPE */
case LV_FONT_GLYPH_FORMAT_IMAGE: {
case LV_DRAW_LETTER_BITMAP_FORMAT_IMAGE: {
lv_draw_image_dsc_t img_dsc;
lv_draw_image_dsc_init(&img_dsc);
img_dsc.opa = glyph_draw_dsc->opa;
@ -113,7 +114,7 @@ static void draw_letter_cb(lv_draw_unit_t * draw_unit, lv_draw_glyph_dsc_t * gly
break;
#if LV_USE_FONT_PLACEHOLDER
case LV_FONT_GLYPH_FORMAT_NONE: {
case LV_DRAW_LETTER_BITMAP_FORMAT_INVALID: {
/* Draw a placeholder rectangle*/
lv_draw_border_dsc_t border_draw_dsc;
lv_draw_border_dsc_init(&border_draw_dsc);

View File

@ -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->format = LV_FONT_GLYPH_FORMAT_A1;
dsc_out->bpp = 1;
dsc_out->is_placeholder = true;
return false;

View File

@ -40,30 +40,6 @@ 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 *
@ -73,8 +49,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*/
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*/
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 */
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*/

View File

@ -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->format = (uint8_t)fdsc->bpp;
dsc_out->bpp = (uint8_t)fdsc->bpp;
dsc_out->is_placeholder = false;
if(is_tab) dsc_out->box_w = dsc_out->box_w * 2;

View File

@ -85,7 +85,7 @@ static bool freetype_get_glyph_dsc_cb(const lv_font_t * font, lv_font_glyph_dsc_
g_dsc->box_w = 0;
g_dsc->ofs_x = 0;
g_dsc->ofs_y = 0;
g_dsc->format = LV_FONT_GLYPH_FORMAT_NONE;
g_dsc->bpp = 0;
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->format = LV_FONT_GLYPH_FORMAT_VECTOR;
dsc_out->bpp = LV_VECFONT_BPP; /*Bit per pixel: 1/2/4/8*/
}
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->format = LV_FONT_GLYPH_FORMAT_A8;
dsc_out->bpp = 8; /*Bit per pixel: 1/2/4/8*/
}
dsc_out->is_placeholder = glyph_index == 0;

View File

@ -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->format = LV_FONT_GLYPH_FORMAT_NONE;
dsc_out->bpp = 0;
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->format = LV_FONT_GLYPH_FORMAT_A8;
dsc_out->bpp = 8; /*Bits per pixel: 1/2/4/8*/
dsc_out->is_placeholder = false;
return true; /*true: glyph found; false: glyph was not found*/
}

View File

@ -115,9 +115,9 @@ static bool imgfont_get_glyph_dsc(const lv_font_t * font, lv_font_glyph_dsc_t *
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->format = LV_FONT_GLYPH_FORMAT_IMAGE; /* is image identifier */
return true;
}