We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 365

Summary: SDL_WM_SetCaption() cannot handle Japanese(and maybe other languages) on Windows
Product: SDL Reporter: aki. <c>
Component: videoAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: 1.2.11   
Hardware: x86   
OS: Windows (All)   
Attachments: Proposed patch to handle Unicode...

Description aki. 2006-11-17 07:06:16 UTC
Hello,

When Japanese is given to SDL_WM_SetCaption() on Windows, it garbles.

WinAPI receives string corresponding to the code page of the system.
Therefore, I think that it should use such as following codes instead of SDL_iconv_utf8_latin1():

char *SDL_iconv_utf8_acp(char *in) {
    Uint16 *lpsz = SDL_iconv_utf8_ucs2(in);
    size_t len = WideCharToMultiByte(CP_ACP, 0, lpsz, -1, NULL, 0, NULL, NULL);
    char *out = SDL_malloc(len + 1);
    WideCharToMultiByte(CP_ACP, 0, lpsz, -1, out, len, NULL, NULL);
    SDL_free(lpsz);
    return out;
}

Regards,
aki. (c@tqzh.tk)
Comment 1 Ryan C. Gordon 2007-02-13 04:54:06 UTC
Created attachment 189 [details]
Proposed patch to handle Unicode...


Here's a proposed patch...it is untested and may not even compile, yet.

It will see if SetWindowTextW() is available in kernel32.dll (as it will be on WinNT, WinXP, Win2000 and Vista), and if so, it feeds the ucs-2 string to it. This will allow, for example, Japanese characters to be used in the titlebar on a WinXP box that uses a Russian codepage.

If SetWindowsTextW() isn't available (Win95, Win98, WinME), then it will use WideCharToMultiByte(CP_ACP, ...) as originally proposed. This will not necessarily work everywhere, but it will probably work in most real life scenarios, and definitely better than assuming a latin1 codepage as we currently do.

If there are no objections, I'll commit this patch once I've had a chance to compile and test it on Windows.

--ryan.
Comment 2 Ryan C. Gordon 2007-02-16 01:21:47 UTC
Fixed in svn revision #2985 for the 1.2 branch.

--ryan.