ev3dev/ev3dev-lang-python

Unicode characters doesn't work

f1refa11 opened this issue · 1 comments

  • ev3dev version: 4.14.117-ev3dev-2.3.5-ev3
  • ev3dev-lang-python version: micropython-ev3dev2 2.1.0, python3-ev3dev 1.2.0, python3-ev3dev2 2.1.0

I wanted to render text in Russian, but when I tried to run the program, it gave me this error:

  File "/usr/lib/python3/dist-packages/PIL/ImageDraw.py", line 233, in text
    mask, offset = font.getmask2(text, self.fontmode)
AttributeError: 'ImageFont' object has no attribute 'getmask2'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/robot/ev3tg/main.py", line 50, in <module>
    display.draw.text((4,4+18*idtext), "\u041f\u0440\u0438\u0432\u0435\u0442", font=fonts.load("charB12"))
  File "/usr/lib/python3/dist-packages/PIL/ImageDraw.py", line 237, in text
    mask = font.getmask(text, self.fontmode)
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-5: ordinal not in range(256)

How can i change the encoding?

Solved the problem using custom ttf font and PIL.ImageFont.truetype("calibri.ttf", 12)