From: Sven Baars Subject: [PATCH v2 5/8] d3dx9: Implement ID3DXFont_GetGlyphData. Message-Id: <20200106143408.12864-5-sbaars@codeweavers.com> Date: Mon, 6 Jan 2020 15:34:05 +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 --- dlls/d3dx9_36/font.c | 64 ++++++++++++++++++++++++++++++++++++-- dlls/d3dx9_36/tests/core.c | 11 +++---- 2 files changed, 66 insertions(+), 9 deletions(-) diff --git a/dlls/d3dx9_36/font.c b/dlls/d3dx9_36/font.c index fe645a51c0..e204ca3012 100644 --- a/dlls/d3dx9_36/font.c +++ b/dlls/d3dx9_36/font.c @@ -166,12 +166,70 @@ static HDC WINAPI ID3DXFontImpl_GetDC(ID3DXFont *iface) return This->hdc; } +/************************************************************ + * ID3DXFont_GetGlyphData + * + * Returns the internally stored texture and some info about + * the position of the requested glyph on that texture + * + * PARAMS + * glyph [I] glyph + * texture [O] length of the string + * blackbox [O] smallest rectangle that completely encloses the glyph on the texture + * cellinc [O] offset from the baseline to the bottom of the glyph + * + * RETURNS + * Success: D3D_OK + * Failure: D3DERR_INVALIDCALL + * D3DXERR_INVALIDDATA + * + * NOTES + * Glyphs which are passed to this function get preloaded, too + * + */ static HRESULT WINAPI ID3DXFontImpl_GetGlyphData(ID3DXFont *iface, UINT glyph, IDirect3DTexture9 **texture, RECT *blackbox, POINT *cellinc) { - FIXME("iface %p, glyph %#x, texture %p, blackbox %p, cellinc %p stub!\n", - iface, glyph, texture, blackbox, cellinc); - return E_NOTIMPL; + struct d3dx_font *This = impl_from_ID3DXFont(iface); + HRESULT hr; + int i; + TRACE("iface %p, glyph %#x, texture %p, blackbox %p, cellinc %p\n", + iface, glyph, texture, blackbox, cellinc); + + for (i = 0; i < This->glyph_count; i++) + if (This->glyphs[i].id == glyph) + { + if (cellinc) + *cellinc = This->glyphs[i].cellinc; + if (blackbox) + *blackbox = This->glyphs[i].blackbox; + if (texture) + *texture = This->glyphs[i].texture; + if (texture && *texture) + IDirect3DTexture9_AddRef(This->glyphs[i].texture); + return D3D_OK; + } + + hr = ID3DXFont_PreloadGlyphs(iface, glyph, glyph); + if (FAILED(hr)) + return hr; + + /* Try again */ + for (i = 0; i < This->glyph_count; i++) + if (This->glyphs[i].id == glyph) + { + if (cellinc) + *cellinc = This->glyphs[i].cellinc; + if (blackbox) + *blackbox = This->glyphs[i].blackbox; + if (texture) + *texture = This->glyphs[i].texture; + if (texture && *texture) + IDirect3DTexture9_AddRef(This->glyphs[i].texture); + return D3D_OK; + } + + return D3DXERR_INVALIDDATA; } static HRESULT WINAPI ID3DXFontImpl_PreloadCharacters(ID3DXFont *iface, UINT first, UINT last) diff --git a/dlls/d3dx9_36/tests/core.c b/dlls/d3dx9_36/tests/core.c index 4b731288c7..4ec591e631 100644 --- a/dlls/d3dx9_36/tests/core.c +++ b/dlls/d3dx9_36/tests/core.c @@ -525,7 +525,6 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) hdc = ID3DXFont_GetDC(font); - todo_wine { hr = ID3DXFont_GetGlyphData(font, 0, NULL, &blackbox, &cellinc); ok(hr == D3D_OK, "ID3DXFont_GetGlyphData returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXFont_GetGlyphData(font, 0, &texture, NULL, &cellinc); @@ -534,7 +533,6 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) hr = ID3DXFont_GetGlyphData(font, 0, &texture, &blackbox, NULL); if(SUCCEEDED(hr)) check_release((IUnknown*)texture, 1); ok(hr == D3D_OK, "ID3DXFont_GetGlyphData returned %#x, expected %#x\n", hr, D3D_OK); - } hr = ID3DXFont_PreloadCharacters(font, 'b', 'a'); ok(hr == D3D_OK, "ID3DXFont_PreloadCharacters returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXFont_PreloadGlyphs(font, 1, 0); @@ -548,7 +546,7 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) ok(ret != GDI_ERROR, "GetGlyphIndicesA failed\n"); hr = ID3DXFont_GetGlyphData(font, glyph, &texture, &blackbox, &cellinc); - todo_wine ok(hr == D3D_OK, "ID3DXFont_GetGlyphData returned %#x, expected %#x\n", hr, D3D_OK); + ok(hr == D3D_OK, "ID3DXFont_GetGlyphData returned %#x, expected %#x\n", hr, D3D_OK); if(SUCCEEDED(hr)) { DWORD ret, levels; TEXTMETRICW tm; @@ -597,8 +595,8 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) { texture = (IDirect3DTexture9*)0xdeadbeef; hr = ID3DXFont_GetGlyphData(font, glyph, &texture, &blackbox, &cellinc); - todo_wine ok(hr == D3D_OK, "ID3DXFont_GetGlyphData returned %#x, expected %#x\n", hr, D3D_OK); - todo_wine ok(!texture, "Got unexpected texture\n"); + ok(hr == D3D_OK, "ID3DXFont_GetGlyphData returned %#x, expected %#x\n", hr, D3D_OK); + ok(!texture, "Got unexpected texture\n"); } check_release((IUnknown*)font, 0); @@ -626,12 +624,13 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) ok(ret != GDI_ERROR, "GetGlyphIndicesA failed\n"); hr = ID3DXFont_GetGlyphData(font, glyph, &texture, NULL, NULL); - todo_wine ok(hr == D3D_OK, "ID3DXFont_GetGlyphData returned %#x, expected %#x\n", hr, D3D_OK); + ok(hr == D3D_OK, "ID3DXFont_GetGlyphData returned %#x, expected %#x\n", hr, D3D_OK); if(SUCCEEDED(hr)) { DWORD levels; D3DSURFACE_DESC desc; levels = IDirect3DTexture9_GetLevelCount(texture); + todo_wine_if(tests[i].expected_levels < 9) ok(levels == tests[i].expected_levels, "Got levels %u, expected %u\n", levels, tests[i].expected_levels); hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc); -- 2.24.0