Parcourir la source

🩹 Followup for lchar_t

Scott Lahteine il y a 1 an
Parent
révision
f39e2bc1e4

+ 4
- 4
Marlin/src/lcd/HD44780/lcdprint_hd44780.cpp Voir le fichier

@@ -1051,10 +1051,10 @@ static int lcd_put_u8str_max_cb(const char * utf8_str, read_byte_cb_t cb_read_by
1051 1051
   pixel_len_t ret = 0;
1052 1052
   const uint8_t *p = (uint8_t *)utf8_str;
1053 1053
   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);
1058 1058
   }
1059 1059
   return (int)ret;
1060 1060
 }

+ 4
- 4
Marlin/src/lcd/TFTGLCD/lcdprint_TFTGLCD.cpp Voir le fichier

@@ -1049,10 +1049,10 @@ static int lcd_put_u8str_max_cb(const char * utf8_str, read_byte_cb_t cb_read_by
1049 1049
   pixel_len_t ret = 0;
1050 1050
   const uint8_t *p = (uint8_t *)utf8_str;
1051 1051
   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);
1056 1056
   }
1057 1057
   return (int)ret;
1058 1058
 }

+ 7
- 7
Marlin/src/lcd/dogm/u8g_fontutf8.cpp Voir le fichier

@@ -106,10 +106,10 @@ static void fontgroup_drawwchar(font_group_t *group, const font_t *fnt_default,
106 106
 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) {
107 107
   const uint8_t *p = (uint8_t*)utf8_msg;
108 108
   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);
113 113
   }
114 114
 }
115 115
 
@@ -154,14 +154,14 @@ static int fontgroup_cb_draw_u8g(void *userdata, const font_t *fnt_current, cons
154 154
  * @param pu8g : U8G pointer
155 155
  * @param x : position x axis
156 156
  * @param y : position y axis
157
- * @param ch : the lchar_t
157
+ * @param wc : the lchar_t
158 158
  * @param max_width : the pixel width of the string allowed
159 159
  *
160 160
  * @return number of pixels advanced
161 161
  *
162 162
  * Draw a UTF-8 string at the specified position
163 163
  */
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) {
165 165
   struct _uxg_drawu8_data_t data;
166 166
   font_group_t *group = &g_fontgroup_root;
167 167
   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
176 176
   data.adv = 0;
177 177
   data.max_width = max_width;
178 178
   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);
180 180
   u8g_SetFont(pu8g, (const u8g_fntpgm_uint8_t*)fnt_default);
181 181
 
182 182
   return data.adv;

+ 14
- 14
Marlin/src/lcd/e3v2/marlinui/dwin_string.cpp Voir le fichier

@@ -50,12 +50,12 @@ uint8_t read_byte(const uint8_t *byte) { return *byte; }
50 50
  *   @ displays an axis name such as XYZUVW, or E for an extruder
51 51
  */
52 52
 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;
54 54
 
55 55
   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);
59 59
 
