https://git.reactos.org/?p=reactos.git;a=commitdiff;h=1558e6d0b3b19446394d18b3cdfd6cdc0869def6

commit 1558e6d0b3b19446394d18b3cdfd6cdc0869def6
Author:     Katayama Hirofumi MZ <[email protected]>
AuthorDate: Tue Jul 13 20:51:28 2021 +0900
Commit:     GitHub <[email protected]>
CommitDate: Tue Jul 13 20:51:28 2021 +0900

    [IMM32] Rewrite ImmGetCompositionFontA/W (#3813)
    
    - Rewrite ImmGetCompositionFontA and ImmGetCompositionFontW functions.
    - Add INIT_* macro definitions in <ddk/imm.h>.
    CORE-11700
---
 dll/win32/imm32/imm.c              | 88 ++++++++++++++++++++++++++++++++------
 sdk/include/reactos/wine/ddk/imm.h |  8 ++++
 2 files changed, 82 insertions(+), 14 deletions(-)

diff --git a/dll/win32/imm32/imm.c b/dll/win32/imm32/imm.c
index 224f616866b..5030f593461 100644
--- a/dll/win32/imm32/imm.c
+++ b/dll/win32/imm32/imm.c
@@ -1457,24 +1457,64 @@ BOOL WINAPI ImmGetCandidateWindow(
     return TRUE;
 }
 
+static VOID APIENTRY LogFontAnsiToWide(const LOGFONTA *plfA, LPLOGFONTW plfW)
+{
+    size_t cch;
+    RtlCopyMemory(plfW, plfA, offsetof(LOGFONTA, lfFaceName));
+    StringCchLengthA(plfA->lfFaceName, _countof(plfA->lfFaceName), &cch);
+    cch = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, plfA->lfFaceName, 
(INT)cch,
+                              plfW->lfFaceName, _countof(plfW->lfFaceName));
+    if (cch > _countof(plfW->lfFaceName) - 1)
+        cch = _countof(plfW->lfFaceName) - 1;
+    plfW->lfFaceName[cch] = 0;
+}
+
+static VOID APIENTRY LogFontWideToAnsi(const LOGFONTW *plfW, LPLOGFONTA plfA)
+{
+    size_t cch;
+    RtlCopyMemory(plfA, plfW, offsetof(LOGFONTW, lfFaceName));
+    StringCchLengthW(plfW->lfFaceName, _countof(plfW->lfFaceName), &cch);
+    cch = WideCharToMultiByte(CP_ACP, 0, plfW->lfFaceName, (INT)cch,
+                              plfA->lfFaceName, _countof(plfA->lfFaceName), 
NULL, NULL);
+    if (cch > _countof(plfA->lfFaceName) - 1)
+        cch = _countof(plfA->lfFaceName) - 1;
+    plfA->lfFaceName[cch] = 0;
+}
+
 /***********************************************************************
  *             ImmGetCompositionFontA (IMM32.@)
  */
 BOOL WINAPI ImmGetCompositionFontA(HIMC hIMC, LPLOGFONTA lplf)
 {
-    LOGFONTW lfW;
-    BOOL rc;
+    PCLIENTIMC pClientImc;
+    BOOL ret = FALSE, bWide;
+    LPINPUTCONTEXT pIC;
 
-    TRACE("(%p, %p):\n", hIMC, lplf);
+    TRACE("ImmGetCompositionFontA(%p, %p)\n", hIMC, lplf);
 
-    rc = ImmGetCompositionFontW(hIMC,&lfW);
-    if (!rc || !lplf)
+    pClientImc = ImmLockClientImc(hIMC);
+    if (pClientImc == NULL)
         return FALSE;
 
-    memcpy(lplf,&lfW,sizeof(LOGFONTA));
-    WideCharToMultiByte(CP_ACP, 0, lfW.lfFaceName, -1, lplf->lfFaceName,
-                        LF_FACESIZE, NULL, NULL);
-    return TRUE;
+    bWide = (pClientImc->dwFlags & CLIENTIMC_WIDE);
+    ImmUnlockClientImc(pClientImc);
+
+    pIC = ImmLockIMC(hIMC);
+    if (pIC == NULL)
+        return FALSE;
+
+    if (pIC->fdwInit & INIT_LOGFONT)
+    {
+        if (bWide)
+            LogFontWideToAnsi(&pIC->lfFont.W, lplf);
+        else
+            *lplf = pIC->lfFont.A;
+
+        ret = TRUE;
+    }
+
+    ImmUnlockIMC(hIMC);
+    return ret;
 }
 
 /***********************************************************************
@@ -1482,16 +1522,36 @@ BOOL WINAPI ImmGetCompositionFontA(HIMC hIMC, 
LPLOGFONTA lplf)
  */
 BOOL WINAPI ImmGetCompositionFontW(HIMC hIMC, LPLOGFONTW lplf)
 {
-    InputContextData *data = get_imc_data(hIMC);
+    PCLIENTIMC pClientImc;
+    BOOL bWide;
+    LPINPUTCONTEXT pIC;
+    BOOL ret = FALSE;
 
-    TRACE("(%p, %p):\n", hIMC, lplf);
+    TRACE("ImmGetCompositionFontW(%p, %p)\n", hIMC, lplf);
 
-    if (!data || !lplf)
+    pClientImc = ImmLockClientImc(hIMC);
+    if (pClientImc == NULL)
         return FALSE;
 
-    *lplf = data->IMC.lfFont.W;
+    bWide = (pClientImc->dwFlags & CLIENTIMC_WIDE);
+    ImmUnlockClientImc(pClientImc);
 
-    return TRUE;
+    pIC = ImmLockIMC(hIMC);
+    if (pIC == NULL)
+        return FALSE;
+
+    if (pIC->fdwInit & INIT_LOGFONT)
+    {
+        if (bWide)
+            *lplf = pIC->lfFont.W;
+        else
+            LogFontAnsiToWide(&pIC->lfFont.A, lplf);
+
+        ret = TRUE;
+    }
+
+    ImmUnlockIMC(hIMC);
+    return ret;
 }
 
 
diff --git a/sdk/include/reactos/wine/ddk/imm.h 
b/sdk/include/reactos/wine/ddk/imm.h
index 583dbd63cc1..106d9603119 100644
--- a/sdk/include/reactos/wine/ddk/imm.h
+++ b/sdk/include/reactos/wine/ddk/imm.h
@@ -87,6 +87,14 @@ C_ASSERT(offsetof(INPUTCONTEXT, dwReserve) == 0x134);
 C_ASSERT(sizeof(INPUTCONTEXT) == 0x140);
 #endif
 
+// bits of fdwInit of INPUTCONTEXT
+#define INIT_STATUSWNDPOS               0x00000001
+#define INIT_CONVERSION                 0x00000002
+#define INIT_SENTENCE                   0x00000004
+#define INIT_LOGFONT                    0x00000008
+#define INIT_COMPFORM                   0x00000010
+#define INIT_SOFTKBDPOS                 0x00000020
+
 LPINPUTCONTEXT WINAPI ImmLockIMC(HIMC);
 
 #endif /* _WINE_IMM_H_ */

Reply via email to