How to display correct chinese character

Description

It is display incorrect character When I use obj_label display chinese “海纳百川” with utf8 in V7.It become “海纳*川”

What MCU/Processor/Board and compiler are you using?

Linux develop board - imx6

What LVGL version are you using?

V7.2.0

What do you want to achieve?

display correct character

What have you tried so far?

remake font lib and display other chinese character “天气时钟”,But result is incorrect too

Code to reproduce

In officer’s demo lv_demo_printf, I modify part program.

static void info_bottom_create(const char * dsc, const char * btn_txt, lv_event_cb_t btn_event_cb, uint32_t delay)
{

    lv_obj_t * txt = lv_label_create(lv_scr_act(), NULL);
    lv_label_set_text(txt, dsc);
    lv_theme_apply(txt, (lv_theme_style_t)LV_DEMO_PRINTER_THEME_LABEL_WHITE);
    lv_obj_add_style(txt, LV_OBJ_PART_MAIN, &style_chinese);
    lv_obj_align(txt, NULL, LV_ALIGN_CENTER, 0, 100);

    lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL);
    lv_theme_apply(btn, (lv_theme_style_t)LV_DEMO_PRINTER_THEME_BTN_BORDER);
    lv_obj_set_size(btn, LV_DEMO_PRINTER_BTN_W, LV_DEMO_PRINTER_BTN_H);
    lv_obj_align(btn, txt, LV_ALIGN_OUT_BOTTOM_MID, 0, 60);
    lv_obj_set_style_local_value_str(btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, btn_txt);
    lv_obj_set_event_cb(btn, btn_event_cb);

    lv_demo_printer_anim_in(txt, delay);
    delay += LV_DEMO_PRINTER_ANIM_DELAY;

    lv_demo_printer_anim_in(btn, delay);
    delay += LV_DEMO_PRINTER_ANIM_DELAY;

    lv_demo_printer_anim_in(btn, delay);
}

LV_EVENT_CB_DECLARE(setup_icon_event_cb)
{
#if 1
    if (e == LV_EVENT_CLICKED) {
        lv_demo_printer_anim_out_all(lv_scr_act(), 0);

        lv_demo_printer_anim_bg(0, LV_DEMO_PRINTER_RED, LV_DEMO_PRINTER_BG_FULL);

        uint32_t delay = 200;
        lv_style_init(&style_chinese);
        lv_style_set_bg_opa(&style_chinese, LV_STATE_DEFAULT, LV_OPA_COVER);
        lv_style_set_bg_color(&style_chinese, LV_STATE_DEFAULT, LV_DEMO_PRINTER_RED);
        lv_style_set_text_font(&style_chinese, LV_STATE_DEFAULT, &myFontYH12);

        info_bottom_create("海纳百川", "BACK", back_to_home_event_cb, delay);
    }
#endif
    icon_generic_event_cb(obj, e);
}

Screenshot and/or video

I suppose you are working with the ‘build in’ font lv_font_simsun_16_cjk.c.

The 百 has the code value 0x767E. When you take a look into lv_font_simsun_16_cjk.c you will see, that there is no glyph for 0x767E. There is one for 0x767C and the next is 0x7684.

In this case you have to provide your own font/glyph file.

Robert

No,I create a new font lib,And I already select the new font lib i sure,You can see my code

 lv_style_init(&style_chinese);
 lv_style_set_bg_opa(&style_chinese, LV_STATE_DEFAULT, LV_OPA_COVER);
 lv_style_set_bg_color(&style_chinese, LV_STATE_DEFAULT, LV_DEMO_PRINTER_RED);
 lv_style_set_text_font(&style_chinese, LV_STATE_DEFAULT, &myFontYH12);

Ok, I see. My fault, sorry.

You wrote:

海纳百川” with utf8 in V7.It become “海纳*川

So the third glyph would be incorrect.
But when I look at your screenshot, the second glyph (which should be 纳) seems to be incorrect.
So it seems, that the font you created is taken (as we can see the 百).

Maybe you check your font source file?

I already test with new font lib,But result as same as old.
Can you give me a chinese font?

Sorry, I don’t have any currently build chinese font.

You use lvgl’s font converter? And create a C sourcefile?
Just open the source file with an text editor and search for 7EB3 (纳, the second glyph, which is not correctly shown!?).

1 Like

Okay.I already test.
It is my fault that i use a incorrect font source.It display correct when i modify a correct font source.

Hello, I want to know what the function icon_generic_event_cb does. Can you explain it? Looking forward to your reply.