diff --git a/lvgl.h b/lvgl.h index 391388033..61becb457 100644 --- a/lvgl.h +++ b/lvgl.h @@ -33,8 +33,6 @@ extern "C" { #include "src/lv_font/lv_font.h" #include "src/lv_font/lv_font_fmt_txt.h" -#include "src/lv_misc/lv_bidi.h" -#include "src/lv_misc/lv_txt_ap.h" #include "src/lv_misc/lv_printf.h" #include "src/lv_widgets/lv_btn.h" diff --git a/src/lv_core/lv_obj.h b/src/lv_core/lv_obj.h index 0fa2b8964..ab5f8980c 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -23,7 +23,6 @@ extern "C" { #include "../lv_misc/lv_mem.h" #include "../lv_misc/lv_ll.h" #include "../lv_misc/lv_color.h" -#include "../lv_misc/lv_bidi.h" #include "../lv_hal/lv_hal.h" #include "../lv_draw/lv_draw_rect.h" #include "../lv_draw/lv_draw_label.h" diff --git a/src/lv_misc/lv_bidi.c b/src/lv_misc/lv_bidi.c index 43fb74bc2..0cbbaad31 100644 --- a/src/lv_misc/lv_bidi.c +++ b/src/lv_misc/lv_bidi.c @@ -34,6 +34,13 @@ typedef struct { /********************** * STATIC PROTOTYPES **********************/ + +static uint32_t lv_bidi_get_next_paragraph(const char * txt); +static lv_bidi_dir_t lv_bidi_get_letter_dir(uint32_t letter); +static bool lv_bidi_letter_is_weak(uint32_t letter); +static bool lv_bidi_letter_is_rtl(uint32_t letter); +static bool lv_bidi_letter_is_neutral(uint32_t letter); + static lv_bidi_dir_t get_next_run(const char * txt, lv_bidi_dir_t base_dir, uint32_t max_len, uint32_t * len, uint16_t * pos_conv_len); static void rtl_reverse(char * dest, const char * src, uint32_t len, uint16_t * pos_conv_out, uint16_t pos_conv_rd_base, @@ -114,71 +121,6 @@ lv_bidi_dir_t lv_bidi_detect_base_dir(const char * txt) if(LV_BIDI_BASE_DIR_DEF == LV_BIDI_DIR_AUTO) return LV_BIDI_DIR_LTR; else return LV_BIDI_BASE_DIR_DEF; } -/** - * Get the direction of a character - * @param letter an Unicode character - * @return `LV_BIDI_DIR_RTL/LTR/WEAK/NEUTRAL` - */ -lv_bidi_dir_t lv_bidi_get_letter_dir(uint32_t letter) -{ - if(lv_bidi_letter_is_rtl(letter)) return LV_BIDI_DIR_RTL; - if(lv_bidi_letter_is_neutral(letter)) return LV_BIDI_DIR_NEUTRAL; - if(lv_bidi_letter_is_weak(letter)) return LV_BIDI_DIR_WEAK; - - return LV_BIDI_DIR_LTR; -} -/** - * Tell whether a character is weak or not - * @param letter an Unicode character - * @return true/false - */ -bool lv_bidi_letter_is_weak(uint32_t letter) -{ - uint32_t i = 0; - static const char weaks[] = "0123456789"; - - do { - uint32_t x = lv_txt_encoded_next(weaks, &i); - if(letter == x) { - return true; - } - } while(weaks[i] != '\0'); - - return false; -} -/** - * Tell whether a character is RTL or not - * @param letter an Unicode character - * @return true/false - */ -bool lv_bidi_letter_is_rtl(uint32_t letter) -{ - if(letter >= 0x5d0 && letter <= 0x5ea) return true; - if(letter == 0x202E) return true; /*Unicode of LV_BIDI_RLO*/ - - /* Check for Persian and Arabic characters [https://en.wikipedia.org/wiki/Arabic_script_in_Unicode]*/ - if(letter >= 0x600 && letter <= 0x6FF) return true; - if(letter >= 0xFB50 && letter <= 0xFDFF) return true; - if(letter >= 0xFE70 && letter <= 0xFEFF) return true; - - return false; -} - -/** - * Tell whether a character is neutral or not - * @param letter an Unicode character - * @return true/false - */ -bool lv_bidi_letter_is_neutral(uint32_t letter) -{ - uint16_t i; - static const char neutrals[] = " \t\n\r.,:;'\"`!?%/\\-=()[]{}<>@#&$|"; - for(i = 0; neutrals[i] != '\0'; i++) { - if(letter == (uint32_t)neutrals[i]) return true; - } - - return false; -} /** * Get the logical position of a character in a line @@ -363,12 +305,16 @@ void lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t len } } +/********************** + * STATIC FUNCTIONS + **********************/ + /** * Get the next paragraph from a text * @param txt the text to process * @return the length of the current paragraph in byte count */ -uint32_t lv_bidi_get_next_paragraph(const char * txt) +static uint32_t lv_bidi_get_next_paragraph(const char * txt) { uint32_t i = 0; @@ -381,9 +327,71 @@ uint32_t lv_bidi_get_next_paragraph(const char * txt) return i; } -/********************** - * STATIC FUNCTIONS - **********************/ +/** + * Get the direction of a character + * @param letter an Unicode character + * @return `LV_BIDI_DIR_RTL/LTR/WEAK/NEUTRAL` + */ +static lv_bidi_dir_t lv_bidi_get_letter_dir(uint32_t letter) +{ + if(lv_bidi_letter_is_rtl(letter)) return LV_BIDI_DIR_RTL; + if(lv_bidi_letter_is_neutral(letter)) return LV_BIDI_DIR_NEUTRAL; + if(lv_bidi_letter_is_weak(letter)) return LV_BIDI_DIR_WEAK; + + return LV_BIDI_DIR_LTR; +} +/** + * Tell whether a character is weak or not + * @param letter an Unicode character + * @return true/false + */ +static bool lv_bidi_letter_is_weak(uint32_t letter) +{ + uint32_t i = 0; + static const char weaks[] = "0123456789"; + + do { + uint32_t x = lv_txt_encoded_next(weaks, &i); + if(letter == x) { + return true; + } + } while(weaks[i] != '\0'); + + return false; +} +/** + * Tell whether a character is RTL or not + * @param letter an Unicode character + * @return true/false + */ +static bool lv_bidi_letter_is_rtl(uint32_t letter) +{ + if(letter >= 0x5d0 && letter <= 0x5ea) return true; + if(letter == 0x202E) return true; /*Unicode of LV_BIDI_RLO*/ + + /* Check for Persian and Arabic characters [https://en.wikipedia.org/wiki/Arabic_script_in_Unicode]*/ + if(letter >= 0x600 && letter <= 0x6FF) return true; + if(letter >= 0xFB50 && letter <= 0xFDFF) return true; + if(letter >= 0xFE70 && letter <= 0xFEFF) return true; + + return false; +} + +/** + * Tell whether a character is neutral or not + * @param letter an Unicode character + * @return true/false + */ +static bool lv_bidi_letter_is_neutral(uint32_t letter) +{ + uint16_t i; + static const char neutrals[] = " \t\n\r.,:;'\"`!?%/\\-=()[]{}<>@#&$|"; + for(i = 0; neutrals[i] != '\0'; i++) { + if(letter == (uint32_t)neutrals[i]) return true; + } + + return false; +} static uint32_t get_txt_len(const char * txt, uint32_t max_len) { diff --git a/src/lv_misc/lv_bidi.h b/src/lv_misc/lv_bidi.h index c6df56c0a..9f79ea612 100644 --- a/src/lv_misc/lv_bidi.h +++ b/src/lv_misc/lv_bidi.h @@ -63,34 +63,6 @@ void lv_bidi_process(const char * str_in, char * str_out, lv_bidi_dir_t base_dir */ lv_bidi_dir_t lv_bidi_detect_base_dir(const char * txt); -/** - * Get the direction of a character - * @param letter an Unicode character - * @return `LV_BIDI_DIR_RTL/LTR/WEAK/NEUTRAL` - */ -lv_bidi_dir_t lv_bidi_get_letter_dir(uint32_t letter); - -/** - * Tell whether a character is weak or not - * @param letter an Unicode character - * @return true/false - */ -bool lv_bidi_letter_is_weak(uint32_t letter); - -/** - * Tell whether a character is RTL or not - * @param letter an Unicode character - * @return true/false - */ -bool lv_bidi_letter_is_rtl(uint32_t letter); - -/** - * Tell whether a character is neutral or not - * @param letter an Unicode character - * @return true/false - */ -bool lv_bidi_letter_is_neutral(uint32_t letter); - /** * Get the logical position of a character in a line * @param str_in the input string. Can be only one line. @@ -134,13 +106,6 @@ uint16_t lv_bidi_get_visual_pos(const char * str_in, char ** bidi_txt, uint16_t void lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t len, lv_bidi_dir_t base_dir, uint16_t * pos_conv_out, uint16_t pos_conv_len); -/** - * Get the next paragraph from a text - * @param txt the text to process - * @return the length of the current paragraph in byte count - */ -uint32_t lv_bidi_get_next_paragraph(const char * txt); - /********************** * MACROS **********************/ diff --git a/src/lv_misc/lv_txt_ap.h b/src/lv_misc/lv_txt_ap.h index 0376b175e..18f746955 100644 --- a/src/lv_misc/lv_txt_ap.h +++ b/src/lv_misc/lv_txt_ap.h @@ -14,7 +14,6 @@ extern "C" { * INCLUDES *********************/ #include -#include "lv_bidi.h" #include "lv_txt.h" #include "../lv_draw/lv_draw.h" diff --git a/src/lv_widgets/lv_cont.c b/src/lv_widgets/lv_cont.c index 0fbd8a0d9..ca1ef68e5 100644 --- a/src/lv_widgets/lv_cont.c +++ b/src/lv_widgets/lv_cont.c @@ -21,7 +21,6 @@ #include "../lv_misc/lv_area.h" #include "../lv_misc/lv_color.h" #include "../lv_misc/lv_math.h" -#include "../lv_misc/lv_bidi.h" /********************* * DEFINES diff --git a/src/lv_widgets/lv_label.c b/src/lv_widgets/lv_label.c index d38e6d90b..9a3f10a40 100644 --- a/src/lv_widgets/lv_label.c +++ b/src/lv_widgets/lv_label.c @@ -16,6 +16,7 @@ #include "../lv_misc/lv_color.h" #include "../lv_misc/lv_math.h" #include "../lv_misc/lv_bidi.h" +#include "../lv_misc/lv_txt_ap.h" #include "../lv_misc/lv_printf.h" #include "../lv_themes/lv_theme.h" diff --git a/src/lv_widgets/lv_slider.c b/src/lv_widgets/lv_slider.c index a83e78e69..06b1b2b46 100644 --- a/src/lv_widgets/lv_slider.c +++ b/src/lv_widgets/lv_slider.c @@ -331,10 +331,11 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par if(w >= h) { lv_coord_t indic_w = w - bg_left - bg_right; - if(base_dir == LV_BIDI_DIR_RTL) + if(base_dir == LV_BIDI_DIR_RTL) { new_value = (slider->coords.x2 - bg_right) - p.x; /*Make the point relative to the indicator*/ - else + } else { new_value = p.x - (slider->coords.x1 + bg_left); /*Make the point relative to the indicator*/ + } new_value = (new_value * range) / indic_w; new_value += ext->bar.min_value; }