Skip to content

Commit

Permalink
Merge pull request #123 from cwl769/master
Browse files Browse the repository at this point in the history
Fix convert from UTF-8 to Unicode
  • Loading branch information
lexus2k committed Aug 19, 2024
2 parents 4a34c0a + 079c79d commit 64aff6b
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/canvas/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,20 +330,25 @@ lcduint_t NanoFont::getTextSize(const char *text, lcduint_t *height)
uint16_t NanoFont::unicode16FromUtf8(uint8_t ch)
{
#ifdef CONFIG_SSD1306_UNICODE_ENABLE
static uint16_t unicode = 0;
ch &= 0x00FF;
if ( !unicode )
if(ch & 0x80)
{
if ( ch >= 0xc0 )
static uint16_t unicode = 0;
static uint8_t rest = 0;
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 64aff6b

Please sign in to comment.