stealthylabs / libssd1306

C graphics and device driver library to write to OLED SSD1306 128x64 or 128x32 using I2C
MIT License
19 stars 8 forks source link

printing non-english characters to display results in '?' #3

Closed spammy1337 closed 2 years ago

spammy1337 commented 2 years ago

First; thank you VERY much for this library! This lib has inspired me to learn more about framebuffers! :)

Ive been trying to get my ssd1306 working with my pretty simple C program (to display the time in numbers and text in swedish to help my son learn the clock). But every time i print a swedish character (å/Å, ä/Ä, ö/Ö) i get undesired glyphs on the display.

From what i gather the freetype2 does handle non-english characters and i tried to define the string as u8"string" ssd1306_framebuffer_draw_text(fbp, u8"A Å", 0, 0, 0, SSD1306_FONT_DEFAULT, 10, &bbox); but the result is A Ã?, and the two character "groups" are not in-line, the second part is slightly lower due to the increased character height (top aligned glyphs).

Im not a experienced C programmer, but it seems like the function ssd1306_framebuffer_draw_text() is disassembling the string into char's witch would break non-english characters since they are described with 2 bytes (in utf8) instead of the one byte used with ascii and char variables.

If anyone knows a work-around or has a alternative print function that allows utf8 (or similar international character encoding) please let me know!

stealthylabs commented 2 years ago

@spammy1337 thank you for the kind words. Yes, indeed the Swedish characters are not displaying correctly. Probably because I am using const char * as the type for the string being sent to FreeType2 and the Swedish characters are > 0x80 which is not being accepted. I think I may need to support uint8_t or some form of Unicode variation in there. Unless, you want to try to edit src/graphics.c yourself to try that , I can do it in a few days and let you know if I succeed.

stealthylabs commented 2 years ago

So the latest commit has an example update in examples/fb_graphics.c . Seems like how the compiler interprets a Å character may be different from how the keyboard may interpret it. So a string like "A Å" is not printed correctly but if I use 0xc5 for Å then it looks ok, but misaligned.

spammy1337 commented 2 years ago

Kind words are served where deserved :) And you have yet to get what you properly deserve for your awesome work on this opensource library! <3

I would really love to be able to do a pull request or whatever its called when posting a suggested fix, just as a way of saying "thanks for the lib", but my skillset is not there yet. So the only thing i can do to "help" is to post a bugreport and hope i won't come across as "privileged". :)

But the alignment issue i mentioned briefly seems to be easily fixable: https://forums.raspberrypi.com/viewtopic.php?t=329740 According to Paeryn on the raspberry forum, in the file ssd1306/src/graphics.c, line304 needs to change from FT_Int y_bmap = y; to FT_Int y_bmap = y - slot->bitmap_top; I vouch for no part of reality in general so inspect and investigate as you see fit. :)

stealthylabs commented 2 years ago

@spammy1337 thank you for that link in the forum. indeed, that fix by Paeryn has fixed the top alignment issue. I think it may have been a typo on my part in the past. I have committed that change in right now so you should see it.

As for the suggestion to use UTF-32 to parse characters, that is valid, but it needs more work and I have never worked with UTF-32 before. I think UTF-8 should now be supported but I will confirm that again later this week.

spammy1337 commented 2 years ago

Thank you very much for fixing this issue and its quite impressive that you had a fix posted less than a day after opening the issue!

I feel silly for even mentioning this, but i broke my installation by trying to force rebuild it from source myself (deleting the lib files i found in /usr/* and follow the install procedure again). I then downloaded the updated lib and tried to install that as a fresh install but i seem to have confused the installer somehow.. The make command reports "nothing to do" while the install locations are not re-populating (and i've already emptied the trash).. Im trying to avoid a system reinstall even though that'll probably work out faster for me..

So, if its not too much to ask, could you please add a brief howto regarding (forced) uninstall and/or update procedures to the readme? :) I know, its probably common know-how for the common linux user, but i was raised in a different ecosystem.. :)

stealthylabs commented 2 years ago

@spammy1337 The issue has been fixed and released in the latest code commit 9602c280e86ed08fb956379b27fc2c9ca217605d

You must install libunistring-dev for it to work. You must then follow instructions in the README to rebuild the code.

$ make distclean
$ ./autogen.sh
$ ./configure
$ make

Then you can see the code in examples/fb_graphics.c and look at the ssd1306_framebuffer_draw_text_utf8() function which will do what you need it to do. It works for me now. I can display the Swedish characters å,ä and ö

stealthylabs commented 2 years ago

Thank you very much for fixing this issue and its quite impressive that you had a fix posted less than a day after opening the issue!

I feel silly for even mentioning this, but i broke my installation by trying to force rebuild it from source myself (deleting the lib files i found in /usr/* and follow the install procedure again). I then downloaded the updated lib and tried to install that as a fresh install but i seem to have confused the installer somehow.. The make command reports "nothing to do" while the install locations are not re-populating (and i've already emptied the trash).. Im trying to avoid a system reinstall even though that'll probably work out faster for me..

So, if its not too much to ask, could you please add a brief howto regarding (forced) uninstall and/or update procedures to the readme? :) I know, its probably common know-how for the common linux user, but i was raised in a different ecosystem.. :)

If you are having trouble re-installing, delete the repo code and rebuild it as in the README.