diff options
author | Dmitry Mikhirev | 2012-08-27 23:39:56 +0400 |
---|---|---|
committer | Dmitry Mikhirev | 2012-08-27 23:39:56 +0400 |
commit | e6d874c734fb9ebec3de5c9b652425b704480a55 (patch) | |
tree | 136def1c0678b8974c2d1c7f18849f9bdb502f46 | |
parent | 94527a8213c689181ca2b2b11b6d919176ceb33f (diff) | |
download | brainuino-e6d874c734fb9ebec3de5c9b652425b704480a55.tar.gz brainuino-e6d874c734fb9ebec3de5c9b652425b704480a55.tar.bz2 brainuino-e6d874c734fb9ebec3de5c9b652425b704480a55.tar.xz brainuino-e6d874c734fb9ebec3de5c9b652425b704480a55.zip |
rewrite text convertion
-rw-r--r-- | brainuino.ino (renamed from brainuino.pde) | 5 | ||||
-rw-r--r-- | font_en.h | 0 | ||||
-rw-r--r-- | font_ru-en.h | 160 | ||||
-rw-r--r-- | lcdprint.cpp | 52 | ||||
-rw-r--r-- | lcdprint.h (renamed from lcdrus.h) | 11 | ||||
-rw-r--r-- | lcdrus.cpp | 120 | ||||
-rw-r--r-- | utf8.cpp | 63 | ||||
-rw-r--r-- | utf8.h | 36 |
8 files changed, 317 insertions, 130 deletions
diff --git a/brainuino.pde b/brainuino.ino index e935d3f..fe59074 100644 --- a/brainuino.pde +++ b/brainuino.ino @@ -24,10 +24,7 @@ #include "pinout.h" #include "game.h" - -#ifdef RUSSIAN -#include "lcdrus.h" -#endif +#include "lcdprint.h" LiquidCrystal lcd(LCD4, LCD6, LCD11, LCD12, LCD13, LCD14); diff --git a/font_en.h b/font_en.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/font_en.h diff --git a/font_ru-en.h b/font_ru-en.h new file mode 100644 index 0000000..2b6c785 --- /dev/null +++ b/font_ru-en.h @@ -0,0 +1,160 @@ +/* + Brainuino Aleph + + Copyright (C) 2012 Dmitry Mikhirev + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef en_ru_h +#define en_ru_h + +#include <avr/pgmspace.h> + +struct charcode { + const int32_t uni; + const char font; +}; + +const charcode charmap[] PROGMEM = { +// tilde + {0x007e, 0xe9}, +// latin-1 supplement + {0x0083, 0xce}, + {0x00a2, 0x5c}, + {0x00a7, 0xfd}, + {0x00a8, 0xe8}, + {0x00ab, 0xc8}, + {0x00b4, 0xe7}, + {0x00b6, 0xfe}, + {0x00b7, 0xdf}, + {0x00bb, 0xc9}, + {0x00bc, 0xf0}, + {0x00bd, 0xf2}, + {0x00be, 0xf3}, + {0x00bf, 0xcd}, + {0x00d7, 0xd5}, + {0x00e7, 0xeb}, + {0x00e9, 0xea}, + {0x00eb, 0xb5}, +// greek + {0x0391, 0x41}, + {0x0392, 0x42}, + {0x0393, 0xa1}, + {0x0395, 0x45}, + {0x0396, 0x5a}, + {0x0397, 0x48}, + {0x0399, 0x49}, + {0x039a, 0x4b}, + {0x039c, 0x4d}, + {0x039d, 0x4e}, + {0x039f, 0x4f}, + {0x03a0, 0xa8}, + {0x03a1, 0x50}, + {0x03a4, 0x54}, + {0x03a5, 0x59}, + {0x03a6, 0xaa}, + {0x03a7, 0x58}, + {0x03ba, 0xba}, + {0x03bf, 0x6f}, + {0x03c0, 0xbe}, + {0x03c1, 0x70}, +// cyryllic + {0x0401, 0xa2}, + {0x0410, 0x41}, + {0x0411, 0xa0}, + {0x0412, 0x42}, + {0x0413, 0xa1}, + {0x0414, 0xe0}, + {0x0415, 0x45}, + {0x0416, 0xa3}, + {0x0417, 0xa4}, + {0x0418, 0xa5}, + {0x0419, 0xa6}, + {0x041a, 0x4b}, + {0x041b, 0xa7}, + {0x041c, 0x4d}, + {0x041e, 0x4f}, + {0x041f, 0xa8}, + {0x0420, 0x50}, + {0x0421, 0x43}, + {0x0422, 0x54}, + {0x0423, 0xa9}, + {0x0424, 0xaa}, + {0x0425, 0x58}, + {0x0426, 0xe1}, + {0x0427, 0xab}, + {0x0428, 0xac}, + {0x0429, 0xe2}, + {0x042a, 0xad}, + {0x042b, 0xae}, + {0x042c, 0x62}, + {0x042d, 0xaf}, + {0x042e, 0xb0}, + {0x042f, 0xb1}, + {0x0430, 0x61}, + {0x0431, 0xb2}, + {0x0432, 0xb3}, + {0x0433, 0xb4}, + {0x0434, 0xe3}, + {0x0435, 0x65}, + {0x0436, 0xb6}, + {0x0437, 0xb7}, + {0x0438, 0xb8}, + {0x0439, 0xb9}, + {0x043a, 0xba}, + {0x043b, 0xbb}, + {0x043c, 0xbc}, + {0x043d, 0xbd}, + {0x043e, 0x6f}, + {0x043f, 0xbf}, + {0x0440, 0x70}, + {0x0441, 0x63}, + {0x0442, 0xbf}, + {0x0443, 0x79}, + {0x0444, 0xe4}, + {0x0445, 0x78}, + {0x0446, 0xe5}, + {0x0447, 0xc0}, + {0x0448, 0xc1}, + {0x0449, 0xe6}, + {0x044a, 0xc2}, + {0x044b, 0xc3}, + {0x044c, 0xc4}, + {0x044d, 0xc5}, + {0x044e, 0xc6}, + {0x044f, 0xc7}, + {0x0451, 0xb5}, +// general punctuation + {0x2010, 0x2e}, + {0x2011, 0x2e}, + {0x2012, 0x2e}, + {0x2013, 0x2e}, + {0x2014, 0x2e}, + {0x2015, 0x2e}, + {0x201c, 0xca}, + {0x201d, 0xcb}, +// one third + {0x2153, 0xf1}, +// arrows + {0x2191, 0xd9}, + {0x2193, 0xda}, + {0x21b5, 0x7e}, +// mathematical operators + {0x2212, 0x2e}, + {0x2218, 0xef}, + {0x22c5, 0xdf} +}; + +#endif diff --git a/lcdprint.cpp b/lcdprint.cpp new file mode 100644 index 0000000..585b2de --- /dev/null +++ b/lcdprint.cpp @@ -0,0 +1,52 @@ +/* + Brainuino Aleph + + Copyright (C) 2011-2012 Dmitry Mikhirev + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + + +#include "lcdprint.h" +#include "font_ru-en.h" +//#include "font_en.h" + +char* convert(utf8 str) +{ + int32_t ucode; + int i, j; + int numcodes = sizeof(charmap)/sizeof(charcode); + char result[str.chars]; + + for (i = 0; i < str.chars; i++) { + ucode = str.get(); + if (ucode > 0x0000) { + if (ucode <= 0x007d) { + result[i] = char(ucode); + } else { + result[i] = 0xff; + for (j = 0; j < numcodes && charmap[j].uni < ucode; j++) { + if (charmap[j].uni == ucode) { + result[i] = charmap[j].font; + } + } + } + } else { + result[i] = 0x00; + break; + } + } + + return result; +} @@ -1,7 +1,7 @@ /* Brainuino Aleph - Copyright (C) 2011 Dmitry Mikhirev + Copyright (C) 2011-2012 Dmitry Mikhirev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,12 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef lcdrus_h -#define lcdrus_h +#ifndef lcdprint_h +#define lcdprint_h -#include <avr/pgmspace.h> -#include <WString.h> +#include "utf8.h" -String convert (String); +char* convert (utf8); #endif diff --git a/lcdrus.cpp b/lcdrus.cpp deleted file mode 100644 index b12a108..0000000 --- a/lcdrus.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - Brainuino Aleph - - Copyright (C) 2011 Dmitry Mikhirev - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "lcdrus.h" - -String convert(String str) -{ - struct toFrom { - prog_char to; - prog_char from[5]; - }; - toFrom symbols[] PROGMEM = {{0x41, "А"}, - {0x42, "В"}, - {0x43, "С"}, - {0x45, "Е"}, - {0x48, "Н"}, - {0x4B, "К"}, - {0x4D, "М"}, - {0x4F, "О"}, - {0x50, "Р"}, - {0x54, "Т"}, - {0x58, "Х"}, - {0x61, "а"}, - {0x62, "Ь"}, - {0x63, "с"}, - {0x65, "е"}, - {0x6F, "о"}, - {0x70, "р"}, - {0x78, "х"}, - {0x79, "у"}, - {0x7E, "↵"}, - {0xA0, "Б"}, - {0xA1, "Г"}, - {0xA2, "Ё"}, - {0xA3, "Ж"}, - {0xA4, "З"}, - {0xA5, "И"}, - {0xA6, "Й"}, - {0xA7, "Л"}, - {0xA8, "П"}, - {0xA9, "У"}, - {0xAA, "Ф"}, - {0xAB, "Ч"}, - {0xAC, "Ш"}, - {0xAD, "Ъ"}, - {0xAE, "Ы"}, - {0xAF, "Э"}, - {0xB0, "Ю"}, - {0xB1, "Я"}, - {0xB2, "б"}, - {0xB3, "в"}, - {0xB4, "г"}, - {0xB5, "ё"}, - {0xB6, "ж"}, - {0xB7, "з"}, - {0xB8, "и"}, - {0xB9, "й"}, - {0xBA, "к"}, - {0xBB, "л"}, - {0xBC, "м"}, - {0xBD, "н"}, - {0xBE, "п"}, - {0xBF, "т"}, - {0xC0, "ч"}, - {0xC1, "ш"}, - {0xC2, "ъ"}, - {0xC3, "ы"}, - {0xC4, "ь"}, - {0xC5, "э"}, - {0xC6, "ю"}, - {0xC7, "я"}, - {0xC8, "«"}, - {0xC9, "»"}, - {0xCA, "〟"}, - {0xCB, "〞"}, - {0xCD, "¿"}, - {0xCE, "ƒ"}, - {0xCF, "£"}, - {0xD3, "‼"}, - {0xD9, "↑"}, - {0xDA, "↓"}, - {0xE0, "Д"}, - {0xE1, "Ц"}, - {0xE2, "Щ"}, - {0xE3, "д"}, - {0xE4, "ф"}, - {0xE5, "ц"}, - {0xE6, "щ"}, - {0xE9, "~"}, - {0xEA, "é"}, - {0xEB, "ç"}, - {0xF0, "¼"}, - {0xF1, "⅓"}, - {0xF2, "½"}, - {0xF3, "¾"}, - {0xFD, "§"}, - {0xFE, "¶"}}; - - uint8_t i; - - for (i = 0; i < sizeof(symbols)/sizeof(toFrom); i++) - str = str.replace((char*)symbols[i].from, symbols[i].to); - return str; -} diff --git a/utf8.cpp b/utf8.cpp new file mode 100644 index 0000000..026d16e --- /dev/null +++ b/utf8.cpp @@ -0,0 +1,63 @@ +/* + Brainuino Aleph + + Copyright (C) 2012 Dmitry Mikhirev + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "utf8.h" +#include <string.h> + +utf8::utf8 (char* string) +{ + bytes = strlen(string); + _string = (char *)malloc(bytes + 1); + strcpy(_string, string); + chars = 0; + for (_index = 0; _index < bytes; _index++) { + if (_string[_index] & 0x80 == 0) { + chars++; + } else if (_string[_index] & 0x20 == 0) { + chars += 2; + _index++; + } else if (_string[_index] & 0x10 == 0) { + chars += 3; + _index += 2; + } else if (_string[_index] & 0x8 == 0) { + chars += 4; + _index += 3; + } + } + _index = 0; +} + +int32_t utf8::get() +{ + int32_t code; + if (_string[_index] & 0x80 == 0) { + code = int32_t(_string[_index]); + _index++; + } else if (_string[_index] & 0x20 == 0) { + code = int32_t(_string[_index] & 0x1f) << 6 | int32_t(_string[_index+1] & 0x3f); + _index += 2; + } else if (_string[_index] & 0x10 == 0) { + code = int32_t(_string[_index] & 0xf) << 12 | int32_t(_string[_index+1] & 0x3f) << 6 | int32_t(_string[_index+2] & 0x3f); + _index += 3; + } else if (_string[_index] & 0x8 == 0) { + code = int32_t(_string[_index] & 0x7) << 18 | int32_t(_string[_index+1] & 0x3f) << 12 | int32_t(_string[_index+2] & 0x3f) << 6 | int32_t(_string[_index+3] & 0x3f); + } + if (_index > bytes) _index = 0; + return code; +} @@ -0,0 +1,36 @@ +/* + Brainuino Aleph + + Copyright (C) 2012 Dmitry Mikhirev + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef utf8_h +#define utf8_h + +#include "Arduino.h" + +class utf8 { + public: + utf8(char* string); + uint16_t chars; + uint16_t bytes; + int32_t get(); + private: + char* _string; + uint16_t _index; +}; + +#endif |