feat(font_glyph_format): refactor draw and font format into lv_font_glyph_format_t
This commit is contained in:
2
Kconfig
2
Kconfig
@@ -718,7 +718,7 @@ menu "LVGL configuration"
|
|||||||
config LV_FONT_FMT_TXT_LARGE
|
config LV_FONT_FMT_TXT_LARGE
|
||||||
bool "Enable it if you have fonts with a lot of characters."
|
bool "Enable it if you have fonts with a lot of characters."
|
||||||
help
|
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
|
but with > 10,000 characters if you see issues probably you
|
||||||
need to enable it.
|
need to enable it.
|
||||||
|
|
||||||
|
|||||||
@@ -13,15 +13,18 @@ For example:
|
|||||||
|
|
||||||
lv_style_set_text_font(&my_style, &lv_font_montserrat_28); /*Set a larger font*/
|
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
|
Fonts have a **format** property. It describes how the glyph draw data is stored.
|
||||||
are used to describe a pixel in a font. The value stored for a pixel
|
It has *2* categories: `Legacy simple format` and `Advanced format`.
|
||||||
determines the pixel's opacity. This way, with higher *bpp*, the edges
|
In the legacy simple format, the font is stored in a simple array of bitmaps.
|
||||||
of the letter can be smoother. The possible *bpp* values are 1, 2, 4 and
|
In the advanced format, the font is stored in a different way like `Vector`, `SVG`, etc.
|
||||||
8 (higher values mean better quality).
|
|
||||||
|
|
||||||
The *bpp* property also affects the amount of memory needed to store a
|
In the legacy simple format, the value stored for a pixel determines the pixel's opacity.
|
||||||
font. For example, *bpp = 4* makes a font nearly four times larger
|
This way, with higher *bpp (bit per pixel)*, the edges of the letter can be smoother.
|
||||||
compared to *bpp = 1*.
|
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
|
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->box_w = 6; /*Width of the bitmap in [px]*/
|
||||||
dsc_out->ofs_x = 0; /*X offset of the bitmap in [pf]*/
|
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->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*/
|
return true; /*true: glyph found; false: glyph was not found*/
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -406,7 +406,7 @@ static void draw_letter(lv_draw_unit_t * draw_unit, lv_draw_glyph_dsc_t * dsc,
|
|||||||
|
|
||||||
if(g.resolved_font) {
|
if(g.resolved_font) {
|
||||||
lv_draw_buf_t * draw_buf = NULL;
|
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*/
|
/*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);
|
draw_buf = lv_draw_buf_reshape(dsc->_draw_buf, 0, g.box_w, g.box_h, LV_STRIDE_AUTO);
|
||||||
if(draw_buf == NULL) {
|
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) {
|
if(dsc->glyph_data == NULL) {
|
||||||
dsc->format = LV_DRAW_LETTER_BITMAP_FORMAT_INVALID;
|
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;
|
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;
|
dsc->format = LV_DRAW_LETTER_VECTOR_FORMAT;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -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->box_h = font_p->line_height;
|
||||||
dsc_out->ofs_x = 0;
|
dsc_out->ofs_x = 0;
|
||||||
dsc_out->ofs_y = 0;
|
dsc_out->ofs_y = 0;
|
||||||
dsc_out->bpp = 1;
|
dsc_out->format = LV_FONT_GLYPH_FORMAT_A1;
|
||||||
dsc_out->is_placeholder = true;
|
dsc_out->is_placeholder = true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -40,6 +40,30 @@ extern "C" {
|
|||||||
* General types
|
* 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.*/
|
/** Describes the properties of a glyph.*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const lv_font_t *
|
const lv_font_t *
|
||||||
@@ -49,8 +73,8 @@ typedef struct {
|
|||||||
uint16_t box_h; /**< Height of the glyph's bounding box*/
|
uint16_t box_h; /**< Height of the glyph's bounding box*/
|
||||||
int16_t ofs_x; /**< x offset of the bounding box*/
|
int16_t ofs_x; /**< x offset of the bounding box*/
|
||||||
int16_t ofs_y; /**< y 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*/
|
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 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*/
|
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*/
|
lv_cache_entry_t * entry; /**< The cache entry of the glyph draw data. Used by the font cache*/
|
||||||
|
|||||||
@@ -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->box_w = gdsc->box_w;
|
||||||
dsc_out->ofs_x = gdsc->ofs_x;
|
dsc_out->ofs_x = gdsc->ofs_x;
|
||||||
dsc_out->ofs_y = gdsc->ofs_y;
|
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;
|
dsc_out->is_placeholder = false;
|
||||||
|
|
||||||
if(is_tab) dsc_out->box_w = dsc_out->box_w * 2;
|
if(is_tab) dsc_out->box_w = dsc_out->box_w * 2;
|
||||||
|
|||||||
@@ -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->box_w = 0;
|
||||||
g_dsc->ofs_x = 0;
|
g_dsc->ofs_x = 0;
|
||||||
g_dsc->ofs_y = 0;
|
g_dsc->ofs_y = 0;
|
||||||
g_dsc->bpp = 0;
|
g_dsc->format = LV_FONT_GLYPH_FORMAT_NONE;
|
||||||
return true;
|
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_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 -
|
dsc_out->ofs_y = FT_F26DOT6_TO_INT(glyph->metrics.horiBearingY -
|
||||||
glyph->metrics.height); /*Y offset of the bitmap measured from the as line*/
|
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) {
|
else if(dsc->render_mode == LV_FREETYPE_FONT_RENDER_MODE_BITMAP) {
|
||||||
FT_Bitmap * glyph_bitmap = &face->glyph->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_x = glyph->bitmap_left; /*X offset of the bitmap in [pf]*/
|
||||||
dsc_out->ofs_y = glyph->bitmap_top -
|
dsc_out->ofs_y = glyph->bitmap_top -
|
||||||
dsc_out->box_h; /*Y offset of the bitmap measured from the as line*/
|
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;
|
dsc_out->is_placeholder = glyph_index == 0;
|
||||||
|
|||||||
@@ -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->box_h = 0; /*height of the bitmap in [px]*/
|
||||||
dsc_out->ofs_x = 0; /*X offset of the bitmap in [pf]*/
|
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->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;
|
dsc_out->is_placeholder = false;
|
||||||
return true;
|
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->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_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->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;
|
dsc_out->is_placeholder = false;
|
||||||
return true; /*true: glyph found; false: glyph was not found*/
|
return true; /*true: glyph found; false: glyph was not found*/
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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->adv_w = header.w;
|
||||||
dsc_out->box_w = header.w;
|
dsc_out->box_w = header.w;
|
||||||
dsc_out->box_h = header.h;
|
dsc_out->box_h = header.h;
|
||||||
dsc_out->bpp = LV_IMGFONT_BPP; /* is image identifier */
|
|
||||||
dsc_out->ofs_x = 0;
|
dsc_out->ofs_x = 0;
|
||||||
dsc_out->ofs_y = offset_y;
|
dsc_out->ofs_y = offset_y;
|
||||||
|
dsc_out->format = LV_FONT_GLYPH_FORMAT_IMAGE; /* is image identifier */
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user