bug#68339: [patch] Set the IME window font to an appropriate size
dANiuu zHaO <[email protected]> Sun, 2 Aug 2026 23:33:46 +0800
| Newsgroups | gmane.emacs.bugs |
|---|---|
| Message-ID | <CAEOE9jdqZPObxGJD1ju1EU1Usjm=qdOj-qNnYvdV+DfDUp=Fcg@mail.gmail.com> |
--0000000000008ef0da065812261d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable My example GIF was sent by mistake =E2=80=94 it was from a different patch.= I didn't notice the difference in the patch folders. Please disregard that example.gif; it demonstrates the work of implementing another patch. dANiuu zHaO <[email protected]> =E4=BA=8E2026=E5=B9=B48=E6=9C=882=E6=97= =A5=E5=91=A8=E6=97=A5 23:27=E5=86=99=E9=81=93=EF=BC=9A > You were right. I only needed to build it once locally and it worked > perfectly =E2=80=94 exactly as you described, with no errors at all. Ther= e's a new > patch and a GIF attached to demonstrate my current work. > Everything works fine on my local machine, but it will likely need more > testing from others. Lastly, thank you for your guidance =E2=80=94 withou= t it, it > would have taken me much longer to figure out the root cause. > Finally, I agree to sign the copyright-assignment agreement. > > Eli Zaretskii <[email protected]> =E4=BA=8E2026=E5=B9=B48=E6=9C=882=E6=97=A5= =E5=91=A8=E6=97=A5 19:59=E5=86=99=E9=81=93=EF=BC=9A > >> > From: dANiuu zHaO <[email protected]> >> > Date: Sun, 2 Aug 2026 11:50:27 +0800 >> > >> > I implemented the fix for this issue based on Vim's approach. I tried >> using the ImmGetCompositionFont API =E2=80=94 >> > it works. I have a simple example that can be used for testing: >> > >> https://github.com/zHaOdANiuu/emacs-w32-draw-preedit.patch/blob/main/exa= mple/ime-get.cpp >> > However, it only works in a simple w32 window. It has no effect inside >> Emacs. >> >> I guess that's because Emacs is built as a console application, or >> perhaps because we don't do something we should do when registering >> our window classes. >> >> > I don't know why it doesn't work in Emacs. Apparently, Vim's Windows >> developers must have also encountered >> > this problem =E2=80=94 they store a font object of type HFONT globally= , >> retrieve the data via the GetObject function, >> > and then set it with ImmSetCompositionFont. >> >> I think this is good enough for our purposes, and the fact that the >> patch is quite small is encouraging. >> >> > This approach does work in Emacs. I obtained the font object via >> FRAME_FONT (f) and got the HFONT handle >> > using the FONT_HANDLE macro from w32font.h, then set the font size =E2= =80=94 >> and it works. >> >> Good! >> >> > However, there is a problem: when zooming the UI in Emacs by holding >> Ctrl + mouse wheel >> > (C-mouse-wheel-text-scale), the font is zoomed, but the IME window fon= t >> does not zoom along with it. >> >> Does it not work even if you start the composition _after_ changing >> the font via the mouse-wheel? If so, I think it's because FRAME_FONT >> gives you the default font, which doesn't take face-remapping (which >> is how text-scale works in Emacs) into account. To get the font after >> remapping, you need to do something like: >> >> . call lookup_basic_face (W, F, DEFAULT_FACE_ID), where W and F and >> the window and the frame; this gives you a face ID >> . use FACE_FROM_ID to get 'struct face' from the above ID >> . obtain the font as face->font >> . if any of that fails, use FRAME_FONT as you do now >> >> > Similarly, I found that the w32_system_caret_x and w32_system_caret_y >> variables are probably not updated >> > during UI scaling either, which causes the IME window to be offset whe= n >> the UI is zoomed significantly. >> >> This is a separate problem, so should be fixed separately. Please >> submit a separate bug report, and let's discuss it there. >> >> Last, but not least: this patch is small enough to accept it without >> copyright assignment, but for us to be able to accept further >> contributions from you, you need to sign the copyright-assignment >> agreement. If you agree, I will send you the form to fill and the >> instructions to go with it. >> >> Thanks. >> > --0000000000008ef0da065812261d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">My example GIF was sent by mistake =E2=80=94 it was from a= different patch. I didn't notice the difference in the patch folders. = Please disregard that example.gif; it demonstrates the work of implementing= another patch.</div><br><div class=3D"gmail_quote gmail_quote_container"><= div dir=3D"ltr" class=3D"gmail_attr">dANiuu zHaO <<a href=3D"mailto:zhao= [email protected]">[email protected]</a>> =E4=BA=8E2026=E5=B9=B48=E6= =9C=882=E6=97=A5=E5=91=A8=E6=97=A5 23:27=E5=86=99=E9=81=93=EF=BC=9A<br></di= v><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;borde= r-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr">You we= re right. I only needed to build it once locally and it worked perfectly = =E2=80=94 exactly as you described, with no errors at all. There's a ne= w patch and a GIF attached to demonstrate my current work.<br>Everything wo= rks fine on my local machine, but it will likely need more testing from oth= ers. Lastly, thank you for your guidance =E2=80=94 without it, it would hav= e taken me much longer to figure out the root cause.<br>Finally, I agree to= sign the copyright-assignment agreement.</div><br><div class=3D"gmail_quot= e"><div dir=3D"ltr" class=3D"gmail_attr">Eli Zaretskii <<a href=3D"mailt= o:[email protected]" target=3D"_blank">[email protected]</a>> =E4=BA=8E2026=E5=B9= =B48=E6=9C=882=E6=97=A5=E5=91=A8=E6=97=A5 19:59=E5=86=99=E9=81=93=EF=BC=9A<= br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8e= x;border-left:1px solid rgb(204,204,204);padding-left:1ex">> From: dANiu= u zHaO <<a href=3D"mailto:[email protected]" target=3D"_blank">zhaoda= [email protected]</a>><br> > Date: Sun, 2 Aug 2026 11:50:27 +0800<br> > <br> > I implemented the fix for this issue based on Vim's approach. I tr= ied using the ImmGetCompositionFont API =E2=80=94<br> > it works. I have a simple example that can be used for testing:<br> > <a href=3D"https://github.com/zHaOdANiuu/emacs-w32-draw-preedit.patch/= blob/main/example/ime-get.cpp" rel=3D"noreferrer" target=3D"_blank">https:/= /github.com/zHaOdANiuu/emacs-w32-draw-preedit.patch/blob/main/example/ime-g= et.cpp</a><br> > However, it only works in a simple w32 window. It has no effect inside= Emacs.<br> <br> I guess that's because Emacs is built as a console application, or<br> perhaps because we don't do something we should do when registering<br> our window classes.<br> <br> > I don't know why it doesn't work in Emacs. Apparently, Vim'= ;s Windows developers must have also encountered<br> > this problem =E2=80=94 they store a font object of type HFONT globally= , retrieve the data via the GetObject function,<br> > and then set it with ImmSetCompositionFont.<br> <br> I think this is good enough for our purposes, and the fact that the<br> patch is quite small is encouraging.<br> <br> > This approach does work in Emacs. I obtained the font object via FRAME= _FONT (f) and got the HFONT handle<br> > using the FONT_HANDLE macro from w32font.h, then set the font size =E2= =80=94 and it works.<br> <br> Good!<br> <br> > However, there is a problem: when zooming the UI in Emacs by holding C= trl + mouse wheel<br> > (C-mouse-wheel-text-scale), the font is zoomed, but the IME window fon= t does not zoom along with it.<br> <br> Does it not work even if you start the composition _after_ changing<br> the font via the mouse-wheel?=C2=A0 If so, I think it's because FRAME_F= ONT<br> gives you the default font, which doesn't take face-remapping (which<br= > is how text-scale works in Emacs) into account.=C2=A0 To get the font after= <br> remapping, you need to do something like:<br> <br> =C2=A0 . call lookup_basic_face (W, F, DEFAULT_FACE_ID), where W and F and<= br> =C2=A0 =C2=A0 the window and the frame; this gives you a face ID<br> =C2=A0 . use FACE_FROM_ID to get 'struct face' from the above ID<br= > =C2=A0 . obtain the font as face->font<br> =C2=A0 . if any of that fails, use FRAME_FONT as you do now<br> <br> > Similarly, I found that the w32_system_caret_x and w32_system_caret_y = variables are probably not updated<br> > during UI scaling either, which causes the IME window to be offset whe= n the UI is zoomed significantly.<br> <br> This is a separate problem, so should be fixed separately.=C2=A0 Please<br> submit a separate bug report, and let's discuss it there.<br> <br> Last, but not least: this patch is small enough to accept it without<br> copyright assignment, but for us to be able to accept further<br> contributions from you, you need to sign the copyright-assignment<br> agreement.=C2=A0 If you agree, I will send you the form to fill and the<br> instructions to go with it.<br> <br> Thanks.<br> </blockquote></div> </blockquote></div> --0000000000008ef0da065812261d--