Browse Source

🩹 Followup for lchar_t

Scott Lahteine 1 year ago
parent
commit
f39e2bc1e4

+ 4
- 4
Marlin/src/lcd/HD44780/lcdprint_hd44780.cpp View File

1051
   pixel_len_t ret = 0;
1051
   pixel_len_t ret = 0;
1052
   const uint8_t *p = (uint8_t *)utf8_str;
1052
   const uint8_t *p = (uint8_t *)utf8_str;
1053
   while (ret < max_length) {
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
   return (int)ret;
1059
   return (int)ret;
1060
 }
1060
 }

+ 4
- 4
Marlin/src/lcd/TFTGLCD/lcdprint_TFTGLCD.cpp View File

1049
   pixel_len_t ret = 0;
1049
   pixel_len_t ret = 0;
1050
   const uint8_t *p = (uint8_t *)utf8_str;
1050
   const uint8_t *p = (uint8_t *)utf8_str;
1051
   while (ret < max_length) {
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
   return (int)ret;
1057
   return (int)ret;
1058
 }
1058
 }

+ 7
- 7
Marlin/src/lcd/dogm/u8g_fontutf8.cpp View File

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

+ 14
- 14
Marlin/src/lcd/e3v2/marlinui/dwin_string.cpp View File

50
  *   @ displays an axis name such as XYZUVW, or E for an extruder
50
  *   @ displays an axis name such as XYZUVW, or E for an extruder
51
  */
51
  */
52
 void DWIN_String::add(const char *tpl, const int8_t index, const char *cstr/*=nullptr*/, FSTR_P const fstr/*=nullptr*/) {
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
   while (*tpl) {
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
     if (ch == '=' || ch == '~' || ch == '*') {
60
     if (ch == '=' || ch == '~' || ch == '*') {
61
       if (index >= 0) {
61
       if (index >= 0) {
80
 }
80
 }
81
 
81
 
82
 void DWIN_String::add(const char *cstr, uint8_t max_len/*=MAX_STRING_LENGTH*/) {
82
 void DWIN_String::add(const char *cstr, uint8_t max_len/*=MAX_STRING_LENGTH*/) {
83
-  lchar_t ch;
83
+  lchar_t wc;
84
   while (*cstr && max_len) {
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
     add_character(ch);
89
     add_character(ch);
90
     */
90
     */
91
-    add(ch);
91
+    add(wc);
92
     max_len--;
92
     max_len--;
93
   }
93
   }
94
   eol();
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
   int ret;
98
   int ret;
99
   size_t idx = 0;
99
   size_t idx = 0;
100
   dwin_charmap_t pinval;
100
   dwin_charmap_t pinval;
101
   dwin_charmap_t *copy_address = nullptr;
101
   dwin_charmap_t *copy_address = nullptr;
102
-  pinval.uchar = ch;
102
+  pinval.uchar = wc;
103
   pinval.idx = -1;
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
   char str[] = { '?', 0 };
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
   else {
110
   else {
111
     copy_address = nullptr;
111
     copy_address = nullptr;

+ 3
- 3
Marlin/src/lcd/e3v2/marlinui/dwin_string.h View File

69
     /**
69
     /**
70
      * @brief Append a UTF-8 character
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
      * @brief Append / Set C-string
78
      * @brief Append / Set C-string

+ 4
- 4
Marlin/src/lcd/e3v2/marlinui/lcdprint_dwin.cpp View File

87
   const uint8_t *p = (uint8_t *)utf8_str;
87
   const uint8_t *p = (uint8_t *)utf8_str;
88
   dwin_string.set();
88
   dwin_string.set();
89
   while (dwin_string.length < max_length) {
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
   DWIN_Draw_String(dwin_font.solid, dwin_font.index, dwin_font.fg, dwin_font.bg, cursor.x, cursor.y, dwin_string.string());
95
   DWIN_Draw_String(dwin_font.solid, dwin_font.index, dwin_font.fg, dwin_font.bg, cursor.x, cursor.y, dwin_string.string());
96
   lcd_advance_cursor(dwin_string.length);
96
   lcd_advance_cursor(dwin_string.length);

+ 0
- 2
Marlin/src/lcd/fontutils.cpp View File

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

+ 11
- 3
Marlin/src/lcd/fontutils.h View File

38
 
38
 
39
 #define MAX_UTF8_CHAR_SIZE 4
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
 // read a byte from ROM or RAM
52
 // read a byte from ROM or RAM
42
 typedef uint8_t (*read_byte_cb_t)(const uint8_t * str);
53
 typedef uint8_t (*read_byte_cb_t)(const uint8_t * str);
43
 
54
 
44
 uint8_t read_byte_ram(const uint8_t *str);
55
 uint8_t read_byte_ram(const uint8_t *str);
45
 uint8_t read_byte_rom(const uint8_t *str);
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
 typedef uint16_t pixel_len_t;
58
 typedef uint16_t pixel_len_t;
51
 #define PIXEL_LEN_NOLIMIT ((pixel_len_t)(-1))
59
 #define PIXEL_LEN_NOLIMIT ((pixel_len_t)(-1))
52
 
60
 

+ 15
- 15
Marlin/src/lcd/lcdprint.cpp View File

47
   const uint8_t *p = (uint8_t*)ptpl;
47
   const uint8_t *p = (uint8_t*)ptpl;
48
   int8_t n = maxlen;
48
   int8_t n = maxlen;
49
   while (n > 0) {
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
       if (ind >= 0) {
54
       if (ind >= 0) {
55
-        if (ch == '*') { lcd_put_lchar('E'); n--; }
55
+        if (wc == '*') { lcd_put_lchar('E'); n--; }
56
         if (n) {
56
         if (n) {
57
-          int8_t inum = ind + ((ch == '=') ? 0 : LCD_FIRST_TOOL);
57
+          int8_t inum = ind + ((wc == '=') ? 0 : LCD_FIRST_TOOL);
58
           if (inum >= 10) {
58
           if (inum >= 10) {
59
             lcd_put_lchar('0' + (inum / 10)); n--;
59
             lcd_put_lchar('0' + (inum / 10)); n--;
60
             inum %= 10;
60
             inum %= 10;
71
         break;
71
         break;
72
       }
72
       }
73
     }
73
     }
74
-    else if (ch == '$' && fstr) {
74
+    else if (wc == '$' && fstr) {
75
       n -= lcd_put_u8str_max_P(FTOP(fstr), n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH);
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
       n -= lcd_put_u8str_max(cstr, n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH);
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
       lcd_put_lchar(AXIS_CHAR(ind));
81
       lcd_put_lchar(AXIS_CHAR(ind));
82
       n--;
82
       n--;
83
     }
83
     }
84
     else {
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
   return n;
89
   return n;
97
   int n = 0;
97
   int n = 0;
98
 
98
 
99
   do {
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
   } while (1);
104
   } while (1);
105
 
105
 
106
   return n * MENU_FONT_WIDTH;
106
   return n * MENU_FONT_WIDTH;

+ 10
- 10
Marlin/src/lcd/marlinui.cpp View File

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

+ 8
- 8
Marlin/src/lcd/tft/tft_string.cpp View File

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

Loading…
Cancel
Save