New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows の保存確認ダイアログのフォントが変 #1100

Open
mattn opened this Issue Sep 26, 2017 · 23 comments

Comments

Projects
None yet
3 participants
@mattn
Member

mattn commented Sep 26, 2017

Windows7 64bit, Windows10 64bit Vim 8.0.1146

Vim の GUI ダイアログは CreateDialogIndirect を使って動的に作っているのだけど、そのフォントサイズの算出方法がどこかで間違ってる。以下、上が gvim、下がメモ帳。

3e414029c4923c23

また本来なら「保存しますか?」というテキストだが、収まっておらず「保存します」が表示されてしまっている。

@mattn

This comment has been minimized.

Show comment
Hide comment
@mattn

mattn Sep 26, 2017

Member

どうやら encoding に依存してるらしい。

Member

mattn commented Sep 26, 2017

どうやら encoding に依存してるらしい。

@k-takata

This comment has been minimized.

Show comment
Hide comment
@k-takata

k-takata Sep 26, 2017

Member

ふむふむ。表示しているのは、gui_w32.c の gui_mch_dialog() で、フォントは get_dialog_font_metrics() で取得しているのか。

Member

k-takata commented Sep 26, 2017

ふむふむ。表示しているのは、gui_w32.c の gui_mch_dialog() で、フォントは get_dialog_font_metrics() で取得しているのか。

@mattn

This comment has been minimized.

Show comment
Hide comment
@mattn

mattn Sep 26, 2017

Member

USE_SYSMENU_FONT を undef したら、さらに酷い事に

フォント?

Member

mattn commented Sep 26, 2017

USE_SYSMENU_FONT を undef したら、さらに酷い事に

フォント?

@k-takata

This comment has been minimized.

Show comment
Hide comment
@k-takata

k-takata Sep 26, 2017

Member

最近だと、UIフォントは SystemParametersInfo(SPI_GETNONCLIENTMETRICS) で取得するのがいいんじゃないだろうか。

Member

k-takata commented Sep 26, 2017

最近だと、UIフォントは SystemParametersInfo(SPI_GETNONCLIENTMETRICS) で取得するのがいいんじゃないだろうか。

@k-takata

This comment has been minimized.

Show comment
Hide comment
@k-takata

k-takata Sep 26, 2017

Member

あ、ちゃんと gui_w32_get_menu_font() の中ではそれを使っていたか。

Member

k-takata commented Sep 26, 2017

あ、ちゃんと gui_w32_get_menu_font() の中ではそれを使っていたか。

@mattn

This comment has been minimized.

Show comment
Hide comment
@mattn

mattn Sep 26, 2017

Member

あと関係ないかもですがボタン幅の最少が "Cancel" という文字で測られてるのも気になりますね。

Member

mattn commented Sep 26, 2017

あと関係ないかもですがボタン幅の最少が "Cancel" という文字で測られてるのも気になりますね。

@mattn

This comment has been minimized.

Show comment
Hide comment
@mattn

mattn Sep 26, 2017

Member
nchar = nCopyAnsiToWideChar(p, TEXT(lfSysmenu.lfFaceName));

この行がうまく行ってないっぽい。メイリオ だと↑の結果になるけど Meiryo でハードコードしたら直るっぽい。

Member

mattn commented Sep 26, 2017

nchar = nCopyAnsiToWideChar(p, TEXT(lfSysmenu.lfFaceName));

この行がうまく行ってないっぽい。メイリオ だと↑の結果になるけど Meiryo でハードコードしたら直るっぽい。

@k-takata

This comment has been minimized.

Show comment
Hide comment
@k-takata

k-takata Sep 26, 2017

Member

変数に TEXT() 使っちゃあかん…

Member

k-takata commented Sep 26, 2017

変数に TEXT() 使っちゃあかん…

@mattn

This comment has been minimized.

Show comment
Hide comment
@mattn

mattn Sep 26, 2017

Member

あw

Member

mattn commented Sep 26, 2017

あw

@mattn

This comment has been minimized.

Show comment
Hide comment
@mattn

mattn Sep 26, 2017

Member

もう1か所ありますね

