diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index 6e0fb3c1230..18cd1595ca8 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -283,9 +283,10 @@ static ME_TextBuffer *ME_MakeText(void) { static LRESULT ME_StreamInText(ME_TextEditor *editor, DWORD dwFormat, ME_InStream *stream, ME_Style *style) { - WCHAR wszText[STREAMIN_BUFFER_SIZE+1]; WCHAR *pText; LRESULT total_bytes_read = 0; + BOOL is_read = FALSE; + static const char bom_utf8[] = {0xEF, 0xBB, 0xBF}; TRACE("%08x %p\n", dwFormat, stream); @@ -304,8 +305,23 @@ static LRESULT ME_StreamInText(ME_TextEditor *editor, DWORD dwFormat, ME_InStrea if (!(dwFormat & SF_UNICODE)) { - /* FIXME? this is doomed to fail on true MBCS like UTF-8, luckily they're unlikely to be used as CP_ACP */ - nWideChars = MultiByteToWideChar(CP_ACP, 0, stream->buffer, stream->dwSize, wszText, STREAMIN_BUFFER_SIZE); + WCHAR wszText[STREAMIN_BUFFER_SIZE+1]; + char * buf = stream->buffer; + DWORD size = stream->dwSize; + DWORD cp = CP_ACP; + + if (!is_read) + { + is_read = TRUE; + if (stream->dwSize >= 3 && !memcmp(stream->buffer, bom_utf8, 3)) + { + cp = CP_UTF8; + buf += 3; + size -= 3; + } + } + + nWideChars = MultiByteToWideChar(cp, 0, buf, size, wszText, STREAMIN_BUFFER_SIZE); pText = wszText; } else diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c index 27f4feed3d7..fa80def12b5 100644 --- a/dlls/riched20/tests/editor.c +++ b/dlls/riched20/tests/editor.c @@ -5120,10 +5120,10 @@ static void test_EM_STREAMIN(void) ok(result == 18, "got %ld, expected %d\n", result, 18); result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer); - todo_wine ok(result == 15, + ok(result == 15, "EM_STREAMIN: Test UTF8WithBOM returned %ld, expected 15\n", result); result = strcmp (buffer,"TestUTF8WithBOM"); - todo_wine ok(result == 0, + ok(result == 0, "EM_STREAMIN: Test UTF8WithBOM set wrong text: Result: %s\n",buffer); ok(es.dwError == 0, "EM_STREAMIN: Test UTF8WithBOM set error %d, expected %d\n", es.dwError, 0);