Skip to content

Commit

Permalink
Extended ASCII codes and cyrillic support
Browse files Browse the repository at this point in the history
  • Loading branch information
osmanovv committed May 21, 2022
1 parent 8e8158e commit e977840
Show file tree
Hide file tree
Showing 4 changed files with 465 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/graphics/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "mesh/http/WiFiAPClient.h"
#endif

#include "fonts/OLEDDisplayFontsRU.h"

using namespace meshtastic; /** @todo remove */

namespace graphics
Expand Down Expand Up @@ -92,7 +94,7 @@ static uint16_t displayWidth, displayHeight;
#define FONT_MEDIUM ArialMT_Plain_24
#define FONT_LARGE ArialMT_Plain_24
#else
#define FONT_SMALL ArialMT_Plain_10
#define FONT_SMALL ArialMT_Plain_10_RU
#define FONT_MEDIUM ArialMT_Plain_16
#define FONT_LARGE ArialMT_Plain_24
#endif
Expand Down
27 changes: 25 additions & 2 deletions src/graphics/Screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,23 @@ class Screen : public concurrency::OSThread
SKIPREST = false;
return ch;
}
else { // extended ASCII codes
LASTCHAR = 0;
SKIPREST = false;

// map UTF-8 cyrillic chars to it Windows-1251 (CP-1251) ASCII codes
if (ch > 143 && ch < 192) return (uint8_t)(ch + 48);
if (ch > 127 && ch < 144) return (uint8_t)(ch + 112);
if (ch == 101) return (uint8_t)(168); // Ё
if (ch == 145) return (uint8_t)(184); // ё

return ch;
}

uint8_t last = LASTCHAR; // get last char
LASTCHAR = ch;

switch (last) { // conversion depnding on first UTF8-character
switch (last) { // conversion depending on first UTF8-character
case 0xC2: {
SKIPREST = false;
return (uint8_t)ch;
Expand All @@ -204,10 +216,21 @@ class Screen : public concurrency::OSThread
SKIPREST = false;
return (uint8_t)(ch | 0xC0);
}
// map UTF-8 cyrillic chars to it Windows-1251 (CP-1251) ASCII codes
// note: in this case we must use compatible font - provided ArialMT_Plain_10/16/24 by 'ThingPulse/esp8266-oled-ssd1306' library
// have empty chars for non-latin ASCII symbols
case 0xD0: {
SKIPREST = false;
return (uint8_t)(0);
}
case 0xD1: {
SKIPREST = false;
return (uint8_t)(0);
}
}

// We want to strip out prefix chars for two-byte char formats
if (ch == 0xC2 || ch == 0xC3 || ch == 0x82)
if (ch == 0xC2 || ch == 0xC3 || ch == 0x82 || ch == 0xD0 || ch == 0xD1)
return (uint8_t)0;

// If we already returned an unconvertable-character symbol for this unconvertable-character sequence, return NULs for the
Expand Down
Loading

0 comments on commit e977840

Please sign in to comment.