My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

utf_mapper.h 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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(C) u8g.print((char)(C))
  27. #else
  28. #define HARDWARE_CHAR_OUT(C) lcd.write((char)(C))
  29. #endif
  30. #if DISABLED(SIMULATE_ROMFONT) && ENABLED(DOGLCD)
  31. #if ENABLED(DISPLAY_CHARSET_ISO10646_1) \
  32. || ENABLED(DISPLAY_CHARSET_ISO10646_5) \
  33. || ENABLED(DISPLAY_CHARSET_ISO10646_KANA) \
  34. || ENABLED(DISPLAY_CHARSET_ISO10646_GREEK) \
  35. || ENABLED(DISPLAY_CHARSET_ISO10646_TR)
  36. #define MAPPER_ONE_TO_ONE
  37. #endif
  38. #else // SIMULATE_ROMFONT || !DOGLCD
  39. #if DISPLAY_CHARSET_HD44780 == JAPANESE
  40. #if ENABLED(MAPPER_C2C3)
  41. const PROGMEM uint8_t utf_recode[] =
  42. { // 0 1 2 3 4 5 6 7 8 9 a b c d e f This is fair for symbols
  43. 0x20,0x3F,0xEC,0xED,0x3F,0x5C,0x7C,0x3F,0x22,0x63,0x61,0x7F,0x3F,0x3F,0x52,0xB0, // c2a
  44. //' ' ¢ £ ­ l " c a « R
  45. 0xDF,0x3F,0x32,0x33,0x27,0xE4,0xF1,0xA5,0x2C,0x31,0xDF,0x7E,0x3F,0x3F,0x3F,0x3F, // c2b but relatively bad for letters.
  46. // ° 2 3 ` N p . , 1 ° »
  47. 0x3F,0x3F,0x3F,0x3F,0xE1,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F, // c38
  48. // ä
  49. 0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0xEF,0x78,0x3F,0x3F,0x3F,0x3F,0xF5,0x3F,0x3F,0xE2, // c39 missing characters display as '?'
  50. // ö x ü ß
  51. 0x3F,0x3F,0x3F,0x3F,0xE1,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F, // c3a
  52. // ä
  53. 0x3F,0xEE,0x3F,0x3F,0x3F,0x3F,0xEF,0xFD,0x3F,0x3F,0x3F,0x3F,0xF5,0x3F,0x3F,0x3F // c3b
  54. // n ö ÷ ü
  55. };
  56. #elif ENABLED(MAPPER_E382E383)
  57. const PROGMEM uint8_t utf_recode[] =
  58. { // 0 1 2 3 4 5 6 7 8 9 a b c d e f
  59. 0x3D,0xB1,0xB1,0xA8,0xB2,0xA9,0xB3,0xAA,0xB4,0xAB,0xB5,0xB6,0xB6,0xB7,0xB7,0xB8, // e382a Please test and correct
  60. // = ア ア ィ イ ゥ ウ ェ エ ォ オ ガ ガ キ キ ク
  61. 0xB8,0xB9,0xB9,0xBA,0xBA,0xBB,0xBB,0xBC,0xBC,0xBD,0xBD,0xBE,0xBE,0xBF,0xBF,0xC0, // e382b
  62. // ク ケ ケ コ コ サ サ シ シ ス ス セ セ ソ ソ タ
  63. 0xC0,0xC1,0xC1,0xC2,0xC2,0xC2,0xC3,0xC3,0xC4,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA, // e3838
  64. // タ チ チ ッ ッ ッ テ テ ト ト ナ ニ ヌ ネ ノ ハ
  65. 0xCA,0xCA,0xCB,0xCB,0xCB,0xCC,0xCC,0xCC,0xCD,0xCD,0xCD,0xCE,0xCE,0xCE,0xCF,0xD0, // e3839
  66. // ハ ハ ヒ ヒ ヒ フ フ フ ヘ ヘ ヘ ホ ホ ホ マ ミ
  67. 0xD1,0xD2,0xD3,0xD4,0xD4,0xD5,0xD5,0xAE,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDC, // e383a
  68. // ム メ モ ャ ャ ユ ユ ョ ヨ ラ リ ル レ ロ ワ ワ
  69. 0xEC,0xA7,0xA6,0xDD,0xCC,0x3F,0x3F,0x3F,0x3F,0x3F,0xA6,0xA5,0xB0,0xA4,0xA4,0x3F // e383b
  70. // ヰ ヱ ヲ ン フ ? ? ? ? ? ヲ ・ ー ヽ ヽ ?
  71. };
  72. #elif ENABLED(MAPPER_D0D1)
  73. #error "Cyrillic on a JAPANESE display makes no sense. There are no matching symbols."
  74. #endif
  75. #elif DISPLAY_CHARSET_HD44780 == WESTERN
  76. #if ENABLED(MAPPER_C2C3)
  77. const PROGMEM uint8_t utf_recode[] =
  78. { // 0 1 2 3 4 5 6 7 8 9 a b c d e f This is relative complete.
  79. 0x20,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0x22,0xA9,0xAA,0xAB,0x3F,0x3F,0xAE,0x3F, // c2a ¡¢£¤¥¦§¨©ª«¬­®¯
  80. //' ' ¡ ¢ £ ¤ ¥ ¦ § " © ª « ? ? ® ?
  81. 0xB0,0xB1,0xB2,0xB3,0x27,0xB5,0xB6,0xB7,0x2C,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, // c2b °±²³´µ¶·¸¹º»¼½¾¿
  82. // ° ± ³ ² ? µ ¶ · , ¹ º » ¼ ½ ¾ ¿
  83. 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, // c38 ÀÁÃÄÅÆÇÈÉÊËÌÍÎÏ
  84. // À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï
  85. 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, // c39 ÐÑÓÔÕÖ×ØÙÚÛÜÝÞß
  86. // Ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ü Ý Þ ß
  87. 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, // c3a àáãäåæçèéêëìíîï
  88. // à á â ã ä å æ ç è é ê ë ì í î ï
  89. 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF // c3b ðñóôõö÷øùúûüýþÿ
  90. // ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ
  91. };
  92. #elif ENABLED(MAPPER_D0D1)
  93. #define MAPPER_D0D1_MOD
  94. const PROGMEM uint8_t utf_recode[] =
  95. {//0 1 2 3 4 5 6 7 8 9 a b c d e f
  96. 0x41,0x80,0x42,0x92,0x81,0x45,0x82,0x83,0x84,0x85,0x4B,0x86,0x4D,0x48,0x4F,0x87, // d0a
  97. // A Б B Г Д E Ж З И Й K Л M H O П
  98. 0x50,0x43,0x54,0x88,0xD8,0x58,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x62,0x8F,0xAC,0xAD, // d0b
  99. // P C T У Ф X Ч ч Ш Щ Ъ Ы b Э Ю Я
  100. 0x61,0x36,0x42,0x92,0x81,0x65,0x82,0xB3,0x84,0x85,0x6B,0x86,0x4D,0x48,0x6F,0x87, // d18
  101. // a 6 B Г Д e Ж ³ И Й k Л M H o П
  102. 0x70,0x63,0x54,0x79,0xD8,0x78,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x62,0x8F,0xAC,0xAD // d19
  103. // p c T y Ф x Ч ч Ш Щ Ъ Ы b Э Ю Я
  104. };
  105. #elif ENABLED(MAPPER_E382E383)
  106. #error "Katakana on a WESTERN display makes no sense. There are no matching symbols."
  107. #endif
  108. #elif DISPLAY_CHARSET_HD44780 == CYRILLIC
  109. #if ENABLED(MAPPER_D0D1)
  110. #define MAPPER_D0D1_MOD
  111. // it is a Russian alphabet translation
  112. // except 0401 --> 0xA2 = Ё, 0451 --> 0xB5 = ё
  113. const PROGMEM uint8_t utf_recode[] =
  114. { 0x41,0xA0,0x42,0xA1,0xE0,0x45,0xA3,0xA4, // unicode U+0400 to U+047f
  115. // A Б->Ё B Г Д E Ж З // 0 Ѐ Ё Ђ Ѓ Є Ѕ І Ї
  116. 0xA5,0xA6,0x4B,0xA7,0x4D,0x48,0x4F,0xA8, // Ј Љ Њ Ћ Ќ Ѝ Ў Џ
  117. // И Й K Л M H O П // 1 А Б В Г Д Е Ж З
  118. 0x50,0x43,0x54,0xA9,0xAA,0x58,0xE1,0xAB, // И Й К Л М Н О П
  119. // P C T У Ф X Ч ч // 2 Р С Т У Ф Х Г Ч
  120. 0xAC,0xE2,0xAD,0xAE,0x62,0xAF,0xB0,0xB1, // Ш Щ Ъ Ы Ь Э Ю Я
  121. // Ш Щ Ъ Ы b Э Ю Я // 3 а б в г д е ж з
  122. 0x61,0xB2,0xB3,0xB4,0xE3,0x65,0xB6,0xB7, // и й к л м н о п
  123. // a б->ё в г д e ж з // 4 р с т у ф х ц ч
  124. 0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0x6F,0xBE, // ш щ ъ ы ь э ю я
  125. // и й к л м н o п // 5 ѐ ё ђ ѓ є ѕ і ї
  126. 0x70,0x63,0xBF,0x79,0xE4,0x78,0xE5,0xC0, // ј љ њ ћ ќ ѝ ў џ
  127. // p c т y ф x ц ч // 6 Ѡ ѡ Ѣ ѣ Ѥ ѥ Ѧ ѧ
  128. 0xC1,0xE6,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7 // Ѫ ѩ Ѫ ѫ Ѭ ѭ Ѯ ѯ
  129. // ш щ ъ ы ь э ю я // 7 Ѱ ѱ Ѳ ѳ Ѵ ѵ Ѷ ѷ
  130. }; // ѻ ѹ Ѻ ѻ Ѽ ѽ Ѿ ѿ
  131. #elif ENABLED(MAPPER_C2C3)
  132. #error "Western languages on a CYRILLIC display makes no sense. There are no matching symbols."
  133. #elif ENABLED(MAPPER_E382E383)
  134. #error "Katakana on a CYRILLIC display makes no sense. There are no matching symbols."
  135. #endif
  136. #else
  137. #error "Something went wrong in the setting of DISPLAY_CHARSET_HD44780"
  138. #endif // DISPLAY_CHARSET_HD44780
  139. #endif // SIMULATE_ROMFONT
  140. #define PRINTABLE(C) (((C) & 0xC0u) != 0x80u)
  141. #if ENABLED(MAPPER_C2C3)
  142. char charset_mapper(const char c) {
  143. static uint8_t utf_hi_char; // UTF-8 high part
  144. static bool seen_c2 = false;
  145. uint8_t d = c;
  146. if (d >= 0x80u) { // UTF-8 handling
  147. if (d >= 0xC0u && !seen_c2) {
  148. utf_hi_char = d - 0xC2u;
  149. seen_c2 = true;
  150. return 0;
  151. }
  152. else if (seen_c2) {
  153. d &= 0x3Fu;
  154. #ifndef MAPPER_ONE_TO_ONE
  155. HARDWARE_CHAR_OUT(pgm_read_byte_near(utf_recode + d + (utf_hi_char << 6) - 0x20));
  156. #else
  157. HARDWARE_CHAR_OUT(0x80u + (utf_hi_char << 6) + d);
  158. #endif
  159. }
  160. else {
  161. HARDWARE_CHAR_OUT('?');
  162. }
  163. }
  164. else {
  165. HARDWARE_CHAR_OUT(c);
  166. }
  167. seen_c2 = false;
  168. return 1;
  169. }
  170. #elif ENABLED(MAPPER_C2C3_TR)
  171. // the C2C3-mapper extended for the 6 altered symbols from C4 and C5 range.
  172. char charset_mapper(const char c) {
  173. static uint8_t utf_hi_char; // UTF-8 high part
  174. static bool seen_c2 = false,
  175. seen_c4 = false,
  176. seen_c5 = false;
  177. uint8_t d = c;
  178. if (d >= 0x80u) { // UTF-8 handling
  179. if (d == 0xC4u) { seen_c4 = true; return 0; }
  180. else if (d == 0xC5u) { seen_c5 = true; return 0; }
  181. else if (d >= 0xC0u && !seen_c2) {
  182. utf_hi_char = d - 0xC2u;
  183. seen_c2 = true;
  184. return 0;
  185. }
  186. else if (seen_c4) {
  187. switch(d) {
  188. case 0x9Eu: d = 0xD0u; break;
  189. case 0x9Fu: d = 0xF0u; break;
  190. case 0xB0u: d = 0xDDu; break;
  191. case 0xB1u: d = 0xFDu; break;
  192. default: d = '?';
  193. }
  194. HARDWARE_CHAR_OUT(d);
  195. }
  196. else if (seen_c5) {
  197. switch(d) {
  198. case 0x9Eu: d = 0xDEu; break;
  199. case 0x9Fu: d = 0xFEu; break;
  200. default: d = '?';
  201. }
  202. HARDWARE_CHAR_OUT(d);
  203. }
  204. else if (seen_c2) {
  205. d &= 0x3Fu;
  206. #ifndef MAPPER_ONE_TO_ONE
  207. HARDWARE_CHAR_OUT(pgm_read_byte_near(utf_recode + d + (utf_hi_char << 6) - 0x20));
  208. #else
  209. HARDWARE_CHAR_OUT(0x80u + (utf_hi_char << 6) + d);
  210. #endif
  211. }
  212. else {
  213. HARDWARE_CHAR_OUT('?');
  214. }
  215. }
  216. else {
  217. HARDWARE_CHAR_OUT(c);
  218. }
  219. seen_c2 = seen_c4 = seen_c5 = false;
  220. return 1;
  221. }
  222. #elif ENABLED(MAPPER_CECF)
  223. char charset_mapper(const char c) {
  224. static uint8_t utf_hi_char; // UTF-8 high part
  225. static bool seen_ce = false;
  226. uint8_t d = c;
  227. if (d >= 0x80) { // UTF-8 handling
  228. if (d >= 0xC0 && !seen_ce) {
  229. utf_hi_char = d - 0xCE;
  230. seen_ce = true;
  231. return 0;
  232. }
  233. else if (seen_ce) {
  234. d &= 0x3F;
  235. #ifndef MAPPER_ONE_TO_ONE
  236. HARDWARE_CHAR_OUT(pgm_read_byte_near(utf_recode + d + (utf_hi_char << 6) - 0x20));
  237. #else
  238. HARDWARE_CHAR_OUT(0x80 + (utf_hi_char << 6) + d);
  239. #endif
  240. }
  241. else {
  242. HARDWARE_CHAR_OUT('?');
  243. }
  244. }
  245. else {
  246. HARDWARE_CHAR_OUT(c);
  247. }
  248. seen_ce = false;
  249. return 1;
  250. }
  251. #elif ENABLED(MAPPER_CECF)
  252. char charset_mapper(const char c) {
  253. static uint8_t utf_hi_char; // UTF-8 high part
  254. static bool seen_ce = false;
  255. uint8_t d = c;
  256. if (d >= 0x80) { // UTF-8 handling
  257. if (d >= 0xC0 && !seen_ce) {
  258. utf_hi_char = d - 0xCE;
  259. seen_ce = true;
  260. return 0;
  261. }
  262. else if (seen_ce) {
  263. d &= 0x3F;
  264. #ifndef MAPPER_ONE_TO_ONE
  265. HARDWARE_CHAR_OUT(pgm_read_byte_near(utf_recode + d + (utf_hi_char << 6) - 0x20));
  266. #else
  267. HARDWARE_CHAR_OUT(0x80 + (utf_hi_char << 6) + d);
  268. #endif
  269. }
  270. else {
  271. HARDWARE_CHAR_OUT('?');
  272. }
  273. }
  274. else {
  275. HARDWARE_CHAR_OUT(c);
  276. }
  277. seen_ce = false;
  278. return 1;
  279. }
  280. #elif ENABLED(MAPPER_D0D1_MOD)
  281. char charset_mapper(const char c) {
  282. // it is a Russian alphabet translation
  283. // except 0401 --> 0xA2 = Ё, 0451 --> 0xB5 = ё
  284. static uint8_t utf_hi_char; // UTF-8 high part
  285. static bool seen_d5 = false;
  286. uint8_t d = c;
  287. if (d >= 0x80) { // UTF-8 handling
  288. if (d >= 0xD0 && !seen_d5) {
  289. utf_hi_char = d - 0xD0;
  290. seen_d5 = true;
  291. return 0;
  292. }
  293. else if (seen_d5) {
  294. d &= 0x3F;
  295. if (!utf_hi_char && d == 1) {
  296. HARDWARE_CHAR_OUT(0xA2); // Ё
  297. }
  298. else if (utf_hi_char == 1 && d == 0x11) {
  299. HARDWARE_CHAR_OUT(0xB5); // ё
  300. }
  301. else {
  302. HARDWARE_CHAR_OUT(pgm_read_byte_near(utf_recode + d + (utf_hi_char << 6) - 0x10));
  303. }
  304. }
  305. else {
  306. HARDWARE_CHAR_OUT('?');
  307. }
  308. }
  309. else {
  310. HARDWARE_CHAR_OUT(c);
  311. }
  312. seen_d5 = false;
  313. return 1;
  314. }
  315. #elif ENABLED(MAPPER_D0D1)
  316. char charset_mapper(const char c) {
  317. static uint8_t utf_hi_char; // UTF-8 high part
  318. static bool seen_d5 = false;
  319. uint8_t d = c;
  320. if (d >= 0x80u) { // UTF-8 handling
  321. if (d >= 0xD0u && !seen_d5) {
  322. utf_hi_char = d - 0xD0u;
  323. seen_d5 = true;
  324. return 0;
  325. }
  326. else if (seen_d5) {
  327. d &= 0x3Fu;
  328. #ifndef MAPPER_ONE_TO_ONE
  329. HARDWARE_CHAR_OUT(pgm_read_byte_near(utf_recode + d + (utf_hi_char << 6) - 0x20));
  330. #else
  331. HARDWARE_CHAR_OUT(0xA0u + (utf_hi_char << 6) + d);
  332. #endif
  333. }
  334. else {
  335. HARDWARE_CHAR_OUT('?');
  336. }
  337. }
  338. else {
  339. HARDWARE_CHAR_OUT(c);
  340. }
  341. seen_d5 = false;
  342. return 1;
  343. }
  344. #elif ENABLED(MAPPER_E382E383)
  345. char charset_mapper(const char c) {
  346. static uint8_t utf_hi_char; // UTF-8 high part
  347. static bool seen_e3 = false,
  348. seen_82_83 = false;
  349. uint8_t d = c;
  350. if (d >= 0x80) { // UTF-8 handling
  351. if (d == 0xE3 && !seen_e3) {
  352. seen_e3 = true;
  353. return 0; // eat 0xE3
  354. }
  355. else if (d >= 0x82 && seen_e3 && !seen_82_83) {
  356. utf_hi_char = d - 0x82;
  357. seen_82_83 = true;
  358. return 0;
  359. }
  360. else if (seen_e3 && seen_82_83) {
  361. d &= 0x3F;
  362. #ifndef MAPPER_ONE_TO_ONE
  363. HARDWARE_CHAR_OUT(pgm_read_byte_near(utf_recode + d + (utf_hi_char << 6) - 0x20));
  364. #else
  365. HARDWARE_CHAR_OUT(0x80 + (utf_hi_char << 6) + d);
  366. #endif
  367. }
  368. else
  369. HARDWARE_CHAR_OUT('?');
  370. }
  371. else
  372. HARDWARE_CHAR_OUT(c);
  373. seen_e3 = false;
  374. seen_82_83 = false;
  375. return 1;
  376. }
  377. #elif ENABLED(MAPPER_C3C4C5_PL)
  378. /**
  379. * Ą C4 84 = 80
  380. * ą C4 85 = 81
  381. * Ć C4 86 = 82
  382. * ć C4 87 = 83
  383. * Ę C4 98 = 84
  384. * ę C4 99 = 85
  385. * Ł C5 81 = 86
  386. * ł C5 82 = 87
  387. * Ń C5 83 = 88
  388. * ń C5 84 = 89
  389. * Ó C3 93 = 8A
  390. * ó C3 B3 = 8B
  391. * Ś C5 9A = 8C
  392. * ś C5 9B = 8D
  393. * Ź C5 B9 = 8E
  394. * ź C5 BA = 8F
  395. * Ż C5 BB = 90
  396. * ż C5 BC = 91
  397. */
  398. char charset_mapper(const char c) {
  399. static bool seen_c3 = false,
  400. seen_c4 = false,
  401. seen_c5 = false;
  402. uint8_t d = c;
  403. if (d >= 0x80u) { // UTF-8 handling
  404. if (d == 0xC4u) { seen_c4 = true; return 0; }
  405. else if (d == 0xC5u) { seen_c5 = true; return 0; }
  406. else if (d == 0xC3u) { seen_c3 = true; return 0; }
  407. else if (seen_c4) {
  408. switch(d) {
  409. case 0x84u ... 0x87u: d -= 4; break; //Ą - ć
  410. case 0x98u ... 0x99u: d -= 20; break; //Ę i ę
  411. default: d = '?';
  412. }
  413. HARDWARE_CHAR_OUT(d);
  414. }
  415. else if (seen_c5) {
  416. switch(d) {
  417. case 0x81u ... 0x84u: d += 5; break; //Ł - ń
  418. case 0x9Au ... 0x9Bu: d -= 0x0Eu; break; //Ś i ś
  419. case 0xB9u ... 0xBCu: d -= 0x2Bu; break; //Ź - ż
  420. default: d = '?';
  421. }
  422. HARDWARE_CHAR_OUT(d);
  423. }
  424. else if (seen_c3) {
  425. switch(d) {
  426. case 0x93u: d = 0x8Au; break; //Ó
  427. case 0xB3u: d = 0x8Bu; break; //ó
  428. d = '?';
  429. }
  430. HARDWARE_CHAR_OUT(d);
  431. }
  432. }
  433. else
  434. HARDWARE_CHAR_OUT(c);
  435. seen_c3 = seen_c4 = seen_c5 = false;
  436. return 1;
  437. }
  438. #elif ENABLED(MAPPER_C3C4C5_CZ)
  439. /**
  440. * Á C3 81 = 80
  441. * É C3 89 = 81
  442. * Í C3 8D = 82
  443. * Ó C3 93 = 83
  444. * Ú C3 9A = 84
  445. * Ý C3 9D = 85
  446. * á C3 A1 = 86
  447. * é C3 A9 = 87
  448. * í C3 AD = 88
  449. * ó C3 B3 = 89
  450. * ú C3 BA = 8A
  451. * ý C3 BD = 8B
  452. * Č C4 8C = 8C
  453. * č C4 8D = 8D
  454. * Ď C4 8E = 8E
  455. * ď C4 8F = 8F
  456. * Ě C4 9A = 90
  457. * ě C4 9B = 91
  458. * Ň C5 87 = 92
  459. * ň C5 88 = 93
  460. * Ř C5 98 = 94
  461. * ř C5 99 = 95
  462. * Š C5 A0 = 96
  463. * š C5 A1 = 97
  464. * Ť C5 A4 = 98
  465. * ť C5 A5 = 99
  466. * Ů C5 AE = 9A
  467. * ů C5 AF = 9B
  468. * Ž C5 BD = 9C
  469. * ž C5 BE = 9D
  470. */
  471. char charset_mapper(const char c) {
  472. static bool seen_c3 = false,
  473. seen_c4 = false,
  474. seen_c5 = false;
  475. uint8_t d = c;
  476. if (d >= 0x80u) { // UTF-8 handling
  477. if (d == 0xC4u) { seen_c4 = true; return 0; }
  478. else if (d == 0xC5u) { seen_c5 = true; return 0; }
  479. else if (d == 0xC3u) { seen_c3 = true; return 0; }
  480. else if (seen_c4) {
  481. switch(d) {
  482. case 0x8Cu ... 0x8Fu: break; // ČčĎď Mapping 1:1
  483. case 0x9Au ... 0x9Bu: d -= 10; break; // Ěě
  484. default: d = '?';
  485. }
  486. HARDWARE_CHAR_OUT(d);
  487. }
  488. else if (seen_c5) {
  489. switch(d) {
  490. case 0x87u ... 0x88u: d += 0x0Bu; break; // Ňň
  491. case 0x98u ... 0x99u: d -= 0x04u; break; // Řř
  492. case 0xA0u ... 0xA1u: d -= 0x0Au; break; // Šš
  493. case 0xA4u ... 0xA5u: d -= 0x0Cu; break; // Ťť
  494. case 0xAEu ... 0xAFu: d -= 0x14u; break; // Ůů
  495. case 0xBDu ... 0xBEu: d -= 0x21u; break; // Žž
  496. default: d = '?';
  497. }
  498. HARDWARE_CHAR_OUT(d);
  499. }
  500. else if (seen_c3) {
  501. switch(d) {
  502. case 0x81u: d = 0x80u; break; // Á
  503. case 0x89u: d = 0x81u; break; // É
  504. case 0x8Du: d = 0x82u; break; // Í
  505. case 0x93u: d = 0x83u; break; // Ó
  506. case 0x9Au: d = 0x84u; break; // Ú
  507. case 0x9Du: d = 0x85u; break; // Ý
  508. case 0xA1u: d = 0x86u; break; // á
  509. case 0xA9u: d = 0x87u; break; // é
  510. case 0xADu: d = 0x88u; break; // í
  511. case 0xB3u: d = 0x89u; break; // ó
  512. case 0xBAu: d = 0x8Au; break; // ú
  513. case 0xBDu: d = 0x8Bu; break; // ý
  514. default: d = '?';
  515. }
  516. HARDWARE_CHAR_OUT(d);
  517. }
  518. }
  519. else
  520. HARDWARE_CHAR_OUT(c);
  521. seen_c3 = seen_c4 = seen_c5 = false;
  522. return 1;
  523. }
  524. #elif ENABLED(MAPPER_C3C4C5_SK)
  525. /**
  526. * Á C3 81 = 80
  527. * Ä C3 84 = 81
  528. * É C3 89 = 82
  529. * Í C3 8D = 83
  530. * Ó C3 93 = 84
  531. * Ô C3 94 = 85
  532. * Ú C3 9A = 86
  533. * Ý C3 9D = 87
  534. * á C3 A1 = 88
  535. * ä C3 A4 = 89
  536. * é C3 A9 = 8A
  537. * í C3 AD = 8B
  538. * ó C3 B3 = 8C
  539. * ô C3 B4 = 8D
  540. * ú C3 BA = 8E
  541. * ý C3 BD = 8F
  542. * Č C4 8C = 90
  543. * č C4 8D = 91
  544. * Ď C4 8E = 92
  545. * ď C4 8F = 93
  546. * Ĺ C4 B9 = 94
  547. * ĺ C4 BA = 95
  548. * Ľ C4 BD = 96
  549. * ľ C4 BE = 97
  550. * Ň C5 87 = 98
  551. * ň C5 88 = 99
  552. * Ŕ C5 94 = 9A
  553. * ŕ C5 95 = 9B
  554. * Š C5 A0 = 9C
  555. * š C5 A1 = 9D
  556. * Ť C5 A4 = 9E
  557. * ť C5 A5 = 9F
  558. * Ž C5 BD = A0
  559. * ž C5 BE = A1
  560. */
  561. char charset_mapper(const char c) {
  562. static bool seen_c3 = false,
  563. seen_c4 = false,
  564. seen_c5 = false;
  565. uint8_t d = c;
  566. if (d >= 0x80u) { // UTF-8 handling
  567. if (d == 0xC4u) { seen_c4 = true; return 0; }
  568. else if (d == 0xC5u) { seen_c5 = true; return 0; }
  569. else if (d == 0xC3u) { seen_c3 = true; return 0; }
  570. else if (seen_c4) {
  571. switch(d) {
  572. case 0x8Cu ... 0x8Fu: d += 0x04u; break; // ČčĎď
  573. case 0xB9u ... 0xBAu: d -= 0x25u; break; // Ĺĺ
  574. case 0xBDu ... 0xBEu: d -= 0x27u; break; // Ľľ
  575. default: d = '?';
  576. }
  577. HARDWARE_CHAR_OUT(d);
  578. }
  579. else if (seen_c5) {
  580. switch(d) {
  581. case 0x87u ... 0x88u: d += 0x11u; break; // Ňň
  582. case 0x94u ... 0x95u: d += 0x06u; break; // Ŕŕ
  583. case 0xA0u ... 0xA1u: d -= 0x04u; break; // Šš
  584. case 0xA4u ... 0xA5u: d -= 0x06u; break; // Ťť
  585. case 0xBDu ... 0xBEu: d -= 0x1Du; break; // Žž
  586. default: d = '?';
  587. }
  588. HARDWARE_CHAR_OUT(d);
  589. }
  590. else if (seen_c3) {
  591. switch(d) {
  592. case 0x81u: d = 0x80u; break; // Á
  593. case 0x84u: d = 0x81u; break; // Ä
  594. case 0x89u: d = 0x82u; break; // É
  595. case 0x8Du: d = 0x83u; break; // Í
  596. case 0x93u: d = 0x84u; break; // Ó
  597. case 0x94u: d = 0x85u; break; // Ô
  598. case 0x9Au: d = 0x86u; break; // Ú
  599. case 0x9Du: d = 0x87u; break; // Ý
  600. case 0xA1u: d = 0x88u; break; // á
  601. case 0xA4u: d = 0x89u; break; // ä
  602. case 0xA9u: d = 0x8Au; break; // é
  603. case 0xADu: d = 0x8Bu; break; // í
  604. case 0xB3u: d = 0x8Cu; break; // ó
  605. case 0xB4u: d = 0x8Du; break; // ô
  606. case 0xBAu: d = 0x8Eu; break; // ú
  607. case 0xBDu: d = 0x8Fu; break; // ý
  608. default: d = '?';
  609. }
  610. HARDWARE_CHAR_OUT(d);
  611. }
  612. }
  613. else
  614. HARDWARE_CHAR_OUT(c);
  615. seen_c3 = seen_c4 = seen_c5 = false;
  616. return 1;
  617. }
  618. #else
  619. #define MAPPER_NON
  620. #undef PRINTABLE
  621. #define PRINTABLE(C) true
  622. char charset_mapper(const char c) {
  623. HARDWARE_CHAR_OUT(c);
  624. return 1;
  625. }
  626. #endif // code mappers
  627. #endif // UTF_MAPPER_H