My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

utf_mapper.h 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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_CECF)
  174. char charset_mapper(const char c) {
  175. static uint8_t utf_hi_char; // UTF-8 high part
  176. static bool seen_ce = false;
  177. uint8_t d = c;
  178. if ( d >= 0x80 ) { // UTF-8 handling
  179. if ( (d >= 0xc0) && (!seen_ce) ) {
  180. utf_hi_char = d - 0xce;
  181. seen_ce = true;
  182. return 0;
  183. }
  184. else if (seen_ce) {
  185. d &= 0x3f;
  186. #ifndef MAPPER_ONE_TO_ONE
  187. HARDWARE_CHAR_OUT((char)pgm_read_byte_near(utf_recode + d + (utf_hi_char << 6) - 0x20));
  188. #else
  189. HARDWARE_CHAR_OUT((char)(0x80 + (utf_hi_char << 6) + d)) ;
  190. #endif
  191. }
  192. else {
  193. HARDWARE_CHAR_OUT('?');
  194. }
  195. }
  196. else {
  197. HARDWARE_CHAR_OUT((char) c );
  198. }
  199. seen_ce = false;
  200. return 1;
  201. }
  202. #elif ENABLED(MAPPER_CECF)
  203. char charset_mapper(const char c) {
  204. static uint8_t utf_hi_char; // UTF-8 high part
  205. static bool seen_ce = false;
  206. uint8_t d = c;
  207. if ( d >= 0x80 ) { // UTF-8 handling
  208. if ( (d >= 0xc0) && (!seen_ce) ) {
  209. utf_hi_char = d - 0xce;
  210. seen_ce = true;
  211. return 0;
  212. }
  213. else if (seen_ce) {
  214. d &= 0x3f;
  215. #ifndef MAPPER_ONE_TO_ONE
  216. HARDWARE_CHAR_OUT((char)pgm_read_byte_near(utf_recode + d + (utf_hi_char << 6) - 0x20));
  217. #else
  218. HARDWARE_CHAR_OUT((char)(0x80 + (utf_hi_char << 6) + d)) ;
  219. #endif
  220. }
  221. else {
  222. HARDWARE_CHAR_OUT('?');
  223. }
  224. }
  225. else {
  226. HARDWARE_CHAR_OUT((char) c );
  227. }
  228. seen_ce = false;
  229. return 1;
  230. }
  231. #elif ENABLED(MAPPER_D0D1_MOD)
  232. char charset_mapper(const char c) {
  233. // it is a Russian alphabet translation
  234. // except 0401 --> 0xa2 = Ё, 0451 --> 0xb5 = ё
  235. static uint8_t utf_hi_char; // UTF-8 high part
  236. static bool seen_d5 = false;
  237. uint8_t d = c;
  238. if (d >= 0x80) { // UTF-8 handling
  239. if (d >= 0xd0 && !seen_d5) {
  240. utf_hi_char = d - 0xd0;
  241. seen_d5 = true;
  242. return 0;
  243. }
  244. else if (seen_d5) {
  245. d &= 0x3f;
  246. if (!utf_hi_char && d == 1) {
  247. HARDWARE_CHAR_OUT((char) 0xa2); // Ё
  248. }
  249. else if (utf_hi_char == 1 && d == 0x11) {
  250. HARDWARE_CHAR_OUT((char)0xb5); // ё
  251. }
  252. else {
  253. HARDWARE_CHAR_OUT((char)pgm_read_byte_near(utf_recode + d + (utf_hi_char << 6) - 0x10));
  254. }
  255. }
  256. else {
  257. HARDWARE_CHAR_OUT('?');
  258. }
  259. }
  260. else {
  261. HARDWARE_CHAR_OUT((char) c );
  262. }
  263. seen_d5 = false;
  264. return 1;
  265. }
  266. #elif ENABLED(MAPPER_D0D1)
  267. char charset_mapper(const char c) {
  268. static uint8_t utf_hi_char; // UTF-8 high part
  269. static bool seen_d5 = false;
  270. uint8_t d = c;
  271. if (d >= 0x80u) { // UTF-8 handling
  272. if (d >= 0xd0u && !seen_d5) {
  273. utf_hi_char = d - 0xd0u;
  274. seen_d5 = true;
  275. return 0;
  276. }
  277. else if (seen_d5) {
  278. d &= 0x3fu;
  279. #ifndef MAPPER_ONE_TO_ONE
  280. HARDWARE_CHAR_OUT((char)pgm_read_byte_near(utf_recode + d + (utf_hi_char << 6) - 0x20));
  281. #else
  282. HARDWARE_CHAR_OUT((char)(0xa0u + (utf_hi_char << 6) + d)) ;
  283. #endif
  284. }
  285. else {
  286. HARDWARE_CHAR_OUT('?');
  287. }
  288. }
  289. else {
  290. HARDWARE_CHAR_OUT((char) c );
  291. }
  292. seen_d5 = false;
  293. return 1;
  294. }
  295. #elif ENABLED(MAPPER_E382E383)
  296. char charset_mapper(const char c) {
  297. static uint8_t utf_hi_char; // UTF-8 high part
  298. static bool seen_e3 = false;
  299. static bool seen_82_83 = false;
  300. uint8_t d = c;
  301. if (d >= 0x80) { // UTF-8 handling
  302. if (d == 0xe3 && !seen_e3) {
  303. seen_e3 = true;
  304. return 0; // eat 0xe3
  305. }
  306. else if (d >= 0x82 && seen_e3 && !seen_82_83) {
  307. utf_hi_char = d - 0x82;
  308. seen_82_83 = true;
  309. return 0;
  310. }
  311. else if (seen_e3 && seen_82_83) {
  312. d &= 0x3f;
  313. #ifndef MAPPER_ONE_TO_ONE
  314. HARDWARE_CHAR_OUT((char)pgm_read_byte_near(utf_recode + d + (utf_hi_char << 6) - 0x20));
  315. #else
  316. HARDWARE_CHAR_OUT((char)(0x80 + (utf_hi_char << 6) + d)) ;
  317. #endif
  318. }
  319. else {
  320. HARDWARE_CHAR_OUT((char) '?' );
  321. }
  322. }
  323. else {
  324. HARDWARE_CHAR_OUT((char) c );
  325. }
  326. seen_e3 = false;
  327. seen_82_83 = false;
  328. return 1;
  329. }
  330. #else
  331. #define MAPPER_NON
  332. char charset_mapper(const char c) {
  333. HARDWARE_CHAR_OUT( c );
  334. return 1;
  335. }
  336. #endif // code mappers
  337. #endif // UTF_MAPPER_H