diff --git a/src/gui_w32.c b/src/gui_w32.c
index aa0948843..662638ed9 100644
--- a/src/gui_w32.c
+++ b/src/gui_w32.c
@@ -7298,7 +7298,7 @@ gui_mch_dialog(
 	    /* point size */
 	    *p++ = -MulDiv(lfSysmenu.lfHeight, 72,
 		    GetDeviceCaps(hdc, LOGPIXELSY));
-	    nchar = nCopyAnsiToWideChar(p, TEXT(lfSysmenu.lfFaceName));
+	    nchar = nCopyAnsiToWideChar(p, lfSysmenu.lfFaceName);
 	}
 	else
 #endif
@@ -7865,13 +7865,13 @@ gui_mch_tearoff(
 	    /* point size */
 	    *p++ = -MulDiv(lfSysmenu.lfHeight, 72,
 		    GetDeviceCaps(hdc, LOGPIXELSY));
-	    nchar = nCopyAnsiToWideChar(p, TEXT(lfSysmenu.lfFaceName));
+	    nchar = nCopyAnsiToWideChar(p, lfSysmenu.lfFaceName);
 	}
 	else
 #endif
 	{
 	    *p++ = DLG_FONT_POINT_SIZE;		// point size
-	    nchar = nCopyAnsiToWideChar (p, TEXT(DLG_FONT_NAME));
+	    nchar = nCopyAnsiToWideChar(p, TEXT(DLG_FONT_NAME));
 	}
 	p += nchar;
     }
Member

mattn commented Sep 26, 2017

もう1か所ありますね

diff --git a/src/gui_w32.c b/src/gui_w32.c
index aa0948843..662638ed9 100644
--- a/src/gui_w32.c
+++ b/src/gui_w32.c
@@ -7298,7 +7298,7 @@ gui_mch_dialog(
 	    /* point size */
 	    *p++ = -MulDiv(lfSysmenu.lfHeight, 72,
 		    GetDeviceCaps(hdc, LOGPIXELSY));
-	    nchar = nCopyAnsiToWideChar(p, TEXT(lfSysmenu.lfFaceName));
+	    nchar = nCopyAnsiToWideChar(p, lfSysmenu.lfFaceName);
 	}
 	else
 #endif
@@ -7865,13 +7865,13 @@ gui_mch_tearoff(
 	    /* point size */
 	    *p++ = -MulDiv(lfSysmenu.lfHeight, 72,
 		    GetDeviceCaps(hdc, LOGPIXELSY));
-	    nchar = nCopyAnsiToWideChar(p, TEXT(lfSysmenu.lfFaceName));
+	    nchar = nCopyAnsiToWideChar(p, lfSysmenu.lfFaceName);
 	}
 	else
 #endif
 	{
 	    *p++ = DLG_FONT_POINT_SIZE;		// point size
-	    nchar = nCopyAnsiToWideChar (p, TEXT(DLG_FONT_NAME));
+	    nchar = nCopyAnsiToWideChar(p, TEXT(DLG_FONT_NAME));
 	}
 	p += nchar;
     }
@mattn

This comment has been minimized.

Show comment
Hide comment
@mattn

mattn Sep 26, 2017

Member

あー、lfFaceName は ANSI なのに utf-8 扱いしてるw

Member

mattn commented Sep 26, 2017

あー、lfFaceName は ANSI なのに utf-8 扱いしてるw

@mattn

This comment has been minimized.

Show comment
Hide comment
@mattn

mattn Sep 26, 2017

Member
diff --git a/src/gui_w32.c b/src/gui_w32.c
index aa0948843..fe5de501f 100644
--- a/src/gui_w32.c
+++ b/src/gui_w32.c
@@ -4384,7 +4384,7 @@ add_dialog_element(
 	WORD clss,
 	const char *caption);
 static LPWORD lpwAlign(LPWORD);
-static int nCopyAnsiToWideChar(LPWORD, LPSTR);
+static int nCopyAnsiToWideChar(LPWORD, LPSTR, BOOL);
 #if defined(FEAT_MENU) && defined(FEAT_TEAROFF)
 static void gui_mch_tearoff(char_u *title, vimmenu_T *menu, int initX, int initY);
 #endif
