/**1* @file lv_text.h2*3*/45#ifndef LV_TXT_H6#define LV_TXT_H78#ifdef __cplusplus9extern "C" {10#endif1112/*********************13* INCLUDES14*********************/15#ifdef LV_CONF_INCLUDE_SIMPLE16#include "lv_conf.h"17#else18#include "../../lv_conf.h"19#endif2021#include "lv_area.h"22#include "lv_font.h"23#include "lv_area.h"2425/*********************26* DEFINES27*********************/28#define LV_TXT_COLOR_CMD "#"2930/**********************31* TYPEDEFS32**********************/33enum34{35LV_TXT_FLAG_NONE = 0x00,36LV_TXT_FLAG_RECOLOR = 0x01, /*Enable parsing of recolor command*/37LV_TXT_FLAG_EXPAND = 0x02, /*Ignore width to avoid automatic word wrapping*/38LV_TXT_FLAG_CENTER = 0x04, /*Align the text to the middle*/39LV_TXT_FLAG_RIGHT = 0x08, /*Align the text to the right*/40};41typedef uint8_t lv_txt_flag_t;4243enum44{45LV_TXT_CMD_STATE_WAIT, /*Waiting for command*/46LV_TXT_CMD_STATE_PAR, /*Processing the parameter*/47LV_TXT_CMD_STATE_IN, /*Processing the command*/48};49typedef uint8_t lv_txt_cmd_state_t;5051/**********************52* GLOBAL PROTOTYPES53**********************/5455/**56* Get size of a text57* @param size_res pointer to a 'point_t' variable to store the result58* @param text pointer to a text59* @param font pinter to font of the text60* @param letter_space letter space of the text61* @param line_space line space of the text62* @param flags settings for the text from 'txt_flag_t' enum63* @param max_width max with of the text (break the lines to fit this size) Set CORD_MAX to avoid line breaks64*/65void lv_txt_get_size(lv_point_t * size_res, const char * text, const lv_font_t * font,66lv_coord_t letter_space, lv_coord_t line_space, lv_coord_t max_width, lv_txt_flag_t flag);6768/**69* Get the next line of text. Check line length and break chars too.70* @param txt a '\0' terminated string71* @param font pointer to a font72* @param letter_space letter space73* @param max_width max with of the text (break the lines to fit this size) Set CORD_MAX to avoid line breaks74* @param flags settings for the text from 'txt_flag_type' enum75* @return the index of the first char of the new line (in byte index not letter index. With UTF-8 they are different)76*/77uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font,78lv_coord_t letter_space, lv_coord_t max_width, lv_txt_flag_t flag);7980/**81* Give the length of a text with a given font82* @param txt a '\0' terminate string83* @param length length of 'txt' in byte count and not characters (Á is 1 character but 2 bytes in UTF-8)84* @param font pointer to a font85* @param letter_space letter space86* @param flags settings for the text from 'txt_flag_t' enum87* @return length of a char_num long text88*/89lv_coord_t lv_txt_get_width(const char * txt, uint16_t length,90const lv_font_t * font, lv_coord_t letter_space, lv_txt_flag_t flag);919293/**94* Check next character in a string and decide if te character is part of the command or not95* @param state pointer to a txt_cmd_state_t variable which stores the current state of command processing96* @param c the current character97* @return true: the character is part of a command and should not be written,98* false: the character should be written99*/100bool lv_txt_is_cmd(lv_txt_cmd_state_t * state, uint32_t c);101102/**103* Insert a string into an other104* @param txt_buf the original text (must be big enough for the result text)105* @param pos position to insert (0: before the original text, 1: after the first char etc.)106* @param ins_txt text to insert107*/108void lv_txt_ins(char * txt_buf, uint32_t pos, const char * ins_txt);109110/**111* Delete a part of a string112* @param txt string to modify113* @param pos position where to start the deleting (0: before the first char, 1: after the first char etc.)114* @param len number of characters to delete115*/116void lv_txt_cut(char * txt, uint32_t pos, uint32_t len);117118/***************************************************************119* GLOBAL FUNCTION POINTERS FOR CAHRACTER ENCODING INTERFACE120***************************************************************/121122/**123* Give the size of an encoded character124* @param str pointer to a character in a string125* @return length of the encoded character (1,2,3 ...). O in invalid126*/127extern uint8_t (*lv_txt_encoded_size)(const char *);128129130/**131* Convert an Unicode letter to encoded132* @param letter_uni an Unicode letter133* @return Encoded character in Little Endian to be compatible with C chars (e.g. 'Á', 'Ü')134*/135extern uint32_t (*lv_txt_unicode_to_encoded)(uint32_t );136137/**138* Convert a wide character, e.g. 'Á' little endian to be compatible with the encoded format.139* @param c a wide character140* @return `c` in the encoded format141*/142extern uint32_t (*lv_txt_encoded_conv_wc) (uint32_t c);143144/**145* Decode the next encoded character from a string.146* @param txt pointer to '\0' terminated string147* @param i start index in 'txt' where to start.148* After the call it will point to the next encoded char in 'txt'.149* NULL to use txt[0] as index150* @return the decoded Unicode character or 0 on invalid data code151*/152extern uint32_t (*lv_txt_encoded_next)(const char *, uint32_t * );153154/**155* Get the previous encoded character form a string.156* @param txt pointer to '\0' terminated string157* @param i_start index in 'txt' where to start. After the call it will point to the previous encoded char in 'txt'.158* @return the decoded Unicode character or 0 on invalid data159*/160extern uint32_t (*lv_txt_encoded_prev)(const char *, uint32_t *);161162/**163* Convert a letter index (in an the encoded text) to byte index.164* E.g. in UTF-8 "AÁRT" index of 'R' is 2 but start at byte 3 because 'Á' is 2 bytes long165* @param txt a '\0' terminated UTF-8 string166* @param enc_id letter index167* @return byte index of the 'enc_id'th letter168*/169extern uint32_t (*lv_txt_encoded_get_byte_id)(const char *, uint32_t);170171/**172* Convert a byte index (in an encoded text) to character index.173* E.g. in UTF-8 "AÁRT" index of 'R' is 2 but start at byte 3 because 'Á' is 2 bytes long174* @param txt a '\0' terminated UTF-8 string175* @param byte_id byte index176* @return character index of the letter at 'byte_id'th position177*/178extern uint32_t (*lv_encoded_get_char_id)(const char *, uint32_t);179180/**181* Get the number of characters (and NOT bytes) in a string.182* E.g. in UTF-8 "ÁBC" is 3 characters (but 4 bytes)183* @param txt a '\0' terminated char string184* @return number of characters185*/186extern uint32_t (*lv_txt_get_encoded_length)(const char *);187188/**********************189* MACROS190**********************/191192#ifdef __cplusplus193} /* extern "C" */194#endif195196#endif /*USE_TXT*/197198199