make LV_TXT_UTF8 always enabled (remove the defeine checks)

This commit is contained in:
Gabor Kiss-Vamosi
2019-03-28 06:11:50 +01:00
parent cd47fd72f6
commit 1cd983941e
6 changed files with 7 additions and 242 deletions

View File

@@ -126,9 +126,6 @@
#endif
/*Text settings*/
#ifndef LV_TXT_UTF8
#define LV_TXT_UTF8 1 /*Enable UTF-8 coded Unicode character usage */
#endif
#ifndef LV_TXT_BREAK_CHARS
#define LV_TXT_BREAK_CHARS " ,.;:-_" /*Can break texts on these chars*/
#endif

View File

@@ -20,62 +20,6 @@ extern "C" {
* - Reserved: 0xE060..0xE07F
*/
#if LV_TXT_UTF8 == 0
#define LV_SYMBOL_GLYPH_FIRST 0xC0
#define LV_SYMBOL_AUDIO _LV_SYMBOL_VALUE1(C0)
#define LV_SYMBOL_VIDEO _LV_SYMBOL_VALUE1(C1)
#define LV_SYMBOL_LIST _LV_SYMBOL_VALUE1(C2)
#define LV_SYMBOL_OK _LV_SYMBOL_VALUE1(C3)
#define LV_SYMBOL_CLOSE _LV_SYMBOL_VALUE1(C4)
#define LV_SYMBOL_POWER _LV_SYMBOL_VALUE1(C5)
#define LV_SYMBOL_SETTINGS _LV_SYMBOL_VALUE1(C6)
#define LV_SYMBOL_TRASH _LV_SYMBOL_VALUE1(C7)
#define LV_SYMBOL_HOME _LV_SYMBOL_VALUE1(C8)
#define LV_SYMBOL_DOWNLOAD _LV_SYMBOL_VALUE1(C9)
#define LV_SYMBOL_DRIVE _LV_SYMBOL_VALUE1(CA)
#define LV_SYMBOL_REFRESH _LV_SYMBOL_VALUE1(CB)
#define LV_SYMBOL_MUTE _LV_SYMBOL_VALUE1(CC)
#define LV_SYMBOL_VOLUME_MID _LV_SYMBOL_VALUE1(CD)
#define LV_SYMBOL_VOLUME_MAX _LV_SYMBOL_VALUE1(CE)
#define LV_SYMBOL_IMAGE _LV_SYMBOL_VALUE1(CF)
#define LV_SYMBOL_EDIT _LV_SYMBOL_VALUE1(D0)
#define LV_SYMBOL_PREV _LV_SYMBOL_VALUE1(D1)
#define LV_SYMBOL_PLAY _LV_SYMBOL_VALUE1(D2)
#define LV_SYMBOL_PAUSE _LV_SYMBOL_VALUE1(D3)
#define LV_SYMBOL_STOP _LV_SYMBOL_VALUE1(D4)
#define LV_SYMBOL_NEXT _LV_SYMBOL_VALUE1(D5)
#define LV_SYMBOL_EJECT _LV_SYMBOL_VALUE1(D6)
#define LV_SYMBOL_LEFT _LV_SYMBOL_VALUE1(D7)
#define LV_SYMBOL_RIGHT _LV_SYMBOL_VALUE1(D8)
#define LV_SYMBOL_PLUS _LV_SYMBOL_VALUE1(D9)
#define LV_SYMBOL_MINUS _LV_SYMBOL_VALUE1(DA)
#define LV_SYMBOL_WARNING _LV_SYMBOL_VALUE1(DB)
#define LV_SYMBOL_SHUFFLE _LV_SYMBOL_VALUE1(DC)
#define LV_SYMBOL_UP _LV_SYMBOL_VALUE1(DD)
#define LV_SYMBOL_DOWN _LV_SYMBOL_VALUE1(DE)
#define LV_SYMBOL_LOOP _LV_SYMBOL_VALUE1(DF)
#define LV_SYMBOL_DIRECTORY _LV_SYMBOL_VALUE1(E0)
#define LV_SYMBOL_UPLOAD _LV_SYMBOL_VALUE1(E1)
#define LV_SYMBOL_CALL _LV_SYMBOL_VALUE1(E2)
#define LV_SYMBOL_CUT _LV_SYMBOL_VALUE1(E3)
#define LV_SYMBOL_COPY _LV_SYMBOL_VALUE1(E4)
#define LV_SYMBOL_SAVE _LV_SYMBOL_VALUE1(E5)
#define LV_SYMBOL_CHARGE _LV_SYMBOL_VALUE1(E6)
#define LV_SYMBOL_BELL _LV_SYMBOL_VALUE1(E7)
#define LV_SYMBOL_KEYBOARD _LV_SYMBOL_VALUE1(E8)
#define LV_SYMBOL_GPS _LV_SYMBOL_VALUE1(E9)
#define LV_SYMBOL_FILE _LV_SYMBOL_VALUE1(EA)
#define LV_SYMBOL_WIFI _LV_SYMBOL_VALUE1(EB)
#define LV_SYMBOL_BATTERY_FULL _LV_SYMBOL_VALUE1(EC)
#define LV_SYMBOL_BATTERY_3 _LV_SYMBOL_VALUE1(ED)
#define LV_SYMBOL_BATTERY_2 _LV_SYMBOL_VALUE1(EE)
#define LV_SYMBOL_BATTERY_1 _LV_SYMBOL_VALUE1(EF)
#define LV_SYMBOL_BATTERY_EMPTY _LV_SYMBOL_VALUE1(F0)
#define LV_SYMBOL_BLUETOOTH _LV_SYMBOL_VALUE1(F1)
#define LV_SYMBOL_GLYPH_LAST 0xF1
#define LV_SYMBOL_DUMMY _LV_SYMBOL_VALUE1(FF) /*Invalid symbol. If written before a string then `lv_img` will show it as a label*/
#else
#define LV_SYMBOL_GLYPH_FIRST 0xF800
#define LV_SYMBOL_AUDIO _LV_SYMBOL_VALUE3(EF,A0,80)
#define LV_SYMBOL_VIDEO _LV_SYMBOL_VALUE3(EF,A0,81)
@@ -129,9 +73,7 @@ extern "C" {
#define LV_SYMBOL_BLUETOOTH _LV_SYMBOL_VALUE3(EF,A0,B1)
#define LV_SYMBOL_GLYPH_LAST 0xF831
#define LV_SYMBOL_DUMMY _LV_SYMBOL_VALUE3(EF,A3,BF) /*Invalid symbol at (U+F831). If written before a string then `lv_img` will show it as a label*/
#endif
#define _LV_SYMBOL_VALUE1(x) (0x ## x)
#define _LV_SYMBOL_VALUE3(x, y, z) (0x ## z ## y ## x)
#define _LV_SYMBOL_NUMSTR(sym) LV_ ## sym ## _NUMSTR = sym
@@ -190,7 +132,6 @@ enum
_LV_SYMBOL_NUMSTR(LV_SYMBOL_DUMMY),
};
#undef _LV_SYMBOL_VALUE1
#undef _LV_SYMBOL_VALUE3
#define _LV_SYMBOL_STR_(x) #x

View File

@@ -35,7 +35,6 @@
**********************/
static bool is_break_char(uint32_t letter);
#if LV_TXT_UTF8
static uint8_t lv_txt_utf8_size(const char * str);
static uint32_t lv_txt_unicode_to_utf8(uint32_t letter_uni);
static uint32_t lv_txt_utf8_conv_wc(uint32_t c);
@@ -44,16 +43,6 @@ static uint32_t lv_txt_utf8_prev(const char * txt, uint32_t * i_start);
static uint32_t lv_txt_utf8_get_byte_id(const char * txt, uint32_t utf8_id);
static uint32_t lv_txt_utf8_get_char_id(const char * txt, uint32_t byte_id);
static uint32_t lv_txt_utf8_get_length(const char * txt);
#else
static uint8_t lv_txt_ascii_size(const char * str);
static uint32_t lv_txt_unicode_to_ascii(uint32_t letter_uni);
static uint32_t lv_txt_ascii_conv_wc(uint32_t c);
static uint32_t lv_txt_ascii_next(const char * txt, uint32_t * i);
static uint32_t lv_txt_ascii_prev(const char * txt, uint32_t * i_start);
static uint32_t lv_txt_ascii_get_byte_id(const char * txt, uint32_t utf8_id);
static uint32_t lv_txt_ascii_get_char_id(const char * txt, uint32_t byte_id);
static uint32_t lv_txt_ascii_get_length(const char * txt);
#endif
/**********************
* STATIC VARIABLES
@@ -63,7 +52,6 @@ static uint32_t lv_txt_ascii_get_length(const char * txt);
/**********************
* GLOBAL VARIABLES
**********************/
#if LV_TXT_UTF8
uint8_t (*lv_txt_encoded_size)(const char *) = lv_txt_utf8_size;
uint32_t (*lv_txt_unicode_to_encoded)(uint32_t) = lv_txt_unicode_to_utf8;
uint32_t (*lv_txt_encoded_conv_wc)(uint32_t) = lv_txt_utf8_conv_wc;
@@ -72,16 +60,7 @@ uint32_t (*lv_txt_encoded_prev)(const char *, uint32_t *) = lv_txt_utf8_prev;
uint32_t (*lv_txt_encoded_get_byte_id)(const char *, uint32_t) = lv_txt_utf8_get_byte_id;
uint32_t (*lv_encoded_get_char_id)(const char *, uint32_t) = lv_txt_utf8_get_char_id;
uint32_t (*lv_txt_get_encoded_length)(const char *) = lv_txt_utf8_get_length;
#else
uint8_t (*lv_txt_encoded_size)(const char *) = lv_txt_ascii_size;
uint32_t (*lv_txt_unicode_to_encoded)(uint32_t) = lv_txt_unicode_to_ascii;
uint32_t (*lv_txt_encoded_conv_wc)(uint32_t) = lv_txt_ascii_conv_wc;
uint32_t (*lv_txt_encoded_next)(const char *, uint32_t *) = lv_txt_ascii_next;
uint32_t (*lv_txt_encoded_prev)(const char *, uint32_t *) = lv_txt_ascii_prev;
uint32_t (*lv_txt_encoded_get_byte_id)(const char *, uint32_t) = lv_txt_ascii_get_byte_id;
uint32_t (*lv_encoded_get_char_id)(const char *, uint32_t) = lv_txt_ascii_get_char_id;
uint32_t (*lv_txt_get_encoded_length)(const char *) = lv_txt_ascii_get_length;
#endif
/**********************
* MACROS
**********************/
@@ -384,9 +363,8 @@ void lv_txt_ins(char * txt_buf, uint32_t pos, const char * ins_txt)
uint32_t old_len = strlen(txt_buf);
uint32_t ins_len = strlen(ins_txt);
uint32_t new_len = ins_len + old_len;
#if LV_TXT_UTF8 != 0
pos = lv_txt_encoded_get_byte_id(txt_buf, pos); /*Convert to byte index instead of letter index*/
#endif
/*Copy the second part into the end to make place to text to insert*/
uint32_t i;
for(i = new_len; i >= pos + ins_len; i--) {
@@ -407,10 +385,9 @@ void lv_txt_cut(char * txt, uint32_t pos, uint32_t len)
{
uint32_t old_len = strlen(txt);
#if LV_TXT_UTF8 != 0
pos = lv_txt_encoded_get_byte_id(txt, pos); /*Convert to byte index instead of letter index*/
len = lv_txt_encoded_get_byte_id(&txt[pos], len);
#endif
/*Copy the second part into the end to make place to text to insert*/
uint32_t i;
@@ -424,8 +401,6 @@ void lv_txt_cut(char * txt, uint32_t pos, uint32_t len)
* UTF-8 ENCODER/DECOER
******************************/
#if LV_TXT_UTF8
/**
* Give the size of an UTF-8 coded character
* @param str pointer to a character in a string
@@ -647,9 +622,6 @@ static uint32_t lv_txt_utf8_get_char_id(const char * txt, uint32_t byte_id)
*/
static uint32_t lv_txt_utf8_get_length(const char * txt)
{
#if LV_TXT_UTF8 == 0
return strlen(txt);
#else
uint32_t len = 0;
uint32_t i = 0;
@@ -659,112 +631,8 @@ static uint32_t lv_txt_utf8_get_length(const char * txt)
}
return len;
#endif
}
#else
/**
* Give the size of an UTF-8 coded character
* @param str pointer to a character in a string
* @return length of the UTF-8 character (1,2,3 or 4). O on invalid code
*/
static uint8_t lv_txt_ascii_size(const char * str)
{
return 1;
}
/**
* Convert an Unicode letter to UTF-8.
* @param letter_uni an Unicode letter
* @return UTF-8 coded character in Little Endian to be compatible with C chars (e.g. 'Á', 'Ű')
*/
static uint32_t lv_txt_unicode_to_ascii(uint32_t letter_uni)
{
if(letter_uni < 128) return letter_uni;
else return ' ';
}
/**
* Convert wide characters to ASCII, however wide characters in ASCII range (e.g. 'A') are ASCII compatible by default.
* So this function does nothing just returns with `c`.
* @param c a character, e.g. 'A'
* @return same as `c`
*/
static uint32_t lv_txt_ascii_conv_wc(uint32_t c)
{
return c;
}
/**
* Decode an UTF-8 character from a string.
* @param txt pointer to '\0' terminated string
* @param i start byte index in 'txt' where to start.
* After call it will point to the next UTF-8 char in 'txt'.
* NULL to use txt[0] as index
* @return the decoded Unicode character or 0 on invalid UTF-8 code
*/
static uint32_t lv_txt_ascii_next(const char * txt, uint32_t * i)
{
if(i == NULL) return txt[1]; /*Get the next char */
uint8_t letter = txt[*i] ;
(*i)++;
return letter;
}
/**
* Get previous UTF-8 character form a string.
* @param txt pointer to '\0' terminated string
* @param i start byte index in 'txt' where to start. After the call it will point to the previous UTF-8 char in 'txt'.
* @return the decoded Unicode character or 0 on invalid UTF-8 code
*/
static uint32_t lv_txt_ascii_prev(const char * txt, uint32_t * i)
{
if(i == NULL) return *(txt - 1); /*Get the prev. char */
(*i)--;
uint8_t letter = txt[*i] ;
return letter;
}
/**
* Convert a character index (in an UTF-8 text) to byte index.
* E.g. in "AÁRT" index of 'R' is 2th char but start at byte 3 because 'Á' is 2 bytes long
* @param txt a '\0' terminated UTF-8 string
* @param utf8_id character index
* @return byte index of the 'utf8_id'th letter
*/
static uint32_t lv_txt_ascii_get_byte_id(const char * txt, uint32_t utf8_id)
{
return utf8_id; /*In Non encoded no difference*/
}
/**
* Convert a byte index (in an UTF-8 text) to character index.
* E.g. in "AÁRT" index of 'R' is 2th char 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
*/
static uint32_t lv_txt_ascii_get_char_id(const char * txt, uint32_t byte_id)
{
return byte_id; /*In Non encoded no difference*/
}
/**
* Get the number of characters (and NOT bytes) in a string. Decode it with UTF-8 if enabled.
* E.g.: "ÁBC" is 3 characters (but 4 bytes)
* @param txt a '\0' terminated char string
* @return number of characters
*/
static uint32_t lv_txt_ascii_get_length(const char * txt)
{
return strlen(txt);
}
#endif
/**********************
* STATIC FUNCTIONS
**********************/

View File

@@ -574,11 +574,7 @@ void lv_label_ins_text(lv_obj_t * label, uint32_t pos, const char * txt)
if(ext->text == NULL) return;
if(pos == LV_LABEL_POS_LAST) {
#if LV_TXT_UTF8 == 0
pos = old_len;
#else
pos = lv_txt_get_encoded_length(ext->text);
#endif
}
lv_txt_ins(ext->text, pos, txt);
@@ -853,19 +849,6 @@ static void lv_label_refr_text(lv_obj_t * label)
uint32_t letter_id = lv_label_get_letter_on(label, &p);
#if LV_TXT_UTF8 == 0
/*Save letters under the dots and replace them with dots*/
uint8_t i;
for(i = 0; i < LV_LABEL_DOT_NUM; i++) {
ext->dot_tmp[i] = ext->text[letter_id + i];
ext->text[letter_id + i] = '.';
}
ext->dot_tmp[LV_LABEL_DOT_NUM] = ext->text[letter_id + LV_LABEL_DOT_NUM];
ext->text[letter_id + LV_LABEL_DOT_NUM] = '\0';
ext->dot_end = letter_id + LV_LABEL_DOT_NUM;
#else
/*Save letters under the dots and replace them with dots*/
uint32_t i;
uint32_t byte_id = lv_txt_encoded_get_byte_id(ext->text, letter_id);
@@ -885,8 +868,6 @@ static void lv_label_refr_text(lv_obj_t * label)
ext->text[byte_id_ori + LV_LABEL_DOT_NUM] = '\0';
ext->dot_end = letter_id + LV_LABEL_DOT_NUM;
#endif
}
}
/*In break mode only the height can change*/
@@ -907,12 +888,6 @@ static void lv_label_revert_dots(lv_obj_t * label)
lv_label_ext_t * ext = lv_obj_get_ext_attr(label);
if(ext->long_mode != LV_LABEL_LONG_DOT) return;
if(ext->dot_end == LV_LABEL_DOT_END_INV) return;
#if LV_TXT_UTF8 == 0
uint32_t i;
for(i = 0; i <= LV_LABEL_DOT_NUM; i++) {
ext->text[ext->dot_end - i] = ext->dot_tmp[LV_LABEL_DOT_NUM - i];
}
#else
uint32_t letter_i = ext->dot_end - LV_LABEL_DOT_NUM;
uint32_t byte_i = lv_txt_encoded_get_byte_id(ext->text, letter_i);
@@ -922,7 +897,6 @@ static void lv_label_revert_dots(lv_obj_t * label)
ext->text[byte_i + i] = ext->dot_tmp[i];
i++;
}
#endif
ext->dot_end = LV_LABEL_DOT_END_INV;
}