@@ -7285,8 +7285,8 @@ gui_mch_dialog(
 
     /* copy the title of the dialog */
     nchar = nCopyAnsiToWideChar(p, (title ?
-				    (LPSTR)title :
-				    (LPSTR)("Vim "VIM_VERSION_MEDIUM)));
+			    (LPSTR)title :
+			    (LPSTR)("Vim "VIM_VERSION_MEDIUM)), TRUE);
     p += nchar;
 
     if (s_usenewlook)
@@ -7298,13 +7298,13 @@ gui_mch_dialog(
 	    /* point size */
 	    *p++ = -MulDiv(lfSysmenu.lfHeight, 72,
 		    GetDeviceCaps(hdc, LOGPIXELSY));
-	    nchar = nCopyAnsiToWideChar(p, TEXT(lfSysmenu.lfFaceName));
+	    nchar = nCopyAnsiToWideChar(p, lfSysmenu.lfFaceName, FALSE);
 	}
 	else
 #endif
 	{
 	    *p++ = DLG_FONT_POINT_SIZE;		// point size
-	    nchar = nCopyAnsiToWideChar(p, TEXT(DLG_FONT_NAME));
+	    nchar = nCopyAnsiToWideChar(p, TEXT(DLG_FONT_NAME), FALSE);
 	}
 	p += nchar;
     }
@@ -7485,7 +7485,7 @@ add_dialog_element(
     *p++ = (WORD)0xffff;
     *p++ = clss;			//2 more here
 
-    nchar = nCopyAnsiToWideChar(p, (LPSTR)caption); //strlen(caption)+1
+    nchar = nCopyAnsiToWideChar(p, (LPSTR)caption, TRUE); //strlen(caption)+1
     p += nchar;
 
     *p++ = 0;  // advance pointer over nExtraStuff WORD   - 2 more
@@ -7521,7 +7521,8 @@ lpwAlign(
     static int
 nCopyAnsiToWideChar(
     LPWORD lpWCStr,
-    LPSTR lpAnsiIn)
+    LPSTR lpAnsiIn,
+    BOOL enc)
 {
     int		nChar = 0;
 #ifdef FEAT_MBYTE
@@ -7529,7 +7530,7 @@ nCopyAnsiToWideChar(
     int		i;
     WCHAR	*wn;
 
-    if (enc_codepage == 0 && (int)GetACP() != enc_codepage)
+    if (enc && enc_codepage == 0 && (int)GetACP() != enc_codepage)
     {
 	/* Not a codepage, use our own conversion function. */
 	wn = enc_to_utf16((char_u *)lpAnsiIn, NULL);
@@ -7852,8 +7853,8 @@ gui_mch_tearoff(
 
     /* copy the title of the dialog */
     nchar = nCopyAnsiToWideChar(p, ((*title)
-				    ? (LPSTR)title
-				    : (LPSTR)("Vim "VIM_VERSION_MEDIUM)));
+			    ? (LPSTR)title
+			    : (LPSTR)("Vim "VIM_VERSION_MEDIUM)), TRUE);
     p += nchar;
 
     if (s_usenewlook)
@@ -7865,13 +7866,13 @@ gui_mch_tearoff(
 	    /* point size */
 	    *p++ = -MulDiv(lfSysmenu.lfHeight, 72,
 		    GetDeviceCaps(hdc, LOGPIXELSY));
-	    nchar = nCopyAnsiToWideChar(p, TEXT(lfSysmenu.lfFaceName));
+	    nchar = nCopyAnsiToWideChar(p, lfSysmenu.lfFaceName, FALSE);
 	}
 	else
 #endif
 	{
 	    *p++ = DLG_FONT_POINT_SIZE;		// point size
-	    nchar = nCopyAnsiToWideChar (p, TEXT(DLG_FONT_NAME));
+	    nchar = nCopyAnsiToWideChar(p, TEXT(DLG_FONT_NAME), FALSE);
 	}
 	p += nchar;
     }

こうか

Member

mattn commented Sep 26, 2017

diff --git a/src/gui_w32.c b/src/gui_w32.c
index aa0948843..fe5de501f 100644
--- a/src/gui_w32.c
+++ b/src/gui_w32.c
@@ -4384,7 +4384,7 @@ add_dialog_element(
 	WORD clss,
 	const char *caption);
 static LPWORD lpwAlign(LPWORD);
-static int nCopyAnsiToWideChar(LPWORD, LPSTR);
+static int nCopyAnsiToWideChar(LPWORD, LPSTR, BOOL);
 #if defined(FEAT_MENU) && defined(FEAT_TEAROFF)
 static void gui_mch_tearoff(char_u *title, vimmenu_T *menu, int initX, int initY);
 #endif
@@ -7285,8 +7285,8 @@ gui_mch_dialog(
 
     /* copy the title of the dialog */
     nchar = nCopyAnsiToWideChar(p, (title ?
-				    (LPSTR)title :
-				    (LPSTR)("Vim "VIM_VERSION_MEDIUM)));
+			    (LPSTR)title :
+			    (LPSTR)("Vim "VIM_VERSION_MEDIUM)), TRUE);
     p += nchar;
 
     if (s_usenewlook)
@@ -7298,13 +7298,13 @@ gui_mch_dialog(
 	    /* point size */
 	    *p++ = -MulDiv(lfSysmenu.lfHeight, 72,
 		    GetDeviceCaps(hdc, LOGPIXELSY));
-	    nchar = nCopyAnsiToWideChar(p, TEXT(lfSysmenu.lfFaceName));
+	    nchar = nCopyAnsiToWideChar(p, lfSysmenu.lfFaceName, FALSE);
 	}
 	else
 #endif
 	{
 	    *p++ = DLG_FONT_POINT_SIZE;		// point size
-	    nchar = nCopyAnsiToWideChar(p, TEXT(DLG_FONT_NAME));
+	    nchar = nCopyAnsiToWideChar(p, TEXT(DLG_FONT_NAME), FALSE);
 	}
 	p += nchar;
     }
