Hello,
I’m developing a game with Pygame2.1 and Python3.9. I’m working on the Windows distribution and I have a problem with the displaying of non-ASCII characters in the window.
I saw a lot of questions similar to mine around on other forums but none of the responses I found has worked for me…
I have strings with characters like "ù à é è ä"
etc.
I create a font object with pygame with
font = pygame.font.Font("myfontfile.ttf", size)
# or with sysfont, which doesn't change anything to this problem
font = pygame.font.SysFont("arial", size)
The I create the text renring surface with
surf = font.render("some string with àéèù...", antialiasing, color)
# With a SysFont, this would give a result like with weird characters in place of the àéè etc, or just holes if I use my custom ttf file.
I have tried things like give my text arguments as bytes, or rencode it and re decode it …:
text = "some string with àéèù..."
surf = font.render(text.encode(), *args) # doesn't work, even worst
# or
surf = font.render(text.encode(sys.stdout.encoding,'replace'), *args) # doesn't work either
# or
surf = font.render(text.encode(sys.stdout.encoding,'replace').decode(), *args) # doesn't work either
# or
surf = font.render(text.encode(sys.stdout.encoding,'replace').decode("utf-8"), *args) # doesn't work either
# or
surf = font.render(bytes(text, "utf-8"), *args) # doesn't work either
I tried pretty much al possible combinations of the above tricks, all with the same result (except that string given as bytes displays the special characters with more weird characters, like with more bytes than decoded as str)
On Linux everything works fine, no matter what font I use.
On Windows it never works.
What am I missing ?
Thank you very much for any help!