mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
chore(text): move "_" funcs to private h (#5913)
This commit is contained in:
parent
c9a6b25885
commit
3e21769fa6
@ -11,6 +11,7 @@
|
||||
#include "../misc/lv_math.h"
|
||||
#include "../core/lv_obj_event.h"
|
||||
#include "../misc/lv_bidi.h"
|
||||
#include "../misc/lv_text_private.h"
|
||||
#include "../misc/lv_assert.h"
|
||||
#include "../stdlib/lv_mem.h"
|
||||
#include "../stdlib/lv_string.h"
|
||||
@ -110,7 +111,7 @@ void LV_ATTRIBUTE_FAST_MEM lv_draw_character(lv_layer_t * layer, lv_draw_label_d
|
||||
return;
|
||||
}
|
||||
|
||||
if(_lv_text_is_marker(unicode_letter)) return;
|
||||
if(lv_text_is_marker(unicode_letter)) return;
|
||||
|
||||
LV_PROFILER_BEGIN;
|
||||
|
||||
@ -125,7 +126,7 @@ void LV_ATTRIBUTE_FAST_MEM lv_draw_character(lv_layer_t * layer, lv_draw_label_d
|
||||
|
||||
/*lv_draw_label needs UTF8 text so convert the Unicode character to an UTF8 string */
|
||||
uint32_t letter_buf[2];
|
||||
letter_buf[0] = _lv_text_unicode_to_encoded(unicode_letter);
|
||||
letter_buf[0] = lv_text_unicode_to_encoded(unicode_letter);
|
||||
letter_buf[1] = '\0';
|
||||
|
||||
const char * letter_buf_char = (const char *)letter_buf;
|
||||
@ -201,14 +202,14 @@ void lv_draw_label_iterate_characters(lv_draw_unit_t * draw_unit, const lv_draw_
|
||||
pos.y += dsc->hint->y;
|
||||
}
|
||||
|
||||
uint32_t line_end = line_start + _lv_text_get_next_line(&dsc->text[line_start], font, dsc->letter_space, w, NULL,
|
||||
dsc->flag);
|
||||
uint32_t line_end = line_start + lv_text_get_next_line(&dsc->text[line_start], font, dsc->letter_space, w, NULL,
|
||||
dsc->flag);
|
||||
|
||||
/*Go the first visible line*/
|
||||
while(pos.y + line_height_font < draw_unit->clip_area->y1) {
|
||||
/*Go to next line*/
|
||||
line_start = line_end;
|
||||
line_end += _lv_text_get_next_line(&dsc->text[line_start], font, dsc->letter_space, w, NULL, dsc->flag);
|
||||
line_end += lv_text_get_next_line(&dsc->text[line_start], font, dsc->letter_space, w, NULL, dsc->flag);
|
||||
pos.y += line_height;
|
||||
|
||||
/*Save at the threshold coordinate*/
|
||||
@ -276,17 +277,17 @@ void lv_draw_label_iterate_characters(lv_draw_unit_t * draw_unit, const lv_draw_
|
||||
uint32_t logical_char_pos = 0;
|
||||
if(sel_start != 0xFFFF && sel_end != 0xFFFF) {
|
||||
#if LV_USE_BIDI
|
||||
logical_char_pos = _lv_text_encoded_get_char_id(dsc->text, line_start);
|
||||
uint32_t t = _lv_text_encoded_get_char_id(bidi_txt, i);
|
||||
logical_char_pos = lv_text_encoded_get_char_id(dsc->text, line_start);
|
||||
uint32_t t = lv_text_encoded_get_char_id(bidi_txt, i);
|
||||
logical_char_pos += _lv_bidi_get_logical_pos(bidi_txt, NULL, line_end - line_start, base_dir, t, NULL);
|
||||
#else
|
||||
logical_char_pos = _lv_text_encoded_get_char_id(dsc->text, line_start + i);
|
||||
logical_char_pos = lv_text_encoded_get_char_id(dsc->text, line_start + i);
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t letter;
|
||||
uint32_t letter_next;
|
||||
_lv_text_encoded_letter_next_2(bidi_txt, &letter, &letter_next, &i);
|
||||
lv_text_encoded_letter_next_2(bidi_txt, &letter, &letter_next, &i);
|
||||
|
||||
letter_w = lv_font_get_glyph_width(font, letter, letter_next);
|
||||
|
||||
@ -341,7 +342,7 @@ void lv_draw_label_iterate_characters(lv_draw_unit_t * draw_unit, const lv_draw_
|
||||
#endif
|
||||
/*Go to next line*/
|
||||
line_start = line_end;
|
||||
line_end += _lv_text_get_next_line(&dsc->text[line_start], font, dsc->letter_space, w, NULL, dsc->flag);
|
||||
line_end += lv_text_get_next_line(&dsc->text[line_start], font, dsc->letter_space, w, NULL, dsc->flag);
|
||||
|
||||
pos.x = coords->x1;
|
||||
/*Align to middle*/
|
||||
@ -378,7 +379,7 @@ static void draw_letter(lv_draw_unit_t * draw_unit, lv_draw_glyph_dsc_t * dsc,
|
||||
{
|
||||
lv_font_glyph_dsc_t g;
|
||||
|
||||
if(_lv_text_is_marker(letter)) /*Markers are valid letters but should not be rendered.*/
|
||||
if(lv_text_is_marker(letter)) /*Markers are valid letters but should not be rendered.*/
|
||||
return;
|
||||
|
||||
LV_PROFILER_BEGIN;
|
||||
|
@ -658,7 +658,7 @@ bool lv_windows_keypad_device_window_message_handler(
|
||||
}
|
||||
|
||||
uint32_t lvgl_code_point =
|
||||
_lv_text_unicode_to_encoded(code_point);
|
||||
lv_text_unicode_to_encoded(code_point);
|
||||
|
||||
lv_windows_push_key_to_keyboard_queue(
|
||||
context,
|
||||
|
@ -8,7 +8,7 @@
|
||||
*********************/
|
||||
|
||||
#include "lv_font.h"
|
||||
#include "../misc/lv_text.h"
|
||||
#include "../misc/lv_text_private.h"
|
||||
#include "../misc/lv_utils.h"
|
||||
#include "../misc/lv_log.h"
|
||||
#include "../misc/lv_assert.h"
|
||||
@ -122,7 +122,7 @@ uint16_t lv_font_get_glyph_width(const lv_font_t * font, uint32_t letter, uint32
|
||||
lv_font_glyph_dsc_t g;
|
||||
|
||||
/*Return zero if letter is marker*/
|
||||
if(_lv_text_is_marker(letter)) return 0;
|
||||
if(lv_text_is_marker(letter)) return 0;
|
||||
|
||||
lv_font_get_glyph_dsc(font, &g, letter, letter_next);
|
||||
return g.adv_w;
|
||||
|
@ -15,6 +15,10 @@ extern "C" {
|
||||
*********************/
|
||||
#include "display/lv_display_private.h"
|
||||
#include "indev/lv_indev_private.h"
|
||||
#include "misc/lv_text_private.h"
|
||||
#include "libs/freetype/lv_freetype_private.h"
|
||||
#include "misc/cache/lv_cache_entry_private.h"
|
||||
#include "misc/cache/lv_cache_private.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
|
@ -7,7 +7,7 @@
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_bidi.h"
|
||||
#include "lv_text.h"
|
||||
#include "lv_text_private.h"
|
||||
#include "lv_types.h"
|
||||
#include "../stdlib/lv_mem.h"
|
||||
#include "../stdlib/lv_string.h"
|
||||
@ -109,7 +109,7 @@ lv_base_dir_t _lv_bidi_detect_base_dir(const char * txt)
|
||||
uint32_t i = 0;
|
||||
uint32_t letter;
|
||||
while(txt[i] != '\0') {
|
||||
letter = _lv_text_encoded_next(txt, &i);
|
||||
letter = lv_text_encoded_next(txt, &i);
|
||||
|
||||
lv_base_dir_t dir;
|
||||
dir = lv_bidi_get_letter_dir(letter);
|
||||
@ -209,7 +209,7 @@ void _lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t le
|
||||
|
||||
/*Process neutral chars in the beginning*/
|
||||
while(rd < len) {
|
||||
uint32_t letter = _lv_text_encoded_next(str_in, &rd);
|
||||
uint32_t letter = lv_text_encoded_next(str_in, &rd);
|
||||
pos_conv_rd++;
|
||||
dir = lv_bidi_get_letter_dir(letter);
|
||||
if(dir == LV_BASE_DIR_NEUTRAL) dir = bracket_process(&ctx, str_in, rd, len, letter, base_dir);
|
||||
@ -217,7 +217,7 @@ void _lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t le
|
||||
}
|
||||
|
||||
if(rd && str_in[rd] != '\0' && rd < len) {
|
||||
_lv_text_encoded_prev(str_in, &rd);
|
||||
lv_text_encoded_prev(str_in, &rd);
|
||||
pos_conv_rd--;
|
||||
}
|
||||
|
||||
@ -294,10 +294,10 @@ static uint32_t lv_bidi_get_next_paragraph(const char * txt)
|
||||
{
|
||||
uint32_t i = 0;
|
||||
|
||||
_lv_text_encoded_next(txt, &i);
|
||||
lv_text_encoded_next(txt, &i);
|
||||
|
||||
while(txt[i] != '\0' && txt[i] != '\n' && txt[i] != '\r') {
|
||||
_lv_text_encoded_next(txt, &i);
|
||||
lv_text_encoded_next(txt, &i);
|
||||
}
|
||||
|
||||
return i;
|
||||
@ -327,7 +327,7 @@ static bool lv_bidi_letter_is_weak(uint32_t letter)
|
||||
static const char weaks[] = "0123456789";
|
||||
|
||||
do {
|
||||
uint32_t x = _lv_text_encoded_next(weaks, &i);
|
||||
uint32_t x = lv_text_encoded_next(weaks, &i);
|
||||
if(letter == x) {
|
||||
return true;
|
||||
}
|
||||
@ -378,7 +378,7 @@ static uint32_t get_txt_len(const char * txt, uint32_t max_len)
|
||||
uint32_t i = 0;
|
||||
|
||||
while(i < max_len && txt[i] != '\0') {
|
||||
_lv_text_encoded_next(txt, &i);
|
||||
lv_text_encoded_next(txt, &i);
|
||||
len++;
|
||||
}
|
||||
|
||||
@ -403,13 +403,13 @@ static lv_base_dir_t get_next_run(lv_bidi_ctx_t * ctx, const char * txt, lv_base
|
||||
|
||||
uint16_t pos_conv_i = 0;
|
||||
|
||||
letter = _lv_text_encoded_next(txt, NULL);
|
||||
letter = lv_text_encoded_next(txt, NULL);
|
||||
lv_base_dir_t dir = lv_bidi_get_letter_dir(letter);
|
||||
if(dir == LV_BASE_DIR_NEUTRAL) dir = bracket_process(ctx, txt, 0, max_len, letter, base_dir);
|
||||
|
||||
/*Find the first strong char. Skip the neutrals*/
|
||||
while(dir == LV_BASE_DIR_NEUTRAL || dir == LV_BASE_DIR_WEAK) {
|
||||
letter = _lv_text_encoded_next(txt, &i);
|
||||
letter = lv_text_encoded_next(txt, &i);
|
||||
|
||||
pos_conv_i++;
|
||||
dir = lv_bidi_get_letter_dir(letter);
|
||||
@ -434,7 +434,7 @@ static lv_base_dir_t get_next_run(lv_bidi_ctx_t * ctx, const char * txt, lv_base
|
||||
/*Find the next char which has different direction*/
|
||||
lv_base_dir_t next_dir = base_dir;
|
||||
while(i_prev < max_len && txt[i] != '\0' && txt[i] != '\n' && txt[i] != '\r') {
|
||||
letter = _lv_text_encoded_next(txt, &i);
|
||||
letter = lv_text_encoded_next(txt, &i);
|
||||
pos_conv_i++;
|
||||
next_dir = lv_bidi_get_letter_dir(letter);
|
||||
if(next_dir == LV_BASE_DIR_NEUTRAL) next_dir = bracket_process(ctx, txt, i, max_len, letter, base_dir);
|
||||
@ -497,7 +497,7 @@ static void rtl_reverse(char * dest, const char * src, uint32_t len, uint16_t *
|
||||
uint16_t pos_conv_wr = 0;
|
||||
|
||||
while(i) {
|
||||
uint32_t letter = _lv_text_encoded_prev(src, &i);
|
||||
uint32_t letter = lv_text_encoded_prev(src, &i);
|
||||
uint16_t pos_conv_letter = --pos_conv_i;
|
||||
|
||||
/*Keep weak letters (numbers) as LTR*/
|
||||
@ -507,7 +507,7 @@ static void rtl_reverse(char * dest, const char * src, uint32_t len, uint16_t *
|
||||
uint16_t pos_conv_last_weak = pos_conv_i;
|
||||
uint16_t pos_conv_first_weak = pos_conv_i;
|
||||
while(i) {
|
||||
letter = _lv_text_encoded_prev(src, &i);
|
||||
letter = lv_text_encoded_prev(src, &i);
|
||||
pos_conv_letter = --pos_conv_i;
|
||||
|
||||
/*No need to call `char_change_to_pair` because there not such chars here*/
|
||||
@ -515,7 +515,7 @@ static void rtl_reverse(char * dest, const char * src, uint32_t len, uint16_t *
|
||||
/*Finish on non-weak char*/
|
||||
/*but treat number and currency related chars as weak*/
|
||||
if(lv_bidi_letter_is_weak(letter) == false && letter != '.' && letter != ',' && letter != '$' && letter != '%') {
|
||||
_lv_text_encoded_next(src, &i); /*Rewind one letter*/
|
||||
lv_text_encoded_next(src, &i); /*Rewind one letter*/
|
||||
pos_conv_i++;
|
||||
first_weak = i;
|
||||
pos_conv_first_weak = pos_conv_i;
|
||||
@ -536,7 +536,7 @@ static void rtl_reverse(char * dest, const char * src, uint32_t len, uint16_t *
|
||||
|
||||
/*Simply store in reversed order*/
|
||||
else {
|
||||
uint32_t letter_size = _lv_text_encoded_size((const char *)&src[i]);
|
||||
uint32_t letter_size = lv_text_encoded_size((const char *)&src[i]);
|
||||
/*Swap arithmetical symbols*/
|
||||
if(letter_size == 1) {
|
||||
uint32_t new_letter = letter = char_change_to_pair(letter);
|
||||
@ -585,7 +585,7 @@ static lv_base_dir_t bracket_process(lv_bidi_ctx_t * ctx, const char * txt, uint
|
||||
*If a char with base dir. direction is found then the brackets will have `base_dir` direction*/
|
||||
uint32_t txt_i = next_pos;
|
||||
while(txt_i < len) {
|
||||
uint32_t letter_next = _lv_text_encoded_next(txt, &txt_i);
|
||||
uint32_t letter_next = lv_text_encoded_next(txt, &txt_i);
|
||||
if(letter_next == bracket_right[i]) {
|
||||
/*Closing bracket found*/
|
||||
break;
|
||||
@ -607,9 +607,9 @@ static lv_base_dir_t bracket_process(lv_bidi_ctx_t * ctx, const char * txt, uint
|
||||
|
||||
/*If there were no matching strong chars in the brackets then check the previous chars*/
|
||||
txt_i = next_pos;
|
||||
if(txt_i) _lv_text_encoded_prev(txt, &txt_i);
|
||||
if(txt_i) lv_text_encoded_prev(txt, &txt_i);
|
||||
while(txt_i > 0) {
|
||||
uint32_t letter_next = _lv_text_encoded_prev(txt, &txt_i);
|
||||
uint32_t letter_next = lv_text_encoded_prev(txt, &txt_i);
|
||||
lv_base_dir_t letter_dir = lv_bidi_get_letter_dir(letter_next);
|
||||
if(letter_dir == LV_BASE_DIR_LTR || letter_dir == LV_BASE_DIR_RTL) {
|
||||
bracket_dir = letter_dir;
|
||||
|
@ -6,7 +6,7 @@
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_text.h"
|
||||
#include "lv_text_private.h"
|
||||
#include "lv_text_ap.h"
|
||||
#include "lv_math.h"
|
||||
#include "lv_log.h"
|
||||
@ -55,23 +55,23 @@
|
||||
* GLOBAL VARIABLES
|
||||
**********************/
|
||||
#if LV_TXT_ENC == LV_TXT_ENC_UTF8
|
||||
uint8_t (*_lv_text_encoded_size)(const char *) = lv_text_utf8_size;
|
||||
uint32_t (*_lv_text_unicode_to_encoded)(uint32_t) = lv_text_unicode_to_utf8;
|
||||
uint32_t (*_lv_text_encoded_conv_wc)(uint32_t) = lv_text_utf8_conv_wc;
|
||||
uint32_t (*_lv_text_encoded_next)(const char *, uint32_t *) = lv_text_utf8_next;
|
||||
uint32_t (*_lv_text_encoded_prev)(const char *, uint32_t *) = lv_text_utf8_prev;
|
||||
uint32_t (*_lv_text_encoded_get_byte_id)(const char *, uint32_t) = lv_text_utf8_get_byte_id;
|
||||
uint32_t (*_lv_text_encoded_get_char_id)(const char *, uint32_t) = lv_text_utf8_get_char_id;
|
||||
uint32_t (*_lv_text_get_encoded_length)(const char *) = lv_text_utf8_get_length;
|
||||
uint8_t (*const lv_text_encoded_size)(const char *) = lv_text_utf8_size;
|
||||
uint32_t (*const lv_text_unicode_to_encoded)(uint32_t) = lv_text_unicode_to_utf8;
|
||||
uint32_t (*const lv_text_encoded_conv_wc)(uint32_t) = lv_text_utf8_conv_wc;
|
||||
uint32_t (*const lv_text_encoded_next)(const char *, uint32_t *) = lv_text_utf8_next;
|
||||
uint32_t (*const lv_text_encoded_prev)(const char *, uint32_t *) = lv_text_utf8_prev;
|
||||
uint32_t (*const lv_text_encoded_get_byte_id)(const char *, uint32_t) = lv_text_utf8_get_byte_id;
|
||||
uint32_t (*const lv_text_encoded_get_char_id)(const char *, uint32_t) = lv_text_utf8_get_char_id;
|
||||
uint32_t (*const lv_text_get_encoded_length)(const char *) = lv_text_utf8_get_length;
|
||||
#elif LV_TXT_ENC == LV_TXT_ENC_ASCII
|
||||
uint8_t (*_lv_text_encoded_size)(const char *) = lv_text_iso8859_1_size;
|
||||
uint32_t (*_lv_text_unicode_to_encoded)(uint32_t) = lv_text_unicode_to_iso8859_1;
|
||||
uint32_t (*_lv_text_encoded_conv_wc)(uint32_t) = lv_text_iso8859_1_conv_wc;
|
||||
uint32_t (*_lv_text_encoded_next)(const char *, uint32_t *) = lv_text_iso8859_1_next;
|
||||
uint32_t (*_lv_text_encoded_prev)(const char *, uint32_t *) = lv_text_iso8859_1_prev;
|
||||
uint32_t (*_lv_text_encoded_get_byte_id)(const char *, uint32_t) = lv_text_iso8859_1_get_byte_id;
|
||||
uint32_t (*_lv_text_encoded_get_char_id)(const char *, uint32_t) = lv_text_iso8859_1_get_char_id;
|
||||
uint32_t (*_lv_text_get_encoded_length)(const char *) = lv_text_iso8859_1_get_length;
|
||||
uint8_t (*const lv_text_encoded_size)(const char *) = lv_text_iso8859_1_size;
|
||||
uint32_t (*const lv_text_unicode_to_encoded)(uint32_t) = lv_text_unicode_to_iso8859_1;
|
||||
uint32_t (*const lv_text_encoded_conv_wc)(uint32_t) = lv_text_iso8859_1_conv_wc;
|
||||
uint32_t (*const lv_text_encoded_next)(const char *, uint32_t *) = lv_text_iso8859_1_next;
|
||||
uint32_t (*const lv_text_encoded_prev)(const char *, uint32_t *) = lv_text_iso8859_1_prev;
|
||||
uint32_t (*const lv_text_encoded_get_byte_id)(const char *, uint32_t) = lv_text_iso8859_1_get_byte_id;
|
||||
uint32_t (*const lv_text_encoded_get_char_id)(const char *, uint32_t) = lv_text_iso8859_1_get_char_id;
|
||||
uint32_t (*const lv_text_get_encoded_length)(const char *) = lv_text_iso8859_1_get_length;
|
||||
|
||||
#endif
|
||||
|
||||
@ -106,7 +106,7 @@ void lv_text_get_size(lv_point_t * size_res, const char * text, const lv_font_t
|
||||
|
||||
/*Calc. the height and longest line*/
|
||||
while(text[line_start] != '\0') {
|
||||
new_line_start += _lv_text_get_next_line(&text[line_start], font, letter_space, max_width, NULL, flag);
|
||||
new_line_start += lv_text_get_next_line(&text[line_start], font, letter_space, max_width, NULL, flag);
|
||||
|
||||
if((unsigned long)size_res->y + (unsigned long)letter_height + (unsigned long)line_space > LV_MAX_OF(int32_t)) {
|
||||
LV_LOG_WARN("integer overflow while calculating text height");
|
||||
@ -185,12 +185,12 @@ static uint32_t lv_text_get_next_word(const char * txt, const lv_font_t * font,
|
||||
uint32_t break_index = NO_BREAK_FOUND; /*only used for "long" words*/
|
||||
uint32_t break_letter_count = 0; /*Number of characters up to the long word break point*/
|
||||
|
||||
letter = _lv_text_encoded_next(txt, &i_next);
|
||||
letter = lv_text_encoded_next(txt, &i_next);
|
||||
i_next_next = i_next;
|
||||
|
||||
/*Obtain the full word, regardless if it fits or not in max_width*/
|
||||
while(txt[i] != '\0') {
|
||||
letter_next = _lv_text_encoded_next(txt, &i_next_next);
|
||||
letter_next = lv_text_encoded_next(txt, &i_next_next);
|
||||
word_len++;
|
||||
|
||||
letter_w = lv_font_get_glyph_width(font, letter, letter_next);
|
||||
@ -208,14 +208,14 @@ static uint32_t lv_text_get_next_word(const char * txt, const lv_font_t * font,
|
||||
}
|
||||
|
||||
/*Check for new line chars and breakchars*/
|
||||
if(letter == '\n' || letter == '\r' || _lv_text_is_break_char(letter)) {
|
||||
if(letter == '\n' || letter == '\r' || lv_text_is_break_char(letter)) {
|
||||
/*Update the output width on the first character if it fits.
|
||||
*Must do this here in case first letter is a break character.*/
|
||||
if(i == 0 && break_index == NO_BREAK_FOUND && word_w_ptr != NULL) *word_w_ptr = cur_w;
|
||||
word_len--;
|
||||
break;
|
||||
}
|
||||
else if(_lv_text_is_a_word(letter_next) || _lv_text_is_a_word(letter)) {
|
||||
else if(lv_text_is_a_word(letter_next) || lv_text_is_a_word(letter)) {
|
||||
/*Found a word for single letter, usually true for CJK*/
|
||||
*word_w_ptr = cur_w;
|
||||
i = i_next;
|
||||
@ -257,7 +257,7 @@ static uint32_t lv_text_get_next_word(const char * txt, const lv_font_t * font,
|
||||
int32_t n_move = LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN - (word_len - break_letter_count);
|
||||
/*Move pointer "i" backwards*/
|
||||
for(; n_move > 0; n_move--) {
|
||||
_lv_text_encoded_prev(txt, &i);
|
||||
lv_text_encoded_prev(txt, &i);
|
||||
/**
|
||||
* TODO: it would be appropriate to update the returned
|
||||
* word width hereHowever, in current usage, this doesn't impact anything.
|
||||
@ -273,9 +273,9 @@ static uint32_t lv_text_get_next_word(const char * txt, const lv_font_t * font,
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t _lv_text_get_next_line(const char * txt, const lv_font_t * font,
|
||||
int32_t letter_space, int32_t max_width,
|
||||
int32_t * used_width, lv_text_flag_t flag)
|
||||
uint32_t lv_text_get_next_line(const char * txt, const lv_font_t * font,
|
||||
int32_t letter_space, int32_t max_width,
|
||||
int32_t * used_width, lv_text_flag_t flag)
|
||||
{
|
||||
if(used_width) *used_width = 0;
|
||||
|
||||
@ -323,7 +323,7 @@ uint32_t _lv_text_get_next_line(const char * txt, const lv_font_t * font,
|
||||
|
||||
/*Always step at least one to avoid infinite loops*/
|
||||
if(i == 0) {
|
||||
uint32_t letter = _lv_text_encoded_next(txt, &i);
|
||||
uint32_t letter = lv_text_encoded_next(txt, &i);
|
||||
if(used_width != NULL) {
|
||||
line_w = lv_font_get_glyph_width(font, letter, '\0');
|
||||
}
|
||||
@ -349,7 +349,7 @@ int32_t lv_text_get_width(const char * txt, uint32_t length, const lv_font_t * f
|
||||
while(i < length) {
|
||||
uint32_t letter;
|
||||
uint32_t letter_next;
|
||||
_lv_text_encoded_letter_next_2(txt, &letter, &letter_next, &i);
|
||||
lv_text_encoded_letter_next_2(txt, &letter, &letter_next, &i);
|
||||
|
||||
int32_t char_width = lv_font_get_glyph_width(font, letter, letter_next);
|
||||
if(char_width > 0) {
|
||||
@ -367,7 +367,7 @@ int32_t lv_text_get_width(const char * txt, uint32_t length, const lv_font_t * f
|
||||
return width;
|
||||
}
|
||||
|
||||
void _lv_text_ins(char * txt_buf, uint32_t pos, const char * ins_txt)
|
||||
void lv_text_ins(char * txt_buf, uint32_t pos, const char * ins_txt)
|
||||
{
|
||||
if(txt_buf == NULL || ins_txt == NULL) return;
|
||||
|
||||
@ -376,7 +376,7 @@ void _lv_text_ins(char * txt_buf, uint32_t pos, const char * ins_txt)
|
||||
if(ins_len == 0) return;
|
||||
|
||||
size_t new_len = ins_len + old_len;
|
||||
pos = _lv_text_encoded_get_byte_id(txt_buf, pos); /*Convert to byte index instead of letter index*/
|
||||
pos = lv_text_encoded_get_byte_id(txt_buf, pos); /*Convert to byte index instead of letter index*/
|
||||
|
||||
/*Copy the second part into the end to make place to text to insert*/
|
||||
size_t i;
|
||||
@ -388,14 +388,14 @@ void _lv_text_ins(char * txt_buf, uint32_t pos, const char * ins_txt)
|
||||
lv_memcpy(txt_buf + pos, ins_txt, ins_len);
|
||||
}
|
||||
|
||||
void _lv_text_cut(char * txt, uint32_t pos, uint32_t len)
|
||||
void lv_text_cut(char * txt, uint32_t pos, uint32_t len)
|
||||
{
|
||||
if(txt == NULL) return;
|
||||
|
||||
size_t old_len = lv_strlen(txt);
|
||||
|
||||
pos = _lv_text_encoded_get_byte_id(txt, pos); /*Convert to byte index instead of letter index*/
|
||||
len = _lv_text_encoded_get_byte_id(&txt[pos], len);
|
||||
pos = lv_text_encoded_get_byte_id(txt, pos); /*Convert to byte index instead of letter index*/
|
||||
len = lv_text_encoded_get_byte_id(&txt[pos], len);
|
||||
|
||||
/*Copy the second part into the end to make place to text to insert*/
|
||||
uint32_t i;
|
||||
@ -404,7 +404,7 @@ void _lv_text_cut(char * txt, uint32_t pos, uint32_t len)
|
||||
}
|
||||
}
|
||||
|
||||
char * _lv_text_set_text_vfmt(const char * fmt, va_list ap)
|
||||
char * lv_text_set_text_vfmt(const char * fmt, va_list ap)
|
||||
{
|
||||
/*Allocate space for the new text by using trick from C99 standard section 7.19.6.12*/
|
||||
va_list ap_copy;
|
||||
@ -446,10 +446,10 @@ char * _lv_text_set_text_vfmt(const char * fmt, va_list ap)
|
||||
return text;
|
||||
}
|
||||
|
||||
void _lv_text_encoded_letter_next_2(const char * txt, uint32_t * letter, uint32_t * letter_next, uint32_t * ofs)
|
||||
void lv_text_encoded_letter_next_2(const char * txt, uint32_t * letter, uint32_t * letter_next, uint32_t * ofs)
|
||||
{
|
||||
*letter = _lv_text_encoded_next(txt, ofs);
|
||||
*letter_next = *letter != '\0' ? _lv_text_encoded_next(&txt[*ofs], NULL) : 0;
|
||||
*letter = lv_text_encoded_next(txt, ofs);
|
||||
*letter_next = *letter != '\0' ? lv_text_encoded_next(&txt[*ofs], NULL) : 0;
|
||||
}
|
||||
|
||||
#if LV_TXT_ENC == LV_TXT_ENC_UTF8
|
||||
@ -629,7 +629,7 @@ static uint32_t lv_text_utf8_prev(const char * txt, uint32_t * i)
|
||||
do {
|
||||
if(cnt >= 4) return 0; /*No UTF-8 char found before the initial*/
|
||||
|
||||
c_size = _lv_text_encoded_size(&txt[*i]);
|
||||
c_size = lv_text_encoded_size(&txt[*i]);
|
||||
if(c_size == 0) {
|
||||
if(*i != 0)
|
||||
(*i)--;
|
||||
@ -640,7 +640,7 @@ static uint32_t lv_text_utf8_prev(const char * txt, uint32_t * i)
|
||||
} while(c_size == 0);
|
||||
|
||||
uint32_t i_tmp = *i;
|
||||
uint32_t letter = _lv_text_encoded_next(txt, &i_tmp); /*Character found, get it*/
|
||||
uint32_t letter = lv_text_encoded_next(txt, &i_tmp); /*Character found, get it*/
|
||||
|
||||
return letter;
|
||||
}
|
||||
@ -657,7 +657,7 @@ static uint32_t lv_text_utf8_get_byte_id(const char * txt, uint32_t utf8_id)
|
||||
uint32_t i;
|
||||
uint32_t byte_cnt = 0;
|
||||
for(i = 0; i < utf8_id && txt[byte_cnt] != '\0'; i++) {
|
||||
uint8_t c_size = _lv_text_encoded_size(&txt[byte_cnt]);
|
||||
uint8_t c_size = lv_text_encoded_size(&txt[byte_cnt]);
|
||||
/* If the char was invalid tell it's 1 byte long*/
|
||||
byte_cnt += c_size ? c_size : 1;
|
||||
}
|
||||
@ -678,7 +678,7 @@ static uint32_t lv_text_utf8_get_char_id(const char * txt, uint32_t byte_id)
|
||||
uint32_t char_cnt = 0;
|
||||
|
||||
while(i < byte_id) {
|
||||
_lv_text_encoded_next(txt, &i); /*'i' points to the next letter so use the prev. value*/
|
||||
lv_text_encoded_next(txt, &i); /*'i' points to the next letter so use the prev. value*/
|
||||
char_cnt++;
|
||||
}
|
||||
|
||||
@ -697,7 +697,7 @@ static uint32_t lv_text_utf8_get_length(const char * txt)
|
||||
uint32_t i = 0;
|
||||
|
||||
while(txt[i] != '\0') {
|
||||
_lv_text_encoded_next(txt, &i);
|
||||
lv_text_encoded_next(txt, &i);
|
||||
len++;
|
||||
}
|
||||
|
||||
|
@ -80,22 +80,6 @@ typedef uint8_t lv_text_align_t;
|
||||
void lv_text_get_size(lv_point_t * size_res, const char * text, const lv_font_t * font, int32_t letter_space,
|
||||
int32_t line_space, int32_t max_width, lv_text_flag_t flag);
|
||||
|
||||
/**
|
||||
* Get the next line of text. Check line length and break chars too.
|
||||
* @param txt a '\0' terminated string
|
||||
* @param font pointer to a font
|
||||
* @param letter_space letter space
|
||||
* @param max_width max width of the text (break the lines to fit this size). Set COORD_MAX to avoid
|
||||
* line breaks
|
||||
* @param used_width When used_width != NULL, save the width of this line if
|
||||
* flag == LV_TEXT_FLAG_NONE, otherwise save -1.
|
||||
* @param flag settings for the text from 'txt_flag_type' enum
|
||||
* @return the index of the first char of the new line (in byte index not letter index. With UTF-8
|
||||
* they are different)
|
||||
*/
|
||||
uint32_t _lv_text_get_next_line(const char * txt, const lv_font_t * font, int32_t letter_space,
|
||||
int32_t max_width, int32_t * used_width, lv_text_flag_t flag);
|
||||
|
||||
/**
|
||||
* Give the length of a text with a given font
|
||||
* @param txt a '\0' terminate string
|
||||
@ -107,222 +91,6 @@ uint32_t _lv_text_get_next_line(const char * txt, const lv_font_t * font, int32_
|
||||
*/
|
||||
int32_t lv_text_get_width(const char * txt, uint32_t length, const lv_font_t * font, int32_t letter_space);
|
||||
|
||||
/**
|
||||
* Insert a string into an other
|
||||
* @param txt_buf the original text (must be big enough for the result text and NULL terminated)
|
||||
* @param pos position to insert (0: before the original text, 1: after the first char etc.)
|
||||
* @param ins_txt text to insert, must be '\0' terminated
|
||||
*/
|
||||
void _lv_text_ins(char * txt_buf, uint32_t pos, const char * ins_txt);
|
||||
|
||||
/**
|
||||
* Delete a part of a string
|
||||
* @param txt string to modify, must be '\0' terminated and should point to a heap or stack frame, not read-only memory.
|
||||
* @param pos position where to start the deleting (0: before the first char, 1: after the first
|
||||
* char etc.)
|
||||
* @param len number of characters to delete
|
||||
*/
|
||||
void _lv_text_cut(char * txt, uint32_t pos, uint32_t len);
|
||||
|
||||
/**
|
||||
* return a new formatted text. Memory will be allocated to store the text.
|
||||
* @param fmt `printf`-like format
|
||||
* @param ap items to print
|
||||
|
||||
* @return pointer to the allocated text string.
|
||||
*/
|
||||
char * _lv_text_set_text_vfmt(const char * fmt, va_list ap) LV_FORMAT_ATTRIBUTE(1, 0);
|
||||
|
||||
/**
|
||||
* Decode two encoded character from a string.
|
||||
* @param txt pointer to '\0' terminated string
|
||||
* @param letter the first decoded Unicode character or 0 on invalid data code
|
||||
* @param letter_next the second decoded Unicode character or 0 on invalid data code
|
||||
* @param ofs start index in 'txt' where to start.
|
||||
* After the call it will point to the next encoded char in 'txt'.
|
||||
* NULL to use txt[0] as index
|
||||
*/
|
||||
void _lv_text_encoded_letter_next_2(const char * txt, uint32_t * letter, uint32_t * letter_next, uint32_t * ofs);
|
||||
|
||||
/**
|
||||
* Test if char is break char or not (a text can broken here or not)
|
||||
* @param letter a letter
|
||||
* @return false: 'letter' is not break char
|
||||
*/
|
||||
static inline bool _lv_text_is_break_char(uint32_t letter)
|
||||
{
|
||||
uint8_t i;
|
||||
bool ret = false;
|
||||
|
||||
/*Compare the letter to TXT_BREAK_CHARS*/
|
||||
for(i = 0; LV_TXT_BREAK_CHARS[i] != '\0'; i++) {
|
||||
if(letter == (uint32_t)LV_TXT_BREAK_CHARS[i]) {
|
||||
ret = true; /*If match then it is break char*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if char is break char or not (a text can broken here or not)
|
||||
* @param letter a letter
|
||||
* @return false: 'letter' is not break char
|
||||
*/
|
||||
static inline bool _lv_text_is_a_word(uint32_t letter)
|
||||
{
|
||||
/*Cheap check on invalid letter*/
|
||||
if(letter == 0) return false;
|
||||
|
||||
/*CJK Unified Ideographs*/
|
||||
if(letter >= 0x4E00 && letter <= 0x9FFF) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*Fullwidth ASCII variants*/
|
||||
if(letter >= 0xFF01 && letter <= 0xFF5E) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*CJK symbols and punctuation*/
|
||||
if(letter >= 0x3000 && letter <= 0x303F) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*CJK Radicals Supplement*/
|
||||
if(letter >= 0x2E80 && letter <= 0x2EFF) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*CJK Strokes*/
|
||||
if(letter >= 0x31C0 && letter <= 0x31EF) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*Hiragana and Katakana*/
|
||||
if(letter >= 0x3040 && letter <= 0x30FF) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*Chinese Vertical Forms*/
|
||||
if(letter >= 0xFE10 && letter <= 0xFE1F) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*CJK Compatibility Forms*/
|
||||
if(letter >= 0xFE30 && letter <= 0xFE4F) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if character can be treated as marker, and don't need to be rendered.
|
||||
* Note, this is not a full list. Add your findings to the list.
|
||||
*
|
||||
* @param letter a letter
|
||||
* @return true if so
|
||||
*/
|
||||
static inline bool _lv_text_is_marker(uint32_t letter)
|
||||
{
|
||||
if(letter < 0x20) return true;
|
||||
|
||||
/*U+061C ARABIC LETTER MARK, see https://www.compart.com/en/unicode/block/U+0600*/
|
||||
if(letter == 0x061C) return true;
|
||||
|
||||
/*U+115F HANGUL CHOSEONG FILLER, See https://www.compart.com/en/unicode/block/U+1100*/
|
||||
if(letter == 0x115F) return true;
|
||||
/*U+1160 HANGUL JUNGSEONG FILLER*/
|
||||
if(letter == 0x1160) return true;
|
||||
|
||||
/*See https://www.compart.com/en/unicode/block/U+1800*/
|
||||
if(letter >= 0x180B && letter <= 0x180E) return true;
|
||||
|
||||
/*See https://www.compart.com/en/unicode/block/U+2000*/
|
||||
if(letter >= 0x200B && letter <= 0x200F) return true;
|
||||
if(letter >= 0x2028 && letter <= 0x202F) return true;
|
||||
if(letter >= 0x205F && letter <= 0x206F) return true;
|
||||
|
||||
/*U+FEFF ZERO WIDTH NO-BREAK SPACE, see https://www.compart.com/en/unicode/block/U+FE70*/
|
||||
if(letter == 0xFEFF) return true;
|
||||
|
||||
if(letter == 0xF8FF) return true; /*LV_SYMBOL_DUMMY*/
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
* GLOBAL FUNCTION POINTERS FOR CHARACTER ENCODING INTERFACE
|
||||
***************************************************************/
|
||||
|
||||
/**
|
||||
* Give the size of an encoded character
|
||||
* @param str pointer to a character in a string
|
||||
* @return length of the encoded character (1,2,3 ...). O in invalid
|
||||
*/
|
||||
extern uint8_t (*_lv_text_encoded_size)(const char *);
|
||||
|
||||
/**
|
||||
* Convert a Unicode letter to encoded
|
||||
* @param letter_uni a Unicode letter
|
||||
* @return Encoded character in Little Endian to be compatible with C chars (e.g. 'Á', 'Ü')
|
||||
*/
|
||||
extern uint32_t (*_lv_text_unicode_to_encoded)(uint32_t);
|
||||
|
||||
/**
|
||||
* Convert a wide character, e.g. 'Á' little endian to be compatible with the encoded format.
|
||||
* @param c a wide character
|
||||
* @return `c` in the encoded format
|
||||
*/
|
||||
extern uint32_t (*_lv_text_encoded_conv_wc)(uint32_t c);
|
||||
|
||||
/**
|
||||
* Decode the next encoded character from a string.
|
||||
* @param txt pointer to '\0' terminated string
|
||||
* @param i start index in 'txt' where to start.
|
||||
* After the call it will point to the next encoded char in 'txt'.
|
||||
* NULL to use txt[0] as index
|
||||
* @return the decoded Unicode character or 0 on invalid data code
|
||||
*/
|
||||
extern uint32_t (*_lv_text_encoded_next)(const char *, uint32_t *);
|
||||
|
||||
/**
|
||||
* Get the previous encoded character form a string.
|
||||
* @param txt pointer to '\0' terminated string
|
||||
* @param i_start index in 'txt' where to start. After the call it will point to the previous
|
||||
* encoded char in 'txt'.
|
||||
* @return the decoded Unicode character or 0 on invalid data
|
||||
*/
|
||||
extern uint32_t (*_lv_text_encoded_prev)(const char *, uint32_t *);
|
||||
|
||||
/**
|
||||
* Convert a letter index (in the encoded text) to byte index.
|
||||
* E.g. in UTF-8 "AÁRT" index of 'R' is 2 but start at byte 3 because 'Á' is 2 bytes long
|
||||
* @param txt a '\0' terminated UTF-8 string
|
||||
* @param enc_id letter index
|
||||
* @return byte index of the 'enc_id'th letter
|
||||
*/
|
||||
extern uint32_t (*_lv_text_encoded_get_byte_id)(const char *, uint32_t);
|
||||
|
||||
/**
|
||||
* Convert a byte index (in an encoded text) to character index.
|
||||
* E.g. in UTF-8 "AÁRT" index of 'R' is 2 but start at byte 3 because 'Á' is 2 bytes long
|
||||
* @param txt a '\0' terminated UTF-8 string
|
||||
* @param byte_id byte index
|
||||
* @return character index of the letter at 'byte_id'th position
|
||||
*/
|
||||
extern uint32_t (*_lv_text_encoded_get_char_id)(const char *, uint32_t);
|
||||
|
||||
/**
|
||||
* Get the number of characters (and NOT bytes) in a string.
|
||||
* E.g. in UTF-8 "ÁBC" is 3 characters (but 4 bytes)
|
||||
* @param txt a '\0' terminated char string
|
||||
* @return number of characters
|
||||
*/
|
||||
extern uint32_t (*_lv_text_get_encoded_length)(const char *);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
@ -7,7 +7,7 @@
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_bidi.h"
|
||||
#include "lv_text.h"
|
||||
#include "lv_text_private.h"
|
||||
#include "lv_text_ap.h"
|
||||
#include "lv_types.h"
|
||||
#include "../stdlib/lv_mem.h"
|
||||
@ -114,12 +114,12 @@ uint32_t _lv_text_ap_calc_bytes_count(const char * txt)
|
||||
uint32_t i, j;
|
||||
uint32_t ch_enc;
|
||||
|
||||
txt_length = _lv_text_get_encoded_length(txt);
|
||||
txt_length = lv_text_get_encoded_length(txt);
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
while(i < txt_length) {
|
||||
ch_enc = _lv_text_encoded_next(txt, &j);
|
||||
ch_enc = lv_text_encoded_next(txt, &j);
|
||||
current_ap_idx = lv_ap_get_char_index(ch_enc);
|
||||
|
||||
if(current_ap_idx != LV_UNDEF_ARABIC_PERSIAN_CHARS)
|
||||
@ -148,7 +148,7 @@ void _lv_text_ap_proc(const char * txt, char * txt_out)
|
||||
uint32_t * ch_fin;
|
||||
char * txt_out_temp;
|
||||
|
||||
txt_length = _lv_text_get_encoded_length(txt);
|
||||
txt_length = lv_text_get_encoded_length(txt);
|
||||
|
||||
ch_enc = (uint32_t *)lv_malloc(sizeof(uint32_t) * (txt_length + 1));
|
||||
ch_fin = (uint32_t *)lv_malloc(sizeof(uint32_t) * (txt_length + 1));
|
||||
@ -156,7 +156,7 @@ void _lv_text_ap_proc(const char * txt, char * txt_out)
|
||||
i = 0;
|
||||
j = 0;
|
||||
while(j < txt_length)
|
||||
ch_enc[j++] = _lv_text_encoded_next(txt, &i);
|
||||
ch_enc[j++] = lv_text_encoded_next(txt, &i);
|
||||
|
||||
ch_enc[j] = 0;
|
||||
|
||||
|
271
src/misc/lv_text_private.h
Normal file
271
src/misc/lv_text_private.h
Normal file
@ -0,0 +1,271 @@
|
||||
/**
|
||||
* @file lv_text_private.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_TEXT_PRIVATE_H
|
||||
#define LV_TEXT_PRIVATE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
#include "lv_text.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Get the next line of text. Check line length and break chars too.
|
||||
* @param txt a '\0' terminated string
|
||||
* @param font pointer to a font
|
||||
* @param letter_space letter space
|
||||
* @param max_width max width of the text (break the lines to fit this size). Set COORD_MAX to avoid
|
||||
* line breaks
|
||||
* @param used_width When used_width != NULL, save the width of this line if
|
||||
* flag == LV_TEXT_FLAG_NONE, otherwise save -1.
|
||||
* @param flag settings for the text from 'txt_flag_type' enum
|
||||
* @return the index of the first char of the new line (in byte index not letter index. With UTF-8
|
||||
* they are different)
|
||||
*/
|
||||
uint32_t lv_text_get_next_line(const char * txt, const lv_font_t * font, int32_t letter_space,
|
||||
int32_t max_width, int32_t * used_width, lv_text_flag_t flag);
|
||||
|
||||
/**
|
||||
* Insert a string into an other
|
||||
* @param txt_buf the original text (must be big enough for the result text and NULL terminated)
|
||||
* @param pos position to insert (0: before the original text, 1: after the first char etc.)
|
||||
* @param ins_txt text to insert, must be '\0' terminated
|
||||
*/
|
||||
void lv_text_ins(char * txt_buf, uint32_t pos, const char * ins_txt);
|
||||
|
||||
/**
|
||||
* Delete a part of a string
|
||||
* @param txt string to modify, must be '\0' terminated and should point to a heap or stack frame, not read-only memory.
|
||||
* @param pos position where to start the deleting (0: before the first char, 1: after the first
|
||||
* char etc.)
|
||||
* @param len number of characters to delete
|
||||
*/
|
||||
void lv_text_cut(char * txt, uint32_t pos, uint32_t len);
|
||||
|
||||
/**
|
||||
* return a new formatted text. Memory will be allocated to store the text.
|
||||
* @param fmt `printf`-like format
|
||||
* @param ap items to print
|
||||
|
||||
* @return pointer to the allocated text string.
|
||||
*/
|
||||
char * lv_text_set_text_vfmt(const char * fmt, va_list ap) LV_FORMAT_ATTRIBUTE(1, 0);
|
||||
|
||||
/**
|
||||
* Decode two encoded character from a string.
|
||||
* @param txt pointer to '\0' terminated string
|
||||
* @param letter the first decoded Unicode character or 0 on invalid data code
|
||||
* @param letter_next the second decoded Unicode character or 0 on invalid data code
|
||||
* @param ofs start index in 'txt' where to start.
|
||||
* After the call it will point to the next encoded char in 'txt'.
|
||||
* NULL to use txt[0] as index
|
||||
*/
|
||||
void lv_text_encoded_letter_next_2(const char * txt, uint32_t * letter, uint32_t * letter_next, uint32_t * ofs);
|
||||
|
||||
/**
|
||||
* Test if char is break char or not (a text can broken here or not)
|
||||
* @param letter a letter
|
||||
* @return false: 'letter' is not break char
|
||||
*/
|
||||
static inline bool lv_text_is_break_char(uint32_t letter)
|
||||
{
|
||||
uint8_t i;
|
||||
bool ret = false;
|
||||
|
||||
/*Compare the letter to TXT_BREAK_CHARS*/
|
||||
for(i = 0; LV_TXT_BREAK_CHARS[i] != '\0'; i++) {
|
||||
if(letter == (uint32_t)LV_TXT_BREAK_CHARS[i]) {
|
||||
ret = true; /*If match then it is break char*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if char is break char or not (a text can broken here or not)
|
||||
* @param letter a letter
|
||||
* @return false: 'letter' is not break char
|
||||
*/
|
||||
static inline bool lv_text_is_a_word(uint32_t letter)
|
||||
{
|
||||
/*Cheap check on invalid letter*/
|
||||
if(letter == 0) return false;
|
||||
|
||||
/*CJK Unified Ideographs*/
|
||||
if(letter >= 0x4E00 && letter <= 0x9FFF) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*Fullwidth ASCII variants*/
|
||||
if(letter >= 0xFF01 && letter <= 0xFF5E) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*CJK symbols and punctuation*/
|
||||
if(letter >= 0x3000 && letter <= 0x303F) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*CJK Radicals Supplement*/
|
||||
if(letter >= 0x2E80 && letter <= 0x2EFF) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*CJK Strokes*/
|
||||
if(letter >= 0x31C0 && letter <= 0x31EF) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*Hiragana and Katakana*/
|
||||
if(letter >= 0x3040 && letter <= 0x30FF) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*Chinese Vertical Forms*/
|
||||
if(letter >= 0xFE10 && letter <= 0xFE1F) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*CJK Compatibility Forms*/
|
||||
if(letter >= 0xFE30 && letter <= 0xFE4F) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if character can be treated as marker, and don't need to be rendered.
|
||||
* Note, this is not a full list. Add your findings to the list.
|
||||
*
|
||||
* @param letter a letter
|
||||
* @return true if so
|
||||
*/
|
||||
static inline bool lv_text_is_marker(uint32_t letter)
|
||||
{
|
||||
if(letter < 0x20) return true;
|
||||
|
||||
/*U+061C ARABIC LETTER MARK, see https://www.compart.com/en/unicode/block/U+0600*/
|
||||
if(letter == 0x061C) return true;
|
||||
|
||||
/*U+115F HANGUL CHOSEONG FILLER, See https://www.compart.com/en/unicode/block/U+1100*/
|
||||
if(letter == 0x115F) return true;
|
||||
/*U+1160 HANGUL JUNGSEONG FILLER*/
|
||||
if(letter == 0x1160) return true;
|
||||
|
||||
/*See https://www.compart.com/en/unicode/block/U+1800*/
|
||||
if(letter >= 0x180B && letter <= 0x180E) return true;
|
||||
|
||||
/*See https://www.compart.com/en/unicode/block/U+2000*/
|
||||
if(letter >= 0x200B && letter <= 0x200F) return true;
|
||||
if(letter >= 0x2028 && letter <= 0x202F) return true;
|
||||
if(letter >= 0x205F && letter <= 0x206F) return true;
|
||||
|
||||
/*U+FEFF ZERO WIDTH NO-BREAK SPACE, see https://www.compart.com/en/unicode/block/U+FE70*/
|
||||
if(letter == 0xFEFF) return true;
|
||||
|
||||
if(letter == 0xF8FF) return true; /*LV_SYMBOL_DUMMY*/
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
* GLOBAL FUNCTION POINTERS FOR CHARACTER ENCODING INTERFACE
|
||||
***************************************************************/
|
||||
|
||||
/**
|
||||
* Give the size of an encoded character
|
||||
* @param str pointer to a character in a string
|
||||
* @return length of the encoded character (1,2,3 ...). O in invalid
|
||||
*/
|
||||
extern uint8_t (*const lv_text_encoded_size)(const char *);
|
||||
|
||||
/**
|
||||
* Convert a Unicode letter to encoded
|
||||
* @param letter_uni a Unicode letter
|
||||
* @return Encoded character in Little Endian to be compatible with C chars (e.g. 'Á', 'Ü')
|
||||
*/
|
||||
extern uint32_t (*const lv_text_unicode_to_encoded)(uint32_t);
|
||||
|
||||
/**
|
||||
* Convert a wide character, e.g. 'Á' little endian to be compatible with the encoded format.
|
||||
* @param c a wide character
|
||||
* @return `c` in the encoded format
|
||||
*/
|
||||
extern uint32_t (*const lv_text_encoded_conv_wc)(uint32_t c);
|
||||
|
||||
/**
|
||||
* Decode the next encoded character from a string.
|
||||
* @param txt pointer to '\0' terminated string
|
||||
* @param i start index in 'txt' where to start.
|
||||
* After the call it will point to the next encoded char in 'txt'.
|
||||
* NULL to use txt[0] as index
|
||||
* @return the decoded Unicode character or 0 on invalid data code
|
||||
*/
|
||||
extern uint32_t (*const lv_text_encoded_next)(const char *, uint32_t *);
|
||||
|
||||
/**
|
||||
* Get the previous encoded character form a string.
|
||||
* @param txt pointer to '\0' terminated string
|
||||
* @param i_start index in 'txt' where to start. After the call it will point to the previous
|
||||
* encoded char in 'txt'.
|
||||
* @return the decoded Unicode character or 0 on invalid data
|
||||
*/
|
||||
extern uint32_t (*const lv_text_encoded_prev)(const char *, uint32_t *);
|
||||
|
||||
/**
|
||||
* Convert a letter index (in the encoded text) to byte index.
|
||||
* E.g. in UTF-8 "AÁRT" index of 'R' is 2 but start at byte 3 because 'Á' is 2 bytes long
|
||||
* @param txt a '\0' terminated UTF-8 string
|
||||
* @param enc_id letter index
|
||||
* @return byte index of the 'enc_id'th letter
|
||||
*/
|
||||
extern uint32_t (*const lv_text_encoded_get_byte_id)(const char *, uint32_t);
|
||||
|
||||
/**
|
||||
* Convert a byte index (in an encoded text) to character index.
|
||||
* E.g. in UTF-8 "AÁRT" index of 'R' is 2 but start at byte 3 because 'Á' is 2 bytes long
|
||||
* @param txt a '\0' terminated UTF-8 string
|
||||
* @param byte_id byte index
|
||||
* @return character index of the letter at 'byte_id'th position
|
||||
*/
|
||||
extern uint32_t (*const lv_text_encoded_get_char_id)(const char *, uint32_t);
|
||||
|
||||
/**
|
||||
* Get the number of characters (and NOT bytes) in a string.
|
||||
* E.g. in UTF-8 "ÁBC" is 3 characters (but 4 bytes)
|
||||
* @param txt a '\0' terminated char string
|
||||
* @return number of characters
|
||||
*/
|
||||
extern uint32_t (*const lv_text_get_encoded_length)(const char *);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_TEXT_PRIVATE_H*/
|
@ -19,6 +19,7 @@
|
||||
#include "../../misc/lv_anim.h"
|
||||
#include "../../misc/lv_math.h"
|
||||
#include "../../misc/lv_text_ap.h"
|
||||
#include "../../misc/lv_text_private.h"
|
||||
#include "../../stdlib/lv_string.h"
|
||||
|
||||
/*********************
|
||||
@ -234,7 +235,7 @@ void lv_dropdown_add_option(lv_obj_t * obj, const char * option, uint32_t pos)
|
||||
|
||||
/*Add delimiter to existing options*/
|
||||
if((insert_pos > 0) && (pos >= dropdown->option_cnt))
|
||||
_lv_text_ins(dropdown->options, _lv_text_encoded_get_char_id(dropdown->options, insert_pos++), "\n");
|
||||
lv_text_ins(dropdown->options, lv_text_encoded_get_char_id(dropdown->options, insert_pos++), "\n");
|
||||
|
||||
/*Insert the new option, adding \n if necessary*/
|
||||
char * ins_buf = lv_malloc(ins_len + 2); /*+ 2 for terminating NULL and possible \n*/
|
||||
@ -247,7 +248,7 @@ void lv_dropdown_add_option(lv_obj_t * obj, const char * option, uint32_t pos)
|
||||
#endif
|
||||
if(pos < dropdown->option_cnt) lv_strcat(ins_buf, "\n");
|
||||
|
||||
_lv_text_ins(dropdown->options, _lv_text_encoded_get_char_id(dropdown->options, insert_pos), ins_buf);
|
||||
lv_text_ins(dropdown->options, lv_text_encoded_get_char_id(dropdown->options, insert_pos), ins_buf);
|
||||
lv_free(ins_buf);
|
||||
|
||||
dropdown->option_cnt++;
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "../../misc/lv_math.h"
|
||||
#include "../../misc/lv_bidi.h"
|
||||
#include "../../misc/lv_text_ap.h"
|
||||
#include "../../misc/lv_text_private.h"
|
||||
#include "../../stdlib/lv_sprintf.h"
|
||||
#include "../../stdlib/lv_string.h"
|
||||
|
||||
@ -154,7 +155,7 @@ void lv_label_set_text_fmt(lv_obj_t * obj, const char * fmt, ...)
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
label->text = _lv_text_set_text_vfmt(fmt, args);
|
||||
label->text = lv_text_set_text_vfmt(fmt, args);
|
||||
va_end(args);
|
||||
label->static_txt = 0; /*Now the text is dynamically allocated*/
|
||||
|
||||
@ -279,7 +280,7 @@ void lv_label_get_letter_pos(const lv_obj_t * obj, uint32_t char_id, lv_point_t
|
||||
|
||||
lv_text_flag_t flag = get_label_flags(label);
|
||||
|
||||
const uint32_t byte_id = _lv_text_encoded_get_byte_id(txt, char_id);
|
||||
const uint32_t byte_id = lv_text_encoded_get_byte_id(txt, char_id);
|
||||
/*Search the line of the index letter*/
|
||||
const int32_t line_space = lv_obj_get_style_text_line_space(obj, LV_PART_MAIN);
|
||||
const int32_t letter_space = lv_obj_get_style_text_letter_space(obj, LV_PART_MAIN);
|
||||
@ -295,7 +296,7 @@ void lv_label_get_letter_pos(const lv_obj_t * obj, uint32_t char_id, lv_point_t
|
||||
uint32_t line_start = 0;
|
||||
uint32_t new_line_start = 0;
|
||||
while(txt[new_line_start] != '\0') {
|
||||
new_line_start += _lv_text_get_next_line(&txt[line_start], font, letter_space, max_w, NULL, flag);
|
||||
new_line_start += lv_text_get_next_line(&txt[line_start], font, letter_space, max_w, NULL, flag);
|
||||
if(byte_id < new_line_start || txt[new_line_start] == '\0')
|
||||
break; /*The line of 'index' letter begins at 'line_start'*/
|
||||
|
||||
@ -324,7 +325,7 @@ void lv_label_get_letter_pos(const lv_obj_t * obj, uint32_t char_id, lv_point_t
|
||||
bidi_txt = &txt[line_start];
|
||||
}
|
||||
else {
|
||||
uint32_t line_char_id = _lv_text_encoded_get_char_id(&txt[line_start], byte_id - line_start);
|
||||
uint32_t line_char_id = lv_text_encoded_get_char_id(&txt[line_start], byte_id - line_start);
|
||||
|
||||
bool is_rtl;
|
||||
uint32_t visual_char_pos = _lv_bidi_get_visual_pos(&txt[line_start], &mutable_bidi_txt, new_line_start - line_start,
|
||||
@ -332,7 +333,7 @@ void lv_label_get_letter_pos(const lv_obj_t * obj, uint32_t char_id, lv_point_t
|
||||
bidi_txt = mutable_bidi_txt;
|
||||
if(is_rtl) visual_char_pos++;
|
||||
|
||||
visual_byte_pos = _lv_text_encoded_get_byte_id(bidi_txt, visual_char_pos);
|
||||
visual_byte_pos = lv_text_encoded_get_byte_id(bidi_txt, visual_char_pos);
|
||||
}
|
||||
#else
|
||||
bidi_txt = &txt[line_start];
|
||||
@ -380,14 +381,14 @@ uint32_t lv_label_get_letter_on(const lv_obj_t * obj, lv_point_t * pos_in, bool
|
||||
|
||||
/*Search the line of the index letter*/;
|
||||
while(txt[line_start] != '\0') {
|
||||
new_line_start += _lv_text_get_next_line(&txt[line_start], font, letter_space, max_w, NULL, flag);
|
||||
new_line_start += lv_text_get_next_line(&txt[line_start], font, letter_space, max_w, NULL, flag);
|
||||
|
||||
if(pos.y <= y + letter_height) {
|
||||
/*The line is found (stored in 'line_start')*/
|
||||
/*Include the NULL terminator in the last line*/
|
||||
uint32_t tmp = new_line_start;
|
||||
uint32_t letter;
|
||||
letter = _lv_text_encoded_prev(txt, &tmp);
|
||||
letter = lv_text_encoded_prev(txt, &tmp);
|
||||
if(letter != '\n' && txt[new_line_start] == '\0') new_line_start++;
|
||||
break;
|
||||
}
|
||||
@ -427,7 +428,7 @@ uint32_t lv_label_get_letter_on(const lv_obj_t * obj, lv_point_t * pos_in, bool
|
||||
/*Be careful 'i' already points to the next character*/
|
||||
uint32_t letter;
|
||||
uint32_t letter_next;
|
||||
_lv_text_encoded_letter_next_2(bidi_txt, &letter, &letter_next, &i);
|
||||
lv_text_encoded_letter_next_2(bidi_txt, &letter, &letter_next, &i);
|
||||
|
||||
int32_t gw = lv_font_get_glyph_width(font, letter, letter_next);
|
||||
|
||||
@ -446,7 +447,7 @@ uint32_t lv_label_get_letter_on(const lv_obj_t * obj, lv_point_t * pos_in, bool
|
||||
#if LV_USE_BIDI
|
||||
if(bidi) {
|
||||
/*Handle Bidi*/
|
||||
uint32_t cid = _lv_text_encoded_get_char_id(bidi_txt, i);
|
||||
uint32_t cid = lv_text_encoded_get_char_id(bidi_txt, i);
|
||||
if(txt[line_start + i] == '\0') {
|
||||
logical_pos = i;
|
||||
}
|
||||
@ -461,10 +462,10 @@ uint32_t lv_label_get_letter_on(const lv_obj_t * obj, lv_point_t * pos_in, bool
|
||||
else
|
||||
#endif
|
||||
{
|
||||
logical_pos = _lv_text_encoded_get_char_id(bidi_txt, i);
|
||||
logical_pos = lv_text_encoded_get_char_id(bidi_txt, i);
|
||||
}
|
||||
|
||||
return logical_pos + _lv_text_encoded_get_char_id(txt, line_start);
|
||||
return logical_pos + lv_text_encoded_get_char_id(txt, line_start);
|
||||
}
|
||||
|
||||
bool lv_label_is_char_under_pos(const lv_obj_t * obj, lv_point_t * pos)
|
||||
@ -489,7 +490,7 @@ bool lv_label_is_char_under_pos(const lv_obj_t * obj, lv_point_t * pos)
|
||||
/*Search the line of the index letter*/
|
||||
int32_t y = 0;
|
||||
while(txt[line_start] != '\0') {
|
||||
new_line_start += _lv_text_get_next_line(&txt[line_start], font, letter_space, max_w, NULL, flag);
|
||||
new_line_start += lv_text_get_next_line(&txt[line_start], font, letter_space, max_w, NULL, flag);
|
||||
|
||||
if(pos->y <= y + letter_height) break; /*The line is found (stored in 'line_start')*/
|
||||
y += letter_height + line_space;
|
||||
@ -520,7 +521,7 @@ bool lv_label_is_char_under_pos(const lv_obj_t * obj, lv_point_t * pos)
|
||||
while(i <= new_line_start - 1) {
|
||||
/*Get the current letter and the next letter for kerning*/
|
||||
/*Be careful 'i' already points to the next character*/
|
||||
_lv_text_encoded_letter_next_2(txt, &letter, &letter_next, &i);
|
||||
lv_text_encoded_letter_next_2(txt, &letter, &letter_next, &i);
|
||||
|
||||
last_x = x;
|
||||
x += lv_font_get_glyph_width(font, letter, letter_next);
|
||||
@ -588,10 +589,10 @@ void lv_label_ins_text(lv_obj_t * obj, uint32_t pos, const char * txt)
|
||||
if(label->text == NULL) return;
|
||||
|
||||
if(pos == LV_LABEL_POS_LAST) {
|
||||
pos = _lv_text_get_encoded_length(label->text);
|
||||
pos = lv_text_get_encoded_length(label->text);
|
||||
}
|
||||
|
||||
_lv_text_ins(label->text, pos, txt);
|
||||
lv_text_ins(label->text, pos, txt);
|
||||
lv_label_set_text(obj, NULL);
|
||||
}
|
||||
|
||||
@ -607,7 +608,7 @@ void lv_label_cut_text(lv_obj_t * obj, uint32_t pos, uint32_t cnt)
|
||||
|
||||
char * label_txt = lv_label_get_text(obj);
|
||||
/*Delete the characters*/
|
||||
_lv_text_cut(label_txt, pos, cnt);
|
||||
lv_text_cut(label_txt, pos, cnt);
|
||||
|
||||
/*Refresh the label*/
|
||||
lv_label_refr_text(obj);
|
||||
@ -1060,7 +1061,7 @@ static void lv_label_refr_text(lv_obj_t * obj)
|
||||
else if(size.y <= lv_font_get_line_height(font)) { /*No dots are required for one-line texts*/
|
||||
label->dot_end = LV_LABEL_DOT_END_INV;
|
||||
}
|
||||
else if(_lv_text_get_encoded_length(label->text) <= LV_LABEL_DOT_NUM) { /*Don't turn to dots all the characters*/
|
||||
else if(lv_text_get_encoded_length(label->text) <= LV_LABEL_DOT_NUM) { /*Don't turn to dots all the characters*/
|
||||
label->dot_end = LV_LABEL_DOT_END_INV;
|
||||
}
|
||||
else {
|
||||
@ -1085,9 +1086,9 @@ static void lv_label_refr_text(lv_obj_t * obj)
|
||||
|
||||
/*Be sure there is space for the dots*/
|
||||
size_t txt_len = lv_strlen(label->text);
|
||||
uint32_t byte_id = _lv_text_encoded_get_byte_id(label->text, letter_id);
|
||||
uint32_t byte_id = lv_text_encoded_get_byte_id(label->text, letter_id);
|
||||
while(byte_id + LV_LABEL_DOT_NUM > txt_len) {
|
||||
_lv_text_encoded_prev(label->text, &byte_id);
|
||||
lv_text_encoded_prev(label->text, &byte_id);
|
||||
letter_id--;
|
||||
}
|
||||
|
||||
@ -1096,8 +1097,8 @@ static void lv_label_refr_text(lv_obj_t * obj)
|
||||
uint32_t i;
|
||||
uint8_t len = 0;
|
||||
for(i = 0; i <= LV_LABEL_DOT_NUM; i++) {
|
||||
len += _lv_text_encoded_size(&label->text[byte_id]);
|
||||
_lv_text_encoded_next(label->text, &byte_id);
|
||||
len += lv_text_encoded_size(&label->text[byte_id]);
|
||||
lv_text_encoded_next(label->text, &byte_id);
|
||||
if(len > LV_LABEL_DOT_NUM || byte_id > txt_len) {
|
||||
break;
|
||||
}
|
||||
@ -1127,7 +1128,7 @@ static void lv_label_revert_dots(lv_obj_t * obj)
|
||||
if(label->dot_end == LV_LABEL_DOT_END_INV) return;
|
||||
|
||||
const uint32_t letter_i = label->dot_end - LV_LABEL_DOT_NUM;
|
||||
const uint32_t byte_i = _lv_text_encoded_get_byte_id(label->text, letter_i);
|
||||
const uint32_t byte_i = lv_text_encoded_get_byte_id(label->text, letter_i);
|
||||
|
||||
/*Restore the characters*/
|
||||
uint8_t i = 0;
|
||||
|
@ -10,6 +10,7 @@
|
||||
#if LV_USE_ROLLER != 0
|
||||
|
||||
#include "../../misc/lv_assert.h"
|
||||
#include "../../misc/lv_text_private.h"
|
||||
#include "../../draw/lv_draw.h"
|
||||
#include "../../core/lv_group.h"
|
||||
#include "../../indev/lv_indev.h"
|
||||
@ -678,7 +679,7 @@ static lv_result_t release_handler(lv_obj_t * obj)
|
||||
|
||||
uint32_t letter_cnt = 0;
|
||||
for(letter_cnt = 0; letter_cnt < letter_i; letter_cnt++) {
|
||||
uint32_t letter = _lv_text_encoded_next(txt, &i);
|
||||
uint32_t letter = lv_text_encoded_next(txt, &i);
|
||||
/*Count he lines to reach the clicked letter. But ignore the last '\n' because it
|
||||
* still belongs to the clicked line*/
|
||||
if(letter == '\n' && i_prev != letter_i) new_opt++;
|
||||
|
@ -11,6 +11,7 @@
|
||||
#if LV_USE_SPAN != 0
|
||||
|
||||
#include "../../misc/lv_assert.h"
|
||||
#include "../../misc/lv_text_private.h"
|
||||
#include "../../core/lv_global.h"
|
||||
|
||||
/*********************
|
||||
@ -406,8 +407,8 @@ uint32_t lv_spangroup_get_expand_width(lv_obj_t * obj, uint32_t max_width)
|
||||
if(max_width > 0 && width >= max_width) {
|
||||
return max_width;
|
||||
}
|
||||
uint32_t letter = _lv_text_encoded_next(cur_txt, &j);
|
||||
uint32_t letter_next = _lv_text_encoded_next(&cur_txt[j], NULL);
|
||||
uint32_t letter = lv_text_encoded_next(cur_txt, &j);
|
||||
uint32_t letter_next = lv_text_encoded_next(&cur_txt[j], NULL);
|
||||
uint32_t letter_w = lv_font_get_glyph_width(font, letter, letter_next);
|
||||
width = width + letter_w + letter_space;
|
||||
}
|
||||
@ -483,11 +484,11 @@ int32_t lv_spangroup_get_expand_height(lv_obj_t * obj, int32_t width)
|
||||
}
|
||||
|
||||
uint32_t tmp_ofs = next_ofs;
|
||||
uint32_t letter = _lv_text_encoded_prev(&cur_txt[cur_txt_ofs], &tmp_ofs);
|
||||
if(!(letter == '\0' || letter == '\n' || letter == '\r' || _lv_text_is_break_char(letter))) {
|
||||
uint32_t letter = lv_text_encoded_prev(&cur_txt[cur_txt_ofs], &tmp_ofs);
|
||||
if(!(letter == '\0' || letter == '\n' || letter == '\r' || lv_text_is_break_char(letter))) {
|
||||
tmp_ofs = 0;
|
||||
letter = _lv_text_encoded_next(&cur_txt[cur_txt_ofs + next_ofs], &tmp_ofs);
|
||||
if(!(letter == '\0' || letter == '\n' || letter == '\r' || _lv_text_is_break_char(letter))) {
|
||||
letter = lv_text_encoded_next(&cur_txt[cur_txt_ofs + next_ofs], &tmp_ofs);
|
||||
if(!(letter == '\0' || letter == '\n' || letter == '\r' || lv_text_is_break_char(letter))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -641,7 +642,7 @@ static bool lv_text_get_snippet(const char * txt, const lv_font_t * font,
|
||||
real_max_width++;
|
||||
#endif
|
||||
|
||||
uint32_t ofs = _lv_text_get_next_line(txt, font, letter_space, real_max_width, use_width, flag);
|
||||
uint32_t ofs = lv_text_get_next_line(txt, font, letter_space, real_max_width, use_width, flag);
|
||||
*end_ofs = ofs;
|
||||
|
||||
if(txt[ofs] == '\0' && *use_width < max_width && !(ofs && (txt[ofs - 1] == '\n' || txt[ofs - 1] == '\r'))) {
|
||||
@ -870,17 +871,17 @@ static void lv_draw_span(lv_obj_t * obj, lv_layer_t * layer)
|
||||
|
||||
if(isfill) {
|
||||
if(next_ofs > 0 && lv_get_snippet_count() > 0) {
|
||||
/* To prevent infinite loops, the _lv_text_get_next_line() may return incomplete words, */
|
||||
/* To prevent infinite loops, the lv_text_get_next_line() may return incomplete words, */
|
||||
/* This phenomenon should be avoided when lv_get_snippet_count() > 0 */
|
||||
if(max_w < use_width) {
|
||||
break;
|
||||
}
|
||||
uint32_t tmp_ofs = next_ofs;
|
||||
uint32_t letter = _lv_text_encoded_prev(&cur_txt[cur_txt_ofs], &tmp_ofs);
|
||||
if(!(letter == '\0' || letter == '\n' || letter == '\r' || _lv_text_is_break_char(letter))) {
|
||||
uint32_t letter = lv_text_encoded_prev(&cur_txt[cur_txt_ofs], &tmp_ofs);
|
||||
if(!(letter == '\0' || letter == '\n' || letter == '\r' || lv_text_is_break_char(letter))) {
|
||||
tmp_ofs = 0;
|
||||
letter = _lv_text_encoded_next(&cur_txt[cur_txt_ofs + next_ofs], &tmp_ofs);
|
||||
if(!(letter == '\0' || letter == '\n' || letter == '\r' || _lv_text_is_break_char(letter))) {
|
||||
letter = lv_text_encoded_next(&cur_txt[cur_txt_ofs + next_ofs], &tmp_ofs);
|
||||
if(!(letter == '\0' || letter == '\n' || letter == '\r' || lv_text_is_break_char(letter))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -990,8 +991,8 @@ static void lv_draw_span(lv_obj_t * obj, lv_layer_t * layer)
|
||||
if(pos.x > clip_area.x2) {
|
||||
break;
|
||||
}
|
||||
uint32_t letter = _lv_text_encoded_next(bidi_txt, &j);
|
||||
uint32_t letter_next = _lv_text_encoded_next(&bidi_txt[j], NULL);
|
||||
uint32_t letter = lv_text_encoded_next(bidi_txt, &j);
|
||||
uint32_t letter_next = lv_text_encoded_next(&bidi_txt[j], NULL);
|
||||
int32_t letter_w = lv_font_get_glyph_width(pinfo->font, letter, letter_next);
|
||||
|
||||
/* skip invalid fields */
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include "../../draw/lv_draw.h"
|
||||
#include "../../misc/lv_assert.h"
|
||||
#include "../../misc/lv_anim.h"
|
||||
#include "../../misc/lv_text.h"
|
||||
#include "../../misc/lv_text_private.h"
|
||||
#include "../../misc/lv_math.h"
|
||||
#include "../../stdlib/lv_string.h"
|
||||
|
||||
@ -134,7 +134,7 @@ void lv_textarea_add_char(lv_obj_t * obj, uint32_t c)
|
||||
lv_result_t res = insert_handler(obj, letter_buf);
|
||||
if(res != LV_RESULT_OK) return;
|
||||
|
||||
uint32_t c_uni = _lv_text_encoded_next((const char *)&c2, NULL);
|
||||
uint32_t c_uni = lv_text_encoded_next((const char *)&c2, NULL);
|
||||
|
||||
if(char_is_accepted(obj, c_uni) == false) {
|
||||
LV_LOG_INFO("Character is not accepted by the text area (too long text or not in the accepted list)");
|
||||
@ -159,7 +159,7 @@ void lv_textarea_add_char(lv_obj_t * obj, uint32_t c)
|
||||
LV_ASSERT_MALLOC(ta->pwd_tmp);
|
||||
if(ta->pwd_tmp == NULL) return;
|
||||
|
||||
_lv_text_ins(ta->pwd_tmp, ta->cursor.pos, (const char *)letter_buf);
|
||||
lv_text_ins(ta->pwd_tmp, ta->cursor.pos, (const char *)letter_buf);
|
||||
|
||||
/*Auto hide characters*/
|
||||
auto_hide_characters(obj);
|
||||
@ -184,8 +184,8 @@ void lv_textarea_add_text(lv_obj_t * obj, const char * txt)
|
||||
if(lv_textarea_get_accepted_chars(obj) || lv_textarea_get_max_length(obj)) {
|
||||
uint32_t i = 0;
|
||||
while(txt[i] != '\0') {
|
||||
uint32_t c = _lv_text_encoded_next(txt, &i);
|
||||
lv_textarea_add_char(obj, _lv_text_unicode_to_encoded(c));
|
||||
uint32_t c = lv_text_encoded_next(txt, &i);
|
||||
lv_textarea_add_char(obj, lv_text_unicode_to_encoded(c));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -209,14 +209,14 @@ void lv_textarea_add_text(lv_obj_t * obj, const char * txt)
|
||||
LV_ASSERT_MALLOC(ta->pwd_tmp);
|
||||
if(ta->pwd_tmp == NULL) return;
|
||||
|
||||
_lv_text_ins(ta->pwd_tmp, ta->cursor.pos, txt);
|
||||
lv_text_ins(ta->pwd_tmp, ta->cursor.pos, txt);
|
||||
|
||||
/*Auto hide characters*/
|
||||
auto_hide_characters(obj);
|
||||
}
|
||||
|
||||
/*Move the cursor after the new text*/
|
||||
lv_textarea_set_cursor_pos(obj, lv_textarea_get_cursor_pos(obj) + _lv_text_get_encoded_length(txt));
|
||||
lv_textarea_set_cursor_pos(obj, lv_textarea_get_cursor_pos(obj) + lv_text_get_encoded_length(txt));
|
||||
|
||||
lv_obj_send_event(obj, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
}
|
||||
@ -238,7 +238,7 @@ void lv_textarea_delete_char(lv_obj_t * obj)
|
||||
char * label_txt = lv_label_get_text(ta->label);
|
||||
|
||||
/*Delete a character*/
|
||||
_lv_text_cut(label_txt, ta->cursor.pos - 1, 1);
|
||||
lv_text_cut(label_txt, ta->cursor.pos - 1, 1);
|
||||
|
||||
/*Refresh the label*/
|
||||
lv_label_set_text(ta->label, label_txt);
|
||||
@ -251,7 +251,7 @@ void lv_textarea_delete_char(lv_obj_t * obj)
|
||||
}
|
||||
|
||||
if(ta->pwd_mode) {
|
||||
_lv_text_cut(ta->pwd_tmp, ta->cursor.pos - 1, 1);
|
||||
lv_text_cut(ta->pwd_tmp, ta->cursor.pos - 1, 1);
|
||||
|
||||
ta->pwd_tmp = lv_realloc(ta->pwd_tmp, lv_strlen(ta->pwd_tmp) + 1);
|
||||
LV_ASSERT_MALLOC(ta->pwd_tmp);
|
||||
@ -297,8 +297,8 @@ void lv_textarea_set_text(lv_obj_t * obj, const char * txt)
|
||||
}
|
||||
uint32_t i = 0;
|
||||
while(txt[i] != '\0') {
|
||||
uint32_t c = _lv_text_encoded_next(txt, &i);
|
||||
lv_textarea_add_char(obj, _lv_text_unicode_to_encoded(c));
|
||||
uint32_t c = lv_text_encoded_next(txt, &i);
|
||||
lv_textarea_add_char(obj, lv_text_unicode_to_encoded(c));
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -360,7 +360,7 @@ void lv_textarea_set_cursor_pos(lv_obj_t * obj, int32_t pos)
|
||||
lv_textarea_t * ta = (lv_textarea_t *)obj;
|
||||
if((uint32_t)ta->cursor.pos == (uint32_t)pos) return;
|
||||
|
||||
uint32_t len = _lv_text_get_encoded_length(lv_label_get_text(ta->label));
|
||||
uint32_t len = lv_text_get_encoded_length(lv_label_get_text(ta->label));
|
||||
|
||||
if(pos < 0) pos = len + pos;
|
||||
|
||||
@ -721,8 +721,8 @@ uint32_t lv_textarea_get_current_char(lv_obj_t * obj)
|
||||
const char * txt = lv_textarea_get_text(obj);
|
||||
lv_textarea_t * ta = (lv_textarea_t *)obj;
|
||||
uint32_t pos = ta->cursor.pos;
|
||||
if(_lv_text_get_encoded_length(txt) >= pos && pos > 0)
|
||||
return _lv_text_encoded_prev(txt, &pos);
|
||||
if(lv_text_get_encoded_length(txt) >= pos && pos > 0)
|
||||
return lv_text_encoded_prev(txt, &pos);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
@ -1003,7 +1003,7 @@ static void pwd_char_hider(lv_obj_t * obj)
|
||||
|
||||
/* When ta->label is empty we get 0 back */
|
||||
char * txt = lv_label_get_text(ta->label);
|
||||
uint32_t enc_len = _lv_text_get_encoded_length(txt);
|
||||
uint32_t enc_len = lv_text_get_encoded_length(txt);
|
||||
if(enc_len == 0) return;
|
||||
|
||||
const char * bullet = lv_textarea_get_password_bullet(obj);
|
||||
@ -1035,7 +1035,7 @@ static bool char_is_accepted(lv_obj_t * obj, uint32_t c)
|
||||
lv_textarea_t * ta = (lv_textarea_t *)obj;
|
||||
|
||||
/*Too many characters?*/
|
||||
if(ta->max_length > 0 && _lv_text_get_encoded_length(lv_textarea_get_text(obj)) >= ta->max_length) {
|
||||
if(ta->max_length > 0 && lv_text_get_encoded_length(lv_textarea_get_text(obj)) >= ta->max_length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1044,7 +1044,7 @@ static bool char_is_accepted(lv_obj_t * obj, uint32_t c)
|
||||
uint32_t i = 0;
|
||||
|
||||
while(ta->accepted_chars[i] != '\0') {
|
||||
uint32_t a = _lv_text_encoded_next(ta->accepted_chars, &i);
|
||||
uint32_t a = lv_text_encoded_next(ta->accepted_chars, &i);
|
||||
if(a == c) return true; /*Accepted*/
|
||||
}
|
||||
|
||||
@ -1083,8 +1083,8 @@ static void refr_cursor_area(lv_obj_t * obj)
|
||||
uint32_t cur_pos = lv_textarea_get_cursor_pos(obj);
|
||||
const char * txt = lv_label_get_text(ta->label);
|
||||
|
||||
uint32_t byte_pos = _lv_text_encoded_get_byte_id(txt, cur_pos);
|
||||
uint32_t letter = _lv_text_encoded_next(&txt[byte_pos], NULL);
|
||||
uint32_t byte_pos = lv_text_encoded_get_byte_id(txt, cur_pos);
|
||||
uint32_t letter = lv_text_encoded_next(&txt[byte_pos], NULL);
|
||||
|
||||
/* Letter height and width */
|
||||
const int32_t letter_h = lv_font_get_line_height(font);
|
||||
@ -1108,8 +1108,8 @@ static void refr_cursor_area(lv_obj_t * obj)
|
||||
letter_pos.y += letter_h + line_space;
|
||||
|
||||
if(letter != '\0') {
|
||||
byte_pos += _lv_text_encoded_size(&txt[byte_pos]);
|
||||
letter = _lv_text_encoded_next(&txt[byte_pos], NULL);
|
||||
byte_pos += lv_text_encoded_size(&txt[byte_pos]);
|
||||
letter = lv_text_encoded_next(&txt[byte_pos], NULL);
|
||||
}
|
||||
|
||||
uint32_t tmp = letter;
|
||||
@ -1346,7 +1346,7 @@ static void draw_cursor(lv_event_t * e)
|
||||
int32_t left = lv_obj_get_style_pad_left(obj, LV_PART_CURSOR) + border_width;
|
||||
int32_t top = lv_obj_get_style_pad_top(obj, LV_PART_CURSOR) + border_width;
|
||||
char letter_buf[8] = {0};
|
||||
lv_memcpy(letter_buf, &txt[ta->cursor.txt_byte_pos], _lv_text_encoded_size(&txt[ta->cursor.txt_byte_pos]));
|
||||
lv_memcpy(letter_buf, &txt[ta->cursor.txt_byte_pos], lv_text_encoded_size(&txt[ta->cursor.txt_byte_pos]));
|
||||
|
||||
cur_area.x1 += left;
|
||||
cur_area.y1 += top;
|
||||
|
@ -86,7 +86,7 @@ lv_obj_t * lv_textarea_create(lv_obj_t * parent);
|
||||
|
||||
/**
|
||||
* Insert a character to the current cursor position.
|
||||
* To add a wide char, e.g. 'Á' use `_lv_text_encoded_conv_wc('Á')`
|
||||
* To add a wide char, e.g. 'Á' use `lv_text_encoded_conv_wc('Á')`
|
||||
* @param obj pointer to a text area object
|
||||
* @param c a character (e.g. 'a')
|
||||
*/
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "../lvgl.h"
|
||||
|
||||
#include "unity/unity.h"
|
||||
#include "../../../src/misc/lv_text_private.h"
|
||||
#include <string.h>
|
||||
|
||||
void test_txt_should_insert_string_into_another(void)
|
||||
@ -13,7 +14,7 @@ void test_txt_should_insert_string_into_another(void)
|
||||
|
||||
strcpy(target, msg);
|
||||
|
||||
_lv_text_ins(target, msg_len, suffix);
|
||||
lv_text_ins(target, msg_len, suffix);
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING("Hello World", target);
|
||||
}
|
||||
@ -26,21 +27,21 @@ void test_txt_should_handle_null_pointers_when_inserting(void)
|
||||
|
||||
strcpy(target, msg);
|
||||
|
||||
_lv_text_ins(target, msg_len, NULL);
|
||||
lv_text_ins(target, msg_len, NULL);
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING("Hello ", target);
|
||||
}
|
||||
|
||||
void test_txt_cut_should_handle_null_pointer_to_txt(void)
|
||||
{
|
||||
_lv_text_cut(NULL, 0, 6);
|
||||
lv_text_cut(NULL, 0, 6);
|
||||
}
|
||||
|
||||
void test_txt_cut_happy_path(void)
|
||||
{
|
||||
char msg[] = "Hello World";
|
||||
|
||||
_lv_text_cut(msg, 0, 6);
|
||||
lv_text_cut(msg, 0, 6);
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING("World", msg);
|
||||
}
|
||||
@ -49,7 +50,7 @@ void test_txt_cut_should_handle_len_longer_than_string_length(void)
|
||||
{
|
||||
char msg[] = "Hello World";
|
||||
|
||||
_lv_text_cut(msg, 0, 30);
|
||||
lv_text_cut(msg, 0, 30);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8(msg[0], 0x00);
|
||||
}
|
||||
@ -59,7 +60,7 @@ void test_txt_get_encoded_next_should_decode_valid_ascii(void)
|
||||
char msg[] = "Hello World!";
|
||||
uint32_t result = 0;
|
||||
|
||||
result = _lv_text_encoded_next(msg, NULL);
|
||||
result = lv_text_encoded_next(msg, NULL);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT32((uint32_t) 'H', result);
|
||||
}
|
||||
@ -69,7 +70,7 @@ void test_txt_get_encoded_next_detect_valid_2_byte_input(void)
|
||||
char msg[] = "\xc3\xb1";
|
||||
uint32_t result = 0;
|
||||
|
||||
result = _lv_text_encoded_next(msg, NULL);
|
||||
result = lv_text_encoded_next(msg, NULL);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT32(241, result);
|
||||
}
|
||||
@ -79,7 +80,7 @@ void test_txt_get_encoded_next_detect_invalid_2_byte_input(void)
|
||||
char msg[] = "\xc3\x28";
|
||||
uint32_t result = 0;
|
||||
|
||||
result = _lv_text_encoded_next(msg, NULL);
|
||||
result = lv_text_encoded_next(msg, NULL);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT32(0, result);
|
||||
}
|
||||
@ -89,7 +90,7 @@ void test_txt_get_encoded_next_detect_valid_3_byte_input(void)
|
||||
char msg[] = "\xe2\x82\xa1";
|
||||
uint32_t result = 0;
|
||||
|
||||
result = _lv_text_encoded_next(msg, NULL);
|
||||
result = lv_text_encoded_next(msg, NULL);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT32(8353, result);
|
||||
}
|
||||
@ -99,7 +100,7 @@ void test_txt_get_encoded_next_detect_invalid_3_byte_input(void)
|
||||
char msg[] = "\xe2\x28\xa1";
|
||||
uint32_t result = 0;
|
||||
|
||||
result = _lv_text_encoded_next(msg, NULL);
|
||||
result = lv_text_encoded_next(msg, NULL);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT32(0, result);
|
||||
}
|
||||
@ -109,7 +110,7 @@ void test_txt_get_encoded_next_detect_valid_4_byte_input(void)
|
||||
char msg[] = "\xf0\x90\x8c\xbc";
|
||||
uint32_t result = 0;
|
||||
|
||||
result = _lv_text_encoded_next(msg, NULL);
|
||||
result = lv_text_encoded_next(msg, NULL);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT32(66364, result);
|
||||
}
|
||||
@ -119,7 +120,7 @@ void test_txt_get_encoded_next_detect_invalid_4_byte_input(void)
|
||||
char msg[] = "\xf0\x28\x8c\x28";
|
||||
uint32_t result = 0;
|
||||
|
||||
result = _lv_text_encoded_next(msg, NULL);
|
||||
result = lv_text_encoded_next(msg, NULL);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT32(0, result);
|
||||
}
|
||||
@ -132,7 +133,7 @@ void test_txt_next_line_should_handle_empty_string(void)
|
||||
int32_t max_width = 0;
|
||||
lv_text_flag_t flag = LV_TEXT_FLAG_NONE;
|
||||
|
||||
uint32_t next_line = _lv_text_get_next_line("", font_ptr, letter_space, max_width, NULL, flag);
|
||||
uint32_t next_line = lv_text_get_next_line("", font_ptr, letter_space, max_width, NULL, flag);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT32(0, next_line);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user