Skip to content

Commit fced331

Browse files
thinkyheadLCh-77
authored andcommitted
🩹 Followup for lchar_t
1 parent 05ab02f commit fced331

11 files changed

+80
-74
lines changed

Marlin/src/lcd/HD44780/lcdprint_hd44780.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1051,10 +1051,10 @@ static int lcd_put_u8str_max_cb(const char * utf8_str, read_byte_cb_t cb_read_by
10511051
pixel_len_t ret = 0;
10521052
const uint8_t *p = (uint8_t *)utf8_str;
10531053
while (ret < max_length) {
1054-
lchar_t ch;
1055-
p = get_utf8_value_cb(p, cb_read_byte, ch);
1056-
if (!ch) break;
1057-
ret += lcd_put_lchar_max(ch, max_length - ret);
1054+
lchar_t wc;
1055+
p = get_utf8_value_cb(p, cb_read_byte, wc);
1056+
if (!wc) break;
1057+
ret += lcd_put_lchar_max(wc, max_length - ret);
10581058
}
10591059
return (int)ret;
10601060
}

Marlin/src/lcd/TFTGLCD/lcdprint_TFTGLCD.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1049,10 +1049,10 @@ static int lcd_put_u8str_max_cb(const char * utf8_str, read_byte_cb_t cb_read_by
10491049
pixel_len_t ret = 0;
10501050
const uint8_t *p = (uint8_t *)utf8_str;
10511051
while (ret < max_length) {
1052-
lchar_t ch;
1053-
p = get_utf8_value_cb(p, cb_read_byte, ch);
1054-
if (!ch) break;
1055-
ret += lcd_put_lchar_max(ch, max_length - ret);
1052+
lchar_t wc;
1053+
p = get_utf8_value_cb(p, cb_read_byte, wc);
1054+
if (!wc) break;
1055+
ret += lcd_put_lchar_max(wc, max_length - ret);
10561056
}
10571057
return (int)ret;
10581058
}

