1 /**
2  * @file lv_text.h
3  *
4  */
5 
6 #ifndef LV_TEXT_H
7 #define LV_TEXT_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /*********************
14  *      INCLUDES
15  *********************/
16 #include "../lv_conf_internal.h"
17 
18 #include "lv_types.h"
19 #include "lv_area.h"
20 #include "../font/lv_font.h"
21 #include "../stdlib/lv_sprintf.h"
22 
23 /*********************
24  *      DEFINES
25  *********************/
26 #ifndef LV_TXT_COLOR_CMD
27 #define LV_TXT_COLOR_CMD "#"
28 #endif
29 
30 #define LV_TXT_ENC_UTF8 1
31 #define LV_TXT_ENC_ASCII 2
32 
33 #define LV_TEXT_LEN_MAX UINT32_MAX
34 
35 /**********************
36  *      TYPEDEFS
37  **********************/
38 
39 /**
40  * Options for text rendering.
41  */
42 
43 typedef enum {
44     LV_TEXT_FLAG_NONE      = 0x00,
45     LV_TEXT_FLAG_EXPAND    = 0x01, /**< Ignore max-width to avoid automatic word wrapping*/
46     LV_TEXT_FLAG_FIT       = 0x02, /**< Max-width is already equal to the longest line. (Used to skip some calculation)*/
47     LV_TEXT_FLAG_BREAK_ALL = 0x04, /**< To prevent overflow, insert breaks between any two characters.
48                                         Otherwise breaks are inserted at word boundaries, as configured via LV_TXT_BREAK_CHARS
49                                         or according to LV_TXT_LINE_BREAK_LONG_LEN, LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN,
50                                         and LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN.*/
51     LV_TEXT_FLAG_RECOLOR   = 0x08, /**< Enable parsing of recolor command*/
52 } lv_text_flag_t;
53 
54 /** Label align policy*/
55 typedef enum {
56     LV_TEXT_ALIGN_AUTO, /**< Align text auto*/
57     LV_TEXT_ALIGN_LEFT, /**< Align text to left*/
58     LV_TEXT_ALIGN_CENTER, /**< Align text to center*/
59     LV_TEXT_ALIGN_RIGHT, /**< Align text to right*/
60 } lv_text_align_t;
61 
62 /** State machine for text renderer. */
63 typedef enum {
64     LV_TEXT_CMD_STATE_WAIT, /**< Waiting for command*/
65     LV_TEXT_CMD_STATE_PAR,  /**< Processing the parameter*/
66     LV_TEXT_CMD_STATE_IN,   /**< Processing the command*/
67 } lv_text_cmd_state_t;
68 
69 /**********************
70  * GLOBAL PROTOTYPES
71  **********************/
72 
73 /**
74  * Get size of a text
75  * @param size_res pointer to a 'point_t' variable to store the result
76  * @param text pointer to a text
77  * @param font pointer to font of the text
78  * @param letter_space letter space of the text
79  * @param line_space line space of the text
80  * @param max_width max width of the text (break the lines to fit this size). Set COORD_MAX to avoid
81  * @param flag settings for the text from ::lv_text_flag_t
82 
83  * line breaks
84  */
85 void lv_text_get_size(lv_point_t * size_res, const char * text, const lv_font_t * font, int32_t letter_space,
86                       int32_t line_space, int32_t max_width, lv_text_flag_t flag);
87 
88 /**
89  * Give the length of a text with a given font
90  * @param txt a '\0' terminate string
91  * @param length length of 'txt' in byte count and not characters (Á is 1 character but 2 bytes in
92  * UTF-8)
93  * @param font pointer to a font
94  * @param letter_space letter space
95  * @return length of a char_num long text
96  */
97 int32_t lv_text_get_width(const char * txt, uint32_t length, const lv_font_t * font, int32_t letter_space);
98 
99 /**
100  * Give the length of a text with a given font with text flags
101  * @param txt a '\0' terminate string
102  * @param length length of 'txt' in byte count and not characters (Á is 1 character but 2 bytes in
103  * UTF-8)
104  * @param font pointer to a font
105  * @param letter_space letter space
106  * @param flags settings for the text from ::lv_text_flag_t
107  * @return length of a char_num long text
108  */
109 int32_t lv_text_get_width_with_flags(const char * txt, uint32_t length, const lv_font_t * font, int32_t letter_space,
110                                      lv_text_flag_t flags);
111 
112 /**
113  * Check if c is command state
114  * @param state
115  * @param c
116  * @return True if c is state
117  */
118 bool lv_text_is_cmd(lv_text_cmd_state_t * state, uint32_t c);
119 /**********************
120  *      MACROS
121  **********************/
122 
123 #ifdef __cplusplus
124 } /*extern "C"*/
125 #endif
126 
127 #endif /*LV_TEXT_H*/
128