tingbot / tingbot-python

๐Ÿ”ฉ Python APIs to write apps for Tingbot
Other
18 stars 9 forks source link

Improved unicode handling #16

Open joerick opened 8 years ago

joerick commented 8 years ago

Some unicode characters are supported (if they're in the font), but some cause the renderer to crash, for example:

screen.text(u'๐Ÿ•ˆโ˜Ÿโš ๐Ÿ’งโœŒโœ‹๐Ÿ‘Ž โœกโš๐Ÿ•† ๐Ÿ•ˆโ˜œโ˜ผโ˜œ โœ‹โ˜  ๐Ÿ‘โšโ˜ โ„โ˜ผโšโ˜นโœ โ˜Ÿโ˜œโ˜Ÿโ˜œโ˜Ÿโ˜œ')
Traceback (most recent call last):
  File "main.py", line 33, in <module>
    screen.text(u'๐Ÿ•ˆโ˜Ÿโš ๐Ÿ’งโœŒโœ‹๐Ÿ‘Ž โœกโš๐Ÿ•† ๐Ÿ•ˆโ˜œโ˜ผโ˜œ โœ‹โ˜  ๐Ÿ‘โšโ˜ โ„โ˜ผโšโ˜นโœ โ˜Ÿโ˜œโ˜Ÿโ˜œโ˜Ÿโ˜œ')
  File "/Applications/Tide.app/Contents/Resources/tingbot/graphics.py", line 208, in text
    super(Screen, self).text(*args, **kwargs)
  File "/Applications/Tide.app/Contents/Resources/tingbot/graphics.py", line 150, in text
    text_image = Image(surface=font.render(string, antialias, _color(color)))
UnicodeError: A Unicode character above '\uFFFF' was found; not supported
joerick commented 8 years ago

Looks like a pygame issue, may be fixable by moving to the freetype backend

furbrain commented 8 years ago

I'm trying to reproduce this in linux, but it doesn't seem to cause any problems for me. However, I've only cut and pasted from the above link - not sure how well the unicode has come across. I've also tried screen.text(u'\U00010143') - which should print a gamma sign but gives me a capital N with a tilde - but no crash.

joerick commented 8 years ago

Interesting. Probably pygame.font uses a different backend on the different platforms. I'd really like emojis to work as well, maybe pygame.freetype would provide that? We'd also have to bundle an emoji font and a unicode font with a good number of glyphs for fallback.