Based on a patch by Tony Wasserka.
Signed-off-by: Sven Baars sbaars@codeweavers.com --- v2: Matteo's changes + a fix for the compiler warning.
dlls/d3dx9_36/font.c | 288 ++++++++++++++++++++++++++++++++----- dlls/d3dx9_36/tests/core.c | 5 +- 2 files changed, 253 insertions(+), 40 deletions(-)
diff --git a/dlls/d3dx9_36/font.c b/dlls/d3dx9_36/font.c index cb09af22f5..b5481785a0 100644 --- a/dlls/d3dx9_36/font.c +++ b/dlls/d3dx9_36/font.c @@ -22,6 +22,16 @@
WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
+struct d3dx_glyph +{ + unsigned int id; + RECT black_box; + POINT cell_inc; + IDirect3DTexture9 *texture; + + struct wine_rb_entry entry; +}; + struct d3dx_font { ID3DXFont ID3DXFont_iface; @@ -29,11 +39,34 @@ struct d3dx_font
IDirect3DDevice9 *device; D3DXFONT_DESCW desc; + TEXTMETRICW metrics;
HDC hdc; HFONT hfont; + + struct wine_rb_tree glyph_tree; + + IDirect3DTexture9 **textures; + unsigned int texture_count, texture_pos; + + unsigned int texture_size, glyph_size, glyphs_per_texture; };
+static int glyph_rb_compare(const void *key, const struct wine_rb_entry *entry) +{ + struct d3dx_glyph *glyph = WINE_RB_ENTRY_VALUE(entry, struct d3dx_glyph, entry); + unsigned int id = (UINT_PTR)key; + + return id - glyph->id; +} + +static void glyph_rb_free(struct wine_rb_entry *entry, void *context) +{ + struct d3dx_glyph *glyph = WINE_RB_ENTRY_VALUE(entry, struct d3dx_glyph, entry); + + heap_free(glyph); +} + static inline struct d3dx_font *impl_from_ID3DXFont(ID3DXFont *iface) { return CONTAINING_RECORD(iface, struct d3dx_font, ID3DXFont_iface); @@ -59,85 +92,95 @@ static HRESULT WINAPI ID3DXFontImpl_QueryInterface(ID3DXFont *iface, REFIID riid
static ULONG WINAPI ID3DXFontImpl_AddRef(ID3DXFont *iface) { - struct d3dx_font *This = impl_from_ID3DXFont(iface); - ULONG ref=InterlockedIncrement(&This->ref); + struct d3dx_font *font = impl_from_ID3DXFont(iface); + ULONG ref = InterlockedIncrement(&font->ref); + TRACE("%p increasing refcount to %u\n", iface, ref); return ref; }
static ULONG WINAPI ID3DXFontImpl_Release(ID3DXFont *iface) { - struct d3dx_font *This = impl_from_ID3DXFont(iface); - ULONG ref=InterlockedDecrement(&This->ref); + struct d3dx_font *font = impl_from_ID3DXFont(iface); + ULONG ref = InterlockedDecrement(&font->ref); + unsigned int i;
TRACE("%p decreasing refcount to %u\n", iface, ref);
- if(ref==0) { - DeleteObject(This->hfont); - DeleteDC(This->hdc); - IDirect3DDevice9_Release(This->device); - HeapFree(GetProcessHeap(), 0, This); + if (!ref) + { + for (i = 0; i < font->texture_count; ++i) + IDirect3DTexture9_Release(font->textures[i]); + + heap_free(font->textures); + + wine_rb_destroy(&font->glyph_tree, glyph_rb_free, NULL); + + DeleteObject(font->hfont); + DeleteDC(font->hdc); + IDirect3DDevice9_Release(font->device); + heap_free(font); } return ref; }
static HRESULT WINAPI ID3DXFontImpl_GetDevice(ID3DXFont *iface, IDirect3DDevice9 **device) { - struct d3dx_font *This = impl_from_ID3DXFont(iface); + struct d3dx_font *font = impl_from_ID3DXFont(iface);
TRACE("iface %p, device %p\n", iface, device);
if( !device ) return D3DERR_INVALIDCALL; - *device = This->device; - IDirect3DDevice9_AddRef(This->device); + *device = font->device; + IDirect3DDevice9_AddRef(font->device);
return D3D_OK; }
static HRESULT WINAPI ID3DXFontImpl_GetDescA(ID3DXFont *iface, D3DXFONT_DESCA *desc) { - struct d3dx_font *This = impl_from_ID3DXFont(iface); + struct d3dx_font *font = impl_from_ID3DXFont(iface);
TRACE("iface %p, desc %p\n", iface, desc);
if( !desc ) return D3DERR_INVALIDCALL; - memcpy(desc, &This->desc, FIELD_OFFSET(D3DXFONT_DESCA, FaceName)); - WideCharToMultiByte(CP_ACP, 0, This->desc.FaceName, -1, desc->FaceName, ARRAY_SIZE(desc->FaceName), NULL, NULL); + memcpy(desc, &font->desc, FIELD_OFFSET(D3DXFONT_DESCA, FaceName)); + WideCharToMultiByte(CP_ACP, 0, font->desc.FaceName, -1, desc->FaceName, ARRAY_SIZE(desc->FaceName), NULL, NULL);
return D3D_OK; }
static HRESULT WINAPI ID3DXFontImpl_GetDescW(ID3DXFont *iface, D3DXFONT_DESCW *desc) { - struct d3dx_font *This = impl_from_ID3DXFont(iface); + struct d3dx_font *font = impl_from_ID3DXFont(iface);
TRACE("iface %p, desc %p\n", iface, desc);
if( !desc ) return D3DERR_INVALIDCALL; - *desc = This->desc; + *desc = font->desc;
return D3D_OK; }
static BOOL WINAPI ID3DXFontImpl_GetTextMetricsA(ID3DXFont *iface, TEXTMETRICA *metrics) { - struct d3dx_font *This = impl_from_ID3DXFont(iface); + struct d3dx_font *font = impl_from_ID3DXFont(iface); TRACE("iface %p, metrics %p\n", iface, metrics); - return GetTextMetricsA(This->hdc, metrics); + return GetTextMetricsA(font->hdc, metrics); }
static BOOL WINAPI ID3DXFontImpl_GetTextMetricsW(ID3DXFont *iface, TEXTMETRICW *metrics) { - struct d3dx_font *This = impl_from_ID3DXFont(iface); + struct d3dx_font *font = impl_from_ID3DXFont(iface); TRACE("iface %p, metrics %p\n", iface, metrics); - return GetTextMetricsW(This->hdc, metrics); + return GetTextMetricsW(font->hdc, metrics); }
static HDC WINAPI ID3DXFontImpl_GetDC(ID3DXFont *iface) { - struct d3dx_font *This = impl_from_ID3DXFont(iface); + struct d3dx_font *font = impl_from_ID3DXFont(iface); TRACE("iface %p\n", iface); - return This->hdc; + return font->hdc; }
static HRESULT WINAPI ID3DXFontImpl_GetGlyphData(ID3DXFont *iface, UINT glyph, @@ -154,10 +197,156 @@ static HRESULT WINAPI ID3DXFontImpl_PreloadCharacters(ID3DXFont *iface, UINT fir return S_OK; }
+static uint32_t morton_decode(uint32_t x) +{ + x &= 0x55555555; + x = (x ^ (x >> 1)) & 0x33333333; + x = (x ^ (x >> 2)) & 0x0f0f0f0f; + x = (x ^ (x >> 4)) & 0x00ff00ff; + x = (x ^ (x >> 8)) & 0x0000ffff; + return x; +} + +/* The glyphs are stored in a grid. Cell sizes vary between different font + * sizes. + * + * The grid is filled in Morton order: + * 1 2 5 6 17 18 21 22 + * 3 4 7 8 19 20 23 24 + * 9 10 13 14 25 26 29 30 + * 11 12 15 16 27 28 31 32 + * 33 34 ... + * ... + * + * i.e. we try to fill one small square, then three equal-sized squares so + * that we get one big square, etc. + * + * The glyphs are positioned around their baseline, which is located at y + * position glyph_size * i + tmAscent. Concerning the x position, the glyphs + * are centered around glyph_size * (i + 0.5). */ static HRESULT WINAPI ID3DXFontImpl_PreloadGlyphs(ID3DXFont *iface, UINT first, UINT last) { - FIXME("iface %p, first %u, last %u stub!\n", iface, first, last); - return E_NOTIMPL; + static const MAT2 mat = { {0,1}, {0,0}, {0,0}, {0,1} }; + struct d3dx_font *font = impl_from_ID3DXFont(iface); + IDirect3DTexture9 *current_texture = NULL; + unsigned int size, stride, glyph, x, y; + struct d3dx_glyph *current_glyph; + D3DLOCKED_RECT lockrect; + GLYPHMETRICS metrics; + BOOL mapped = FALSE; + DWORD *pixel_data; + BYTE *buffer; + HRESULT hr; + + TRACE("iface %p, first %u, last %u\n", iface, first, last); + + if (last < first) + return D3D_OK; + + if (font->texture_count) + current_texture = font->textures[font->texture_count - 1]; + + for (glyph = first; glyph <= last; ++glyph) + { + if (wine_rb_get(&font->glyph_tree, ULongToPtr(glyph))) + continue; + + current_glyph = heap_alloc(sizeof(*current_glyph)); + if (!current_glyph) + { + if (mapped) + IDirect3DTexture9_UnlockRect(current_texture, 0); + return E_OUTOFMEMORY; + } + + current_glyph->id = glyph; + current_glyph->texture = NULL; + wine_rb_put(&font->glyph_tree, ULongToPtr(current_glyph->id), ¤t_glyph->entry); + + size = GetGlyphOutlineW(font->hdc, glyph, GGO_GLYPH_INDEX | GGO_GRAY8_BITMAP, &metrics, 0, NULL, &mat); + if (size == GDI_ERROR) + { + WARN("GetGlyphOutlineW failed\n"); + continue; + } + if (!size) + continue; + + buffer = heap_alloc(size); + if (!buffer) + { + if (mapped) + IDirect3DTexture9_UnlockRect(current_texture, 0); + return E_OUTOFMEMORY; + } + + GetGlyphOutlineW(font->hdc, glyph, GGO_GLYPH_INDEX | GGO_GRAY8_BITMAP, &metrics, size, buffer, &mat); + + if (font->texture_pos == font->glyphs_per_texture) + { + unsigned int new_texture_count = font->texture_count + 1; + IDirect3DTexture9 **new_textures; + + if (mapped) + IDirect3DTexture9_UnlockRect(current_texture, 0); + mapped = FALSE; + new_textures = heap_realloc(font->textures, new_texture_count * sizeof(*new_textures)); + if (!new_textures) + { + heap_free(buffer); + return E_OUTOFMEMORY; + } + font->textures = new_textures; + + if (FAILED(hr = IDirect3DDevice9_CreateTexture(font->device, font->texture_size, + font->texture_size, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, + &font->textures[font->texture_count], NULL))) + { + heap_free(buffer); + return hr; + } + + current_texture = font->textures[font->texture_count++]; + font->texture_pos = 0; + } + + if (!mapped) + { + if (FAILED(hr = IDirect3DTexture9_LockRect(current_texture, 0, &lockrect, NULL, 0))) + { + heap_free(buffer); + return hr; + } + mapped = TRUE; + } + + x = morton_decode(font->texture_pos) * font->glyph_size; + y = morton_decode(font->texture_pos >> 1) * font->glyph_size; + + current_glyph->black_box.left = x - metrics.gmptGlyphOrigin.x + font->glyph_size / 2 + - metrics.gmBlackBoxX / 2; + current_glyph->black_box.top = y - metrics.gmptGlyphOrigin.y + font->metrics.tmAscent + 1; + current_glyph->black_box.right = current_glyph->black_box.left + metrics.gmBlackBoxX; + current_glyph->black_box.bottom = current_glyph->black_box.top + metrics.gmBlackBoxY; + current_glyph->cell_inc.x = metrics.gmptGlyphOrigin.x - 1; + current_glyph->cell_inc.y = font->metrics.tmAscent - metrics.gmptGlyphOrigin.y - 1; + current_glyph->texture = current_texture; + + pixel_data = lockrect.pBits; + stride = (metrics.gmBlackBoxX + 3) & ~3; + for (y = 0; y < metrics.gmBlackBoxY; ++y) + for (x = 0; x < metrics.gmBlackBoxX; ++x) + pixel_data[(current_glyph->black_box.top + y) * lockrect.Pitch / 4 + + current_glyph->black_box.left + x] = + (buffer[y * stride + x] * 255 / 64 << 24) | 0x00ffffffu; + + heap_free(buffer); + ++font->texture_pos; + } + if (mapped) + IDirect3DTexture9_UnlockRect(current_texture, 0); + + return D3D_OK; }
static HRESULT WINAPI ID3DXFontImpl_PreloadTextA(ID3DXFont *iface, const char *string, INT count) @@ -291,8 +480,8 @@ HRESULT WINAPI D3DXCreateFontIndirectA(IDirect3DDevice9 *device, const D3DXFONT_ HRESULT WINAPI D3DXCreateFontIndirectW(IDirect3DDevice9 *device, const D3DXFONT_DESCW *desc, ID3DXFont **font) { D3DDEVICE_CREATION_PARAMETERS cpars; - D3DDISPLAYMODE mode; struct d3dx_font *object; + D3DDISPLAYMODE mode; IDirect3D9 *d3d; HRESULT hr;
@@ -305,39 +494,62 @@ HRESULT WINAPI D3DXCreateFontIndirectW(IDirect3DDevice9 *device, const D3DXFONT_ IDirect3DDevice9_GetCreationParameters(device, &cpars); IDirect3DDevice9_GetDisplayMode(device, 0, &mode); hr = IDirect3D9_CheckDeviceFormat(d3d, cpars.AdapterOrdinal, cpars.DeviceType, mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8); - if(FAILED(hr)) { + if (FAILED(hr)) + { IDirect3D9_Release(d3d); return D3DXERR_INVALIDDATA; } IDirect3D9_Release(d3d);
- object = HeapAlloc(GetProcessHeap(), 0, sizeof(struct d3dx_font)); - if(object==NULL) { - *font=NULL; + object = heap_alloc_zero(sizeof(struct d3dx_font)); + if (!object) + { + *font = NULL; return E_OUTOFMEMORY; } object->ID3DXFont_iface.lpVtbl = &D3DXFont_Vtbl; - object->ref=1; - object->device=device; - object->desc=*desc; + object->ref = 1; + object->device = device; + object->desc = *desc;
object->hdc = CreateCompatibleDC(NULL); - if( !object->hdc ) { - HeapFree(GetProcessHeap(), 0, object); + if (!object->hdc) + { + heap_free(object); return D3DXERR_INVALIDDATA; }
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 ) { + if (!object->hfont) + { DeleteDC(object->hdc); - HeapFree(GetProcessHeap(), 0, object); + heap_free(object); return D3DXERR_INVALIDDATA; } SelectObject(object->hdc, object->hfont);
+ wine_rb_init(&object->glyph_tree, glyph_rb_compare); + + if (!GetTextMetricsW(object->hdc, &object->metrics)) + { + DeleteObject(object->hfont); + DeleteDC(object->hdc); + heap_free(object); + return D3DXERR_INVALIDDATA; + } + + object->glyph_size = make_pow2(object->metrics.tmHeight); + + object->texture_size = object->glyph_size; + if (object->glyph_size < 256) + object->texture_size = min(256, object->texture_size * 16); + + object->glyphs_per_texture = object->texture_size * object->texture_size / (object->glyph_size * object->glyph_size); + object->texture_pos = object->glyphs_per_texture; + IDirect3DDevice9_AddRef(device); - *font=&object->ID3DXFont_iface; + *font = &object->ID3DXFont_iface;
return D3D_OK; } diff --git a/dlls/d3dx9_36/tests/core.c b/dlls/d3dx9_36/tests/core.c index c44473396b..22d265b9fc 100644 --- a/dlls/d3dx9_36/tests/core.c +++ b/dlls/d3dx9_36/tests/core.c @@ -556,7 +556,7 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) hr = ID3DXFont_PreloadCharacters(font, 'b', 'a'); ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); hr = ID3DXFont_PreloadGlyphs(font, 1, 0); - todo_wine ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
hr = ID3DXFont_PreloadCharacters(font, 'a', 'a'); ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); @@ -586,6 +586,7 @@ static void test_ID3DXFont(IDirect3DDevice9 *device)
ret = ID3DXFont_GetTextMetricsW(font, &tm); ok(ret, "Got unexpected ret %#x.\n", ret); + ok(blackbox.right - blackbox.left == glyph_metrics.gmBlackBoxX + 2, "Character %c: got %d, expected %d.\n", c, blackbox.right - blackbox.left, glyph_metrics.gmBlackBoxX + 2); ok(blackbox.bottom - blackbox.top == glyph_metrics.gmBlackBoxY + 2, "Character %c: got %d, expected %d.\n", @@ -603,7 +604,7 @@ static void test_ID3DXFont(IDirect3DDevice9 *device)
/* Test multiple textures */ hr = ID3DXFont_PreloadGlyphs(font, 0, 1000); - todo_wine ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
/* Test glyphs that are not rendered */ for (glyph = 1; glyph < 4; ++glyph)
Based on a patch by Tony Wasserka.
Signed-off-by: Sven Baars sbaars@codeweavers.com --- v2: rename blackbox to black_box, cellinc to cell_inc, use the new rb_tree index
dlls/d3dx9_36/font.c | 35 ++++++++++++++++++++++--- dlls/d3dx9_36/tests/core.c | 53 +++++++++++++++++--------------------- 2 files changed, 55 insertions(+), 33 deletions(-)
diff --git a/dlls/d3dx9_36/font.c b/dlls/d3dx9_36/font.c index b5481785a0..03dc7544b3 100644 --- a/dlls/d3dx9_36/font.c +++ b/dlls/d3dx9_36/font.c @@ -184,11 +184,38 @@ static HDC WINAPI ID3DXFontImpl_GetDC(ID3DXFont *iface) }
static HRESULT WINAPI ID3DXFontImpl_GetGlyphData(ID3DXFont *iface, UINT glyph, - IDirect3DTexture9 **texture, RECT *blackbox, POINT *cellinc) + IDirect3DTexture9 **texture, RECT *black_box, POINT *cell_inc) { - FIXME("iface %p, glyph %#x, texture %p, blackbox %p, cellinc %p stub!\n", - iface, glyph, texture, blackbox, cellinc); - return E_NOTIMPL; + struct d3dx_font *font = impl_from_ID3DXFont(iface); + struct wine_rb_entry *entry; + HRESULT hr; + + TRACE("iface %p, glyph %#x, texture %p, black_box %p, cell_inc %p\n", + iface, glyph, texture, black_box, cell_inc); + + hr = ID3DXFont_PreloadGlyphs(iface, glyph, glyph); + if (FAILED(hr)) + return hr; + + entry = wine_rb_get(&font->glyph_tree, ULongToPtr(glyph)); + if (entry) + { + struct d3dx_glyph *current_glyph = WINE_RB_ENTRY_VALUE(entry, struct d3dx_glyph, entry); + + if (cell_inc) + *cell_inc = current_glyph->cell_inc; + if (black_box) + *black_box = current_glyph->black_box; + if (texture) + { + *texture = current_glyph->texture; + if (*texture) + IDirect3DTexture9_AddRef(current_glyph->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 22d265b9fc..b8e680d1c5 100644 --- a/dlls/d3dx9_36/tests/core.c +++ b/dlls/d3dx9_36/tests/core.c @@ -543,16 +543,15 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) hdc = ID3DXFont_GetDC(font); ok(!!hdc, "Got unexpected hdc %p.\n", hdc);
- todo_wine { hr = ID3DXFont_GetGlyphData(font, 0, NULL, &blackbox, &cellinc); ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); hr = ID3DXFont_GetGlyphData(font, 0, &texture, NULL, &cellinc); - if(SUCCEEDED(hr)) check_release((IUnknown *)texture, 1); + check_release((IUnknown *)texture, 1); ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); hr = ID3DXFont_GetGlyphData(font, 0, &texture, &blackbox, NULL); - if(SUCCEEDED(hr)) check_release((IUnknown *)texture, 1); + check_release((IUnknown *)texture, 1); ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - } + hr = ID3DXFont_PreloadCharacters(font, 'b', 'a'); ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); hr = ID3DXFont_PreloadGlyphs(font, 1, 0); @@ -567,12 +566,10 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) ok(count != GDI_ERROR, "Got unexpected count %u.\n", count);
hr = ID3DXFont_GetGlyphData(font, glyph, &texture, &blackbox, &cellinc); - todo_wine ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - if (FAILED(hr)) - continue; + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
levels = IDirect3DTexture9_GetLevelCount(texture); - ok(levels == 5, "Character %c: got unexpected levels %u.\n", c, levels); + todo_wine ok(levels == 5, "Character %c: got unexpected levels %u.\n", c, levels); hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &surf_desc); ok(hr == D3D_OK, "Character %c: got unexpected hr %#x.\n", c, hr); ok(surf_desc.Format == D3DFMT_A8R8G8B8, "Character %c: got unexpected format %#x.\n", c, surf_desc.Format); @@ -587,9 +584,9 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) ret = ID3DXFont_GetTextMetricsW(font, &tm); ok(ret, "Got unexpected ret %#x.\n", ret);
- ok(blackbox.right - blackbox.left == glyph_metrics.gmBlackBoxX + 2, "Character %c: got %d, expected %d.\n", + todo_wine ok(blackbox.right - blackbox.left == glyph_metrics.gmBlackBoxX + 2, "Character %c: got %d, expected %d.\n", c, blackbox.right - blackbox.left, glyph_metrics.gmBlackBoxX + 2); - ok(blackbox.bottom - blackbox.top == glyph_metrics.gmBlackBoxY + 2, "Character %c: got %d, expected %d.\n", + todo_wine ok(blackbox.bottom - blackbox.top == glyph_metrics.gmBlackBoxY + 2, "Character %c: got %d, expected %d.\n", c, blackbox.bottom - blackbox.top, glyph_metrics.gmBlackBoxY + 2); ok(cellinc.x == glyph_metrics.gmptGlyphOrigin.x - 1, "Character %c: got %d, expected %d.\n", c, cellinc.x, glyph_metrics.gmptGlyphOrigin.x - 1); @@ -611,8 +608,8 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) { texture = (IDirect3DTexture9 *)0xdeadbeef; hr = ID3DXFont_GetGlyphData(font, glyph, &texture, &blackbox, &cellinc); - todo_wine ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - todo_wine ok(!texture, "Got unexpected texture %p.\n", texture); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + ok(!texture, "Got unexpected texture %p.\n", texture); }
check_release((IUnknown *)font, 0); @@ -631,23 +628,21 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) ok(count != GDI_ERROR, "Test %u: got unexpected count %u.\n", i, count);
hr = ID3DXFont_GetGlyphData(font, glyph, &texture, NULL, NULL); - todo_wine ok(hr == D3D_OK, "Test %u: got unexpected hr %#x.\n", i, hr); - if(SUCCEEDED(hr)) { - DWORD levels; - D3DSURFACE_DESC desc; - - levels = IDirect3DTexture9_GetLevelCount(texture); - ok(levels == tests[i].expected_levels, "Test %u: got unexpected levels %u.\n", i, levels); - hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - ok(desc.Format == D3DFMT_A8R8G8B8, "Test %u: got unexpected format %#x.\n", i, desc.Format); - ok(desc.Usage == 0, "Test %u: got unexpected usage %#x.\n", i, desc.Usage); - ok(desc.Width == tests[i].expected_size, "Test %u: got unexpected width %u.\n", i, desc.Width); - ok(desc.Height == tests[i].expected_size, "Test %u: got unexpected height %u.\n", i, desc.Height); - ok(desc.Pool == D3DPOOL_MANAGED, "Test %u: got unexpected pool %u.\n", i, desc.Pool); - - IDirect3DTexture9_Release(texture); - } + ok(hr == D3D_OK, "Test %u: got unexpected hr %#x.\n", i, hr); + + levels = IDirect3DTexture9_GetLevelCount(texture); + todo_wine_if(tests[i].expected_levels < 9) + ok(levels == tests[i].expected_levels, "Test %u: got unexpected levels %u.\n", i, levels); + + hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &surf_desc); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + ok(surf_desc.Format == D3DFMT_A8R8G8B8, "Test %u: got unexpected format %#x.\n", i, surf_desc.Format); + ok(surf_desc.Usage == 0, "Test %u: got unexpected usage %#x.\n", i, surf_desc.Usage); + ok(surf_desc.Width == tests[i].expected_size, "Test %u: got unexpected width %u.\n", i, surf_desc.Width); + ok(surf_desc.Height == tests[i].expected_size, "Test %u: got unexpected height %u.\n", i, surf_desc.Height); + ok(surf_desc.Pool == D3DPOOL_MANAGED, "Test %u: got unexpected pool %u.\n", i, surf_desc.Pool); + + IDirect3DTexture9_Release(texture);
/* ID3DXFontImpl_DrawText */ D3DXCreateSprite(device, &sprite);
Based on a patch by Tony Wasserka.
Signed-off-by: Sven Baars sbaars@codeweavers.com --- dlls/d3dx9_36/font.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)
diff --git a/dlls/d3dx9_36/font.c b/dlls/d3dx9_36/font.c index 03dc7544b3..00ba068f8e 100644 --- a/dlls/d3dx9_36/font.c +++ b/dlls/d3dx9_36/font.c @@ -220,8 +220,39 @@ static HRESULT WINAPI ID3DXFontImpl_GetGlyphData(ID3DXFont *iface, UINT glyph,
static HRESULT WINAPI ID3DXFontImpl_PreloadCharacters(ID3DXFont *iface, UINT first, UINT last) { - FIXME("iface %p, first %u, last %u stub!\n", iface, first, last); - return S_OK; + struct d3dx_font *font = impl_from_ID3DXFont(iface); + UINT i, count; + WORD *indices; + WCHAR *chars; + + TRACE("iface %p, first %u, last %u\n", iface, first, last); + + if (last < first) return D3D_OK; + + count = last - first + 1; + indices = heap_alloc(count * sizeof(WORD)); + if (!indices) + return E_OUTOFMEMORY; + + chars = heap_alloc(count * sizeof(WCHAR)); + if (!chars) + { + heap_free(indices); + return E_OUTOFMEMORY; + } + + for (i = 0; i < count; ++i) + chars[i] = (WCHAR)(first + i); + + GetGlyphIndicesW(font->hdc, chars, count, indices, 0); + + for (i = 0; i < count; ++i) + ID3DXFont_PreloadGlyphs(iface, indices[i], indices[i]); + + heap_free(chars); + heap_free(indices); + + return D3D_OK; }
static uint32_t morton_decode(uint32_t x)
Based on a patch by Tony Wasserka.
Signed-off-by: Sven Baars sbaars@codeweavers.com --- dlls/d3dx9_36/font.c | 48 ++++++++++++++++++++++++++++++++++---- dlls/d3dx9_36/tests/core.c | 2 -- 2 files changed, 44 insertions(+), 6 deletions(-)
diff --git a/dlls/d3dx9_36/font.c b/dlls/d3dx9_36/font.c index 00ba068f8e..44bd08a9fb 100644 --- a/dlls/d3dx9_36/font.c +++ b/dlls/d3dx9_36/font.c @@ -409,14 +409,54 @@ 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_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 *font = impl_from_ID3DXFont(iface); + WORD *indices; + UINT i; + + 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(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);
On Wed, Feb 26, 2020 at 12:10 PM Sven Baars sbaars@codeweavers.com wrote:
Based on a patch by Tony Wasserka.
Signed-off-by: Sven Baars sbaars@codeweavers.com
dlls/d3dx9_36/font.c | 48 ++++++++++++++++++++++++++++++++++---- dlls/d3dx9_36/tests/core.c | 2 -- 2 files changed, 44 insertions(+), 6 deletions(-)
diff --git a/dlls/d3dx9_36/font.c b/dlls/d3dx9_36/font.c index 00ba068f8e..44bd08a9fb 100644 --- a/dlls/d3dx9_36/font.c +++ b/dlls/d3dx9_36/font.c @@ -409,14 +409,54 @@ 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_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 *font = impl_from_ID3DXFont(iface);
- WORD *indices;
- UINT i;
- 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(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);
-- 2.24.0
Hi Sven,
this patch (like the others) needs to be updated to the current d3d style: no INT / UINT (or otherwise Windows-specific) local variable types when there is no particular reason, period at the end of trace messages, body of a single instruction if on the next line, use sizeof(*var) in heap_alloc() instead of sizeof(type).
Based on a patch by Tony Wasserka.
Signed-off-by: Sven Baars sbaars@codeweavers.com --- dlls/d3dx9_36/font.c | 125 +++++++++++++++++++++++++++++++++++-- dlls/d3dx9_36/tests/core.c | 59 ++++++++--------- 2 files changed, 146 insertions(+), 38 deletions(-)
diff --git a/dlls/d3dx9_36/font.c b/dlls/d3dx9_36/font.c index 44bd08a9fb..861d083cf7 100644 --- a/dlls/d3dx9_36/font.c +++ b/dlls/d3dx9_36/font.c @@ -462,17 +462,130 @@ 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_a(string), count, wine_dbgstr_rect(rect), format, color); + + if (!string || count == 0) + return 0; + + countW = MultiByteToWideChar(CP_ACP, 0, string, count < 0 ? -1 : count, NULL, 0); + + if (countW == 0) + return 0; + + wstr = heap_alloc_zero(countW * sizeof(WCHAR)); + if (!wstr) + return 0; + + MultiByteToWideChar(CP_ACP, 0, string, count < 0 ? -1 : count, wstr, countW); + + ret = ID3DXFont_DrawTextW(iface, sprite, wstr, count, 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_w(string), count, wine_dbgstr_rect(rect), format, color); + + if (!string) + return 0; + + if (count < 0) + count = lstrlenW(string); + + if (count == 0) + 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; + UINT i; + + ZeroMemory(&results, sizeof(GCP_RESULTSW)); + results.nGlyphs = count; + + results.lpCaretPos = heap_alloc(count * sizeof(INT)); + if (!results.lpCaretPos) + goto cleanup; + + results.lpGlyphs = heap_alloc(count * sizeof(WCHAR)); + if (!results.lpGlyphs) + { + heap_free(results.lpCaretPos); + goto cleanup; + } + + GetCharacterPlacementW(font->hdc, string, count, 0, &results, 0); + + for (i = 0; i < results.nGlyphs; ++i) + { + LPDIRECT3DTEXTURE9 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); }
On Wed, Feb 26, 2020 at 12:10 PM Sven Baars sbaars@codeweavers.com wrote:
Based on a patch by Tony Wasserka.
Signed-off-by: Sven Baars sbaars@codeweavers.com
dlls/d3dx9_36/font.c | 125 +++++++++++++++++++++++++++++++++++-- dlls/d3dx9_36/tests/core.c | 59 ++++++++--------- 2 files changed, 146 insertions(+), 38 deletions(-)
I have a number of style nitpicks in addition to those mentioned in reply to the previous patch, inline.
diff --git a/dlls/d3dx9_36/font.c b/dlls/d3dx9_36/font.c index 44bd08a9fb..861d083cf7 100644 --- a/dlls/d3dx9_36/font.c +++ b/dlls/d3dx9_36/font.c @@ -462,17 +462,130 @@ 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_a(string), count, wine_dbgstr_rect(rect), format, color);
- if (!string || count == 0)
return 0;
!count
- countW = MultiByteToWideChar(CP_ACP, 0, string, count < 0 ? -1 : count, NULL, 0);
- if (countW == 0)
return 0;
- wstr = heap_alloc_zero(countW * sizeof(WCHAR));
- if (!wstr)
return 0;
- MultiByteToWideChar(CP_ACP, 0, string, count < 0 ? -1 : count, wstr, countW);
- ret = ID3DXFont_DrawTextW(iface, sprite, wstr, count, 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_w(string), count, wine_dbgstr_rect(rect), format, color);
- if (!string)
return 0;
- if (count < 0)
count = lstrlenW(string);
- if (count == 0)
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;
If one of the branches of the if requires braces, the other one should have them too.
- 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;
UINT i;
ZeroMemory(&results, sizeof(GCP_RESULTSW));
Just memset() instead. Also you want to use sizeof(results), like in the memory allocation functions.
results.nGlyphs = count;
results.lpCaretPos = heap_alloc(count * sizeof(INT));
if (!results.lpCaretPos)
goto cleanup;
results.lpGlyphs = heap_alloc(count * sizeof(WCHAR));
if (!results.lpGlyphs)
{
heap_free(results.lpCaretPos);
goto cleanup;
}
GetCharacterPlacementW(font->hdc, string, count, 0, &results, 0);
for (i = 0; i < results.nGlyphs; ++i)
{
LPDIRECT3DTEXTURE9 texture;
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;
}