Skip to content

Commit

Permalink
Fixing convert from UTF-8 to Unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
cwl769 committed Aug 4, 2024
1 parent 4a34c0a commit 8ff7a77
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/canvas/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,19 +331,24 @@ uint16_t NanoFont::unicode16FromUtf8(uint8_t ch)
{
#ifdef CONFIG_SSD1306_UNICODE_ENABLE
static uint16_t unicode = 0;
ch &= 0x00FF;
if ( !unicode )
static uint8_t rest = 0;
if(ch & 0x80)
{
if ( ch >= 0xc0 )
if(ch & 0x40)
{
unicode = ch;
uint8_t mask = 0x1f;
rest = 1;
while( ((~mask) & ch) == ((~mask) & 0xff) ) mask >>= 1, ++rest;
unicode = ch & mask;
return SSD1306_MORE_CHARS_REQUIRED;
}
return ch;
else
{
unicode = (unicode << 6) | (ch & 0x3f);
return (--rest) ? SSD1306_MORE_CHARS_REQUIRED : unicode;
}
}
uint16_t code = ((unicode & 0x1f) << 6) | (ch & 0x3f);
unicode = 0;
return code;
return ch;
#else
return ch;
#endif
Expand Down

0 comments on commit 8ff7a77

Please sign in to comment.