Sfoglia il codice sorgente

Insert utf_mapper.h

Top -> down
- Decide what output function is to use.
- Precautions. If non of the DISPLAY_CHARSET_HD44780's is selected fall back to Japanese.
- When we are not on the dogms setup a mapping table depending on display type and mapper.
- If we are on dogm we use ONE To ONE mapping - except kanji.
- select and define one of the mapping functions.
AnHardt 10 anni fa
parent
commit
c4b0087f7a
1 ha cambiato i file con 255 aggiunte e 0 eliminazioni
  1. 255
    0
      Marlin/utf_mapper.h

+ 255
- 0
Marlin/utf_mapper.h Vedi File

@@ -0,0 +1,255 @@
1
+#ifndef UTF_MAPPER_H
2
+#define UTF_MAPPER_H
3
+
4
+#include  "language.h"
5
+
6
+#ifdef DOGLCD
7
+  #define HARDWAERE_CHAR_OUT u8g.print
8
+#else
9
+  #define HARDWAERE_CHAR_OUT lcd.write
10
+#endif
11
+
12
+#if !(defined( DISPLAY_CHARSET_HD44780_JAPAN ) || defined( DISPLAY_CHARSET_HD44780_WESTERN ) || defined( DISPLAY_CHARSET_HD44780_CYRILIC ))
13
+  #define DISPLAY_CHARSET_HD44780_JAPAN
14
+#endif
15
+
16
+#ifndef DOGLCD
17
+  #ifdef DISPLAY_CHARSET_KANJI
18
+    #error("Kanji does not work on character based displays!");
19
+  #elif defined( DISPLAY_CHARSET_HD44780_JAPAN )
20
+    #if defined( MAPPER_C2C3 )
21
+      const PROGMEM uint8_t utf_recode[] =
22
+           { // 0    1    2    3    4    5    6    7    8    9    a    b    c    d    e    f          This is fair for symbols
23
+             0x20,0x3f,0xec,0xed,0x3f,0x5c,0x7c,0x3f,0x22,0x63,0x61,0x7f,0x3f,0x3f,0x52,0xb0,  // c2a
24
+  //          ' '       ¢    £         ­    l         "    c    a    «              R
25
+             0xdf,0x3f,0x32,0x33,0x27,0xe4,0xf1,0xa5,0x2c,0x31,0xdf,0x7e,0x3f,0x3f,0x3f,0x3f,  // c2b but relatively bad for letters.
26
+  //          °         2    3    `    N    p    .    ,    1    °    »
27
+             0x3f,0x3f,0x3f,0x3f,0xe1,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,  // c38
28
+  //                              ä
29
+             0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0xef,0x78,0x3f,0x3f,0x3f,0x3f,0xf5,0x3f,0x3f,0xe2,  // c39 missing characters display as '?'
30
+  //                                        ö     x                       ü              ä
31
+             0x3f,0x3f,0x3f,0x3f,0xe1,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,  // c3a
32
+  //                              ä
33
+             0x3f,0xee,0x3f,0x3f,0x3f,0x3f,0xef,0xed,0x3f,0x3f,0x3f,0x3f,0xf5,0x3f,0x3f,0x3f   // c3b
34
+  //               n                        ö                             ü
35
+           };
36
+    #elif defined( MAPPER_E382E383 )
37
+      const PROGMEM uint8_t utf_recode[] =
38
+           { // 0    1    2    3    4    5    6    7    8    9    a    b    c    d    e    f
39
+             0x3d,0xb1,0xb1,0xa8,0xb2,0xa9,0xb3,0xaa,0xb4,0xab,0xb5,0xb6,0xb6,0xb7,0xb7,0xb8,  // e382a Please test and correct
40
+  //          =    ア    ア    ィ    イ    ゥ    ウ    ェ    エ    ォ    オ   ガ    ガ    キ   キ    ク
41
+             0xb8,0xb9,0xb9,0xba,0xba,0xbb,0xbb,0xbc,0xbc,0xbd,0xbd,0xbe,0xbe,0xbf,0xbf,0xc0,  // e382b
42
+  //          ク    ケ    ケ   コ    コ    サ    サ    シ    シ   ス    ス    セ    セ    ソ   ソ    タ
43
+             0xc0,0xc1,0xc1,0xc2,0xc2,0xc2,0xc3,0xc3,0xc4,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,  // e3838
44
+  //          タ    チ    チ    ッ    ッ    ッ    テ   テ    ト    ト    ナ    ニ    ヌ    ネ   ノ    ハ
45
+             0xca,0xca,0xcb,0xcb,0xcb,0xcc,0xcc,0xcc,0xcd,0xcd,0xcd,0xce,0xce,0xce,0xcf,0xd0,  // e3839
46
+  //          ハ    ハ    ヒ   ヒ    ヒ     フ    フ   フ    ヘ    ヘ    ヘ    ホ    ホ    ホ   マ    ミ
47
+             0xd1,0xd2,0xd3,0xd4,0xd4,0xd5,0xd5,0xae,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdc,  // e383a
48
+  //          ム    メ    モ    ャ   ャ    ユ    ユ    ョ    ヨ    ラ    リ    ル    レ    ロ   ワ    ワ
49
+             0xec,0xa7,0xa6,0xdd,0xcc,0x3f,0x3f,0x3f,0x3f,0x3f,0xa6,0xa5,0xb0,0xa4,0xa4,0x3f   // e383b
50
+  //          ヰ    ヱ    ヲ    ン    フ    ?    ?   ?    ?    ?    ヲ    ・    ー    ヽ    ヽ   ?
51
+           };
52
+    #elif defined( MAPPER_D0D1 )
53
+      #error( "Cyrillic on a japanese dsplay makes no sense. There are no matching symbols.");
54
+    #endif
55
+
56
+  #elif defined( DISPLAY_CHARSET_HD44780_WESTERN )
57
+    #if defined( MAPPER_C2C3 )
58
+      const PROGMEM uint8_t utf_recode[] =
59
+           { // 0    1    2    3    4    5    6    7    8    9    a    b    c    d    e    f   This is relative complete.
60
+             0x20,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0x22,0xa9,0xaa,0xab,0x3f,0x3f,0xae,0x3f,  // c2a ¡¢£¤¥¦§¨©ª«¬­®¯
61
+  //         ' '   ¡    ¢    £    ¤    ¥    ¦    §    "    ©    ª    «    ?    ?    ®    ?
62
+             0xb0,0xb1,0xb2,0xb3,0x27,0xb5,0xb6,0xb7,0x2c,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,  // c2b °±²³´µ¶·¸¹º»¼½¾¿
63
+  //          °    ±    ³    ²    ?    µ    ¶    ·    ,    ¹    º    »    ¼    ½    ¾    ¿
64
+             0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,  // c38 ÀÁÃÄÅÆÇÈÉÊËÌÍÎÏ
65
+  //          À    Á    Â    Ã    Ä    Å    Æ    Ç    È    É    Ê    Ë    Ì    Í    Î    Ï
66
+             0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf,  // c39 ÐÑÓÔÕÖרÙÚÛÜÝÞß
67
+  //          Ð    Ñ    Ò    Ó    Ô    Õ    Ö    ×    Ø    Ù    Ú    Û    Ü    Ý    Þ    ß
68
+             0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,  // c3a àáãäåæçèéêëìíîï 
69
+  //          à    á    â    ã    ä    å    æ    ç    è    é    ê    ë    ì    í    î    ï
70
+             0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff   // c3b ðñóôõö÷øùúûüýþÿ
71
+  //          ð    ñ    ò    ó    ô    õ    ö    ÷    ø    ù    ú    û    ü    ý    þ    ÿ
72
+           };
73
+    #elif defined( MAPPER_D0D1 )
74
+      #define MAPPER_D0D1_MOD
75
+      const PROGMEM uint8_t utf_recode[] =
76
+           {//0    1    2    3    4    5    6    7    8    9    a    b    c    d    e    f
77
+             0x41,0x80,0x42,0x92,0x81,0x45,0x82,0x83,0x84,0x85,0x4b,0x86,0x4d,0x48,0x4f,0x87,  // d0a
78
+  //          A    Б    B    Г    Д    E    Ж    З    И    Й    K    Л    M    H    O    П
79
+             0x50,0x43,0x54,0x88,0xd8,0x58,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x62,0x8f,0xac,0xad,  // d0b
80
+  //          P    C    T    У    Ф    X    Ч    ч    Ш    Щ    Ъ    Ы    b    Э    Ю    Я
81
+             0x61,0x36,0x42,0x92,0x81,0x65,0x82,0xb3,0x84,0x85,0x6b,0x86,0x4d,0x48,0x6f,0x87,  // d18
82
+  //          a    6    B    Г    Д    e    Ж    ³    И    Й    k    Л    M    H    o    П
83
+             0x70,0x63,0x54,0x79,0xd8,0x78,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x62,0x8f,0xac,0xad   // d19
84
+  //          p    c    T    y    Ф    x    Ч    ч    Ш    Щ    Ъ    Ы    b    Э    Ю    Я
85
+            };
86
+    #elif defined( MAPPER_E382E383 )
87
+      #error( "Katakana on a western display makes no sense. There are no matching symbols." );
88
+    #endif
89
+
90
+  #elif defined( DISPLAY_CHARSET_HD44780_CYRILIC )
91
+    #if defined( MAPPER_D0D1 )
92
+      #define MAPPER_D0D1_MOD
93
+      // it is a Russian alphabet translation
94
+      // except 0401 --> 0xa2 = Ё, 0451 --> 0xb5 = ё
95
+      const PROGMEM uint8_t utf_recode[] =
96
+             { 0x41,0xa0,0x42,0xa1,0xe0,0x45,0xa3,0xa4,   // unicode U+0400 to U+047f
97
+  //            A   Б->Ё  B    Г    Д    E    Ж    З      // 0  Ѐ Ё Ђ Ѓ Є Ѕ І Ї
98
+               0xa5,0xa6,0x4b,0xa7,0x4d,0x48,0x4f,0xa8,   //    Ј Љ Њ Ћ Ќ Ѝ Ў Џ
99
+  //            И    Й    K    Л    M    H    O    П      // 1  А Б В Г Д Е Ж З
100
+               0x50,0x43,0x54,0xa9,0xaa,0x58,0xe1,0xab,   //    И Й К Л М Н О П
101
+  //            P    C    T    У    Ф    X    Ч    ч      // 2  Р С Т У Ф Х Г Ч
102
+               0xac,0xe2,0xad,0xae,0x62,0xaf,0xb0,0xb1,   //    Ш Щ Ъ Ы Ь Э Ю Я
103
+  //            Ш    Щ    Ъ    Ы    b    Э    Ю    Я      // 3  а б в г д е ж з
104
+               0x61,0xb2,0xb3,0xb4,0xe3,0x65,0xb6,0xb7,   //    и й к л м н о п
105
+  //            a   б->ё  в    г    д    e    ж    з      // 4  р с т у ф х ц ч
106
+               0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0x6f,0xbe,   //    ш щ ъ ы ь э ю я
107
+  //            и    й    к    л    м    н    o    п      // 5  ѐ ё ђ ѓ є ѕ і ї
108
+               0x70,0x63,0xbf,0x79,0xe4,0x78,0xe5,0xc0,   //    ј љ њ ћ ќ ѝ ў џ
109
+  //            p    c    т    y    ф    x    ц    ч      // 6  Ѡ ѡ Ѣ ѣ Ѥ ѥ Ѧ ѧ
110
+               0xc1,0xe6,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7    //    Ѫ ѩ Ѫ ѫ Ѭ ѭ Ѯ ѯ
111
+  //            ш    щ    ъ    ы    ь    э    ю    я      // 7  Ѱ ѱ Ѳ ѳ Ѵ ѵ Ѷ ѷ
112
+             };                                           //    ѻ ѹ Ѻ ѻ Ѽ ѽ Ѿ ѿ
113
+    #elif defined( MAPPER_C2C3 )
114
+      #error( "Western languages on a cyrillic display makes no sense. There are no matching symbols." );
115
+    #elif defined( MAPPER_E382E383 )
116
+      #error( "Katakana on a cyrillic display makes no sense. There are no matching symbols." );
117
+    #endif
118
+  #endif
119
+#else //DOGLCD
120
+  #if defined( DISPLAY_CHARSET_KANJI )
121
+    #define MAPPER_NON
122
+  #else
123
+    #define MAPPER_ONE_TO_ONE
124
+  #endif
125
+#endif //DOGLCD
126
+
127
+#if defined( MAPPER_NON )
128
+  char charset_mapper(char c){
129
+    HARDWAERE_CHAR_OUT( c );
130
+    return 1;
131
+  }
132
+#elif defined( MAPPER_C2C3 )
133
+  uint8_t utf_hi_char; // UTF-8 high part
134
+  bool seen_c2 = false;
135
+  char charset_mapper(char c){
136
+    uint8_t d = c;
137
+    if ( d >= 0x80 ) { // UTF-8 handling
138
+      if ( (d >= 0xc0) && (!seen_c2) ) {
139
+        utf_hi_char = d - 0xc2;
140
+        seen_c2 = true;
141
+        return 0;
142
+      }
143
+      else if (seen_c2){
144
+        d &= 0x3f;
145
+        #ifndef MAPPER_ONE_TO_ONE
146
+          HARDWAERE_CHAR_OUT( (char) pgm_read_byte_near( utf_recode + d + ( utf_hi_char << 6 ) - 0x20)       );
147
+        #else
148
+          HARDWAERE_CHAR_OUT( (char) (0x80 + ( utf_hi_char << 6 ) + d) ) ;
149
+        #endif
150
+      }
151
+      else {
152
+          HARDWAERE_CHAR_OUT('?');
153
+      }
154
+    }
155
+    else {
156
+      HARDWAERE_CHAR_OUT((char) c );
157
+    }
158
+    seen_c2 = false;
159
+    return 1;
160
+  }
161
+#elif defined( MAPPER_D0D1_MOD )
162
+  uint8_t utf_hi_char; // UTF-8 high part
163
+  bool seen_d5 = false;
164
+  char charset_mapper(char c){
165
+    // it is a Russian alphabet translation
166
+    // except 0401 --> 0xa2 = Ё, 0451 --> 0xb5 = ё
167
+    uint8_t d = c;
168
+    if ( d >= 0x80 ) { // UTF-8 handling
169
+      if ((d >= 0xd0) && (!seen_d5)) {
170
+        utf_hi_char = d - 0xd0;
171
+        seen_d5 = true;
172
+        return 0;
173
+      } else if (seen_d5) {
174
+          d &= 0x3f;
175
+          if ( !utf_hi_char && ( d == 1 )) {
176
+            HARDWAERE_CHAR_OUT((char) 0xa2 ); // Ё
177
+        } else if ((utf_hi_char == 1) && (d == 0x11)) {
178
+            HARDWAERE_CHAR_OUT((char) 0xb5 ); // ё
179
+          } else {
180
+            HARDWAERE_CHAR_OUT((char) pgm_read_byte_near( utf_recode + d + ( utf_hi_char << 6 ) - 0x10 ));
181
+          }
182
+        }
183
+        else {
184
+          HARDWAERE_CHAR_OUT('?');
185
+        }
186
+    } else {
187
+      HARDWAERE_CHAR_OUT((char) c );
188
+    }
189
+    seen_d5 = false;
190
+    return 1;
191
+  }
192
+#elif defined( MAPPER_D0D1 )
193
+  uint8_t utf_hi_char; // UTF-8 high part
194
+  bool seen_d5 = false;
195
+  char charset_mapper(char c){
196
+    // it is a Russian alphabet translation
197
+    // except 0401 --> 0xa2 = Ё, 0451 --> 0xb5 = ё
198
+    uint8_t d = c;
199
+    if ( d >= 0x80 ) { // UTF-8 handling
200
+      if ((d >= 0xd0) && (!seen_d5)) {
201
+        utf_hi_char = d - 0xd0;
202
+        seen_d5 = true;
203
+        return 0;
204
+      } else if (seen_d5) {
205
+          d &= 0x3f;
206
+        #ifndef MAPPER_ONE_TO_ONE
207
+          HARDWAERE_CHAR_OUT( (char) pgm_read_byte_near( utf_recode + d + ( utf_hi_char << 6 ) - 0x20)       );
208
+        #else
209
+          HARDWAERE_CHAR_OUT( (char) (0x80 + ( utf_hi_char << 6 ) + d) ) ;
210
+        #endif
211
+      } else {
212
+        HARDWAERE_CHAR_OUT('?');
213
+      }
214
+    } else {
215
+      HARDWAERE_CHAR_OUT((char) c );
216
+    }
217
+    seen_d5 = false;
218
+    return 1;
219
+  }
220
+#elif defined( MAPPER_E382E383 )
221
+  uint8_t utf_hi_char; // UTF-8 high part
222
+  bool seen_e3 = false;
223
+  bool seen_82_83 = false;
224
+  char charset_mapper(char c){
225
+  uint8_t d = c;
226
+    if ( d >= 0x80 ) { // UTF-8 handling
227
+      if ( (d == 0xe3) && (seen_e3 == false)) {
228
+        seen_e3 = true;
229
+        return 0;      // eat 0xe3
230
+      } else if ( (d >= 0x82) && (seen_e3 == true) && (seen_82_83 == false)) {
231
+        utf_hi_char = d - 0x82;
232
+        seen_82_83 = true;
233
+        return 0;
234
+      } else if ((seen_e3 == true) && (seen_82_83 == true)){
235
+        d &= 0x3f;
236
+        #ifndef MAPPER_ONE_TO_ONE
237
+          HARDWAERE_CHAR_OUT( (char) pgm_read_byte_near( utf_recode + d + ( utf_hi_char << 6 ) - 0x20)       );
238
+        #else
239
+          HARDWAERE_CHAR_OUT( (char) (0x80 + ( utf_hi_char << 6 ) + d) ) ;
240
+        #endif
241
+      } else {
242
+        HARDWAERE_CHAR_OUT((char) '?' );
243
+      }
244
+    } else {
245
+      HARDWAERE_CHAR_OUT((char) c );
246
+    }
247
+    seen_e3 = false;
248
+    seen_82_83 = false;
249
+    return 1;
250
+  }
251
+#else
252
+  #error "You have to define one of the DISPLAY_INPUT_CODE_MAPPERs in your language_xx.h file" // should not occur because (en) will set.
253
+#endif // code mappers
254
+
255
+#endif // UTF_MAPPER_H

Loading…
Annulla
Salva