From: Sven Baars Subject: [PATCH v2 7/8] d3dx9: Implement ID3DXFont_PreloadText. Message-Id: <20200106143408.12864-7-sbaars@codeweavers.com> Date: Mon, 6 Jan 2020 15:34:07 +0100 In-Reply-To: <20200106143408.12864-1-sbaars@codeweavers.com> References: <20200106143408.12864-1-sbaars@codeweavers.com> Based on a patch by Tony Wasserka. Signed-off-by: Sven Baars --- v2: Fix MultiByteToWideChar usage. dlls/d3dx9_36/font.c | 63 +++++++++++++++++++++++++++++++++++--- dlls/d3dx9_36/tests/core.c | 2 -- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/dlls/d3dx9_36/font.c b/dlls/d3dx9_36/font.c index e7e4f33d2c..3742bd7006 100644 --- a/dlls/d3dx9_36/font.c +++ b/dlls/d3dx9_36/font.c @@ -446,16 +446,71 @@ static HRESULT WINAPI ID3DXFontImpl_PreloadGlyphs(ID3DXFont *iface, UINT first, return D3D_OK; } +/************************************************************ + * ID3DXFont_PreloadText + * + * Preloads a string into the internal texture + * + * PARAMS + * string [I] string to be preloaded + * count [I] length of the string + * + * RETURNS + * Success: D3D_OK, if we successfully preload the text or + * if string and count are NULL + * Failure: D3DERR_INVALIDCALL, if string is NULL and count is not 0 + * + */ 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_a(string), count); + + if (!string && count == 0) 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(WCHAR)); + if (!wstr) + return E_OUTOFMEMORY; + + MultiByteToWideChar(CP_ACP, 0, string, count < 0 ? -1 : count, wstr, countW); + + hr = ID3DXFont_PreloadTextW(iface, wstr, count); + + 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 *This = impl_from_ID3DXFont(iface); + UINT i; + WORD *indices; + + TRACE("iface %p, string %s, count %d\n", iface, debugstr_w(string), count); + + if (!string && count == 0) return D3D_OK; + if (!string) return D3DERR_INVALIDCALL; + if (count < 0) count = lstrlenW(string); + + indices = heap_alloc(count * sizeof(WORD)); + if (!indices) + return E_OUTOFMEMORY; + + GetGlyphIndicesW(This->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 4ec591e631..b96df47de5 100644 --- a/dlls/d3dx9_36/tests/core.c +++ b/dlls/d3dx9_36/tests/core.c @@ -479,7 +479,6 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) /* ID3DXFont_PreloadText */ hr = D3DXCreateFontA(device, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Tahoma", &font); if(SUCCEEDED(hr)) { - todo_wine { hr = ID3DXFont_PreloadTextA(font, NULL, -1); ok(hr == D3DERR_INVALIDCALL, "ID3DXFont_PreloadTextA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); hr = ID3DXFont_PreloadTextA(font, NULL, 0); @@ -505,7 +504,6 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) ok(hr == D3D_OK, "ID3DXFont_PreloadTextW returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXFont_PreloadTextW(font, emptyW, -1); ok(hr == D3D_OK, "ID3DXFont_PreloadTextW returned %#x, expected %#x\n", hr, D3D_OK); - } check_release((IUnknown*)font, 0); } else skip("Failed to create a ID3DXFont object\n"); -- 2.24.0