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:
@@ -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*/
|
||||
LV_LOG_WARN("lv_draw_letter: glyph dsc. not found for U+%" PRIX32, letter);
|
||||
|
||||
#if LV_USE_FONT_PLACEHOLDER
|
||||
/* draw placeholder */
|
||||
lv_area_t glyph_coords;
|
||||
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_width = 1;
|
||||
draw_ctx->draw_rect(draw_ctx, &glyph_dsc, &glyph_coords);
|
||||
#endif
|
||||
}
|
||||
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(dsc_out);
|
||||
|
||||
#if LV_USE_FONT_PLACEHOLDER
|
||||
const lv_font_t * placeholder_font = NULL;
|
||||
#endif
|
||||
|
||||
const lv_font_t * f = font_p;
|
||||
|
||||
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;
|
||||
return true;
|
||||
}
|
||||
#if LV_USE_FONT_PLACEHOLDER
|
||||
else if(placeholder_font == NULL) {
|
||||
placeholder_font = f;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
f = f->fallback;
|
||||
}
|
||||
|
||||
#if LV_USE_FONT_PLACEHOLDER
|
||||
if(placeholder_font != NULL) {
|
||||
placeholder_font->get_glyph_dsc(placeholder_font, dsc_out, letter, letter_next);
|
||||
dsc_out->resolved_font = placeholder_font;
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if(letter < 0x20 ||
|
||||
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;
|
||||
}
|
||||
else {
|
||||
#if LV_USE_FONT_PLACEHOLDER
|
||||
dsc_out->box_w = font_p->line_height / 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;
|
||||
|
||||
@@ -1225,6 +1225,19 @@
|
||||
#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
|
||||
*=================*/
|
||||
|
||||
Reference in New Issue
Block a user