Ticket #8928: sdl-caption.diff

File sdl-caption.diff, 1.1 KB (added by eriktorbjorn, 16 years ago)

Patch against current SVN

  • backends/platform/sdl/sdl.cpp

     
    383383}
    384384
    385385void OSystem_SDL::setWindowCaption(const char *caption) {
    386         SDL_WM_SetCaption(caption, caption);
     386        // SDL expects the string to be encoded as UTF-8, but ScummVM uses
     387        // ISO 8859-1 (Latin-1) internally. Convert the string, if necessary.
     388
     389        int len = strlen(caption);
     390        int utf8len = 0;
     391        int i;
     392
     393        for (i = 0; i < len; i++) {
     394                if (caption[i] & 0x80)
     395                        utf8len += 2;
     396                else
     397                        utf8len++;
     398        }
     399
     400        if (utf8len > len) {
     401                char *utf8caption = (char *)malloc(utf8len);
     402                int j = 0;
     403
     404                for (i = 0; i < len; i++) {
     405                        if (caption[i] & 0x80) {
     406                                utf8caption[j++] = 0xC0 | ((caption[i] >> 6) & 0x03);
     407                                utf8caption[j++] = 0x80 | (caption[i] & 0x3F);
     408                        } else
     409                                utf8caption[j++] = caption[i];
     410                }
     411
     412                SDL_WM_SetCaption(utf8caption, utf8caption);
     413                free(utf8caption);
     414        } else
     415                SDL_WM_SetCaption(caption, caption);
    387416}
    388417
    389418bool OSystem_SDL::hasFeature(Feature f) {