Based on a patch by Tony Wasserka.
Signed-off-by: Sven Baars sbaars@codeweavers.com --- v3: Use debugstr_{a,w}n and pass count < 0 ? countW - 1 : countW to PreloadTextW. Resent because yesterday the first 3 patches went missing.
dlls/d3dx9_36/font.c | 56 +++++++++++++++++++++++++++++++++++--- dlls/d3dx9_36/tests/core.c | 2 -- 2 files changed, 52 insertions(+), 6 deletions(-)
diff --git a/dlls/d3dx9_36/font.c b/dlls/d3dx9_36/font.c index 9196295637..81ba1e4fa0 100644 --- a/dlls/d3dx9_36/font.c +++ b/dlls/d3dx9_36/font.c @@ -420,14 +420,62 @@ static HRESULT WINAPI ID3DXFontImpl_PreloadGlyphs(ID3DXFont *iface, UINT first,
static HRESULT WINAPI ID3DXFontImpl_PreloadTextA(ID3DXFont *iface, const char *string, INT count) { - FIXME("iface %p, string %s, count %d stub!\n", iface, debugstr_a(string), count); - return E_NOTIMPL; + WCHAR *wstr; + HRESULT hr; + int countW; + + TRACE("iface %p, string %s, count %d.\n", iface, debugstr_an(string, count), count); + + if (!string && !count) + return D3D_OK; + + if (!string) + return D3DERR_INVALIDCALL; + + countW = MultiByteToWideChar(CP_ACP, 0, string, count < 0 ? -1 : count, NULL, 0); + + wstr = heap_alloc(countW * sizeof(*wstr)); + if (!wstr) + return E_OUTOFMEMORY; + + MultiByteToWideChar(CP_ACP, 0, string, count < 0 ? -1 : count, wstr, countW); + + hr = ID3DXFont_PreloadTextW(iface, wstr, count < 0 ? countW - 1 : countW); + + heap_free(wstr); + + return hr; }
static HRESULT WINAPI ID3DXFontImpl_PreloadTextW(ID3DXFont *iface, const WCHAR *string, INT count) { - FIXME("iface %p, string %s, count %d stub!\n", iface, debugstr_w(string), count); - return E_NOTIMPL; + struct d3dx_font *font = impl_from_ID3DXFont(iface); + WORD *indices; + int i; + + TRACE("iface %p, string %s, count %d.\n", iface, debugstr_wn(string, count), count); + + if (!string && !count) + return D3D_OK; + + if (!string) + return D3DERR_INVALIDCALL; + + if (count < 0) + count = lstrlenW(string); + + indices = heap_alloc(count * sizeof(*indices)); + if (!indices) + return E_OUTOFMEMORY; + + GetGlyphIndicesW(font->hdc, string, count, indices, 0); + + for (i = 0; i < count; ++i) + ID3DXFont_PreloadGlyphs(iface, indices[i], indices[i]); + + heap_free(indices); + + return D3D_OK; }
static INT WINAPI ID3DXFontImpl_DrawTextA(ID3DXFont *iface, ID3DXSprite *sprite, diff --git a/dlls/d3dx9_36/tests/core.c b/dlls/d3dx9_36/tests/core.c index b8e680d1c5..662483b687 100644 --- a/dlls/d3dx9_36/tests/core.c +++ b/dlls/d3dx9_36/tests/core.c @@ -504,7 +504,6 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) DEFAULT_QUALITY, DEFAULT_PITCH, "Tahoma", &font); ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
- todo_wine { hr = ID3DXFont_PreloadTextA(font, NULL, -1); ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr); hr = ID3DXFont_PreloadTextA(font, NULL, 0); @@ -530,7 +529,6 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); hr = ID3DXFont_PreloadTextW(font, L"", -1); ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - }
check_release((IUnknown*)font, 0);
Based on a patch by Tony Wasserka.
Signed-off-by: Sven Baars sbaars@codeweavers.com --- v3: Same as the previous patch
dlls/d3dx9_36/font.c | 128 +++++++++++++++++++++++++++++++++++-- dlls/d3dx9_36/tests/core.c | 59 ++++++++--------- 2 files changed, 149 insertions(+), 38 deletions(-)
diff --git a/dlls/d3dx9_36/font.c b/dlls/d3dx9_36/font.c index 81ba1e4fa0..8ca35b8c21 100644 --- a/dlls/d3dx9_36/font.c +++ b/dlls/d3dx9_36/font.c @@ -481,17 +481,133 @@ static HRESULT WINAPI ID3DXFontImpl_PreloadTextW(ID3DXFont *iface, const WCHAR * static INT WINAPI ID3DXFontImpl_DrawTextA(ID3DXFont *iface, ID3DXSprite *sprite, const char *string, INT count, RECT *rect, DWORD format, D3DCOLOR color) { - FIXME("iface %p, sprite %p, string %s, count %d, rect %s, format %#x, color 0x%08x stub!\n", - iface, sprite, debugstr_a(string), count, wine_dbgstr_rect(rect), format, color); - return 1; + int ret, countW; + WCHAR *wstr; + + TRACE("iface %p, sprite %p, string %s, count %d, rect %s, format %#x, color 0x%08x.\n", + iface, sprite, debugstr_an(string, count), count, wine_dbgstr_rect(rect), format, color); + + if (!string || !count) + return 0; + + countW = MultiByteToWideChar(CP_ACP, 0, string, count < 0 ? -1 : count, NULL, 0); + + if (!countW) + return 0; + + wstr = heap_alloc_zero(countW * sizeof(*wstr)); + if (!wstr) + return 0; + + MultiByteToWideChar(CP_ACP, 0, string, count < 0 ? -1 : count, wstr, countW); + + ret = ID3DXFont_DrawTextW(iface, sprite, wstr, count < 0 ? countW - 1 : countW, + rect, format, color); + + heap_free(wstr); + + return ret; }
static INT WINAPI ID3DXFontImpl_DrawTextW(ID3DXFont *iface, ID3DXSprite *sprite, const WCHAR *string, INT count, RECT *rect, DWORD format, D3DCOLOR color) { - FIXME("iface %p, sprite %p, string %s, count %d, rect %s, format %#x, color 0x%08x stub!\n", - iface, sprite, debugstr_w(string), count, wine_dbgstr_rect(rect), format, color); - return 1; + struct d3dx_font *font = impl_from_ID3DXFont(iface); + ID3DXSprite *target = sprite; + RECT textrect = {0}; + int lh, x, y; + int ret = 0; + + TRACE("iface %p, sprite %p, string %s, count %d, rect %s, format %#x, color 0x%08x.\n", + iface, sprite, debugstr_wn(string, count), count, wine_dbgstr_rect(rect), format, color); + + if (!string) + return 0; + + if (count < 0) + count = lstrlenW(string); + + if (!count) + return 0; + + if (!rect) + { + y = ID3DXFont_DrawTextW(iface, NULL, string, count, &textrect, format | DT_CALCRECT, 0); + + if (format & DT_CALCRECT) + return y; + } + else + { + textrect = *rect; + } + + x = textrect.left; + y = textrect.top; + + lh = font->metrics.tmHeight; + + if (!(format & DT_CALCRECT) && !sprite) + { + D3DXCreateSprite(font->device, &target); + ID3DXSprite_Begin(target, 0); + } + + if (!(format & DT_CALCRECT)) + { + GCP_RESULTSW results; + D3DXVECTOR3 pos; + int i; + + memset(&results, 0, sizeof(results)); + results.nGlyphs = count; + + results.lpCaretPos = heap_alloc(count * sizeof(*results.lpCaretPos)); + if (!results.lpCaretPos) + goto cleanup; + + results.lpGlyphs = heap_alloc(count * sizeof(*results.lpGlyphs)); + if (!results.lpGlyphs) + { + heap_free(results.lpCaretPos); + goto cleanup; + } + + GetCharacterPlacementW(font->hdc, string, count, 0, &results, 0); + + for (i = 0; i < results.nGlyphs; ++i) + { + IDirect3DTexture9 *texture; + POINT cell_inc; + RECT black_box; + + ID3DXFont_GetGlyphData(iface, results.lpGlyphs[i], &texture, &black_box, &cell_inc); + + if (!texture) + continue; + + pos.x = cell_inc.x + x + results.lpCaretPos[i]; + pos.y = cell_inc.y + y; + + ID3DXSprite_Draw(target, texture, &black_box, NULL, &pos, color); + IDirect3DTexture9_Release(texture); + } + + heap_free(results.lpCaretPos); + heap_free(results.lpGlyphs); + } + y += lh; + + ret = y - textrect.top; + +cleanup: + if (target != sprite) + { + ID3DXSprite_End(target); + ID3DXSprite_Release(target); + } + + return ret; }
static HRESULT WINAPI ID3DXFontImpl_OnLostDevice(ID3DXFont *iface) diff --git a/dlls/d3dx9_36/tests/core.c b/dlls/d3dx9_36/tests/core.c index 662483b687..c1e0eac0c8 100644 --- a/dlls/d3dx9_36/tests/core.c +++ b/dlls/d3dx9_36/tests/core.c @@ -652,8 +652,6 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) hr = ID3DXSprite_Begin(sprite, D3DXSPRITE_ALPHABLEND); ok (hr == D3D_OK, "Test %d: got unexpected hr %#x.\n", i, hr);
- todo_wine - { height = ID3DXFont_DrawTextW(font, sprite, testW, -1, &rect, DT_TOP, 0xffffffff); ok(height == tests[i].font_height, "Test %d: got unexpected height %u.\n", i, height); height = ID3DXFont_DrawTextW(font, sprite, testW, size, &rect, DT_TOP, 0xffffffff); @@ -662,12 +660,11 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) ok(height == tests[i].font_height, "Test %d: got unexpected height %u.\n", i, height); height = ID3DXFont_DrawTextW(font, sprite, testW, size, &rect, DT_LEFT | DT_NOCLIP, 0xffffffff); ok(height == tests[i].font_height, "Test %d: got unexpected height %u.\n", i, height); - }
SetRectEmpty(&rect); height = ID3DXFont_DrawTextW(font, sprite, testW, size, &rect, DT_LEFT | DT_CALCRECT, 0xffffffff); - todo_wine ok(height == tests[i].font_height, "Test %d: got unexpected height %u.\n", i, height); + ok(height == tests[i].font_height, "Test %d: got unexpected height %u.\n", i, height); ok(!rect.left, "Test %d: got unexpected rect left %d.\n", i, rect.left); ok(!rect.top, "Test %d: got unexpected rect top %d.\n", i, rect.top); todo_wine ok(rect.right, "Test %d: got unexpected rect right %d.\n", i, rect.right); @@ -687,7 +684,6 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) DEFAULT_QUALITY, DEFAULT_PITCH, "Tahoma", &font); ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
- todo_wine { SetRect(&rect, 10, 10, 200, 200);
height = ID3DXFont_DrawTextA(font, NULL, "test", -2, &rect, 0, 0xFF00FF); @@ -723,10 +719,10 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) SetRect(&rect, 10, 10, 50, 50);
height = ID3DXFont_DrawTextA(font, NULL, long_text, -1, &rect, DT_WORDBREAK, 0xff00ff); - ok(height == 60, "Got unexpected height %d.\n", height); + todo_wine ok(height == 60, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextA(font, NULL, long_text, -1, &rect, DT_WORDBREAK | DT_NOCLIP, 0xff00ff); - ok(height == 96, "Got unexpected height %d.\n", height); + todo_wine ok(height == 96, "Got unexpected height %d.\n", height);
SetRect(&rect, 10, 10, 200, 200);
@@ -760,16 +756,16 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) SetRect(&rect, 10, 10, 50, 50);
height = ID3DXFont_DrawTextW(font, NULL, long_textW, -1, &rect, DT_WORDBREAK, 0xff00ff); - ok(height == 60, "Got unexpected height %d.\n", height); + todo_wine ok(height == 60, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, long_textW, -1, &rect, DT_WORDBREAK | DT_NOCLIP, 0xff00ff); - ok(height == 96, "Got unexpected height %d.\n", height); + todo_wine ok(height == 96, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"a\na", -1, &rect, 0, 0xff00ff); - ok(height == 24, "Got unexpected height %d.\n", height); + todo_wine ok(height == 24, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"a\r\na", -1, &rect, 0, 0xff00ff); - ok(height == 24, "Got unexpected height %d.\n", height); + todo_wine ok(height == 24, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"a\ra", -1, &rect, 0, 0xff00ff); ok(height == 12, "Got unexpected height %d.\n", height); @@ -778,71 +774,70 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) ok(height == 12, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"a\naaaaa aaaa", -1, &rect, 0, 0xff00ff); - ok(height == 24, "Got unexpected height %d.\n", height); + todo_wine ok(height == 24, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"a\naaaaa aaaa", -1, &rect, DT_WORDBREAK, 0xff00ff); - ok(height == 36, "Got unexpected height %d.\n", height); + todo_wine ok(height == 36, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"1\n2\n3\n4\n5\n6", -1, &rect, 0, 0xff00ff); - ok(height == 48, "Got unexpected height %d.\n", height); + todo_wine ok(height == 48, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"1\n2\n3\n4\n5\n6", -1, &rect, DT_NOCLIP, 0xff00ff); - ok(height == 72, "Got unexpected height %d.\n", height); + todo_wine ok(height == 72, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"\t\t\t\t\t\t\t\t\t\t", -1, &rect, DT_WORDBREAK, 0xff00ff); - ok(height == 0, "Got unexpected height %d.\n", height); + todo_wine ok(height == 0, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"\t\t\t\t\t\t\t\t\t\ta", -1, &rect, DT_WORDBREAK, 0xff00ff); ok(height == 12, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"\taaaaaaaaaa", -1, &rect, DT_WORDBREAK, 0xff00ff); - ok(height == 24, "Got unexpected height %d.\n", height); + todo_wine ok(height == 24, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"\taaaaaaaaaa", -1, &rect, DT_EXPANDTABS | DT_WORDBREAK, 0xff00ff); - ok(height == 36, "Got unexpected height %d.\n", height); + todo_wine ok(height == 36, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"\taaa\taaa\taaa", -1, &rect, DT_WORDBREAK, 0xff00ff); - ok(height == 24, "Got unexpected height %d.\n", height); + todo_wine ok(height == 24, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"\taaa\taaa\taaa", -1, &rect, DT_EXPANDTABS | DT_WORDBREAK, 0xff00ff); - ok(height == 48, "Got unexpected height %d.\n", height); + todo_wine ok(height == 48, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"\t\t\t\t\t\t\t\t\t\t", -1, &rect, DT_EXPANDTABS | DT_WORDBREAK, 0xff00ff); - ok(height == 60, "Got unexpected height %d.\n", height); + todo_wine ok(height == 60, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"a\ta", -1, &rect, DT_EXPANDTABS | DT_WORDBREAK, 0xff00ff); ok(height == 12, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"a\ta\ta", -1, &rect, DT_EXPANDTABS | DT_WORDBREAK, 0xff00ff); - ok(height == 24, "Got unexpected height %d.\n", height); + todo_wine ok(height == 24, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaaaaaaaaaaaaaaaaaa", -1, &rect, DT_WORDBREAK, 0xff00ff); - ok(height == 36, "Got unexpected height %d.\n", height); + todo_wine ok(height == 36, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"a a", -1, &rect, DT_WORDBREAK, 0xff00ff); - ok(height == 36, "Got unexpected height %d.\n", height); + todo_wine ok(height == 36, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_WORDBREAK, 0xff00ff); - ok(height == 36, "Got unexpected height %d.\n", height); + todo_wine ok(height == 36, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_WORDBREAK | DT_RIGHT, 0xff00ff); - ok(height == 36, "Got unexpected height %d.\n", height); + todo_wine ok(height == 36, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_WORDBREAK | DT_RIGHT, 0xff00ff); - ok(height == 36, "Got unexpected height %d.\n", height); + todo_wine ok(height == 36, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_BOTTOM, 0xff00ff); - ok(height == 40, "Got unexpected height %d.\n", height); + todo_wine ok(height == 40, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_VCENTER, 0xff00ff); - ok(height == 32, "Got unexpected height %d.\n", height); + todo_wine ok(height == 32, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_RIGHT, 0xff00ff); - ok(height == 24, "Got unexpected height %d.\n", height); + todo_wine ok(height == 24, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CENTER, 0xff00ff); - ok(height == 24, "Got unexpected height %d.\n", height); - } + todo_wine ok(height == 24, "Got unexpected height %d.\n", height);
ID3DXFont_Release(font); }
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Sven Baars sbaars@codeweavers.com --- dlls/d3dx9_36/font.c | 109 ++++++++++++++++++++++++++----------- dlls/d3dx9_36/tests/core.c | 14 ++--- 2 files changed, 83 insertions(+), 40 deletions(-)
diff --git a/dlls/d3dx9_36/font.c b/dlls/d3dx9_36/font.c index 8ca35b8c21..23e6e5c401 100644 --- a/dlls/d3dx9_36/font.c +++ b/dlls/d3dx9_36/font.c @@ -509,14 +509,49 @@ static INT WINAPI ID3DXFontImpl_DrawTextA(ID3DXFont *iface, ID3DXSprite *sprite, return ret; }
+#define LF 10 +#define CR 13 +static const WCHAR *TEXT_NextLineW(HDC hdc, const WCHAR *str, int *count, + WCHAR *dest, int *len, int width, SIZE *retsize) +{ + int max_len = *len; + int i = 0, j = 0; + + while (*count && str[i] != LF) + { + --(*count); + if (j < max_len && str[i] != CR) + dest[j++] = str[i]; + ++i; + } + + GetTextExtentExPointW(hdc, dest, j, width, NULL, NULL, retsize); + + if (*count && str[i] == LF) + { + --(*count); + ++i; + } + + *len = j; + if (*count) + return str + i; + else + return NULL; +} + +#define MAX_BUFFER 1024 static INT WINAPI ID3DXFontImpl_DrawTextW(ID3DXFont *iface, ID3DXSprite *sprite, const WCHAR *string, INT count, RECT *rect, DWORD format, D3DCOLOR color) { struct d3dx_font *font = impl_from_ID3DXFont(iface); ID3DXSprite *target = sprite; + const WCHAR *strPtr = string; + WCHAR line[MAX_BUFFER]; RECT textrect = {0}; - int lh, x, y; + int lh, x, y, width; int ret = 0; + SIZE size;
TRACE("iface %p, sprite %p, string %s, count %d, rect %s, format %#x, color 0x%08x.\n", iface, sprite, debugstr_wn(string, count), count, wine_dbgstr_rect(rect), format, color); @@ -544,6 +579,7 @@ static INT WINAPI ID3DXFontImpl_DrawTextW(ID3DXFont *iface, ID3DXSprite *sprite,
x = textrect.left; y = textrect.top; + width = textrect.right - textrect.left;
lh = font->metrics.tmHeight;
@@ -553,50 +589,57 @@ static INT WINAPI ID3DXFontImpl_DrawTextW(ID3DXFont *iface, ID3DXSprite *sprite, ID3DXSprite_Begin(target, 0); }
- if (!(format & DT_CALCRECT)) + while (strPtr) { - GCP_RESULTSW results; - D3DXVECTOR3 pos; - int i; - - memset(&results, 0, sizeof(results)); - results.nGlyphs = count; + int len = ARRAY_SIZE(line);
- results.lpCaretPos = heap_alloc(count * sizeof(*results.lpCaretPos)); - if (!results.lpCaretPos) - goto cleanup; + strPtr = TEXT_NextLineW(font->hdc, strPtr, &count, line, &len, width, &size);
- results.lpGlyphs = heap_alloc(count * sizeof(*results.lpGlyphs)); - if (!results.lpGlyphs) + if (!(format & DT_CALCRECT)) { - heap_free(results.lpCaretPos); - goto cleanup; - } + GCP_RESULTSW results; + D3DXVECTOR3 pos; + int i;
- GetCharacterPlacementW(font->hdc, string, count, 0, &results, 0); + memset(&results, 0, sizeof(results)); + results.nGlyphs = len;
- for (i = 0; i < results.nGlyphs; ++i) - { - IDirect3DTexture9 *texture; - POINT cell_inc; - RECT black_box; + results.lpCaretPos = heap_alloc(len * sizeof(*results.lpCaretPos)); + if (!results.lpCaretPos) + goto cleanup;
- ID3DXFont_GetGlyphData(iface, results.lpGlyphs[i], &texture, &black_box, &cell_inc); + results.lpGlyphs = heap_alloc(len * sizeof(*results.lpGlyphs)); + if (!results.lpGlyphs) + { + heap_free(results.lpCaretPos); + goto cleanup; + }
- if (!texture) - continue; + GetCharacterPlacementW(font->hdc, line, len, 0, &results, 0);
- pos.x = cell_inc.x + x + results.lpCaretPos[i]; - pos.y = cell_inc.y + y; + for (i = 0; i < results.nGlyphs; ++i) + { + IDirect3DTexture9 *texture; + POINT cell_inc; + RECT black_box;
- ID3DXSprite_Draw(target, texture, &black_box, NULL, &pos, color); - IDirect3DTexture9_Release(texture); - } + ID3DXFont_GetGlyphData(iface, results.lpGlyphs[i], &texture, &black_box, &cell_inc);
- heap_free(results.lpCaretPos); - heap_free(results.lpGlyphs); + if (!texture) + continue; + + pos.x = cell_inc.x + x + results.lpCaretPos[i]; + pos.y = cell_inc.y + y; + + ID3DXSprite_Draw(target, texture, &black_box, NULL, &pos, color); + IDirect3DTexture9_Release(texture); + } + + heap_free(results.lpCaretPos); + heap_free(results.lpGlyphs); + } + y += lh; } - y += lh;
ret = y - textrect.top;
diff --git a/dlls/d3dx9_36/tests/core.c b/dlls/d3dx9_36/tests/core.c index c1e0eac0c8..c6f5beff43 100644 --- a/dlls/d3dx9_36/tests/core.c +++ b/dlls/d3dx9_36/tests/core.c @@ -762,19 +762,19 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) todo_wine ok(height == 96, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"a\na", -1, &rect, 0, 0xff00ff); - todo_wine ok(height == 24, "Got unexpected height %d.\n", height); + ok(height == 24, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"a\r\na", -1, &rect, 0, 0xff00ff); - todo_wine ok(height == 24, "Got unexpected height %d.\n", height); + ok(height == 24, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"a\ra", -1, &rect, 0, 0xff00ff); ok(height == 12, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"a\na", -1, &rect, DT_SINGLELINE, 0xff00ff); - ok(height == 12, "Got unexpected height %d.\n", height); + todo_wine ok(height == 12, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"a\naaaaa aaaa", -1, &rect, 0, 0xff00ff); - todo_wine ok(height == 24, "Got unexpected height %d.\n", height); + ok(height == 24, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"a\naaaaa aaaa", -1, &rect, DT_WORDBREAK, 0xff00ff); todo_wine ok(height == 36, "Got unexpected height %d.\n", height); @@ -783,7 +783,7 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) todo_wine ok(height == 48, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"1\n2\n3\n4\n5\n6", -1, &rect, DT_NOCLIP, 0xff00ff); - todo_wine ok(height == 72, "Got unexpected height %d.\n", height); + ok(height == 72, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"\t\t\t\t\t\t\t\t\t\t", -1, &rect, DT_WORDBREAK, 0xff00ff); todo_wine ok(height == 0, "Got unexpected height %d.\n", height); @@ -834,10 +834,10 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) todo_wine ok(height == 32, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_RIGHT, 0xff00ff); - todo_wine ok(height == 24, "Got unexpected height %d.\n", height); + ok(height == 24, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CENTER, 0xff00ff); - todo_wine ok(height == 24, "Got unexpected height %d.\n", height); + ok(height == 24, "Got unexpected height %d.\n", height);
ID3DXFont_Release(font); }
On Tue, Mar 3, 2020 at 9:55 AM Sven Baars sbaars@codeweavers.com wrote:
Signed-off-by: Sven Baars sbaars@codeweavers.com
dlls/d3dx9_36/font.c | 109 ++++++++++++++++++++++++++----------- dlls/d3dx9_36/tests/core.c | 14 ++--- 2 files changed, 83 insertions(+), 40 deletions(-)
I like how you split the large DrawText() patch into smaller, self contained pieces, much appreciated!
diff --git a/dlls/d3dx9_36/font.c b/dlls/d3dx9_36/font.c index 8ca35b8c21..23e6e5c401 100644 --- a/dlls/d3dx9_36/font.c +++ b/dlls/d3dx9_36/font.c @@ -509,14 +509,49 @@ static INT WINAPI ID3DXFontImpl_DrawTextA(ID3DXFont *iface, ID3DXSprite *sprite, return ret; }
+#define LF 10 +#define CR 13
It seems nicer to me to use the usual character constants '\n' and '\r' instead.
+static const WCHAR *TEXT_NextLineW(HDC hdc, const WCHAR *str, int *count,
WCHAR *dest, int *len, int width, SIZE *retsize)
A few style nitpicks: line continuations should be 8 white spaces, the int variables should be unsigned int where it makes sense. Also the function could probably use a name not resembling the Win32 API as much, e.g. get_next_line(). BTW you can use ~100 columns per line.
count and len can be a bit confusing, maybe qualify them like "dst_size". Another thing to consider is splitting the (input) size of the "dest" string and the (output) length of the line into two separate arguments.
+{
- int max_len = *len;
- int i = 0, j = 0;
- while (*count && str[i] != LF)
- {
--(*count);
if (j < max_len && str[i] != CR)
dest[j++] = str[i];
++i;
- }
This will silently cut lines longer than max_len. Maybe print a WARN() when that happens?
- GetTextExtentExPointW(hdc, dest, j, width, NULL, NULL, retsize);
- if (*count && str[i] == LF)
- {
--(*count);
++i;
- }
- *len = j;
- if (*count)
return str + i;
- else
return NULL;
The else is unnecessary here.
+}
+#define MAX_BUFFER 1024 static INT WINAPI ID3DXFontImpl_DrawTextW(ID3DXFont *iface, ID3DXSprite *sprite, const WCHAR *string, INT count, RECT *rect, DWORD format, D3DCOLOR color) { struct d3dx_font *font = impl_from_ID3DXFont(iface); ID3DXSprite *target = sprite;
- const WCHAR *strPtr = string;
Let's avoid camelCase variable names. In this case I think you can just update "string" along the way, no need for a separate variable.
- WCHAR line[MAX_BUFFER]; RECT textrect = {0};
- int lh, x, y;
- int lh, x, y, width; int ret = 0;
- SIZE size;
size is effectively unused at the moment. Unless it becomes useful afterwards, it should probably just be dropped from the helper function arguments.
Hi Sven,
I'm attaching a diff to be applied on top of this patch. Does it look okay to you? In particular I'm interested if you have more tests not yet upstream.
On 03-03-2020 14:06, Matteo Bruni wrote:
Hi Sven,
I'm attaching a diff to be applied on top of this patch. Does it look okay to you? In particular I'm interested if you have more tests not yet upstream.
Hi Matteo,
I have some more tests, but only for DrawText. I send those with the patches that fix the tests, because otherwise they would add dead code.
If you apply a similar diff to this one to the first DrawText patch (2/5), however, I expect the tests that are already present to fail (I believe those tests also represent actual applications). For consistency I did the same thing for PreloadText. I could add some tests to check if it also fails for PreloadText if you like.
Cheers, Sven
On Tue, Mar 3, 2020 at 2:18 PM Sven Baars sbaars@codeweavers.com wrote:
On 03-03-2020 14:06, Matteo Bruni wrote:
Hi Sven,
I'm attaching a diff to be applied on top of this patch. Does it look okay to you? In particular I'm interested if you have more tests not yet upstream.
Hi Matteo,
I have some more tests, but only for DrawText. I send those with the patches that fix the tests, because otherwise they would add dead code.
If you apply a similar diff to this one to the first DrawText patch (2/5), however, I expect the tests that are already present to fail (I believe those tests also represent actual applications). For consistency I did the same thing for PreloadText. I could add some tests to check if it also fails for PreloadText if you like.
Cool, that's what I was looking for, thanks. Yes, similar changes to DrawTextA() cause a failure for the "", -1 test (in particular because of removing the conditional - 1 to countW). I think I still like it more like this though (after fixing the test failure, of course). Anyway, I'll review the other patches later.
BTW I don't think you can test that for PreloadTextA() since the function doesn't return a character count or anything observable.
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=66216
Your paranoid android.
=== debian10 (build log) ===
error: patch failed: dlls/d3dx9_36/font.c:426 Task: Patch failed to apply
=== debian10 (build log) ===
error: patch failed: dlls/d3dx9_36/font.c:426 Task: Patch failed to apply