@@ -7485,7 +7485,7 @@ add_dialog_element(
     *p++ = (WORD)0xffff;
     *p++ = clss;			//2 more here
 
-    nchar = nCopyAnsiToWideChar(p, (LPSTR)caption); //strlen(caption)+1
+    nchar = nCopyAnsiToWideChar(p, (LPSTR)caption, TRUE); //strlen(caption)+1
     p += nchar;
 
     *p++ = 0;  // advance pointer over nExtraStuff WORD   - 2 more
@@ -7521,7 +7521,8 @@ lpwAlign(
     static int
 nCopyAnsiToWideChar(
     LPWORD lpWCStr,
-    LPSTR lpAnsiIn)
+    LPSTR lpAnsiIn,
+    BOOL enc)
 {
     int		nChar = 0;
 #ifdef FEAT_MBYTE
@@ -7529,7 +7530,7 @@ nCopyAnsiToWideChar(
     int		i;
     WCHAR	*wn;
 
-    if (enc_codepage == 0 && (int)GetACP() != enc_codepage)
+    if (enc && enc_codepage == 0 && (int)GetACP() != enc_codepage)
     {
 	/* Not a codepage, use our own conversion function. */
 	wn = enc_to_utf16((char_u *)lpAnsiIn, NULL);
@@ -7852,8 +7853,8 @@ gui_mch_tearoff(
 
     /* copy the title of the dialog */
     nchar = nCopyAnsiToWideChar(p, ((*title)
-				    ? (LPSTR)title
-				    : (LPSTR)("Vim "VIM_VERSION_MEDIUM)));
+			    ? (LPSTR)title
+			    : (LPSTR)("Vim "VIM_VERSION_MEDIUM)), TRUE);
     p += nchar;
 
     if (s_usenewlook)
@@ -7865,13 +7866,13 @@ gui_mch_tearoff(
 	    /* point size */
 	    *p++ = -MulDiv(lfSysmenu.lfHeight, 72,
 		    GetDeviceCaps(hdc, LOGPIXELSY));
-	    nchar = nCopyAnsiToWideChar(p, TEXT(lfSysmenu.lfFaceName));
+	    nchar = nCopyAnsiToWideChar(p, lfSysmenu.lfFaceName, FALSE);
 	}
 	else
 #endif
 	{
 	    *p++ = DLG_FONT_POINT_SIZE;		// point size
-	    nchar = nCopyAnsiToWideChar (p, TEXT(DLG_FONT_NAME));
+	    nchar = nCopyAnsiToWideChar(p, TEXT(DLG_FONT_NAME), FALSE);
 	}
 	p += nchar;
     }

こうか

@mattn

This comment has been minimized.

Show comment
Hide comment
@mattn

mattn Sep 26, 2017

Member

なおりed
bea149a6e91115f1

Member

mattn commented Sep 26, 2017

なおりed
bea149a6e91115f1

@mattn

This comment has been minimized.

Show comment
Hide comment
@mattn

mattn Sep 26, 2017

Member

tearoff 時のダイアログも直ってますね。

修正前

c08205cbbd576005

修正後

895b3a1ae8a0434a

Member

mattn commented Sep 26, 2017

tearoff 時のダイアログも直ってますね。

修正前

c08205cbbd576005

修正後

895b3a1ae8a0434a

@mattn

This comment has been minimized.

Show comment
Hide comment
@mattn

mattn Sep 26, 2017

Member

ついでにここもおかしかった?

if (enc_codepage == 0 && (int)GetACP() != enc_codepage)

== でなく >= ?

Member

mattn commented Sep 26, 2017

ついでにここもおかしかった?

if (enc_codepage == 0 && (int)GetACP() != enc_codepage)

== でなく >= ?

@mattn

This comment has been minimized.

Show comment
Hide comment
@mattn
Member

mattn commented Sep 26, 2017

@YoshihiroIto

This comment has been minimized.

Show comment
Hide comment
@YoshihiroIto

YoshihiroIto Sep 26, 2017

image

関連話題かなと思い報告です。
私の環境だと、文字とアイコンが重なってしまいます。

YoshihiroIto commented Sep 26, 2017

image

関連話題かなと思い報告です。
私の環境だと、文字とアイコンが重なってしまいます。

@mattn

This comment has been minimized.

Show comment
Hide comment
@mattn

mattn Sep 26, 2017

Member

パッチ後の画像でしょうか?
OS を教えて貰えますか?

Member

mattn commented Sep 26, 2017

パッチ後の画像でしょうか?
OS を教えて貰えますか?

@YoshihiroIto

This comment has been minimized.

Show comment
Hide comment
@YoshihiroIto

YoshihiroIto Sep 26, 2017

パッチ前の環境です。

Windows 10 Home 64bit
バージョン 1703
OSビルド 15063.608

gvimはkaoriyaさん最新ビルド(596)です。

YoshihiroIto commented Sep 26, 2017

パッチ前の環境です。

Windows 10 Home 64bit
バージョン 1703
OSビルド 15063.608

gvimはkaoriyaさん最新ビルド(596)です。

@k-takata

This comment has been minimized.

Show comment
Hide comment
@k-takata

k-takata Sep 26, 2017

Member

HiDPI対応が不十分なのかもしれません。

Member

k-takata commented Sep 26, 2017

HiDPI対応が不十分なのかもしれません。

@mattn

This comment has been minimized.

Show comment
Hide comment
@mattn

mattn Sep 26, 2017

Member

ひとまず patch 8.0.1150

Member

mattn commented Sep 26, 2017

ひとまず patch 8.0.1150

@mattn

This comment has been minimized.

Show comment
Hide comment
@mattn

mattn Sep 26, 2017

Member

Windows 10 Vim 8.0.1142 です。

vim

Member

mattn commented Sep 26, 2017

Windows 10 Vim 8.0.1142 です。

vim

@mattn

This comment has been minimized.

Show comment
Hide comment
@mattn

mattn Sep 26, 2017

Member

ダイアログ幅の最大が 400px でハードコードされてるので、フォントの設定が大きいと被るんでしょうね。

Member

mattn commented Sep 26, 2017

ダイアログ幅の最大が 400px でハードコードされてるので、フォントの設定が大きいと被るんでしょうね。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment