SDL: Center the composition text in the text input area

From a7d4f0a76c310a36f2cafa0211be70bcbe068090 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 28 Jun 2024 17:08:54 -0700
Subject: [PATCH] Center the composition text in the text input area

---
 src/video/windows/SDL_windowskeyboard.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/video/windows/SDL_windowskeyboard.c b/src/video/windows/SDL_windowskeyboard.c
index d654699bf2d5c..52e162aff0e34 100644
--- a/src/video/windows/SDL_windowskeyboard.c
+++ b/src/video/windows/SDL_windowskeyboard.c
@@ -656,11 +656,17 @@ static void IME_SetTextInputArea(SDL_VideoData *videodata, const SDL_Rect *rect,
     if (himc) {
         COMPOSITIONFORM cof;
         CANDIDATEFORM caf;
+        int font_height = rect->h;
+
+        LOGFONTW font;
+        if (ImmGetCompositionFontW(himc, &font)) {
+            font_height = font.lfHeight;
+        }
 
         SDL_zero(cof);
         cof.dwStyle = CFS_RECT;
         cof.ptCurrentPos.x = rect->x + cursor;
-        cof.ptCurrentPos.y = rect->y;
+        cof.ptCurrentPos.y = rect->y + (rect->h - font_height) / 2;
         cof.rcArea.left = rect->x;
         cof.rcArea.right = (LONG)rect->x + rect->w;
         cof.rcArea.top = rect->y;
@@ -1055,6 +1061,9 @@ SDL_bool WIN_HandleIMEMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM *lParam
         case IMN_SETCOMPOSITIONWINDOW:
             SDL_DebugIMELog("IMN_SETCOMPOSITIONWINDOW\n");
             break;
+        case IMN_SETCOMPOSITIONFONT:
+            SDL_DebugIMELog("IMN_SETCOMPOSITIONFONT\n");
+            break;
         case IMN_SETCANDIDATEPOS:
             SDL_DebugIMELog("IMN_SETCANDIDATEPOS\n");
             break;