/* Give the length of a text with a given font  */
lv_coord_t lv_txt_get_width(const char *txt, uint16_t length, const lv_font_t *font, lv_coord_t letter_space, lv_txt_flag_t flag)
/* Give the length of a text with a given font  */
lv_coord_t lv_txt_get_width(const char *txt, uint16_t length, const lv_font_t *font, lv_coord_t letter_space, lv_txt_flag_t flag)
{
    if(txt == NULL) return 0;
    if(font == NULL) return 0;
    uint32_t i = 0;
    lv_coord_t width = 0;
    lv_txt_cmd_state_t cmd_state = LV_TXT_CMD_STATE_WAIT;
    uint32_t letter;
    if(length != 0) {
        while(i < length) {
            letter = lv_txt_encoded_next(txt, &i);
            if((flag & LV_TXT_FLAG_RECOLOR) != 0) {
                if(lv_txt_is_cmd(&cmd_state, letter) != false) {
                    continue;
                }
            }
            width += lv_font_get_width(font, letter);
            width += letter_space;
        }
        width -= letter_space;
    }
    return width;
}