60 60
     if (ch == '=' || ch == '~' || ch == '*') {
61 61
       if (index >= 0) {
@@ -80,32 +80,32 @@ void DWIN_String::add(const char *tpl, const int8_t index, const char *cstr/*=nu
80 80
 }
81 81
 
82 82
 void DWIN_String::add(const char *cstr, uint8_t max_len/*=MAX_STRING_LENGTH*/) {
83
-  lchar_t ch;
83
+  lchar_t wc;
84 84
   while (*cstr && max_len) {
85
-    cstr = get_utf8_value_cb(cstr, read_byte, ch);
85
+    cstr = get_utf8_value_cb(cstr, read_byte, wc);
86 86
     /*
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);
89 89
     add_character(ch);
90 90
     */
91
-    add(ch);
91
+    add(wc);
92 92
     max_len--;
93 93
   }
94 94
   eol();
95 95
 }
96 96
 
97
-void DWIN_String::add(const lchar_t &ch) {
97
+void DWIN_String::add(const lchar_t &wc) {
98 98
   int ret;
99 99
   size_t idx = 0;
100 100
   dwin_charmap_t pinval;
101 101
   dwin_charmap_t *copy_address = nullptr;
102
-  pinval.uchar = ch;
102
+  pinval.uchar = wc;
103 103
   pinval.idx = -1;
104 104
 
105
-  // For 8-bit ASCII just print the single ch
105
+  // For 8-bit ASCII just print the single character
106 106
   char str[] = { '?', 0 };
107
-  if (ch < 255) {
108
-    str[0] = (char)ch;
107
+  if (wc < 255) {
108
+    str[0] = (char)wc;
109 109
   }
110 110
   else {
111 111
     copy_address = nullptr;

+ 3
- 3
Marlin/src/lcd/e3v2/marlinui/dwin_string.h Voir le fichier

@@ -69,10 +69,10 @@ class DWIN_String {
69 69
     /**
70 70
      * @brief Append a UTF-8 character
71 71
      *
72
-     * @param ch The UTF-8 character
72
+     * @param wc The UTF-8 character
73 73
      */
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); }
76 76
 
77 77
     /**
78 78
      * @brief Append / Set C-string

+ 4
- 4
Marlin/src/lcd/e3v2/marlinui/lcdprint_dwin.cpp Voir le fichier

@@ -87,10 +87,10 @@ static int lcd_put_u8str_max_cb(const char * utf8_str, read_byte_cb_t cb_read_by
87 87
   const uint8_t *p = (uint8_t *)utf8_str;
88 88
   dwin_string.set();
89 89
   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);
94 94
   }
95 95
   DWIN_Draw_String(dwin_font.solid, dwin_font.index, dwin_font.fg, dwin_font.bg, cursor.x, cursor.y, dwin_string.string());
96 96
   lcd_advance_cursor(dwin_string.length);

+ 0
- 2
Marlin/src/lcd/fontutils.cpp Voir le fichier

@@ -31,8 +31,6 @@
31 31
 
32 32
 #include "../inc/MarlinConfig.h"
33 33
 
34
-#define MAX_UTF8_CHAR_SIZE 4
35
-
36 34
 #if HAS_WIRED_LCD
37 35
   #include "marlinui.h"
38 36
   #include "../MarlinCore.h"

+ 11
- 3
Marlin/src/lcd/fontutils.h Voir le fichier

@@ -38,15 +38,23 @@
38 38
 
39 39
 #define MAX_UTF8_CHAR_SIZE 4
40 40
 
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
+
41 52
 // read a byte from ROM or RAM
42 53
 typedef uint8_t (*read_byte_cb_t)(const uint8_t * str);
43 54
 
44 55
 uint8_t read_byte_ram(const uint8_t *str);
45 56
 uint8_t read_byte_rom(const uint8_t *str);
46 57
 
47
-// An extra long character type because wchar_t is only 2 bytes
48
-typedef uint32_t lchar_t;
49
-
50 58
 typedef uint16_t pixel_len_t;
51 59
 #define PIXEL_LEN_NOLIMIT ((pixel_len_t)(-1))
52 60
 

+ 15
- 15
Marlin/src/lcd/lcdprint.cpp Voir le fichier

@@ -47,14 +47,14 @@ lcd_uint_t lcd_put_u8str_P(PGM_P const ptpl, const int8_t ind, const char *cstr/
47 47
   const uint8_t *p = (uint8_t*)ptpl;
48 48
   int8_t n = maxlen;
49 49
   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 == '*') {
54 54
       if (ind >= 0) {
55
-        if (ch == '*') { lcd_put_lchar('E'); n--; }
55
+        if (wc == '*') { lcd_put_lchar('E'); n--; }
56 56
         if (n) {
57
-          int8_t inum = ind + ((ch == '=') ? 0 : LCD_FIRST_TOOL);
57
+          int8_t inum = ind + ((wc == '=') ? 0 : LCD_FIRST_TOOL);
58 58
           if (inum >= 10) {
59 59
             lcd_put_lchar('0' + (inum / 10)); n--;
60 60
             inum %= 10;
@@ -71,19 +71,19 @@ lcd_uint_t lcd_put_u8str_P(PGM_P const ptpl, const int8_t ind, const char *cstr/
71 71
         break;
72 72
       }
73 73
     }
74
-    else if (ch == '$' && fstr) {
74
+    else if (wc == '$' && fstr) {
75 75
       n -= lcd_put_u8str_max_P(FTOP(fstr), n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH);
76 76
     }
77
-    else if (ch == '$' && cstr) {
77
+    else if (wc == '$' && cstr) {
78 78
       n -= lcd_put_u8str_max(cstr, n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH);
79 79
     }
80
-    else if (ch == '@') {
80
+    else if (wc == '@') {
81 81
       lcd_put_lchar(AXIS_CHAR(ind));
82 82
       n--;
83 83
     }
84 84
     else {
85
-      lcd_put_lchar(ch);
86
-      n -= ch > 255 ? prop : 1;
85
+      lcd_put_lchar(wc);
86
+      n -= wc > 255 ? prop : 1;
87 87
     }
88 88
   }
89 89
   return n;
@@ -97,10 +97,10 @@ int calculateWidth(PGM_P const pstr) {
97 97
   int n = 0;
98 98
 
99 99
   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;
104 104
   } while (1);
105 105
 
106 106
   return n * MENU_FONT_WIDTH;

+ 10
- 10
Marlin/src/lcd/marlinui.cpp Voir le fichier

@@ -417,26 +417,26 @@ void MarlinUI::init() {
417 417
         };
418 418
 
419 419
         const uint8_t *p = (uint8_t*)string;
420
-        lchar_t ch;
420
+        lchar_t wc;
421 421
         if (wordwrap) {
422 422
           const uint8_t *wrd = nullptr;
423 423
           uint8_t c = 0;
424 424
           // find the end of the part
425 425
           for (;;) {
426 426
             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
429 429
             // 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
432 432
               // Past the right and the word is not too long?
433 433
               if (col + c > LCD_WIDTH && col >= (LCD_WIDTH) / 4) _newline(); // should it wrap?
434 434
               c += !eol;                  // +1 so the space will be printed
435 435
               col += c;                   // advance col to new position
436 436
               while (c) {                 // character countdown
437 437
                 --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
440 440
               }
441 441
               if (eol) break;             // all done!
442 442
               wrd = nullptr;              // set up for next word
@@ -446,9 +446,9 @@ void MarlinUI::init() {
446 446
         }
447 447
         else {
448 448
           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);
452 452
             col++;
453 453
             if (col >= LCD_WIDTH) _newline();
454 454
           }

+ 8
- 8
Marlin/src/lcd/tft/tft_string.cpp Voir le fichier

@@ -94,12 +94,12 @@ void TFT_String::set() {
94 94
  *   @ displays an axis name such as XYZUVW, or E for an extruder
95 95
  */
96 96
 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;
98 98
 
99 99
   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);
103 103
 
104 104
     if (ch == '=' || ch == '~' || ch == '*') {
105 105
       if (index >= 0) {
@@ -124,11 +124,11 @@ void TFT_String::add(const char *tpl, const int8_t index, const char *cstr/*=nul
124 124
 }
125 125
 
126 126
 void TFT_String::add(const char *cstr, uint8_t max_len/*=MAX_STRING_LENGTH*/) {
127
-  lchar_t ch;
127
+  lchar_t wc;
128 128
   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);
132 132
     add_character(ch);
133 133
     max_len--;
134 134
   }

Chargement…
Annuler
Enregistrer