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

Question: UTF-8 characters handling #11

Open
rodizio1 opened this issue Mar 3, 2018 · 2 comments
Open

Question: UTF-8 characters handling #11

rodizio1 opened this issue Mar 3, 2018 · 2 comments

Comments

@rodizio1
Copy link

rodizio1 commented Mar 3, 2018

First of all, thanks a lot for your work on this library. The dynamic font loading feature is really great.

I have a question about "special" UTF-8 characters. I would like to implement different graphical elements like a signal strength bar by using font icons. What I've tried and what works is simply putting the special characters into a buffer and then drawing it with the Text function like this:

sprintf(buffer, "▁▂▃▄▅▆▇");
Text(x, y, buffer, myfont, text_scale);

I guess this works because the above characters are from the dejavu font which is a system font on Raspbian and the editor and everything supports utf-8.

Now I have made another TTF font from a bunch of SVGs and the above doesn't work anymore,
is there a way to print these characters by their numbers? The usual \x0A C-like escaping doesn't seem to work with multibyte characters.

@paeryn
Copy link
Owner

paeryn commented Mar 5, 2018

If your font has correct cmap tables for mapping the character codes used in the string to the correct glyphs then it should work (though there isn't any way to choose which cmap table if multiple ones exist. The Text() function converts the string from multibyte to wide_char depending on the C locale setting, Each wide_char is then looked up in the font's mapping table to select the correct glyph to draw. The way it is set up is that the FreeType library will pick a unicode cmap as being the active cmap with no way to select anything else,

@rodizio1
Copy link
Author

rodizio1 commented Mar 7, 2018

Thanks for the explanation, I'll try that out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants