Open quswadress opened 1 year ago
Windows uses UTF-16 encoding for Unicode.
So in src_c/scrap_win.c
:
https://github.com/pygame/pygame/blob/8d929587ec246e214408763e778ec2a1813c9ff7/src_c/scrap_win.c#L274
GetClipboardData
will give utf-16 (not utf-8) data.
It seems that this data is never actually converted: https://github.com/pygame/pygame/blob/8d929587ec246e214408763e778ec2a1813c9ff7/src_c/scrap_win.c#L297-L307
To get this to return utf-8, you would need to convert it from utf-16 to utf-8 here (using WideCharToMultiByte
from the Windows API or using one of the Python C API functions or something else).
Environment:
Current behavior:
pygame.scrap.get("text/plain;charset=utf-8")[:-1].decode("utf-8")
cannot be decoded in utf-8 encoding, but can in utf-16. This is not user friendly. You said utf-8 then be nice to be able to decode to utf-8.Expected behavior:
pygame.scrap.get("text/plain;charset=utf-8").decode("utf-8")
should return a plain python string with the text I copied.Screenshots English text is decoded as it should be:
But unicode characters are not decoded:![](https://user-images.githubusercontent.com/62151102/230629414-1dd54f78-2c7b-4910-a4b4-020d94408e76.png)
Steps to reproduce:
pip install pygame
python main.py
.Test code