[PATCH 3/5] d3dx9: Handle vertical alignment in ID3DXFont_DrawText.

Sven Baars sbaars at codeweavers.com
Tue Mar 10 05:21:40 CDT 2020


Signed-off-by: Sven Baars <sbaars at codeweavers.com>
---
 dlls/d3dx9_36/font.c       | 30 ++++++++++++++++++++++++------
 dlls/d3dx9_36/tests/core.c | 14 ++++++++++++--
 2 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/dlls/d3dx9_36/font.c b/dlls/d3dx9_36/font.c
index 3645903367..bd81a7044b 100644
--- a/dlls/d3dx9_36/font.c
+++ b/dlls/d3dx9_36/font.c
@@ -603,12 +603,12 @@ static INT WINAPI ID3DXFontImpl_DrawTextW(ID3DXFont *iface, ID3DXSprite *sprite,
         const WCHAR *string, INT count, RECT *rect, DWORD format, D3DCOLOR color)
 {
     struct d3dx_font *font = impl_from_ID3DXFont(iface);
+    RECT calcrect, textrect = {0};
     ID3DXSprite *target = sprite;
-    WCHAR *line;
-    RECT textrect = {0};
     int lh, x, y, width;
     int max_width = 0;
     int ret = 0;
+    WCHAR *line;
     SIZE size;
 
     TRACE("iface %p, sprite %p, string %s, count %d, rect %s, format %#x, color 0x%08x.\n",
@@ -641,9 +641,27 @@ static INT WINAPI ID3DXFontImpl_DrawTextW(ID3DXFont *iface, ID3DXSprite *sprite,
         textrect = *rect;
     }
 
-    x = textrect.left;
-    y = textrect.top;
-    width = textrect.right - textrect.left;
+    calcrect = textrect;
+
+    if (format & (DT_VCENTER | DT_BOTTOM))
+    {
+        y = ID3DXFont_DrawTextW(iface, NULL, string, count, &calcrect,
+                                format & ~DT_BOTTOM & ~DT_VCENTER, 0);
+
+        if (format & DT_VCENTER)
+        {
+            calcrect.top = textrect.top + (textrect.bottom - textrect.top - y) / 2;
+            calcrect.bottom = calcrect.top + y;
+        }
+        else if (format & DT_BOTTOM)
+        {
+            calcrect.top = textrect.bottom - y;
+        }
+    }
+
+    x = calcrect.left;
+    y = calcrect.top;
+    width = calcrect.right - calcrect.left;
 
     lh = font->metrics.tmHeight;
 
@@ -718,7 +736,7 @@ static INT WINAPI ID3DXFontImpl_DrawTextW(ID3DXFont *iface, ID3DXSprite *sprite,
 
     if (format & DT_CALCRECT)
     {
-        *rect = textrect;
+        *rect = calcrect;
 
         rect->bottom = y;
         rect->right = rect->left + max_width;
diff --git a/dlls/d3dx9_36/tests/core.c b/dlls/d3dx9_36/tests/core.c
index 6fae8bf8d5..7800e6036c 100644
--- a/dlls/d3dx9_36/tests/core.c
+++ b/dlls/d3dx9_36/tests/core.c
@@ -837,10 +837,10 @@ static void test_ID3DXFont(IDirect3DDevice9 *device)
     ok(height == 36, "Got unexpected height %d.\n", height);
 
     height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_BOTTOM, 0xff00ff);
-    todo_wine ok(height == 40, "Got unexpected height %d.\n", height);
+    ok(height == 40, "Got unexpected height %d.\n", height);
 
     height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_VCENTER, 0xff00ff);
-    todo_wine ok(height == 32, "Got unexpected height %d.\n", height);
+    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);
@@ -853,6 +853,16 @@ static void test_ID3DXFont(IDirect3DDevice9 *device)
     ok(height == 24, "Got unexpected height %d.\n", height);
     check_rect(&rect, 10, 10, 30, 34);
 
+    SetRect(&rect, 10, 10, 50, 50);
+    height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_BOTTOM | DT_CALCRECT, 0xff00ff);
+    ok(height == 40, "Got unexpected height %d.\n", height);
+    check_rect(&rect, 10, 26, 30, 50);
+
+    SetRect(&rect, 10, 10, 50, 50);
+    height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_VCENTER | DT_CALCRECT, 0xff00ff);
+    ok(height == 32, "Got unexpected height %d.\n", height);
+    check_rect(&rect, 10, 18, 30, 42);
+
     ID3DXFont_Release(font);
 }
 
-- 
2.24.0




More information about the wine-devel mailing list