🩹 Remove poison wchar_t macro

This commit is contained in:
Scott Lahteine
2022-07-01 04:49:37 -05:00
parent 814b53750f
commit 80c7abd727
26 changed files with 244 additions and 239 deletions

View File

@@ -50,12 +50,12 @@ uint8_t read_byte(const uint8_t *byte) { return *byte; }
* @ displays an axis name such as XYZUVW, or E for an extruder
*/
void DWIN_String::add(const char *tpl, const int8_t index, const char *cstr/*=nullptr*/, FSTR_P const fstr/*=nullptr*/) {
wchar_t wchar;
lchar_t wc;
while (*tpl) {
tpl = get_utf8_value_cb(tpl, read_byte, &wchar);
if (wchar > 255) wchar |= 0x0080;
const uint8_t ch = uint8_t(wchar & 0x00FF);
tpl = get_utf8_value_cb(tpl, read_byte, wc);
if (wc > 255) wc |= 0x0080;
const uint8_t ch = uint8_t(wc & 0x00FF);
if (ch == '=' || ch == '~' || ch == '*') {
if (index >= 0) {
@@ -80,32 +80,32 @@ void DWIN_String::add(const char *tpl, const int8_t index, const char *cstr/*=nu
}
void DWIN_String::add(const char *cstr, uint8_t max_len/*=MAX_STRING_LENGTH*/) {
wchar_t wchar;
lchar_t wc;
while (*cstr && max_len) {
cstr = get_utf8_value_cb(cstr, read_byte, &wchar);
cstr = get_utf8_value_cb(cstr, read_byte, wc);
/*
if (wchar > 255) wchar |= 0x0080;
uint8_t ch = uint8_t(wchar & 0x00FF);
if (wc > 255) wc |= 0x0080;
const uint8_t ch = uint8_t(wc & 0x00FF);
add_character(ch);
*/
add(wchar);
add(wc);
max_len--;
}
eol();
}
void DWIN_String::add(const wchar_t character) {
void DWIN_String::add(const lchar_t &wc) {
int ret;
size_t idx = 0;
dwin_charmap_t pinval;
dwin_charmap_t *copy_address = nullptr;
pinval.uchar = character;
pinval.uchar = wc;
pinval.idx = -1;
// For 8-bit ASCII just print the single character
char str[] = { '?', 0 };
if (character < 255) {
str[0] = (char)character;
if (wc < 255) {
str[0] = (char)wc;
}
else {
copy_address = nullptr;

View File

@@ -29,7 +29,7 @@
#include <stdint.h>
typedef struct _dwin_charmap_t {
wchar_t uchar; // the unicode char
lchar_t uchar; // the unicode char
uint8_t idx; // the glyph of the char in the ROM
uint8_t idx2; // the char used to be combined with the idx to simulate a single char
} dwin_charmap_t;
@@ -69,10 +69,10 @@ class DWIN_String {
/**
* @brief Append a UTF-8 character
*
* @param character The UTF-8 character
* @param wc The UTF-8 character
*/
static void add(wchar_t character);
static void set(wchar_t character) { set(); add(character); }
static void add(const lchar_t &wc);
static void set(const lchar_t &wc) { set(); add(wc); }
/**
* @brief Append / Set C-string

View File

@@ -63,7 +63,7 @@ int lcd_put_dwin_string() {
// return < 0 on error
// return the advanced cols
int lcd_put_wchar_max(const wchar_t c, const pixel_len_t max_length) {
int lcd_put_lchar_max(const lchar_t &c, const pixel_len_t max_length) {
dwin_string.set(c);
dwin_string.truncate(max_length);
// Draw the char(s) at the cursor and advance the cursor
@@ -87,10 +87,10 @@ static int lcd_put_u8str_max_cb(const char * utf8_str, read_byte_cb_t cb_read_by
const uint8_t *p = (uint8_t *)utf8_str;
dwin_string.set();
while (dwin_string.length < max_length) {
wchar_t ch = 0;
p = get_utf8_value_cb(p, cb_read_byte, &ch);
if (!ch) break;
dwin_string.add(ch);
lchar_t wc;
p = get_utf8_value_cb(p, cb_read_byte, wc);
if (!wc) break;
dwin_string.add(wc);
}
DWIN_Draw_String(dwin_font.solid, dwin_font.index, dwin_font.fg, dwin_font.bg, cursor.x, cursor.y, dwin_string.string());
lcd_advance_cursor(dwin_string.length);

View File

@@ -213,7 +213,7 @@ void MarlinUI::draw_status_message(const bool blink) {
lcd_put_u8str(status_message);
// Fill the rest with spaces
while (slen < max_status_chars) { lcd_put_wchar(' '); ++slen; }
while (slen < max_status_chars) { lcd_put_lchar(' '); ++slen; }
}
}
else {
@@ -227,10 +227,10 @@ void MarlinUI::draw_status_message(const bool blink) {
// If the string doesn't completely fill the line...
if (rlen < max_status_chars) {
lcd_put_wchar('.'); // Always at 1+ spaces left, draw a dot
lcd_put_lchar('.'); // Always at 1+ spaces left, draw a dot
uint8_t chars = max_status_chars - rlen; // Amount of space left in characters
if (--chars) { // Draw a second dot if there's space
lcd_put_wchar('.');
lcd_put_lchar('.');
if (--chars)
lcd_put_u8str_max(status_message, chars); // Print a second copy of the message
}
@@ -254,7 +254,7 @@ void MarlinUI::draw_status_message(const bool blink) {
lcd_put_u8str_max(status_message, max_status_chars);
// Fill the rest with spaces if there are missing spaces
while (slen < max_status_chars) { lcd_put_wchar(' '); ++slen; }
while (slen < max_status_chars) { lcd_put_lchar(' '); ++slen; }
}
#endif