My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

utf_mapper.h 14KB

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