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 1 commit
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
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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it is better to move unicode variable inside if (ch & 0x80) branch. Please, check clang compiler results.

ch &= 0x00FF;
if ( !unicode )
static uint8_t rest = 0;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rest should not be static and must be placed in if (ch & 0x40) branch

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
Loading