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

Problem rendering Unicode characters through Pillow with DejaVuSans #67

Open
vicariousdrama opened this issue Mar 17, 2022 · 2 comments
Labels
bug Something isn't working panel:raretoshi Issues affecting the raretoshi panel

Comments

@vicariousdrama
Copy link
Owner

See the following log output

Getting Raretoshi information for user RRizzling
Using cached data from 1647482490
Holding 89 is video/mp4 which is unsupported.
Picking another at random. Check count 1.
Holding 83 is image/gif which is unsupported.
Picking another at random. Check count 2.
Picked holding 75 titled Un₿eliever V with ipfshash QmXwt9GFbe6R8R9giVMcqeavAsrUsjnh51V5kHLS5VCPdH

The title of the work is Un₿eliever V with the bitcoin symbol.

However the generated image ends up showing the empty box for unicode characters like this.

The font in use in the vicarioustext file is /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf

May need to use a different font, at least for raretoshi.

Run with the following to reproduce

./raretoshi.py RRizzling 75

Tested with the /usr/share/fonts/truetype/noto/NotoMono-Regular.ttf font but it also fails

@vicariousdrama vicariousdrama added the bug Something isn't working label Mar 17, 2022
@vicariousdrama
Copy link
Owner Author

See also from
https://ourpython.com/python/does-pillow-want-my-text-parameters-to-be-unicode-or-strings

You're usually better off using explicit backslash escapes, like \u250c instead of ??, especially if you don't even know how to tell if the file is UTF-8, much less how to fix it.

Second, you almost never want to put non-ASCII characters into a str literal; use a unicode literal unless you have a good reason to do otherwise.

On top of that, if you pass draw.text a str, PIL will decode it with your default charset—which again is probably not UTF-8. So, even if everything else so far were correct, your code would be handing over some UTF-8 to be parsed as cp1252, so mojibake again. Using a unicode literal would avoid this problem entirely; otherwise, you need to pass text.decode('utf-8').

Putting that all together:

text = u"\u250c\u2500\u2510\u2502\u2514\u2518\u255e\u2550\u2561\u2564\u2567\u2558\u255b"
And now the coding declaration and the actual encoding used to save the file don't matter, because the file is pure ASCII.

@vicariousdrama
Copy link
Owner Author

will try multiple fonts installed with

sudo apt-get install ttf-mscorefonts-installer

@vicariousdrama vicariousdrama changed the title raretoshi panel support for unicode characters Need support for unicode characters Apr 13, 2023
@vicariousdrama vicariousdrama added the panel:raretoshi Issues affecting the raretoshi panel label Apr 13, 2023
@vicariousdrama vicariousdrama changed the title Need support for unicode characters Problem rendering Unicode characters through Pillow with DejaVuSans Jul 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working panel:raretoshi Issues affecting the raretoshi panel
Projects
None yet
Development

No branches or pull requests

1 participant