Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix convert from UTF-8 to Unicode #123

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading