From 5e0577c2b85fd0e5fa35e467d93a17f2cdbf834a Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Mon, 30 Aug 2021 08:08:09 +0300 Subject: [PATCH] d3dx10/font: Create gdi objects on font object creation. Signed-off-by: Nikolay Sivov Signed-off-by: Matteo Bruni Signed-off-by: Alexandre Julliard --- dlls/d3dx10_43/Makefile.in | 2 +- dlls/d3dx10_43/font.c | 30 ++++++++++++++++++++++++++---- dlls/d3dx10_43/tests/d3dx10.c | 33 ++++++++++++++++++--------------- 3 files changed, 45 insertions(+), 20 deletions(-) diff --git a/dlls/d3dx10_43/Makefile.in b/dlls/d3dx10_43/Makefile.in index b6baed2b619..5509bca7e08 100644 --- a/dlls/d3dx10_43/Makefile.in +++ b/dlls/d3dx10_43/Makefile.in @@ -1,6 +1,6 @@ MODULE = d3dx10_43.dll IMPORTLIB = d3dx10 -IMPORTS = d3d10_1 d3dcompiler dxguid uuid +IMPORTS = d3d10_1 d3dcompiler dxguid uuid gdi32 DELAYIMPORTS = windowscodecs EXTRADLLFLAGS = -mno-cygwin -Wb,--prefer-native diff --git a/dlls/d3dx10_43/font.c b/dlls/d3dx10_43/font.c index 77604895903..d1590c8cc99 100644 --- a/dlls/d3dx10_43/font.c +++ b/dlls/d3dx10_43/font.c @@ -32,6 +32,8 @@ struct d3dx_font ID3DX10Font ID3DX10Font_iface; LONG refcount; + HDC hdc; + HFONT hfont; D3DX10_FONT_DESCW desc; ID3D10Device *device; }; @@ -77,6 +79,8 @@ static ULONG WINAPI d3dx_font_Release(ID3DX10Font *iface) if (!refcount) { + DeleteObject(font->hfont); + DeleteDC(font->hdc); ID3D10Device_Release(font->device); heap_free(font); } @@ -142,9 +146,11 @@ static BOOL WINAPI d3dx_font_GetTextMetricsW(ID3DX10Font *iface, TEXTMETRICW *me static HDC WINAPI d3dx_font_GetDC(ID3DX10Font *iface) { - FIXME("iface %p stub!\n", iface); + struct d3dx_font *font = impl_from_ID3DX10Font(iface); - return NULL; + TRACE("iface %p.\n", iface); + + return font->hdc; } static HRESULT WINAPI d3dx_font_GetGlyphData(ID3DX10Font *iface, UINT glyph, @@ -353,12 +359,28 @@ HRESULT WINAPI D3DX10CreateFontIndirectW(ID3D10Device *device, const D3DX10_FONT if (!device || !desc || !font) return D3DERR_INVALIDCALL; + *font = NULL; + if (!(object = heap_alloc_zero(sizeof(*object)))) - { - *font = NULL; return E_OUTOFMEMORY; + + object->hdc = CreateCompatibleDC(NULL); + if (!object->hdc) + { + heap_free(object); + return E_FAIL; } + object->hfont = CreateFontW(desc->Height, desc->Width, 0, 0, desc->Weight, desc->Italic, FALSE, FALSE, desc->CharSet, + desc->OutputPrecision, CLIP_DEFAULT_PRECIS, desc->Quality, desc->PitchAndFamily, desc->FaceName); + if (!object->hfont) + { + DeleteDC(object->hdc); + heap_free(object); + return E_FAIL; + } + SelectObject(object->hdc, object->hfont); + object->ID3DX10Font_iface.lpVtbl = &d3dx_font_vtbl; object->refcount = 1; object->device = device; diff --git a/dlls/d3dx10_43/tests/d3dx10.c b/dlls/d3dx10_43/tests/d3dx10.c index eec2bfd3206..499d219924d 100644 --- a/dlls/d3dx10_43/tests/d3dx10.c +++ b/dlls/d3dx10_43/tests/d3dx10.c @@ -2200,13 +2200,12 @@ static void test_font(void) ok(hr == S_OK, "Unexpected hr %#x.\n", hr); hdc = ID3DX10Font_GetDC(font); -todo_wine ok(!!hdc, "Unexpected hdc %p.\n", hdc); - ret = ID3DX10Font_GetTextMetricsA(font, &metrics); -todo_wine - ok(ret, "Unexpected ret %#x.\n", ret); ret = GetTextMetricsA(hdc, &expmetrics); + ok(ret, "Unexpected ret %#x.\n", ret); + + ret = ID3DX10Font_GetTextMetricsA(font, &metrics); todo_wine ok(ret, "Unexpected ret %#x.\n", ret); @@ -2303,7 +2302,6 @@ todo_wine ok(hr == S_OK, "Unexpected hr %#x.\n", hr); hdc = ID3DX10Font_GetDC(font); -todo_wine ok(!!hdc, "Unexpected hdc %p.\n", hdc); hr = ID3DX10Font_GetGlyphData(font, 0, NULL, &blackbox, &cellinc); @@ -2333,15 +2331,20 @@ todo_wine for (c = 'b'; c <= 'z'; ++c) { - if (!hdc) break; - winetest_push_context("Character %c", c); count = GetGlyphIndicesA(hdc, &c, 1, &glyph, 0); ok(count != GDI_ERROR, "Unexpected count %u.\n", count); hr = ID3DX10Font_GetGlyphData(font, glyph, &srv, &blackbox, &cellinc); + todo_wine ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + if (FAILED(hr)) + { + winetest_pop_context(); + break; + } + ID3D10ShaderResourceView_GetResource(srv, &resource); hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture2D, (void **)&texture); ok(hr == S_OK, "Unexpected hr %#x.\n", hr); @@ -2415,22 +2418,22 @@ todo_wine ok(hr == S_OK, "Unexpected hr %#x.\n", hr); hdc = ID3DX10Font_GetDC(font); - todo_wine ok(!!hdc, "Unexpected hdc %p.\n", hdc); - if (!hdc) - { - ID3DX10Font_Release(font); - winetest_pop_context(); - break; - } - count = GetGlyphIndicesA(hdc, &c, 1, &glyph, 0); ok(count != GDI_ERROR, "Unexpected count %u.\n", count); hr = ID3DX10Font_GetGlyphData(font, glyph, &srv, NULL, NULL); + todo_wine ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + if (FAILED(hr)) + { + ID3DX10Font_Release(font); + winetest_pop_context(); + break; + } + ID3D10ShaderResourceView_GetResource(srv, &resource); hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture2D, (void **)&texture); ok(hr == S_OK, "Unexpected hr %#x.\n", hr);