My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utf_mapper.h 12KB

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