master b7b23fce2a6: Set the IME window font on MS-Windows to the appropriate size

Eli Zaretskii <[email protected]>
Newsgroups gmane.emacs.diffs
Message-ID <[email protected]>
branch: master
commit b7b23fce2a6b1c446074b709a9c39584340d713d
Author: zdn <[email protected]>
Commit: Eli Zaretskii <[email protected]>

    Set the IME window font on MS-Windows to the appropriate size
    
    * src/w32fns.c (w32_wnd_proc): Set the font of the composition
    window using 'w32_system_remap_font'.
    * src/w32term.c (w32_draw_window_cursor): Update
    'w32_system_remap_font' by  using 'lookup_basic_face' to obtain the
    face ID of a remapped face.
    * src/w32term.h (w32_system_remap_font): Add declaration.
    (Bug#68339)
---
 src/w32fns.c  | 11 +++++++++++
 src/w32term.c |  7 +++++++
 src/w32term.h |  2 ++
 3 files changed, 20 insertions(+)

diff --git a/src/w32fns.c b/src/w32fns.c
index 726fe52affc..21303a106f4 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -47,6 +47,7 @@ along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
 
 #include "lisp.h"
 #include "w32term.h"
+#include "w32font.h"
 #include "frame.h"
 #include "window.h"
 #include "buffer.h"
@@ -200,6 +201,9 @@ typedef BOOL (WINAPI * ImmSetCompositionWindow_Proc) (IN HIMC context,
 typedef BOOL (WINAPI * ImmGetOpenStatus_Proc) (IN HIMC);
 typedef BOOL (WINAPI * ImmSetOpenStatus_Proc) (IN HIMC, IN BOOL);
 
+/* Set IME font.  */
+typedef BOOL (WINAPI * ImmSetCompositionFont_Proc) (IN HIMC, LPLOGFONTW lplf);
+
 typedef HMONITOR (WINAPI * MonitorFromPoint_Proc) (IN POINT pt, IN DWORD flags);
 typedef BOOL (WINAPI * GetMonitorInfo_Proc)
   (IN HMONITOR monitor, OUT struct MONITOR_INFO* info);
@@ -247,6 +251,7 @@ static ImmGetCompositionString_Proc get_composition_string_fn = NULL;
 static ImmGetContext_Proc get_ime_context_fn = NULL;
 static ImmGetOpenStatus_Proc get_ime_open_status_fn = NULL;
 static ImmSetOpenStatus_Proc set_ime_open_status_fn = NULL;
+static ImmSetCompositionFont_Proc set_ime_composition_font_fn = NULL;
 static ImmReleaseContext_Proc release_ime_context_fn = NULL;
 static ImmSetCompositionWindow_Proc set_ime_composition_window_fn = NULL;
 static MonitorFromPoint_Proc monitor_from_point_fn = NULL;
@@ -5032,6 +5037,7 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
       else
 	{
 	  COMPOSITIONFORM form;
+	  LOGFONTW lf;
 	  HIMC context;
 	  struct window *w;
 
@@ -5077,6 +5083,8 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 	  if (!context)
 	    goto dflt;
 
+	  GetObjectW (FONT_HANDLE (w32_system_remap_font), sizeof (lf), &lf);
+	  set_ime_composition_font_fn (context, &lf);
 	  set_ime_composition_window_fn (context, &form);
 	  release_ime_context_fn (hwnd, context);
 	}
@@ -12332,6 +12340,9 @@ globals_of_w32fns (void)
       get_proc_addr (imm32_lib, "ImmGetOpenStatus");
     set_ime_open_status_fn = (ImmSetOpenStatus_Proc)
       get_proc_addr (imm32_lib, "ImmSetOpenStatus");
+
+    set_ime_composition_font_fn = (ImmSetCompositionFont_Proc)
+      get_proc_addr (imm32_lib, "ImmSetCompositionFontW");
   }
 
   HMODULE hm_kernel32 = GetModuleHandle ("kernel32.dll");
diff --git a/src/w32term.c b/src/w32term.c
index 728f6ce856d..ae9a32ba828 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -180,6 +180,8 @@ static GetTouchInputInfo_proc pfnGetTouchInputInfo;
 #define SM_CYVIRTUALSCREEN 79
 #endif
 
+struct font *w32_system_remap_font;
+
 /* The handle of the frame that currently owns the system caret.  */
 HWND w32_system_caret_hwnd;
 int w32_system_caret_height;
@@ -6670,6 +6672,8 @@ w32_draw_window_cursor (struct window *w, struct glyph_row *glyph_row,
       if (active_p)
 	{
 	  struct frame *f = XFRAME (WINDOW_FRAME (w));
+	  int face_id = lookup_basic_face (w, f, DEFAULT_FACE_ID);
+	  struct face *face = FACE_FROM_ID_OR_NULL (f, face_id);
 	  HWND hwnd = FRAME_W32_WINDOW (f);
 
 	  w32_system_caret_x
@@ -6682,6 +6686,9 @@ w32_draw_window_cursor (struct window *w, struct glyph_row *glyph_row,
 	    + WINDOW_HEADER_LINE_HEIGHT (w);
 	  w32_system_caret_mode_height = WINDOW_MODE_LINE_HEIGHT (w);
 
+	  w32_system_remap_font =
+	    (face && face->font) ? face->font : FRAME_FONT (f);
+
 	  PostMessage (hwnd, WM_IME_STARTCOMPOSITION, 0, 0);
 
 	  /* If the size of the active cursor changed, destroy the old
diff --git a/src/w32term.h b/src/w32term.h
index aec957b20b3..7fc5ee80b03 100644
--- a/src/w32term.h
+++ b/src/w32term.h
@@ -872,6 +872,8 @@ typedef BOOL (WINAPI * AppendMenuW_Proc) (
     IN UINT_PTR,
     IN LPCWSTR);
 
+extern struct font *w32_system_remap_font;
+
 extern HWND w32_system_caret_hwnd;
 extern int w32_system_caret_height;
 extern int w32_system_caret_x;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.