Given a font and text string in UTF-8 (can be a bidi string), how do I find the string width in pixels?
Thanks.
Given a font and text string in UTF-8 (can be a bidi string), how do I find the string width in pixels?
Thanks.
I used this code but did not work:
_lv_txt_ap_proc(my_str, ctx_str);
width = _lv_txt_get_width(ctx_str, _lv_txt_get_encoded_length(ctx_str), my_font, 0, 0);
It looks that lv_txt_get_width handles only the utf8 character code. While _lv_txt_ap_proc converts it to its contextual code that’s suitable for display (contextual analysis may change letter shape and consequently changes the width).
If I comment _lv_txt_ap_proc I will get an approximate width but not exact.
Here is the correct way to find text width in pixels
lv_point_t p;
_lv_txt_ap_proc(my_str, ctx_text);
_lv_txt_get_size(&p, ctxi_text, my_font, 0, 0, LV_COORD_MAX, LV_TXT_FLAG_EXPAND);
p.x contains the total width in pixels.
LVGL contains a lot of good resources, but need to dig.
Excellent work.