View File

@@ -63,11 +63,7 @@ typedef struct
/*New data for this type */
char * text; /*Text of the label*/
lv_label_long_mode_t long_mode; /*Determinate what to do with the long texts*/
#if LV_TXT_UTF8 == 0
char dot_tmp[LV_LABEL_DOT_NUM + 1]; /*Store the character which are replaced by dots (Handled by the library)*/
#else
char dot_tmp[LV_LABEL_DOT_NUM * 4 + 1]; /*Store the character which are replaced by dots (Handled by the library)*/
#endif
uint16_t dot_end; /*The text end position in dot mode (Handled by the library)*/
uint16_t anim_speed; /*Speed of scroll and roll animation in px/sec unit*/

View File

@@ -388,12 +388,9 @@ void lv_ta_del_char(lv_obj_t * ta)
}
if(ext->pwd_mode != 0) {
#if LV_TXT_UTF8 == 0
lv_txt_cut(ext->pwd_tmp, ext->cursor.pos - 1, 1);
#else
uint32_t byte_pos = lv_txt_encoded_get_byte_id(ext->pwd_tmp, ext->cursor.pos - 1);
lv_txt_cut(ext->pwd_tmp, ext->cursor.pos - 1, lv_txt_encoded_size(&label_txt[byte_pos]));
#endif
ext->pwd_tmp = lv_mem_realloc(ext->pwd_tmp, strlen(ext->pwd_tmp) + 1);
lv_mem_assert(ext->pwd_tmp);
if(ext->pwd_tmp == NULL) return;
@@ -1101,14 +1098,9 @@ static bool lv_ta_scrollable_design(lv_obj_t * scrl, const lv_area_t * mask, lv_
} else if(ext->cursor.type == LV_CURSOR_BLOCK) {
lv_draw_rect(&cur_area, mask, &cur_style, opa_scale);
#if LV_TXT_UTF8 == 0
char letter_buf[2];
letter_buf[0] = txt[ext->cursor.txt_byte_pos];
letter_buf[1] = '\0';
#else
char letter_buf[8] = {0};
memcpy(letter_buf, &txt[ext->cursor.txt_byte_pos], lv_txt_encoded_size(&txt[ext->cursor.txt_byte_pos]));
#endif
cur_area.x1 += cur_style.body.padding.left;
cur_area.y1 += cur_style.body.padding.top;
lv_draw_label(&cur_area, mask, &cur_style, opa_scale, letter_buf, LV_TXT_FLAG_NONE, 0);
@@ -1435,14 +1427,11 @@ static void refr_cursor_area(lv_obj_t * ta)
uint16_t cur_pos = lv_ta_get_cursor_pos(ta);
const char * txt = lv_label_get_text(ext->label);
uint32_t byte_pos;
#if LV_TXT_UTF8 != 0
byte_pos = lv_txt_encoded_get_byte_id(txt, cur_pos);
uint32_t letter = lv_txt_encoded_next(&txt[byte_pos], NULL);
#else
byte_pos = cur_pos;
uint32_t letter = txt[byte_pos];
#endif
lv_coord_t letter_h = lv_font_get_height(label_style->text.font);
/*Set letter_w (set not 0 on non printable but valid chars)*/