1 /** 2 * @file lv_bifi.h 3 * 4 */ 5 6 #ifndef LV_BIDI_H 7 #define LV_BIDI_H 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 /********************* 14 * INCLUDES 15 *********************/ 16 #include "../lv_conf_internal.h" 17 18 #include <stdbool.h> 19 #include <stdint.h> 20 21 /********************* 22 * DEFINES 23 *********************/ 24 /* Special non printable strong characters. 25 * They can be inserted to texts to affect the run's direction*/ 26 #define LV_BIDI_LRO "\xE2\x80\xAD" /*U+202D*/ 27 #define LV_BIDI_RLO "\xE2\x80\xAE" /*U+202E*/ 28 29 /********************** 30 * TYPEDEFS 31 **********************/ 32 enum { 33 /*The first 4 values are stored in `lv_obj_t` on 2 bits*/ 34 LV_BIDI_DIR_LTR = 0x00, 35 LV_BIDI_DIR_RTL = 0x01, 36 LV_BIDI_DIR_AUTO = 0x02, 37 LV_BIDI_DIR_INHERIT = 0x03, 38 39 LV_BIDI_DIR_NEUTRAL = 0x20, 40 LV_BIDI_DIR_WEAK = 0x21, 41 }; 42 43 typedef uint8_t lv_bidi_dir_t; 44 45 /********************** 46 * GLOBAL PROTOTYPES 47 **********************/ 48 #if LV_USE_BIDI 49 50 /** 51 * Convert a text to get the characters in the correct visual order according to 52 * Unicode Bidirectional Algorithm 53 * @param str_in the text to process 54 * @param str_out store the result here. Has the be `strlen(str_in)` length 55 * @param base_dir `LV_BIDI_DIR_LTR` or `LV_BIDI_DIR_RTL` 56 */ 57 void _lv_bidi_process(const char * str_in, char * str_out, lv_bidi_dir_t base_dir); 58 59 /** 60 * Auto-detect the direction of a text based on the first strong character 61 * @param txt the text to process 62 * @return `LV_BIDI_DIR_LTR` or `LV_BIDI_DIR_RTL` 63 */ 64 lv_bidi_dir_t _lv_bidi_detect_base_dir(const char * txt); 65 66 /** 67 * Get the logical position of a character in a line 68 * @param str_in the input string. Can be only one line. 69 * @param bidi_txt internally the text is bidi processed which buffer can be get here. 70 * If not required anymore has to freed with `lv_mem_free()` 71 * Can be `NULL` is unused 72 * @param len length of the line in character count 73 * @param base_dir base direction of the text: `LV_BIDI_DIR_LTR` or `LV_BIDI_DIR_RTL` 74 * @param visual_pos the visual character position which logical position should be get 75 * @param is_rtl tell the the char at `visual_pos` is RTL or LTR context 76 * @return the logical character position 77 */ 78 uint16_t _lv_bidi_get_logical_pos(const char * str_in, char ** bidi_txt, uint32_t len, lv_bidi_dir_t base_dir, 79 uint32_t visual_pos, bool * is_rtl); 80 81 /** 82 * Get the visual position of a character in a line 83 * @param str_in the input string. Can be only one line. 84 * @param bidi_txt internally the text is bidi processed which buffer can be get here. 85 * If not required anymore has to freed with `lv_mem_free()` 86 * Can be `NULL` is unused 87 * @param len length of the line in character count 88 * @param base_dir base direction of the text: `LV_BIDI_DIR_LTR` or `LV_BIDI_DIR_RTL` 89 * @param logical_pos the logical character position which visual position should be get 90 * @param is_rtl tell the the char at `logical_pos` is RTL or LTR context 91 * @return the visual character position 92 */ 93 uint16_t _lv_bidi_get_visual_pos(const char * str_in, char ** bidi_txt, uint16_t len, lv_bidi_dir_t base_dir, 94 uint32_t logical_pos, bool * is_rtl); 95 96 /** 97 * Bidi process a paragraph of text 98 * @param str_in the string to process 99 * @param str_out store the result here 100 * @param len length of the text 101 * @param base_dir base dir of the text 102 * @param pos_conv_out an `uint16_t` array to store the related logical position of the character. 103 * Can be `NULL` is unused 104 * @param pos_conv_len length of `pos_conv_out` in element count 105 */ 106 void _lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t len, lv_bidi_dir_t base_dir, 107 uint16_t * pos_conv_out, uint16_t pos_conv_len); 108 109 /********************** 110 * MACROS 111 **********************/ 112 113 #endif /*LV_USE_BIDI*/ 114 115 #ifdef __cplusplus 116 } /* extern "C" */ 117 #endif 118 119 #endif /*LV_BIDI_H*/ 120