Signed-off-by: Sven Baars sbaars@codeweavers.com --- dlls/gdi32/font.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/dlls/gdi32/font.c b/dlls/gdi32/font.c index d451f30c3e..8788426a2c 100644 --- a/dlls/gdi32/font.c +++ b/dlls/gdi32/font.c @@ -3313,6 +3313,9 @@ GetCharacterPlacementW( TRACE("%s, %d, %d, 0x%08x\n", debugstr_wn(lpString, uCount), uCount, nMaxExtent, dwFlags);
+ if (!uCount) + return 0; + if (!lpResults) return GetTextExtentPoint32W(hdc, lpString, uCount, &size) ? MAKELONG(size.cx, size.cy) : 0;
Signed-off-by: Sven Baars sbaars@codeweavers.com --- dlls/d3dx9_36/tests/core.c | 78 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+)
diff --git a/dlls/d3dx9_36/tests/core.c b/dlls/d3dx9_36/tests/core.c index f5c539ca85..c44473396b 100644 --- a/dlls/d3dx9_36/tests/core.c +++ b/dlls/d3dx9_36/tests/core.c @@ -770,6 +770,84 @@ static void test_ID3DXFont(IDirect3DDevice9 *device)
height = ID3DXFont_DrawTextW(font, NULL, long_textW, -1, &rect, DT_WORDBREAK | DT_NOCLIP, 0xff00ff); 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); + + height = ID3DXFont_DrawTextW(font, NULL, L"a\r\na", -1, &rect, 0, 0xff00ff); + 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); + + height = ID3DXFont_DrawTextW(font, NULL, L"a\naaaaa aaaa", -1, &rect, 0, 0xff00ff); + 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); + + 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); + + 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); + + 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); + + 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); + + height = ID3DXFont_DrawTextW(font, NULL, L"\taaaaaaaaaa", -1, &rect, DT_EXPANDTABS | DT_WORDBREAK, 0xff00ff); + 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); + + 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); + + 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); + + 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); + + height = ID3DXFont_DrawTextW(font, NULL, L"aaaaaaaaaaaaaaaaaaaa", -1, &rect, DT_WORDBREAK, 0xff00ff); + 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); + + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_WORDBREAK, 0xff00ff); + 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); + + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_WORDBREAK | DT_RIGHT, 0xff00ff); + 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); + + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_VCENTER, 0xff00ff); + 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); + + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CENTER, 0xff00ff); + ok(height == 24, "Got unexpected height %d.\n", height); }
ID3DXFont_Release(font);
Signed-off-by: Sven Baars sbaars@codeweavers.com --- dlls/d3dx9_36/d3dx9_private.h | 14 ++++++++++++++ dlls/d3dx9_36/texture.c | 15 --------------- 2 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/dlls/d3dx9_36/d3dx9_private.h b/dlls/d3dx9_36/d3dx9_private.h index 61ec320ba5..b1c8db3dff 100644 --- a/dlls/d3dx9_36/d3dx9_private.h +++ b/dlls/d3dx9_36/d3dx9_private.h @@ -225,6 +225,20 @@ static inline BOOL is_param_type_sampler(D3DXPARAMETER_TYPE type) || type == D3DXPT_SAMPLER3D || type == D3DXPT_SAMPLERCUBE; }
+/* Returns the smallest power of 2 which is greater than or equal to num */ +static inline UINT make_pow2(UINT num) +{ + num--; + num |= num >> 1; + num |= num >> 2; + num |= num >> 4; + num |= num >> 8; + num |= num >> 16; + num++; + + return num; +} + struct d3dx_parameter;
enum pres_reg_tables diff --git a/dlls/d3dx9_36/texture.c b/dlls/d3dx9_36/texture.c index d96ade9aed..6af4458904 100644 --- a/dlls/d3dx9_36/texture.c +++ b/dlls/d3dx9_36/texture.c @@ -30,21 +30,6 @@ static BOOL is_pow2(UINT num) return !(num & (num - 1)); }
-/* Returns the smallest power of 2 which is greater than or equal to num */ -static UINT make_pow2(UINT num) -{ - UINT result = 1; - - /* In the unlikely event somebody passes a large value, make sure we don't enter an infinite loop */ - if (num >= 0x80000000) - return 0x80000000; - - while (result < num) - result <<= 1; - - return result; -} - static HRESULT get_surface(D3DRESOURCETYPE type, struct IDirect3DBaseTexture9 *tex, int face, UINT level, struct IDirect3DSurface9 **surf) {
Based on a patch by Tony Wasserka.
Signed-off-by: Sven Baars sbaars@codeweavers.com --- dlls/d3dx9_36/font.c | 276 ++++++++++++++++++++++++++++++++----- dlls/d3dx9_36/tests/core.c | 5 +- 2 files changed, 242 insertions(+), 39 deletions(-)
diff --git a/dlls/d3dx9_36/font.c b/dlls/d3dx9_36/font.c index cb09af22f5..2c910b8b14 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 +{ + UINT id; + RECT blackbox; + POINT cellinc; + 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; + UINT texture_count, texture_pos; + + UINT 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); + const UINT *id = 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);
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) + { + UINT i; + for(i = 0; i < font->texture_count; ++i) + IDirect3DTexture9_Release(font->textures[i]); + + if (font->textures) + 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,146 @@ static HRESULT WINAPI ID3DXFontImpl_PreloadCharacters(ID3DXFont *iface, UINT fir return S_OK; }
+static UINT morton_decode(UINT 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 a 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; + struct d3dx_font *font = impl_from_ID3DXFont(iface); + UINT glyph, x, y; + HRESULT hr; + + TRACE("iface %p, first %u, last %u\n", iface, first, last); + + if (last < first) + return D3D_OK; + + for (glyph = first; glyph <= last; ++glyph) + { + DWORD buflen, *pixel_data; + BYTE *buffer; + GLYPHMETRICS metrics; + D3DLOCKED_RECT lockrect; + MAT2 mat = { {0,1}, {0,0}, {0,0}, {0,1} }; + UINT stride, offx, offy; + IDirect3DTexture9 *current_texture; + struct d3dx_glyph *current_glyph; + + /* Check whether the glyph is already preloaded */ + if (wine_rb_get(&font->glyph_tree, &glyph)) + continue; + + /* Calculate glyph position */ + offx = morton_decode(font->texture_pos) * font->glyph_size; + offy = morton_decode(font->texture_pos >> 1) * font->glyph_size; + + current_glyph = heap_alloc(sizeof(struct d3dx_glyph)); + if (!current_glyph) + return E_OUTOFMEMORY; + + current_glyph->id = glyph; + current_glyph->texture = NULL; + wine_rb_put(&font->glyph_tree, ¤t_glyph->id, ¤t_glyph->entry); + + /* Get the glyph data */ + buflen = GetGlyphOutlineW(font->hdc, glyph, GGO_GLYPH_INDEX | GGO_GRAY8_BITMAP, &metrics, 0, NULL, &mat); + if (buflen == GDI_ERROR) + { + WARN("GetGlyphOutlineW failed\n"); + continue; + } + + /* Glyph of size 0 */ + if (!buflen) + continue; + + buffer = heap_alloc(buflen); + if (!buffer) + return E_OUTOFMEMORY; + + GetGlyphOutlineW(font->hdc, glyph, GGO_GLYPH_INDEX | GGO_GRAY8_BITMAP, &metrics, buflen, buffer, &mat); + + /* Create a new texture if necessary */ + if (font->texture_pos == font->glyphs_per_texture) + { + IDirect3DTexture9 **new_textures; + UINT new_texture_count = font->texture_count + 1; + + new_textures = heap_realloc(font->textures, new_texture_count * sizeof(IDirect3DTexture9 *)); + 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; + } + + ++font->texture_count; + font->texture_pos = 0; + offx = 0; + offy = 0; + } + + current_texture = font->textures[font->texture_count - 1]; + + /* Fill in glyph data */ + current_glyph->blackbox.left = offx - metrics.gmptGlyphOrigin.x + font->glyph_size / 2 - metrics.gmBlackBoxX / 2; + current_glyph->blackbox.top = offy - metrics.gmptGlyphOrigin.y + font->metrics.tmAscent + 1; + current_glyph->blackbox.right = current_glyph->blackbox.left + metrics.gmBlackBoxX; + current_glyph->blackbox.bottom = current_glyph->blackbox.top + metrics.gmBlackBoxY; + current_glyph->cellinc.x = metrics.gmptGlyphOrigin.x - 1; + current_glyph->cellinc.y = font->metrics.tmAscent - metrics.gmptGlyphOrigin.y - 1; + current_glyph->texture = current_texture; + + /* Copy glyph data to the texture */ + if (FAILED(hr = IDirect3DTexture9_LockRect(current_texture, 0, &lockrect, ¤t_glyph->blackbox, 0))) + { + heap_free(buffer); + return hr; + } + + 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[x + y * lockrect.Pitch / 4] = ((buffer[x + y * stride] * 255 / 64) << 24) + 0xffffff; + + IDirect3DTexture9_UnlockRect(current_texture, 0); + + heap_free(buffer); + + ++font->texture_pos; + } + + return D3D_OK; }
static HRESULT WINAPI ID3DXFontImpl_PreloadTextA(ID3DXFont *iface, const char *string, INT count) @@ -305,39 +484,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 = make_pow2(object->glyph_size); + if (object->glyph_size < 256) + object->texture_size = min(256, object->texture_size << 4); + + 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)
On Thu, Feb 13, 2020 at 5:14 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 | 276 ++++++++++++++++++++++++++++++++----- dlls/d3dx9_36/tests/core.c | 5 +- 2 files changed, 242 insertions(+), 39 deletions(-)
I have reworked this patch a bit but I might have broken it. I'm attaching it here, can you test that it still works?
On 25-02-2020 18:22, Matteo Bruni wrote:
On Thu, Feb 13, 2020 at 5:14 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 | 276 ++++++++++++++++++++++++++++++++----- dlls/d3dx9_36/tests/core.c | 5 +- 2 files changed, 242 insertions(+), 39 deletions(-)
I have reworked this patch a bit but I might have broken it. I'm attaching it here, can you test that it still works?
Hi Matteo,
It does still work, but it adds a new compiler warning:
../../../dlls/d3dx9_36/font.c: In function ‘ID3DXFontImpl_PreloadGlyphs’: ../../../dlls/d3dx9_36/font.c:251:44: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] if (wine_rb_get(&font->glyph_tree, (void *)glyph)) ^ ../../../dlls/d3dx9_36/font.c:264:40: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] wine_rb_put(&font->glyph_tree, (void *)current_glyph->id, ¤t_glyph->entry); ^ Cheers, Sven
Based on a patch by Tony Wasserka.
Signed-off-by: Sven Baars sbaars@codeweavers.com --- dlls/d3dx9_36/font.c | 33 +++++++++++++++++++++--- dlls/d3dx9_36/tests/core.c | 53 +++++++++++++++++--------------------- 2 files changed, 54 insertions(+), 32 deletions(-)
diff --git a/dlls/d3dx9_36/font.c b/dlls/d3dx9_36/font.c index 2c910b8b14..ae72f049bd 100644 --- a/dlls/d3dx9_36/font.c +++ b/dlls/d3dx9_36/font.c @@ -186,9 +186,36 @@ static HDC WINAPI ID3DXFontImpl_GetDC(ID3DXFont *iface) 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 *font = impl_from_ID3DXFont(iface); + struct wine_rb_entry *entry; + HRESULT hr; + + TRACE("iface %p, glyph %#x, texture %p, blackbox %p, cellinc %p\n", + iface, glyph, texture, blackbox, cellinc); + + hr = ID3DXFont_PreloadGlyphs(iface, glyph, glyph); + if (FAILED(hr)) + return hr; + + entry = wine_rb_get(&font->glyph_tree, &glyph); + if (entry) + { + struct d3dx_glyph *current_glyph = WINE_RB_ENTRY_VALUE(entry, struct d3dx_glyph, entry); + + if (cellinc) + *cellinc = current_glyph->cellinc; + if (blackbox) + *blackbox = current_glyph->blackbox; + 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 ae72f049bd..909a85ada4 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; + WCHAR *chars; + WORD *indices; + + 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 UINT morton_decode(UINT x)
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=65143
Your paranoid android.
=== debian10 (32 bit Chinese:China report) ===
On Thu, Feb 13, 2020 at 05:13:43PM +0100, Sven Baars wrote:
Signed-off-by: Sven Baars sbaars@codeweavers.com
dlls/gdi32/font.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/dlls/gdi32/font.c b/dlls/gdi32/font.c index d451f30c3e..8788426a2c 100644 --- a/dlls/gdi32/font.c +++ b/dlls/gdi32/font.c @@ -3313,6 +3313,9 @@ GetCharacterPlacementW( TRACE("%s, %d, %d, 0x%08x\n", debugstr_wn(lpString, uCount), uCount, nMaxExtent, dwFlags);
- if (!uCount)
return 0;
- if (!lpResults) return GetTextExtentPoint32W(hdc, lpString, uCount, &size) ? MAKELONG(size.cx, size.cy) : 0;
Some tests would be good. As well as testing the return value, one might also test if anything is updated in 'lpResults'.
Huw.