feat(font): add font placeholder drawing configuration (#3446)
* feat(font): add font placeholder drawing configuration * Turn on placeholder by default in Kconfig Signed-off-by: pengyiqiang <pengyiqiang@xiaomi.com> * When disabled LV_USE_FONT_PLACEHOLDER set box_w=0 * Remove placeholder_font to get glyphs Signed-off-by: pengyiqiang <pengyiqiang@xiaomi.com> Co-authored-by: pengyiqiang <pengyiqiang@xiaomi.com>
This commit is contained in:
4
Kconfig
4
Kconfig
@@ -655,6 +655,10 @@ menu "LVGL configuration"
|
|||||||
Set the pixel order of the display.
|
Set the pixel order of the display.
|
||||||
Important only if "subpx fonts" are used.
|
Important only if "subpx fonts" are used.
|
||||||
With "normal" font it doesn't matter.
|
With "normal" font it doesn't matter.
|
||||||
|
|
||||||
|
config LV_USE_FONT_PLACEHOLDER
|
||||||
|
bool "Enable drawing placeholders when glyph dsc is not found."
|
||||||
|
default y
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
menu "Text Settings"
|
menu "Text Settings"
|
||||||
|
|||||||
@@ -405,6 +405,9 @@
|
|||||||
#define LV_FONT_SUBPX_BGR 0 /*0: RGB; 1:BGR order*/
|
#define LV_FONT_SUBPX_BGR 0 /*0: RGB; 1:BGR order*/
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*Enable drawing placeholders when glyph dsc is not found*/
|
||||||
|
#define LV_USE_FONT_PLACEHOLDER 1
|
||||||
|
|
||||||
/*=================
|
/*=================
|
||||||
* TEXT SETTINGS
|
* TEXT SETTINGS
|
||||||
*=================*/
|
*=================*/
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ void lv_draw_sw_letter(lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t * dsc
|
|||||||
letter != 0x200c) { /*ZERO WIDTH NON-JOINER*/
|
letter != 0x200c) { /*ZERO WIDTH NON-JOINER*/
|
||||||
LV_LOG_WARN("lv_draw_letter: glyph dsc. not found for U+%" PRIX32, letter);
|
LV_LOG_WARN("lv_draw_letter: glyph dsc. not found for U+%" PRIX32, letter);
|
||||||
|
|
||||||
|
#if LV_USE_FONT_PLACEHOLDER
|
||||||
/* draw placeholder */
|
/* draw placeholder */
|
||||||
lv_area_t glyph_coords;
|
lv_area_t glyph_coords;
|
||||||
lv_draw_rect_dsc_t glyph_dsc;
|
lv_draw_rect_dsc_t glyph_dsc;
|
||||||
@@ -119,6 +120,7 @@ void lv_draw_sw_letter(lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t * dsc
|
|||||||
glyph_dsc.border_color = dsc->color;
|
glyph_dsc.border_color = dsc->color;
|
||||||
glyph_dsc.border_width = 1;
|
glyph_dsc.border_width = 1;
|
||||||
draw_ctx->draw_rect(draw_ctx, &glyph_dsc, &glyph_coords);
|
draw_ctx->draw_rect(draw_ctx, &glyph_dsc, &glyph_coords);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,10 @@ bool lv_font_get_glyph_dsc(const lv_font_t * font_p, lv_font_glyph_dsc_t * dsc_o
|
|||||||
LV_ASSERT_NULL(font_p);
|
LV_ASSERT_NULL(font_p);
|
||||||
LV_ASSERT_NULL(dsc_out);
|
LV_ASSERT_NULL(dsc_out);
|
||||||
|
|
||||||
|
#if LV_USE_FONT_PLACEHOLDER
|
||||||
const lv_font_t * placeholder_font = NULL;
|
const lv_font_t * placeholder_font = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
const lv_font_t * f = font_p;
|
const lv_font_t * f = font_p;
|
||||||
|
|
||||||
dsc_out->resolved_font = NULL;
|
dsc_out->resolved_font = NULL;
|
||||||
@@ -80,19 +83,22 @@ bool lv_font_get_glyph_dsc(const lv_font_t * font_p, lv_font_glyph_dsc_t * dsc_o
|
|||||||
dsc_out->resolved_font = f;
|
dsc_out->resolved_font = f;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
#if LV_USE_FONT_PLACEHOLDER
|
||||||
else if(placeholder_font == NULL) {
|
else if(placeholder_font == NULL) {
|
||||||
placeholder_font = f;
|
placeholder_font = f;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
f = f->fallback;
|
f = f->fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LV_USE_FONT_PLACEHOLDER
|
||||||
if(placeholder_font != NULL) {
|
if(placeholder_font != NULL) {
|
||||||
placeholder_font->get_glyph_dsc(placeholder_font, dsc_out, letter, letter_next);
|
placeholder_font->get_glyph_dsc(placeholder_font, dsc_out, letter, letter_next);
|
||||||
dsc_out->resolved_font = placeholder_font;
|
dsc_out->resolved_font = placeholder_font;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if(letter < 0x20 ||
|
if(letter < 0x20 ||
|
||||||
letter == 0xf8ff || /*LV_SYMBOL_DUMMY*/
|
letter == 0xf8ff || /*LV_SYMBOL_DUMMY*/
|
||||||
@@ -101,8 +107,13 @@ bool lv_font_get_glyph_dsc(const lv_font_t * font_p, lv_font_glyph_dsc_t * dsc_o
|
|||||||
dsc_out->adv_w = 0;
|
dsc_out->adv_w = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
#if LV_USE_FONT_PLACEHOLDER
|
||||||
dsc_out->box_w = font_p->line_height / 2;
|
dsc_out->box_w = font_p->line_height / 2;
|
||||||
dsc_out->adv_w = dsc_out->box_w + 2;
|
dsc_out->adv_w = dsc_out->box_w + 2;
|
||||||
|
#else
|
||||||
|
dsc_out->box_w = 0;
|
||||||
|
dsc_out->adv_w = 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
dsc_out->resolved_font = NULL;
|
dsc_out->resolved_font = NULL;
|
||||||
|
|||||||
@@ -1225,6 +1225,19 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*Enable drawing placeholders when glyph dsc is not found*/
|
||||||
|
#ifndef LV_USE_FONT_PLACEHOLDER
|
||||||
|
#ifdef _LV_KCONFIG_PRESENT
|
||||||
|
#ifdef CONFIG_LV_USE_FONT_PLACEHOLDER
|
||||||
|
#define LV_USE_FONT_PLACEHOLDER CONFIG_LV_USE_FONT_PLACEHOLDER
|
||||||
|
#else
|
||||||
|
#define LV_USE_FONT_PLACEHOLDER 0
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define LV_USE_FONT_PLACEHOLDER 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/*=================
|
/*=================
|
||||||
* TEXT SETTINGS
|
* TEXT SETTINGS
|
||||||
*=================*/
|
*=================*/
|
||||||
|
|||||||
Reference in New Issue
Block a user