bug#68339: [patch] Set the IME window font to an appropriate size

dANiuu zHaO <[email protected]> Fri, 7 Aug 2026 14:29:52 +0800
Newsgroups gmane.emacs.bugs
Message-ID <CAEOE9jeJPtD-JZm8Fj7s7Tgteti9azwH5y_7OBV_pcUH_Te+qQ@mail.gmail.com>
[PATCH 5] Set the IME window font to an appropriate size

Added a check for face->font so that it can fall back to FRAME_FONT.
If any issues are found during testing, please feel free to contact me.

dANiuu zHaO <[email protected]> 于2026年8月7日周五 13:53写道:

> Yes, it does need some time for people to test it. My copyright assignment
> paperwork has been signed, but I haven't heard back yet.
>
> As for the code, I will set up `face->fallback` later. I honestly didn't
> expect `face->font` could return NULL.
>
> Eli Zaretskii <[email protected]> 于2026年8月7日周五 13:45写道:
>
>> > From: dANiuu zHaO <[email protected]>
>> > Date: Fri, 7 Aug 2026 11:36:41 +0800
>> > Cc: Eason Huang <[email protected]>, [email protected]
>> >
>> > @@ -6682,6 +6686,8 @@ 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 : FRAME_FONT (f);
>>
>> face->font can yield NULL in some rare cases, so there's another
>> face->fallback missing here, to use FRAME_FONT in that case as well.
>>
>> Otherwise, I think we should wait for a while for people to test this
>> patch (and for your copyright-assignment paperwork), before we install
>> it.
>>
>> Thanks.
>>
>
0001-Set-the-IME-window-font-to-an-appropriate-size.patch (application/octet-stream, 4.3 KB)
From 7278ddb4e6ff683e9d26e55eacda3736fd436661 Mon Sep 17 00:00:00 2001
From: zdn <[email protected]>
Date: Sun, 2 Aug 2026 11:05:02 +0800
Subject: [PATCH] Set the IME window font to an appropriate size.

* src/w32fns.c (w32_wnd_proc): Using FONT_HANDLE to HFONT from
w32_system_remap_font.
* src/w32term.c (w32_draw_window_cursor): Update
w32_system_remap_font by  using lookup_basic_face to obtain the faceID,
then passing it to FACE_FROM_ID_OR_NULL to get the corresponding face struct.
* src/w32term.h: Add w32_system_remap_font point
---
 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 726fe52..21303a1 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -47,6 +47,7 @@ #define COBJMACROS /* Ask for C definitions for COM.  */
 
 #include "lisp.h"
 #include "w32term.h"
+#include "w32font.h"
 #include "frame.h"
 #include "window.h"
 #include "buffer.h"
@@ -200,6 +201,9 @@ #define CCHDEVICENAME 32
 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 @@ #define CCHDEVICENAME 32
 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 728f6ce..ae9a32b 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -180,6 +180,8 @@ #define SM_CXVIRTUALSCREEN 78
 #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 aec957b..7fc5ee8 100644
--- a/src/w32term.h
+++ b/src/w32term.h
@@ -872,6 +872,8 @@ #define TME_LEAVE 0x00000002;
     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;
-- 
2.55.0