Marlin/src/lcd/dogm/u8g_fontutf8.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ static void fontgroup_drawwchar(font_group_t *group, const font_t *fnt_default,
106106
static void fontgroup_drawstring(font_group_t *group, const font_t *fnt_default, const char *utf8_msg, read_byte_cb_t cb_read_byte, void * userdata, fontgroup_cb_draw_t cb_draw_ram) {
107107
const uint8_t *p = (uint8_t*)utf8_msg;
108108
for (;;) {
109-
lchar_t ch;
110-
p = get_utf8_value_cb(p, cb_read_byte, ch);
111-
if (!ch) break;
112-
fontgroup_drawwchar(group, fnt_default, ch, userdata, cb_draw_ram);
109+
lchar_t wc;
110+
p = get_utf8_value_cb(p, cb_read_byte, wc);
111+
if (!wc) break;
112+
fontgroup_drawwchar(group, fnt_default, wc, userdata, cb_draw_ram);
113113
}
114114
}
115115

@@ -154,14 +154,14 @@ static int fontgroup_cb_draw_u8g(void *userdata, const font_t *fnt_current, cons
154154
* @param pu8g : U8G pointer
155155
* @param x : position x axis
156156
* @param y : position y axis
157-
* @param ch : the lchar_t
157+
* @param wc : the lchar_t
158158
* @param max_width : the pixel width of the string allowed
159159
*
160160
* @return number of pixels advanced
161161
*
162162
* Draw a UTF-8 string at the specified position
163163
*/
164-
unsigned int uxg_DrawWchar(u8g_t *pu8g, unsigned int x, unsigned int y, const lchar_t &ch, pixel_len_t max_width) {
164+
unsigned int uxg_DrawWchar(u8g_t *pu8g, unsigned int x, unsigned int y, const lchar_t &wc, pixel_len_t max_width) {
165165
struct _uxg_drawu8_data_t data;
166166
font_group_t *group = &g_fontgroup_root;
167167
const font_t *fnt_default = uxg_GetFont(pu8g);
@@ -176,7 +176,7 @@ unsigned int uxg_DrawWchar(u8g_t *pu8g, unsigned int x, unsigned int y, const lc
176176
data.adv = 0;
177177
data.max_width = max_width;
178178
data.fnt_prev = nullptr;
179-
fontgroup_drawwchar(group, fnt_default, ch, (void*)&data, fontgroup_cb_draw_u8g);
179+
fontgroup_drawwchar(group, fnt_default, wc, (void*)&data, fontgroup_cb_draw_u8g);
180180
u8g_SetFont(pu8g, (const u8g_fntpgm_uint8_t*)fnt_default);
181181

182182
return data.adv;

Marlin/src/lcd/e3v2/marlinui/dwin_string.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ uint8_t read_byte(const uint8_t *byte) { return *byte; }
5050
* @ displays an axis name such as XYZUVW, or E for an extruder
5151
*/
5252
void DWIN_String::add(const char *tpl, const int8_t index, const char *cstr/*=nullptr*/, FSTR_P const fstr/*=nullptr*/) {
53-
lchar_t ch;
53+
lchar_t wc;
5454

5555
while (*tpl) {
56-
tpl = get_utf8_value_cb(tpl, read_byte, ch);
57-
if (ch > 255) ch |= 0x0080;
58-
const uint8_t ch = uint8_t(ch & 0x00FF);
56+
tpl = get_utf8_value_cb(tpl, read_byte, wc);
57+
if (wc > 255) wc |= 0x0080;
58+
const uint8_t ch = uint8_t(wc & 0x00FF);
5959

6060
if (ch == '=' || ch == '~' || ch == '*') {
6161
if (index >= 0) {
@@ -80,32 +80,32 @@ void DWIN_String::add(const char *tpl, const int8_t index, const char *cstr/*=nu
8080
}
8181

8282
void DWIN_String::add(const char *cstr, uint8_t max_len/*=MAX_STRING_LENGTH*/) {
83-
lchar_t ch;
83+
lchar_t wc;
8484
while (*cstr && max_len) {
85-
cstr = get_utf8_value_cb(cstr, read_byte, ch);
85+
cstr = get_utf8_value_cb(cstr, read_byte, wc);
8686
/*
87-
if (ch > 255) ch |= 0x0080;
88-
uint8_t ch = uint8_t(ch & 0x00FF);
87+
if (wc > 255) wc |= 0x0080;
88+
const uint8_t ch = uint8_t(wc & 0x00FF);
8989
add_character(ch);
9090
*/
91-
add(ch);
91+
add(wc);
9292
max_len--;
9393
}
9494
eol();
9595
}
9696

97-
void DWIN_String::add(const lchar_t &ch) {
97+
void DWIN_String::add(const lchar_t &wc) {
9898
int ret;
9999
size_t idx = 0;
100100
dwin_charmap_t pinval;
101101
dwin_charmap_t *copy_address = nullptr;
102-
pinval.uchar = ch;
102+
pinval.uchar = wc;
103103
pinval.idx = -1;
104104

105-
// For 8-bit ASCII just print the single ch
105+
// For 8-bit ASCII just print the single character
106106
char str[] = { '?', 0 };
107-
if (ch < 255) {
108-
str[0] = (char)ch;
107+
if (wc < 255) {
108+
str[0] = (char)wc;
109109
}
110110
else {
111111
copy_address = nullptr;

Marlin/src/lcd/e3v2/marlinui/dwin_string.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ class DWIN_String {
6969
/**
7070
* @brief Append a UTF-8 character
7171
*
72-
* @param ch The UTF-8 character
72+
* @param wc The UTF-8 character
7373
*/
74-
static void add(const lchar_t &ch);
75-
static void set(const lchar_t &ch) { set(); add(ch); }
74+
static void add(const lchar_t &wc);
75+
static void set(const lchar_t &wc) { set(); add(wc); }
7676

7777
/**
7878
* @brief Append / Set C-string

Marlin/src/lcd/e3v2/marlinui/lcdprint_dwin.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ static int lcd_put_u8str_max_cb(const char * utf8_str, read_byte_cb_t cb_read_by
8787
const uint8_t *p = (uint8_t *)utf8_str;
8888
dwin_string.set();
8989
while (dwin_string.length < max_length) {
90-
lchar_t ch;
91-
p = get_utf8_value_cb(p, cb_read_byte, ch);
92-
if (!ch) break;
93-
dwin_string.add(ch);
90+
lchar_t wc;
91+
p = get_utf8_value_cb(p, cb_read_byte, wc);
92+
if (!wc) break;
93+
dwin_string.add(wc);
9494
}
9595
DWIN_Draw_String(dwin_font.solid, dwin_font.index, dwin_font.fg, dwin_font.bg, cursor.x, cursor.y, dwin_string.string());
9696
lcd_advance_cursor(dwin_string.length);

Marlin/src/lcd/fontutils.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131

3232
#include "../inc/MarlinConfig.h"
3333

34-
#define MAX_UTF8_CHAR_SIZE 4
35-
3634
#if HAS_WIRED_LCD
3735
#include "marlinui.h"
3836
#include "../MarlinCore.h"

Marlin/src/lcd/fontutils.h

+11-3
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,23 @@
3838

3939
#define MAX_UTF8_CHAR_SIZE 4
4040

41+
// Use a longer character type (if needed) because wchar_t is only 16 bits wide
42+
#ifdef MAX_UTF8_CHAR_SIZE
43+
#if MAX_UTF8_CHAR_SIZE > 2
44+
typedef uint32_t lchar_t;
45+
#else
46+
typedef wchar_t lchar_t;
47+
#endif
48+
#else
49+
#define wchar_t uint32_t
50+
#endif
51+
4152
// read a byte from ROM or RAM
4253
typedef uint8_t (*read_byte_cb_t)(const uint8_t * str);
4354

4455
uint8_t read_byte_ram(const uint8_t *str);
4556
uint8_t read_byte_rom(const uint8_t *str);
4657

47-
// An extra long character type because wchar_t is only 2 bytes
48-
typedef uint32_t lchar_t;
49-
5058
typedef uint16_t pixel_len_t;
5159
#define PIXEL_LEN_NOLIMIT ((pixel_len_t)(-1))
5260

Marlin/src/lcd/lcdprint.cpp

+15-15
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ lcd_uint_t lcd_put_u8str_P(PGM_P const ptpl, const int8_t ind, const char *cstr/
4747
const uint8_t *p = (uint8_t*)ptpl;
4848
int8_t n = maxlen;
4949
while (n > 0) {
50-
lchar_t ch;
51-
p = get_utf8_value_cb(p, read_byte_rom, ch);
52-
if (!ch) break;
53-
if (ch == '=' || ch == '~' || ch == '*') {
50+
lchar_t wc;
51+
p = get_utf8_value_cb(p, read_byte_rom, wc);
52+
if (!wc) break;
53+
if (wc == '=' || wc == '~' || wc == '*') {
5454
if (ind >= 0) {
55-
if (ch == '*') { lcd_put_lchar('E'); n--; }
55+
if (wc == '*') { lcd_put_lchar('E'); n--; }
5656
if (n) {
57-
int8_t inum = ind + ((ch == '=') ? 0 : LCD_FIRST_TOOL);
57+
int8_t inum = ind + ((wc == '=') ? 0 : LCD_FIRST_TOOL);
5858
if (inum >= 10) {
5959
lcd_put_lchar('0' + (inum / 10)); n--;
6060
inum %= 10;
@@ -71,19 +71,19 @@ lcd_uint_t lcd_put_u8str_P(PGM_P const ptpl, const int8_t ind, const char *cstr/
7171
break;
7272
}
7373
}
74-
else if (ch == '$' && fstr) {
74+
else if (wc == '$' && fstr) {
7575
n -= lcd_put_u8str_max_P(FTOP(fstr), n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH);
7676
}
77-
else if (ch == '$' && cstr) {
77+
else if (wc == '$' && cstr) {
7878
n -= lcd_put_u8str_max(cstr, n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH);
7979
}
80-
else if (ch == '@') {
80+
else if (wc == '@') {
8181
lcd_put_lchar(AXIS_CHAR(ind));
8282
n--;
8383
}
8484
else {
85-
lcd_put_lchar(ch);
86-
n -= ch > 255 ? prop : 1;
85+
lcd_put_lchar(wc);
86+
n -= wc > 255 ? prop : 1;
8787
}
8888
}
8989
return n;
@@ -97,10 +97,10 @@ int calculateWidth(PGM_P const pstr) {
9797
int n = 0;
9898

9999
do {
100-
lchar_t ch;
101-
p = get_utf8_value_cb(p, read_byte_rom, ch);
102-
if (!ch) break;
103-
n += (ch > 255) ? prop : 1;
100+
lchar_t wc;
101+
p = get_utf8_value_cb(p, read_byte_rom, wc);
102+
if (!wc) break;
103+
n += (wc > 255) ? prop : 1;
104104
} while (1);
105105

106106
return n * MENU_FONT_WIDTH;

Marlin/src/lcd/marlinui.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -417,26 +417,26 @@ void MarlinUI::init() {
417417
};
418418

419419
const uint8_t *p = (uint8_t*)string;
420-
lchar_t ch;
420+
lchar_t wc;
421421
if (wordwrap) {
422422
const uint8_t *wrd = nullptr;
423423
uint8_t c = 0;
424424
// find the end of the part
425425
for (;;) {
426426
if (!wrd) wrd = p; // Get word start /before/ advancing
427-
p = get_utf8_value_cb(p, cb_read_byte, ch);
428-
const bool eol = !ch; // zero ends the string
427+
p = get_utf8_value_cb(p, cb_read_byte, wc);
428+
const bool eol = !wc; // zero ends the string
429429
// End or a break between phrases?
430-
if (eol || ch == ' ' || ch == '-' || ch == '+' || ch == '.') {
431-
if (!c && ch == ' ') { if (wrd) wrd++; continue; } // collapse extra spaces
430+
if (eol || wc == ' ' || wc == '-' || wc == '+' || wc == '.') {
431+
if (!c && wc == ' ') { if (wrd) wrd++; continue; } // collapse extra spaces
432432
// Past the right and the word is not too long?
433433
if (col + c > LCD_WIDTH && col >= (LCD_WIDTH) / 4) _newline(); // should it wrap?
434434
c += !eol; // +1 so the space will be printed
435435
col += c; // advance col to new position
436436
while (c) { // character countdown
437437
--c; // count down to zero
438-
wrd = get_utf8_value_cb(wrd, cb_read_byte, ch); // get characters again
439-
lcd_put_lchar(ch); // character to the LCD
438+
wrd = get_utf8_value_cb(wrd, cb_read_byte, wc); // get characters again
439+
lcd_put_lchar(wc); // character to the LCD
440440
}
441441
if (eol) break; // all done!
442442
wrd = nullptr; // set up for next word
@@ -446,9 +446,9 @@ void MarlinUI::init() {
446446
}
447447
else {
448448
for (;;) {
449-
p = get_utf8_value_cb(p, cb_read_byte, ch);
450-
if (!ch) break;
451-
lcd_put_lchar(ch);
449+
p = get_utf8_value_cb(p, cb_read_byte, wc);
450+
if (!wc) break;
451+
lcd_put_lchar(wc);
452452
col++;
453453
if (col >= LCD_WIDTH) _newline();
454454
}

Marlin/src/lcd/tft/tft_string.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ void TFT_String::set() {
9494
* @ displays an axis name such as XYZUVW, or E for an extruder
9595
*/
9696
void TFT_String::add(const char *tpl, const int8_t index, const char *cstr/*=nullptr*/, FSTR_P const fstr/*=nullptr*/) {
97-
lchar_t ch;
97+
lchar_t wc;
9898

9999
while (*tpl) {
100-
tpl = get_utf8_value_cb(tpl, read_byte_ram, ch);
101-
if (ch > 255) ch |= 0x0080;
102-
const uint8_t ch = uint8_t(ch & 0x00FF);
100+
tpl = get_utf8_value_cb(tpl, read_byte_ram, wc);
101+
if (wc > 255) wc |= 0x0080;
102+
const uint8_t ch = uint8_t(wc & 0x00FF);
103103

104104
if (ch == '=' || ch == '~' || ch == '*') {
105105
if (index >= 0) {
@@ -124,11 +124,11 @@ void TFT_String::add(const char *tpl, const int8_t index, const char *cstr/*=nul
124124
}
125125

126126
void TFT_String::add(const char *cstr, uint8_t max_len/*=MAX_STRING_LENGTH*/) {
127-
lchar_t ch;
127+
lchar_t wc;
128128
while (*cstr && max_len) {
129-
cstr = get_utf8_value_cb(cstr, read_byte_ram, ch);
130-
if (ch > 255) ch |= 0x0080;
131-
const uint8_t ch = uint8_t(ch & 0x00FF);
129+
cstr = get_utf8_value_cb(cstr, read_byte_ram, wc);
130+
if (wc > 255) wc |= 0x0080;
131+
const uint8_t ch = uint8_t(wc & 0x00FF);
132132
add_character(ch);
133133
max_len--;
134134
}

0 commit comments

Comments
 (0)