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 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #ifndef UTF_MAPPER_H
  23. #define UTF_MAPPER_H
  24. #include "language.h"
  25. #if ENABLED(DOGLCD)
  26. #define HARDWARE_CHAR_OUT u8g.print
  27. #else
  28. #define HARDWARE_CHAR_OUT lcd.write
  29. #endif
  30. #if DISABLED(SIMULATE_ROMFONT) && ENABLED(DOGLCD)
  31. #if ENABLED(DISPLAY_CHARSET_ISO10646_1)
  32. #define MAPPER_ONE_TO_ONE
  33. #elif ENABLED(DISPLAY_CHARSET_ISO10646_5)
  34. #define MAPPER_ONE_TO_ONE
  35. #elif ENABLED(DISPLAY_CHARSET_ISO10646_KANA)
  36. #define MAPPER_ONE_TO_ONE
  37. #elif ENABLED(DISPLAY_CHARSET_ISO10646_GREEK)
  38. #define MAPPER_ONE_TO_ONE
  39. #elif ENABLED(DISPLAY_CHARSET_ISO10646_TR)
  40. #define MAPPER_ONE_TO_ONE
  41. #endif
  42. #else // SIMULATE_ROMFONT
  43. #if DISPLAY_CHARSET_HD44780 == JAPANESE
  44. #if ENABLED(MAPPER_C2C3)
  45. const PROGMEM uint8_t utf_recode[] =
  46. { // 0 1 2 3 4 5 6 7 8 9 a b c d e f This is fair for symbols
  47. 0x20,0x3f,0xec,0xed,0x3f,0x5c,0x7c,0x3f,0x22,0x63,0x61,0x7f,0x3f,0x3f,0x52,0xb0, // c2a
  48. //' ' ¢ £ ­ l " c a « R
  49. 0xdf,0x3f,0x32,0x33,0x27,0xe4,0xf1,0xa5,0x2c,0x31,0xdf,0x7e,0x3f,0x3f,0x3f,0x3f, // c2b but relatively bad for letters.
  50. // ° 2 3 ` N p . , 1 ° »
  51. 0x3f,0x3f,0x3f,0x3f,0xe1,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f, // c38
  52. // ä
  53. 0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0xef,0x78,0x3f,0x3f,0x3f,0x3f,0xf5,0x3f,0x3f,0xe2, // c39 missing characters display as '?'
  54. // ö x ü ß
  55. 0x3f,0x3f,0x3f,0x3f,0xe1,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f, // c3a
  56. // ä
  57. 0x3f,0xee,0x3f,0x3f,0x3f,0x3f,0xef,0xfd,0x3f,0x3f,0x3f,0x3f,0xf5,0x3f,0x3f,0x3f // c3b
  58. // n ö ÷ ü
  59. };
  60. #elif ENABLED(MAPPER_E382E383)
  61. const PROGMEM uint8_t utf_recode[] =
  62. { // 0 1 2 3 4 5 6 7 8 9 a b c d e f
  63. 0x3d,0xb1,0xb1,0xa8,0xb2,0xa9,0xb3,0xaa,0xb4,0xab,0xb5,0xb6,0xb6,0xb7,0xb7,0xb8, // e382a Please test and correct
  64. // = ア ア ィ イ ゥ ウ ェ エ ォ オ ガ ガ キ キ ク
  65. 0xb8,0xb9,0xb9,0xba,0xba,0xbb,0xbb,0xbc,0xbc,0xbd,0xbd,0xbe,0xbe,0xbf,0xbf,0xc0, // e382b
  66. // ク ケ ケ コ コ サ サ シ シ ス ス セ セ ソ ソ タ
  67. 0xc0,0xc1,0xc1,0xc2,0xc2,0xc2,0xc3,0xc3,0xc4,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca, // e3838
  68. // タ チ チ ッ ッ ッ テ テ ト ト ナ ニ ヌ ネ ノ ハ
  69. 0xca,0xca,0xcb,0xcb,0xcb,0xcc,0xcc,0xcc,0xcd,0xcd,0xcd,0xce,0xce,0xce,0xcf,0xd0, // e3839
  70. // ハ ハ ヒ ヒ ヒ フ フ フ ヘ ヘ ヘ ホ ホ ホ マ ミ
  71. 0xd1,0xd2,0xd3,0xd4,0xd4,0xd5,0xd5,0xae,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdc, // e383a
  72. // ム メ モ ャ ャ ユ ユ ョ ヨ ラ リ ル レ ロ ワ ワ
  73. 0xec,0xa7,0xa6,0xdd,0xcc,0x3f,0x3f,0x3f,0x3f,0x3f,0xa6,0xa5,0xb0,0xa4,0xa4,0x3f // e383b
  74. // ヰ ヱ ヲ ン フ ? ? ? ? ? ヲ ・ ー ヽ ヽ ?
  75. };
  76. #elif ENABLED(MAPPER_D0D1)
  77. #error "Cyrillic on a JAPANESE display makes no sense. There are no matching symbols."
  78. #endif
  79. #elif DISPLAY_CHARSET_HD44780 == WESTERN
  80. #if ENABLED(MAPPER_C2C3)
  81. const PROGMEM uint8_t utf_recode[] =
  82. { // 0 1 2 3 4 5 6 7 8 9 a b c d e f This is relative complete.
  83. 0x20,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0x22,0xa9,0xaa,0xab,0x3f,0x3f,0xae,0x3f, // c2a ¡¢£¤¥¦§¨©ª«¬­®¯
  84. //' ' ¡ ¢ £ ¤ ¥ ¦ § " © ª « ? ? ® ?
  85. 0xb0,0xb1,0xb2,0xb3,0x27,0xb5,0xb6,0xb7,0x2c,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf, // c2b °±²³´µ¶·¸¹º»¼½¾¿
  86. // ° ± ³ ² ? µ ¶ · , ¹ º » ¼ ½ ¾ ¿
  87. 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf, // c38 ÀÁÃÄÅÆÇÈÉÊËÌÍÎÏ
  88. // À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï
  89. 0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf, // c39 ÐÑÓÔÕÖ×ØÙÚÛÜÝÞß
  90. // Ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ü Ý Þ ß
  91. 0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef, // c3a àáãäåæçèéêëìíîï
  92. // à á â ã ä å æ ç è é ê ë ì í î ï
  93. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff // c3b ðñóôõö÷øùúûüýþÿ
  94. // ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ
  95. };
  96. #elif ENABLED(MAPPER_D0D1)
  97. #define MAPPER_D0D1_MOD
  98. const PROGMEM uint8_t utf_recode[] =
  99. {//0 1 2 3 4 5 6 7 8 9 a b c d e f
  100. 0x41,0x80,0x42,0x92,0x81,0x45,0x82,0x83,0x84,0x85,0x4b,0x86,0x4d,0x48,0x4f,0x87, // d0a
  101. // A Б B Г Д E Ж З И Й K Л M H O П
  102. 0x50,0x43,0x54,0x88,0xd8,0x58,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x62,0x8f,0xac,0xad, // d0b
  103. // P C T У Ф X Ч ч Ш Щ Ъ Ы b Э Ю Я
  104. 0x61,0x36,0x42,0x92,0x81,0x65,0x82,0xb3,0x84,0x85,0x6b,0x86,0x4d,0x48,0x6f,0x87, // d18
  105. // a 6 B Г Д e Ж ³ И Й k Л M H o П
  106. 0x70,0x63,0x54,0x79,0xd8,0x78,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x62,0x8f,0xac,0xad // d19
  107. // p c T y Ф x Ч ч Ш Щ Ъ Ы b Э Ю Я
  108. };
  109. #elif ENABLED(MAPPER_E382E383)
  110. #error "Katakana on a WESTERN display makes no sense. There are no matching symbols."
  111. #endif
  112. #elif DISPLAY_CHARSET_HD44780 == CYRILLIC
  113. #if ENABLED(MAPPER_D0D1)
  114. #define MAPPER_D0D1_MOD
  115. // it is a Russian alphabet translation
  116. // except 0401 --> 0xa2 = Ё, 0451 --> 0xb5 = ё
  117. const PROGMEM uint8_t utf_recode[] =
  118. { 0x41,0xa0,0x42,0xa1,0xe0,0x45,0xa3,0xa4, // unicode U+0400 to U+047f
  119. // A Б->Ё B Г Д E Ж З // 0 Ѐ Ё Ђ Ѓ Є Ѕ І Ї
  120. 0xa5,0xa6,0x4b,0xa7,0x4d,0x48,0x4f,0xa8, // Ј Љ Њ Ћ Ќ Ѝ Ў Џ
  121. // И Й K Л M H O П // 1 А Б В Г Д Е Ж З
  122. 0x50,0x43,0x54,0xa9,0xaa,0x58,0xe1,0xab, // И Й К Л М Н О П
  123. // P C T У Ф X Ч ч // 2 Р С Т У Ф Х Г Ч
  124. 0xac,0xe2,0xad,0xae,0x62,0xaf,0xb0,0xb1, // Ш Щ Ъ Ы Ь Э Ю Я
  125. // Ш Щ Ъ Ы b Э Ю Я // 3 а б в г д е ж з
  126. 0x61,0xb2,0xb3,0xb4,0xe3,0x65,0xb6,0xb7, // и й к л м н о п
  127. // a б->ё в г д e ж з // 4 р с т у ф х ц ч
  128. 0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0x6f,0xbe, // ш щ ъ ы ь э ю я
  129. // и й к л м н o п // 5 ѐ ё ђ ѓ є ѕ і ї
  130. 0x70,0x63,0xbf,0x79,0xe4,0x78,0xe5,0xc0, // ј љ њ ћ ќ ѝ ў џ
  131. // p c т y ф x ц ч // 6 Ѡ ѡ Ѣ ѣ Ѥ ѥ Ѧ ѧ
  132. 0xc1,0xe6,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7 // Ѫ ѩ Ѫ ѫ Ѭ ѭ Ѯ ѯ
  133. // ш щ ъ ы ь э ю я // 7 Ѱ ѱ Ѳ ѳ Ѵ ѵ Ѷ ѷ
  134. }; // ѻ ѹ Ѻ ѻ Ѽ ѽ Ѿ ѿ
  135. #elif ENABLED(MAPPER_C2C3)
  136. #error "Western languages on a CYRILLIC display makes no sense. There are no matching symbols."
  137. #elif ENABLED(MAPPER_E382E383)
  138. #error "Katakana on a CYRILLIC display makes no sense. There are no matching symbols."
  139. #endif
  140. #else
  141. #error "Something went wrong in the setting of DISPLAY_CHARSET_HD44780"
  142. #endif // DISPLAY_CHARSET_HD44780
  143. #endif // SIMULATE_ROMFONT
  144. #if ENABLED(MAPPER_C2C3)
  145. char charset_mapper(const char c) {
  146. static uint8_t utf_hi_char; // UTF-8 high part
  147. static bool seen_c2 = false;
  148. uint8_t d = c;
  149. if ( d >= 0x80u ) { // UTF-8 handling
  150. if ( (d >= 0xc0u) && (!seen_c2) ) {
  151. utf_hi_char = d - 0xc2u;
  152. seen_c2 = true;
  153. return 0;
  154. }
  155. else if (seen_c2) {
  156. d &= 0x3fu;
  157. #ifndef MAPPER_ONE_TO_ONE
  158. HARDWARE_CHAR_OUT((char)pgm_read_byte_near(utf_recode + d + (utf_hi_char << 6) - 0x20));
  159. #else
  160. HARDWARE_CHAR_OUT((char)(0x80u + (utf_hi_char << 6) + d)) ;
  161. #endif
  162. }
  163. else {
  164. HARDWARE_CHAR_OUT('?');
  165. }
  166. }
  167. else {
  168. HARDWARE_CHAR_OUT((char) c );
  169. }
  170. seen_c2 = false;
  171. return 1;
  172. }
  173. #elif ENABLED(MAPPER_C2C3_TR)
  174. // the C2C3-mapper extended for the 6 altered symbols from C4 and C5 range.
  175. char charset_mapper(const char c) {
  176. static uint8_t utf_hi_char; // UTF-8 high part
  177. static bool seen_c2 = false;
  178. static bool seen_c4 = false;
  179. static bool seen_c5 = false;
  180. uint8_t d = c;
  181. if ( d >= 0x80u ) { // UTF-8 handling
  182. if ( d == 0xc4u ) {seen_c4 = true; return 0;}
  183. else if ( d == 0xc5u ) {seen_c5 = true; return 0;}
  184. else if ( (d >= 0xc0u) && (!seen_c2) ) {
  185. utf_hi_char = d - 0xc2u;
  186. seen_c2 = true;
  187. return 0;
  188. }
  189. else if (seen_c4) {
  190. switch(d) {
  191. case 0x9eu: d = 0xd0u; break;
  192. case 0x9fu: d = 0xf0u; break;
  193. case 0xb0u: d = 0xddu; break;
  194. case 0xb1u: d = 0xfdu; break;
  195. default: d = '?';
  196. }
  197. HARDWARE_CHAR_OUT((char)d) ;
  198. }
  199. else if (seen_c5) {
  200. switch(d) {
  201. case 0x9eu: d = 0xdeu; break;
  202. case 0x9fu: d = 0xfeu; break;
  203. default: d = '?';
  204. }
  205. HARDWARE_CHAR_OUT((char)d) ;
  206. }
  207. else if (seen_c2) {
  208. d &= 0x3fu;
  209. #ifndef MAPPER_ONE_TO_ONE
  210. HARDWARE_CHAR_OUT((char)pgm_read_byte_near(utf_recode + d + (utf_hi_char << 6) - 0x20));
  211. #else
  212. HARDWARE_CHAR_OUT((char)(0x80u + (utf_hi_char << 6) + d)) ;
  213. #endif
  214. }
  215. else {
  216. HARDWARE_CHAR_OUT('?');
  217. }
  218. }
  219. else {
  220. HARDWARE_CHAR_OUT((char) c );
  221. }
  222. seen_c2 = seen_c4 = seen_c5 = false;
  223. return 1;
  224. }
  225. #elif ENABLED(MAPPER_CECF)
  226. char charset_mapper(const char c) {
  227. static uint8_t utf_hi_char; // UTF-8 high part
  228. static bool seen_ce = false;
  229. uint8_t d = c;
  230. if ( d >= 0x80 ) { // UTF-8 handling
  231. if ( (d >= 0xc0) && (!seen_ce) ) {
  232. utf_hi_char = d - 0xce;
  233. seen_ce = true;
  234. return 0;
  235. }
  236. else if (seen_ce) {
  237. d &= 0x3f;
  238. #ifndef MAPPER_ONE_TO_ONE
  239. HARDWARE_CHAR_OUT((char)pgm_read_byte_near(utf_recode + d + (utf_hi_char << 6) - 0x20));
  240. #else
  241. HARDWARE_CHAR_OUT((char)(0x80 + (utf_hi_char << 6) + d)) ;
  242. #endif
  243. }
  244. else {
  245. HARDWARE_CHAR_OUT('?');
  246. }
  247. }
  248. else {
  249. HARDWARE_CHAR_OUT((char) c );
  250. }
  251. seen_ce = false;
  252. return 1;
  253. }
  254. #elif ENABLED(MAPPER_CECF)
  255. char charset_mapper(const char c) {
  256. static uint8_t utf_hi_char; // UTF-8 high part
  257. static bool seen_ce = false;
  258. uint8_t d = c;
  259. if ( d >= 0x80 ) { // UTF-8 handling
  260. if ( (d >= 0xc0) && (!seen_ce) ) {
  261. utf_hi_char = d - 0xce;
  262. seen_ce = true;
  263. return 0;
  264. }
  265. else if (seen_ce) {
  266. d &= 0x3f;
  267. #ifndef MAPPER_ONE_TO_ONE
  268. HARDWARE_CHAR_OUT((char)pgm_read_byte_near(utf_recode + d + (utf_hi_char << 6) - 0x20));
  269. #else
  270. HARDWARE_CHAR_OUT((char)(0x80 + (utf_hi_char << 6) + d)) ;
  271. #endif
  272. }
  273. else {
  274. HARDWARE_CHAR_OUT('?');
  275. }
  276. }
  277. else {
  278. HARDWARE_CHAR_OUT((char) c );
  279. }
  280. seen_ce = false;
  281. return 1;
  282. }
  283. #elif ENABLED(MAPPER_D0D1_MOD)
  284. char charset_mapper(const char c) {
  285. // it is a Russian alphabet translation
  286. // except 0401 --> 0xa2 = Ё, 0451 --> 0xb5 = ё
  287. static uint8_t utf_hi_char; // UTF-8 high part
  288. static bool seen_d5 = false;
  289. uint8_t d = c;
  290. if (d >= 0x80) { // UTF-8 handling
  291. if (d >= 0xd0 && !seen_d5) {
  292. utf_hi_char = d - 0xd0;
  293. seen_d5 = true;
  294. return 0;
  295. }
  296. else if (seen_d5) {
  297. d &= 0x3f;
  298. if (!utf_hi_char && d == 1) {
  299. HARDWARE_CHAR_OUT((char) 0xa2); // Ё
  300. }
  301. else if (utf_hi_char == 1 && d == 0x11) {
  302. HARDWARE_CHAR_OUT((char)0xb5); // ё
  303. }
  304. else {
  305. HARDWARE_CHAR_OUT((char)pgm_read_byte_near(utf_recode + d + (utf_hi_char << 6) - 0x10));
  306. }
  307. }
  308. else {
  309. HARDWARE_CHAR_OUT('?');
  310. }
  311. }
  312. else {
  313. HARDWARE_CHAR_OUT((char) c );
  314. }
  315. seen_d5 = false;
  316. return 1;
  317. }
  318. #elif ENABLED(MAPPER_D0D1)
  319. char charset_mapper(const char c) {
  320. static uint8_t utf_hi_char; // UTF-8 high part
  321. static bool seen_d5 = false;
  322. uint8_t d = c;
  323. if (d >= 0x80u) { // UTF-8 handling
  324. if (d >= 0xd0u && !seen_d5) {
  325. utf_hi_char = d - 0xd0u;
  326. seen_d5 = true;
  327. return 0;
  328. }
  329. else if (seen_d5) {
  330. d &= 0x3fu;
  331. #ifndef MAPPER_ONE_TO_ONE
  332. HARDWARE_CHAR_OUT((char)pgm_read_byte_near(utf_recode + d + (utf_hi_char << 6) - 0x20));
  333. #else
  334. HARDWARE_CHAR_OUT((char)(0xa0u + (utf_hi_char << 6) + d)) ;
  335. #endif
  336. }
  337. else {
  338. HARDWARE_CHAR_OUT('?');
  339. }
  340. }
  341. else {
  342. HARDWARE_CHAR_OUT((char) c );
  343. }
  344. seen_d5 = false;
  345. return 1;
  346. }
  347. #elif ENABLED(MAPPER_E382E383)
  348. char charset_mapper(const char c) {
  349. static uint8_t utf_hi_char; // UTF-8 high part
  350. static bool seen_e3 = false;
  351. static bool seen_82_83 = false;
  352. uint8_t d = c;
  353. if (d >= 0x80) { // UTF-8 handling
  354. if (d == 0xe3 && !seen_e3) {
  355. seen_e3 = true;
  356. return 0; // eat 0xe3
  357. }
  358. else if (d >= 0x82 && seen_e3 && !seen_82_83) {
  359. utf_hi_char = d - 0x82;
  360. seen_82_83 = true;
  361. return 0;
  362. }
  363. else if (seen_e3 && seen_82_83) {
  364. d &= 0x3f;
  365. #ifndef MAPPER_ONE_TO_ONE
  366. HARDWARE_CHAR_OUT((char)pgm_read_byte_near(utf_recode + d + (utf_hi_char << 6) - 0x20));
  367. #else
  368. HARDWARE_CHAR_OUT((char)(0x80 + (utf_hi_char << 6) + d)) ;
  369. #endif
  370. }
  371. else {
  372. HARDWARE_CHAR_OUT((char) '?' );
  373. }
  374. }
  375. else {
  376. HARDWARE_CHAR_OUT((char) c );
  377. }
  378. seen_e3 = false;
  379. seen_82_83 = false;
  380. return 1;
  381. }
  382. #else
  383. #define MAPPER_NON
  384. char charset_mapper(const char c) {
  385. HARDWARE_CHAR_OUT( c );
  386. return 1;
  387. }
  388. #endif // code mappers
  389. #endif // UTF_MAPPER_H