mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
feat(font_glyph_format): refactor draw and font format into lv_font_glyph_format_t
(#5540)
This commit is contained in:
parent
b9575fb3b7
commit
84917689da
2
Kconfig
2
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.
|
||||
|
||||
|
@ -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*/
|
||||
}
|
||||
|
@ -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(LV_FONT_GLYPH_FORMAT_NONE < g.format && 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) {
|
||||
@ -422,21 +422,10 @@ 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);
|
||||
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_DRAW_LETTER_BITMAP_FORMAT_A8;
|
||||
}
|
||||
dsc->format = dsc->glyph_data ? g.format : LV_FONT_GLYPH_FORMAT_NONE;
|
||||
}
|
||||
else {
|
||||
dsc->format = LV_DRAW_LETTER_BITMAP_FORMAT_INVALID;
|
||||
dsc->format = LV_FONT_GLYPH_FORMAT_NONE;
|
||||
}
|
||||
|
||||
dsc->letter_coords = &letter_coords;
|
||||
|
@ -72,16 +72,9 @@ 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_draw_glyph_bitmap_format_t format;
|
||||
lv_font_glyph_format_t format;
|
||||
const lv_area_t * letter_coords;
|
||||
const lv_area_t * bg_coords;
|
||||
const lv_font_glyph_dsc_t * g;
|
||||
|
@ -79,73 +79,81 @@ 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) {
|
||||
if(glyph_draw_dsc->format == LV_DRAW_LETTER_BITMAP_FORMAT_INVALID) {
|
||||
switch(glyph_draw_dsc->format) {
|
||||
|
||||
case LV_FONT_GLYPH_FORMAT_NONE: {
|
||||
#if LV_USE_FONT_PLACEHOLDER
|
||||
/* Draw a placeholder rectangle*/
|
||||
lv_draw_border_dsc_t border_draw_dsc;
|
||||
lv_draw_border_dsc_init(&border_draw_dsc);
|
||||
border_draw_dsc.opa = glyph_draw_dsc->opa;
|
||||
border_draw_dsc.color = glyph_draw_dsc->color;
|
||||
border_draw_dsc.width = 1;
|
||||
lv_draw_vglite_border(draw_unit, &border_draw_dsc, glyph_draw_dsc->bg_coords);
|
||||
/* Draw a placeholder rectangle*/
|
||||
lv_draw_border_dsc_t border_draw_dsc;
|
||||
lv_draw_border_dsc_init(&border_draw_dsc);
|
||||
border_draw_dsc.opa = glyph_draw_dsc->opa;
|
||||
border_draw_dsc.color = glyph_draw_dsc->color;
|
||||
border_draw_dsc.width = 1;
|
||||
lv_draw_vglite_border(draw_unit, &border_draw_dsc, glyph_draw_dsc->bg_coords);
|
||||
#endif
|
||||
}
|
||||
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;
|
||||
}
|
||||
break;
|
||||
case LV_FONT_GLYPH_FORMAT_A1 ... LV_FONT_GLYPH_FORMAT_A8: {
|
||||
/*Do not draw transparent things*/
|
||||
if(glyph_draw_dsc->opa <= LV_OPA_MIN)
|
||||
return;
|
||||
|
||||
lv_layer_t * layer = draw_unit->target_layer;
|
||||
lv_layer_t * layer = draw_unit->target_layer;
|
||||
|
||||
lv_area_t blend_area;
|
||||
if(!_lv_area_intersect(&blend_area, glyph_draw_dsc->letter_coords, draw_unit->clip_area))
|
||||
return;
|
||||
lv_area_move(&blend_area, -layer->buf_area.x1, -layer->buf_area.y1);
|
||||
lv_area_t blend_area;
|
||||
if(!_lv_area_intersect(&blend_area, glyph_draw_dsc->letter_coords, draw_unit->clip_area))
|
||||
return;
|
||||
lv_area_move(&blend_area, -layer->buf_area.x1, -layer->buf_area.y1);
|
||||
|
||||
const lv_draw_buf_t * draw_buf = glyph_draw_dsc->glyph_data;
|
||||
const void * mask_buf = draw_buf->data;
|
||||
const lv_draw_buf_t * draw_buf = glyph_draw_dsc->glyph_data;
|
||||
const void * mask_buf = draw_buf->data;
|
||||
|
||||
uint32_t mask_width = lv_area_get_width(glyph_draw_dsc->letter_coords);
|
||||
uint32_t mask_height = lv_area_get_height(glyph_draw_dsc->letter_coords);
|
||||
uint32_t mask_stride = draw_buf->header.stride;
|
||||
uint32_t mask_width = lv_area_get_width(glyph_draw_dsc->letter_coords);
|
||||
uint32_t mask_height = lv_area_get_height(glyph_draw_dsc->letter_coords);
|
||||
uint32_t mask_stride = draw_buf->header.stride;
|
||||
|
||||
lv_area_t mask_area;
|
||||
mask_area.x1 = blend_area.x1 - (glyph_draw_dsc->letter_coords->x1 - layer->buf_area.x1);
|
||||
mask_area.y1 = blend_area.y1 - (glyph_draw_dsc->letter_coords->y1 - layer->buf_area.y1);
|
||||
mask_area.x2 = mask_width - 1;
|
||||
mask_area.y2 = mask_height - 1;
|
||||
lv_area_t mask_area;
|
||||
mask_area.x1 = blend_area.x1 - (glyph_draw_dsc->letter_coords->x1 - layer->buf_area.x1);
|
||||
mask_area.y1 = blend_area.y1 - (glyph_draw_dsc->letter_coords->y1 - layer->buf_area.y1);
|
||||
mask_area.x2 = mask_width - 1;
|
||||
mask_area.y2 = mask_height - 1;
|
||||
|
||||
if(!vglite_buf_aligned(mask_buf, mask_stride, LV_COLOR_FORMAT_A8)) {
|
||||
/* Draw a placeholder rectangle*/
|
||||
lv_draw_border_dsc_t border_draw_dsc;
|
||||
lv_draw_border_dsc_init(&border_draw_dsc);
|
||||
border_draw_dsc.opa = glyph_draw_dsc->opa;
|
||||
border_draw_dsc.color = glyph_draw_dsc->color;
|
||||
border_draw_dsc.width = 1;
|
||||
lv_draw_vglite_border(draw_unit, &border_draw_dsc, glyph_draw_dsc->bg_coords);
|
||||
}
|
||||
else {
|
||||
/* Set src_vgbuf structure. */
|
||||
vglite_set_src_buf(mask_buf, mask_width, mask_height, mask_stride, LV_COLOR_FORMAT_A8);
|
||||
if(!vglite_buf_aligned(mask_buf, mask_stride, LV_COLOR_FORMAT_A8)) {
|
||||
/* Draw a placeholder rectangle*/
|
||||
lv_draw_border_dsc_t border_draw_dsc;
|
||||
lv_draw_border_dsc_init(&border_draw_dsc);
|
||||
border_draw_dsc.opa = glyph_draw_dsc->opa;
|
||||
border_draw_dsc.color = glyph_draw_dsc->color;
|
||||
border_draw_dsc.width = 1;
|
||||
lv_draw_vglite_border(draw_unit, &border_draw_dsc, glyph_draw_dsc->bg_coords);
|
||||
}
|
||||
else {
|
||||
/* Set src_vgbuf structure. */
|
||||
vglite_set_src_buf(mask_buf, mask_width, mask_height, mask_stride, LV_COLOR_FORMAT_A8);
|
||||
|
||||
/* Set vgmatrix. */
|
||||
vglite_set_translation_matrix(&blend_area);
|
||||
/* Set vgmatrix. */
|
||||
vglite_set_translation_matrix(&blend_area);
|
||||
|
||||
lv_draw_buf_invalidate_cache((void *)mask_buf, mask_stride, LV_COLOR_FORMAT_A8, &mask_area);
|
||||
lv_draw_buf_invalidate_cache((void *)mask_buf, mask_stride, LV_COLOR_FORMAT_A8, &mask_area);
|
||||
|
||||
_vglite_draw_letter(&mask_area, glyph_draw_dsc->color, glyph_draw_dsc->opa);
|
||||
}
|
||||
}
|
||||
else if(glyph_draw_dsc->format == LV_DRAW_LETTER_BITMAP_FORMAT_IMAGE) {
|
||||
_vglite_draw_letter(&mask_area, glyph_draw_dsc->color, glyph_draw_dsc->opa);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LV_FONT_GLYPH_FORMAT_IMAGE: {
|
||||
#if LV_USE_IMGFONT
|
||||
lv_draw_img_dsc_t img_dsc;
|
||||
lv_draw_img_dsc_init(&img_dsc);
|
||||
img_dsc.angle = 0;
|
||||
img_dsc.zoom = LV_ZOOM_NONE;
|
||||
img_dsc.opa = glyph_draw_dsc->opa;
|
||||
img_dsc.src = glyph_draw_dsc->glyph_data;
|
||||
lv_draw_vglite_img(draw_unit, &img_dsc, glyph_draw_dsc->letter_coords);
|
||||
lv_draw_img_dsc_t img_dsc;
|
||||
lv_draw_img_dsc_init(&img_dsc);
|
||||
img_dsc.angle = 0;
|
||||
img_dsc.zoom = LV_ZOOM_NONE;
|
||||
img_dsc.opa = glyph_draw_dsc->opa;
|
||||
img_dsc.src = glyph_draw_dsc->glyph_data;
|
||||
lv_draw_vglite_img(draw_unit, &img_dsc, glyph_draw_dsc->letter_coords);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,73 +63,80 @@ 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) {
|
||||
if(glyph_draw_dsc->format == LV_DRAW_LETTER_BITMAP_FORMAT_INVALID) {
|
||||
switch(glyph_draw_dsc->format) {
|
||||
case LV_FONT_GLYPH_FORMAT_NONE: {
|
||||
#if LV_USE_FONT_PLACEHOLDER
|
||||
/* Draw a placeholder rectangle*/
|
||||
lv_draw_border_dsc_t border_draw_dsc;
|
||||
lv_draw_border_dsc_init(&border_draw_dsc);
|
||||
border_draw_dsc.opa = glyph_draw_dsc->opa;
|
||||
border_draw_dsc.color = glyph_draw_dsc->color;
|
||||
border_draw_dsc.width = 1;
|
||||
//lv_draw_sw_border(u, &border_draw_dsc, glyph_draw_dsc->bg_coords);
|
||||
lv_draw_dave2d_border(unit, &border_draw_dsc, glyph_draw_dsc->bg_coords);
|
||||
/* Draw a placeholder rectangle*/
|
||||
lv_draw_border_dsc_t border_draw_dsc;
|
||||
lv_draw_border_dsc_init(&border_draw_dsc);
|
||||
border_draw_dsc.opa = glyph_draw_dsc->opa;
|
||||
border_draw_dsc.color = glyph_draw_dsc->color;
|
||||
border_draw_dsc.width = 1;
|
||||
//lv_draw_sw_border(u, &border_draw_dsc, glyph_draw_dsc->bg_coords);
|
||||
lv_draw_dave2d_border(unit, &border_draw_dsc, glyph_draw_dsc->bg_coords);
|
||||
#endif
|
||||
}
|
||||
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;
|
||||
// lv_memzero(&blend_dsc, sizeof(blend_dsc));
|
||||
// blend_dsc.color = glyph_draw_dsc->color;
|
||||
// blend_dsc.opa = glyph_draw_dsc->opa;
|
||||
// blend_dsc.mask_buf = glyph_draw_dsc->glyph_data;
|
||||
// blend_dsc.mask_area = &mask_area;
|
||||
// blend_dsc.blend_area = glyph_draw_dsc->letter_coords;
|
||||
// blend_dsc.mask_res = LV_DRAW_SW_MASK_RES_CHANGED;
|
||||
//lv_draw_sw_blend(u, &blend_dsc);
|
||||
}
|
||||
break;
|
||||
case LV_FONT_GLYPH_FORMAT_A1 ... LV_FONT_GLYPH_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;
|
||||
// lv_memzero(&blend_dsc, sizeof(blend_dsc));
|
||||
// blend_dsc.color = glyph_draw_dsc->color;
|
||||
// blend_dsc.opa = glyph_draw_dsc->opa;
|
||||
// blend_dsc.mask_buf = glyph_draw_dsc->glyph_data;
|
||||
// blend_dsc.mask_area = &mask_area;
|
||||
// blend_dsc.blend_area = glyph_draw_dsc->letter_coords;
|
||||
// blend_dsc.mask_res = LV_DRAW_SW_MASK_RES_CHANGED;
|
||||
//lv_draw_sw_blend(u, &blend_dsc);
|
||||
|
||||
lv_draw_buf_t * draw_buf = glyph_draw_dsc->glyph_data;
|
||||
lv_draw_buf_t * draw_buf = glyph_draw_dsc->glyph_data;
|
||||
|
||||
#if defined(RENESAS_CORTEX_M85)
|
||||
#if (BSP_CFG_DCACHE_ENABLED)
|
||||
d1_cacheblockflush(unit->d2_handle, 0, draw_buf->data, draw_buf->data_size);
|
||||
d1_cacheblockflush(unit->d2_handle, 0, draw_buf->data, draw_buf->data_size);
|
||||
#endif
|
||||
#endif
|
||||
d2_settexture(unit->d2_handle, (void *)draw_buf->data,
|
||||
(d2_s32)lv_draw_buf_width_to_stride((uint32_t)lv_area_get_width(&letter_coords), LV_COLOR_FORMAT_A8),
|
||||
lv_area_get_width(&letter_coords), lv_area_get_height(&letter_coords), d2_mode_alpha8);
|
||||
d2_settexopparam(unit->d2_handle, d2_cc_red, glyph_draw_dsc->color.red, 0);
|
||||
d2_settexopparam(unit->d2_handle, d2_cc_green, glyph_draw_dsc->color.green, 0);
|
||||
d2_settexopparam(unit->d2_handle, d2_cc_blue, glyph_draw_dsc->color.blue, 0);
|
||||
d2_settexopparam(unit->d2_handle, d2_cc_alpha, glyph_draw_dsc->opa, 0);
|
||||
d2_settexture(unit->d2_handle, (void *)draw_buf->data,
|
||||
(d2_s32)lv_draw_buf_width_to_stride((uint32_t)lv_area_get_width(&letter_coords), LV_COLOR_FORMAT_A8),
|
||||
lv_area_get_width(&letter_coords), lv_area_get_height(&letter_coords), d2_mode_alpha8);
|
||||
d2_settexopparam(unit->d2_handle, d2_cc_red, glyph_draw_dsc->color.red, 0);
|
||||
d2_settexopparam(unit->d2_handle, d2_cc_green, glyph_draw_dsc->color.green, 0);
|
||||
d2_settexopparam(unit->d2_handle, d2_cc_blue, glyph_draw_dsc->color.blue, 0);
|
||||
d2_settexopparam(unit->d2_handle, d2_cc_alpha, glyph_draw_dsc->opa, 0);
|
||||
|
||||
d2_settextureoperation(unit->d2_handle, d2_to_multiply, d2_to_multiply, d2_to_multiply, d2_to_multiply);
|
||||
d2_settextureoperation(unit->d2_handle, d2_to_multiply, d2_to_multiply, d2_to_multiply, d2_to_multiply);
|
||||
|
||||
d2_settexturemapping(unit->d2_handle, D2_FIX4(letter_coords.x1), D2_FIX4(letter_coords.y1), D2_FIX16(0), D2_FIX16(0),
|
||||
D2_FIX16(1), D2_FIX16(0), D2_FIX16(0), D2_FIX16(1));
|
||||
d2_settexturemapping(unit->d2_handle, D2_FIX4(letter_coords.x1), D2_FIX4(letter_coords.y1), D2_FIX16(0), D2_FIX16(0),
|
||||
D2_FIX16(1), D2_FIX16(0), D2_FIX16(0), D2_FIX16(1));
|
||||
|
||||
d2_settexturemode(unit->d2_handle, d2_tm_filter);
|
||||
d2_settexturemode(unit->d2_handle, d2_tm_filter);
|
||||
|
||||
d2_setfillmode(unit->d2_handle, d2_fm_texture);
|
||||
d2_setfillmode(unit->d2_handle, d2_fm_texture);
|
||||
|
||||
d2_renderbox(unit->d2_handle, (d2_point)D2_FIX4(letter_coords.x1),
|
||||
(d2_point)D2_FIX4(letter_coords.y1),
|
||||
(d2_point)D2_FIX4(lv_area_get_width(&letter_coords)),
|
||||
(d2_point)D2_FIX4(lv_area_get_height(&letter_coords)));
|
||||
d2_renderbox(unit->d2_handle, (d2_point)D2_FIX4(letter_coords.x1),
|
||||
(d2_point)D2_FIX4(letter_coords.y1),
|
||||
(d2_point)D2_FIX4(lv_area_get_width(&letter_coords)),
|
||||
(d2_point)D2_FIX4(lv_area_get_height(&letter_coords)));
|
||||
|
||||
d2_setfillmode(unit->d2_handle, current_fillmode);
|
||||
}
|
||||
else if(glyph_draw_dsc->format == LV_DRAW_LETTER_BITMAP_FORMAT_IMAGE) {
|
||||
d2_setfillmode(unit->d2_handle, current_fillmode);
|
||||
}
|
||||
break;
|
||||
case LV_FONT_GLYPH_FORMAT_IMAGE: {
|
||||
#if LV_USE_IMGFONT
|
||||
lv_draw_image_dsc_t img_dsc;
|
||||
lv_draw_image_dsc_init(&img_dsc);
|
||||
img_dsc.rotation = 0;
|
||||
img_dsc.scale_x = LV_SCALE_NONE;
|
||||
img_dsc.scale_y = LV_SCALE_NONE;
|
||||
img_dsc.opa = glyph_draw_dsc->opa;
|
||||
img_dsc.src = glyph_draw_dsc->glyph_data;
|
||||
//lv_draw_sw_image(draw_unit, &img_dsc, glyph_draw_dsc->letter_coords);
|
||||
lv_draw_image_dsc_t img_dsc;
|
||||
lv_draw_image_dsc_init(&img_dsc);
|
||||
img_dsc.rotation = 0;
|
||||
img_dsc.scale_x = LV_SCALE_NONE;
|
||||
img_dsc.scale_y = LV_SCALE_NONE;
|
||||
img_dsc.opa = glyph_draw_dsc->opa;
|
||||
img_dsc.src = glyph_draw_dsc->glyph_data;
|
||||
//lv_draw_sw_image(draw_unit, &img_dsc, glyph_draw_dsc->letter_coords);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,45 +66,53 @@ 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) {
|
||||
if(glyph_draw_dsc->format == LV_DRAW_LETTER_BITMAP_FORMAT_INVALID) {
|
||||
switch(glyph_draw_dsc->format) {
|
||||
case LV_FONT_GLYPH_FORMAT_NONE: {
|
||||
#if LV_USE_FONT_PLACEHOLDER
|
||||
/* Draw a placeholder rectangle*/
|
||||
lv_draw_border_dsc_t border_draw_dsc;
|
||||
lv_draw_border_dsc_init(&border_draw_dsc);
|
||||
border_draw_dsc.opa = glyph_draw_dsc->opa;
|
||||
border_draw_dsc.color = glyph_draw_dsc->color;
|
||||
border_draw_dsc.width = 1;
|
||||
lv_draw_sw_border(draw_unit, &border_draw_dsc, glyph_draw_dsc->bg_coords);
|
||||
/* Draw a placeholder rectangle*/
|
||||
lv_draw_border_dsc_t border_draw_dsc;
|
||||
lv_draw_border_dsc_init(&border_draw_dsc);
|
||||
border_draw_dsc.opa = glyph_draw_dsc->opa;
|
||||
border_draw_dsc.color = glyph_draw_dsc->color;
|
||||
border_draw_dsc.width = 1;
|
||||
lv_draw_sw_border(draw_unit, &border_draw_dsc, glyph_draw_dsc->bg_coords);
|
||||
#endif
|
||||
}
|
||||
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;
|
||||
lv_memzero(&blend_dsc, sizeof(blend_dsc));
|
||||
blend_dsc.color = glyph_draw_dsc->color;
|
||||
blend_dsc.opa = glyph_draw_dsc->opa;
|
||||
lv_draw_buf_t * draw_buf = glyph_draw_dsc->glyph_data;
|
||||
blend_dsc.mask_buf = draw_buf->data;
|
||||
blend_dsc.mask_area = &mask_area;
|
||||
blend_dsc.mask_stride = draw_buf->header.stride;
|
||||
blend_dsc.blend_area = glyph_draw_dsc->letter_coords;
|
||||
blend_dsc.mask_res = LV_DRAW_SW_MASK_RES_CHANGED;
|
||||
}
|
||||
break;
|
||||
case LV_FONT_GLYPH_FORMAT_A1 ... LV_FONT_GLYPH_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;
|
||||
lv_memzero(&blend_dsc, sizeof(blend_dsc));
|
||||
blend_dsc.color = glyph_draw_dsc->color;
|
||||
blend_dsc.opa = glyph_draw_dsc->opa;
|
||||
lv_draw_buf_t * draw_buf = glyph_draw_dsc->glyph_data;
|
||||
blend_dsc.mask_buf = draw_buf->data;
|
||||
blend_dsc.mask_area = &mask_area;
|
||||
blend_dsc.mask_stride = draw_buf->header.stride;
|
||||
blend_dsc.blend_area = glyph_draw_dsc->letter_coords;
|
||||
blend_dsc.mask_res = LV_DRAW_SW_MASK_RES_CHANGED;
|
||||
|
||||
lv_draw_sw_blend(draw_unit, &blend_dsc);
|
||||
}
|
||||
else if(glyph_draw_dsc->format == LV_DRAW_LETTER_BITMAP_FORMAT_IMAGE) {
|
||||
lv_draw_sw_blend(draw_unit, &blend_dsc);
|
||||
}
|
||||
break;
|
||||
case LV_FONT_GLYPH_FORMAT_IMAGE: {
|
||||
#if LV_USE_IMGFONT
|
||||
lv_draw_image_dsc_t img_dsc;
|
||||
lv_draw_image_dsc_init(&img_dsc);
|
||||
img_dsc.rotation = 0;
|
||||
img_dsc.scale_x = LV_SCALE_NONE;
|
||||
img_dsc.scale_y = LV_SCALE_NONE;
|
||||
img_dsc.opa = glyph_draw_dsc->opa;
|
||||
img_dsc.src = glyph_draw_dsc->glyph_data;
|
||||
lv_draw_sw_image(draw_unit, &img_dsc, glyph_draw_dsc->letter_coords);
|
||||
lv_draw_image_dsc_t img_dsc;
|
||||
lv_draw_image_dsc_init(&img_dsc);
|
||||
img_dsc.rotation = 0;
|
||||
img_dsc.scale_x = LV_SCALE_NONE;
|
||||
img_dsc.scale_y = LV_SCALE_NONE;
|
||||
img_dsc.opa = glyph_draw_dsc->opa;
|
||||
img_dsc.src = glyph_draw_dsc->glyph_data;
|
||||
lv_draw_sw_image(draw_unit, &img_dsc, glyph_draw_dsc->letter_coords);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(fill_draw_dsc && fill_area) {
|
||||
|
@ -88,15 +88,14 @@ 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_DRAW_LETTER_BITMAP_FORMAT_A8: {
|
||||
case LV_FONT_GLYPH_FORMAT_A1 ... LV_FONT_GLYPH_FORMAT_A8: {
|
||||
draw_letter_bitmap(u, glyph_draw_dsc);
|
||||
}
|
||||
break;
|
||||
|
||||
#if LV_USE_FREETYPE
|
||||
case LV_DRAW_LETTER_VECTOR_FORMAT: {
|
||||
case LV_FONT_GLYPH_FORMAT_VECTOR: {
|
||||
if(lv_freetype_is_outline_font(glyph_draw_dsc->g->resolved_font)) {
|
||||
draw_letter_outline(u, glyph_draw_dsc);
|
||||
}
|
||||
@ -104,7 +103,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_DRAW_LETTER_BITMAP_FORMAT_IMAGE: {
|
||||
case LV_FONT_GLYPH_FORMAT_IMAGE: {
|
||||
lv_draw_image_dsc_t img_dsc;
|
||||
lv_draw_image_dsc_init(&img_dsc);
|
||||
img_dsc.opa = glyph_draw_dsc->opa;
|
||||
@ -114,7 +113,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_DRAW_LETTER_BITMAP_FORMAT_INVALID: {
|
||||
case LV_FONT_GLYPH_FORMAT_NONE: {
|
||||
/* Draw a placeholder rectangle*/
|
||||
lv_draw_border_dsc_t border_draw_dsc;
|
||||
lv_draw_border_dsc_init(&border_draw_dsc);
|
||||
|
@ -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;
|
||||
|
@ -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*/
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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*/
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user