diff options
-rw-r--r-- | src/draw/sdl/lv_draw_sdl_label.c | 15 | ||||
-rw-r--r-- | src/draw/sw/lv_draw_sw_letter.c | 19 | ||||
-rw-r--r-- | src/font/lv_font.c | 43 |
3 files changed, 64 insertions, 13 deletions
diff --git a/src/draw/sdl/lv_draw_sdl_label.c b/src/draw/sdl/lv_draw_sdl_label.c index a067c8af4..344f40aed 100644 --- a/src/draw/sdl/lv_draw_sdl_label.c +++ b/src/draw/sdl/lv_draw_sdl_label.c @@ -77,6 +77,21 @@ void lv_draw_sdl_draw_letter(lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t letter != 0xf8ff && /*LV_SYMBOL_DUMMY*/ letter != 0x200c) { /*ZERO WIDTH NON-JOINER*/ LV_LOG_WARN("lv_draw_letter: glyph dsc. not found for U+%X", letter); + + /* draw placeholder */ + lv_area_t glyph_coords; + lv_draw_rect_dsc_t glyph_dsc; + lv_coord_t begin_x = pos_p->x + g.ofs_x; + lv_coord_t begin_y = pos_p->y + g.ofs_y; + lv_area_set(&glyph_coords, begin_x, begin_y, begin_x + g.box_w, begin_y + g.box_h); + lv_draw_rect_dsc_init(&glyph_dsc); + glyph_dsc.bg_opa = LV_OPA_MIN; + glyph_dsc.outline_opa = LV_OPA_MIN; + glyph_dsc.shadow_opa = LV_OPA_MIN; + glyph_dsc.bg_img_opa = LV_OPA_MIN; + glyph_dsc.border_color = dsc->color; + glyph_dsc.border_width = 1; + draw_ctx->draw_rect(draw_ctx, &glyph_dsc, &glyph_coords); } return; } diff --git a/src/draw/sw/lv_draw_sw_letter.c b/src/draw/sw/lv_draw_sw_letter.c index e7578cffb..61869f137 100644 --- a/src/draw/sw/lv_draw_sw_letter.c +++ b/src/draw/sw/lv_draw_sw_letter.c @@ -97,13 +97,28 @@ void lv_draw_sw_letter(lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t * dsc { lv_font_glyph_dsc_t g; bool g_ret = lv_font_get_glyph_dsc(dsc->font, &g, letter, '\0'); - if(g_ret == false) { + if(g_ret == false) { /*Add warning if the dsc is not found *but do not print warning for non printable ASCII chars (e.g. '\n')*/ if(letter >= 0x20 && letter != 0xf8ff && /*LV_SYMBOL_DUMMY*/ letter != 0x200c) { /*ZERO WIDTH NON-JOINER*/ - LV_LOG_WARN("lv_draw_letter: glyph dsc. not found for U+%X", (unsigned int)letter); + LV_LOG_WARN("lv_draw_letter: glyph dsc. not found for U+%" PRIX32, letter); + + /* draw placeholder */ + lv_area_t glyph_coords; + lv_draw_rect_dsc_t glyph_dsc; + lv_coord_t begin_x = pos_p->x + g.ofs_x; + lv_coord_t begin_y = pos_p->y + g.ofs_y; + lv_area_set(&glyph_coords, begin_x, begin_y, begin_x + g.box_w, begin_y + g.box_h); + lv_draw_rect_dsc_init(&glyph_dsc); + glyph_dsc.bg_opa = LV_OPA_MIN; + glyph_dsc.outline_opa = LV_OPA_MIN; + glyph_dsc.shadow_opa = LV_OPA_MIN; + glyph_dsc.bg_img_opa = LV_OPA_MIN; + glyph_dsc.border_color = dsc->color; + glyph_dsc.border_width = 1; + draw_ctx->draw_rect(draw_ctx, &glyph_dsc, &glyph_coords); } return; } diff --git a/src/font/lv_font.c b/src/font/lv_font.c index 0e7a2fe74..8389e61dc 100644 --- a/src/font/lv_font.c +++ b/src/font/lv_font.c @@ -66,18 +66,41 @@ 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); - dsc_out->resolved_font = NULL; + const lv_font_t * placeholder_font = NULL; const lv_font_t * f = font_p; - bool found = false; + + dsc_out->resolved_font = NULL; + while(f) { - found = f->get_glyph_dsc(f, dsc_out, letter, letter_next); - if(found && !dsc_out->is_placeholder) { - dsc_out->resolved_font = f; - break; + bool found = f->get_glyph_dsc(f, dsc_out, letter, letter_next); + if(found) { + if(!dsc_out->is_placeholder) { + dsc_out->resolved_font = f; + return true; + } + else if(placeholder_font == NULL) { + placeholder_font = f; + } } f = f->fallback; } - return found; + + if(placeholder_font != NULL) { + placeholder_font->get_glyph_dsc(placeholder_font, dsc_out, letter, letter_next); + dsc_out->resolved_font = placeholder_font; + return true; + } + + dsc_out->resolved_font = NULL; + dsc_out->box_w = font_p->line_height / 2; + dsc_out->adv_w = dsc_out->box_w + 2; + dsc_out->box_h = font_p->line_height; + dsc_out->ofs_x = 0; + dsc_out->ofs_y = 0; + dsc_out->bpp = 1; + dsc_out->is_placeholder = true; + + return false; } /** @@ -91,10 +114,8 @@ uint16_t lv_font_get_glyph_width(const lv_font_t * font, uint32_t letter, uint32 { LV_ASSERT_NULL(font); lv_font_glyph_dsc_t g; - bool ret; - ret = lv_font_get_glyph_dsc(font, &g, letter, letter_next); - if(ret) return g.adv_w; - else return 0; + lv_font_get_glyph_dsc(font, &g, letter, letter_next); + return g.adv_w; } /********************** |