[Ttssh2-commit] [7714] ttssh2、ビジュアル化fingerprintの表示に等幅フォントを設定する

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2019年 5月 27日 (月) 22:23:19 JST


Revision: 7714
          https://osdn.net/projects/ttssh2/scm/svn/commits/7714
Author:   zmatsuo
Date:     2019-05-27 22:23:19 +0900 (Mon, 27 May 2019)
Log Message:
-----------
ttssh2、ビジュアル化fingerprintの表示に等幅フォントを設定する

- 従来のフォント関連の設定が不要になったのでUTIL_get_lang_font()を削除
- モニタのDPIに合わせて等幅フォントを取得する UTIL_get_lang_fixedfont()を追加
- DPIが変化したとき、OSがフォントを再設定するので、DPIに合わせたサイズのフォントを再設定するようにした

Modified Paths:
--------------
    trunk/ttssh2/ttxssh/hosts.c
    trunk/ttssh2/ttxssh/ttxssh.c
    trunk/ttssh2/ttxssh/ttxssh.h
    trunk/ttssh2/ttxssh/util.c
    trunk/ttssh2/ttxssh/util.h

-------------- next part --------------
Modified: trunk/ttssh2/ttxssh/hosts.c
===================================================================
--- trunk/ttssh2/ttxssh/hosts.c	2019-05-27 13:23:08 UTC (rev 7713)
+++ trunk/ttssh2/ttxssh/hosts.c	2019-05-27 13:23:19 UTC (rev 7714)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 1998-2001, Robert O'Callahan
- * (C) 2004-2017 TeraTerm Project
+ * (C) 2004-2019 TeraTerm Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -40,6 +40,7 @@
 #include "hosts.h"
 #include "dns.h"
 #include "dlglib.h"
+#include "compat_win.h"
 
 #include <openssl/bn.h>
 #include <openssl/evp.h>
@@ -984,7 +985,11 @@
 
 	SetDlgItemText(dlg, IDC_HOSTWARNING, buf2);
 
-	SendMessage(GetDlgItem(dlg, IDC_FP_RANDOMART), WM_SETFONT, (WPARAM)GetStockObject(ANSI_FIXED_FONT), TRUE);
+	pvar->hFontFixed = UTIL_get_lang_fixedfont(dlg, pvar->ts->UILanguageFile);
+	if (pvar->hFontFixed != NULL) {
+		SendDlgItemMessage(dlg, IDC_FP_RANDOMART, WM_SETFONT,
+						   (WPARAM)pvar->hFontFixed, MAKELPARAM(TRUE,0));
+	}
 
 	CheckDlgButton(dlg, IDC_FP_HASH_ALG_SHA256, TRUE);
 	hosts_dlg_set_fingerprint(pvar, dlg, SSH_DIGEST_SHA256);
@@ -1830,6 +1835,26 @@
 			return FALSE;
 		}
 
+	case WM_DPICHANGED:
+		pvar = (PTInstVar) GetWindowLongPtr(dlg, DWLP_USER);
+		if (pvar->hFontFixed != NULL) {
+			DeleteObject(pvar->hFontFixed);
+		}
+		pvar->hFontFixed = UTIL_get_lang_fixedfont(dlg, pvar->ts->UILanguageFile);
+		if (pvar->hFontFixed != NULL) {
+			SendDlgItemMessage(dlg, IDC_FP_RANDOMART, WM_SETFONT,
+							   (WPARAM)pvar->hFontFixed, MAKELPARAM(TRUE,0));
+		}
+		return FALSE;
+
+	case WM_DESTROY:
+		pvar = (PTInstVar) GetWindowLongPtr(dlg, DWLP_USER);
+		if (pvar->hFontFixed != NULL) {
+			DeleteObject(pvar->hFontFixed);
+			pvar->hFontFixed = NULL;
+		}
+		return FALSE;
+
 	default:
 		return FALSE;
 	}
@@ -1963,6 +1988,26 @@
 			return FALSE;
 		}
 
+	case WM_DPICHANGED:
+		pvar = (PTInstVar) GetWindowLongPtr(dlg, DWLP_USER);
+		if (pvar->hFontFixed != NULL) {
+			DeleteObject(pvar->hFontFixed);
+		}
+		pvar->hFontFixed = UTIL_get_lang_fixedfont(dlg, pvar->ts->UILanguageFile);
+		if (pvar->hFontFixed != NULL) {
+			SendDlgItemMessage(dlg, IDC_FP_RANDOMART, WM_SETFONT,
+							   (WPARAM)pvar->hFontFixed, MAKELPARAM(TRUE,0));
+		}
+		return FALSE;
+
+	case WM_DESTROY:
+		pvar = (PTInstVar) GetWindowLongPtr(dlg, DWLP_USER);
+		if (pvar->hFontFixed != NULL) {
+			DeleteObject(pvar->hFontFixed);
+			pvar->hFontFixed = NULL;
+		}
+		return FALSE;
+
 	default:
 		return FALSE;
 	}
@@ -1975,8 +2020,6 @@
                                          LPARAM lParam)
 {
 	PTInstVar pvar;
-//	LOGFONT logfont;
-//	HFONT font;
 	char uimsg[MAX_UIMSG];
 
 	switch (msg) {
@@ -2099,6 +2142,26 @@
 			return FALSE;
 		}
 
+	case WM_DPICHANGED:
+		pvar = (PTInstVar) GetWindowLongPtr(dlg, DWLP_USER);
+		if (pvar->hFontFixed != NULL) {
+			DeleteObject(pvar->hFontFixed);
+		}
+		pvar->hFontFixed = UTIL_get_lang_fixedfont(dlg, pvar->ts->UILanguageFile);
+		if (pvar->hFontFixed != NULL) {
+			SendDlgItemMessage(dlg, IDC_FP_RANDOMART, WM_SETFONT,
+							   (WPARAM)pvar->hFontFixed, MAKELPARAM(TRUE,0));
+		}
+		return FALSE;
+
+	case WM_DESTROY:
+		pvar = (PTInstVar) GetWindowLongPtr(dlg, DWLP_USER);
+		if (pvar->hFontFixed != NULL) {
+			DeleteObject(pvar->hFontFixed);
+			pvar->hFontFixed = NULL;
+		}
+		return FALSE;
+
 	default:
 		return FALSE;
 	}

Modified: trunk/ttssh2/ttxssh/ttxssh.c
===================================================================
--- trunk/ttssh2/ttxssh/ttxssh.c	2019-05-27 13:23:08 UTC (rev 7713)
+++ trunk/ttssh2/ttxssh/ttxssh.c	2019-05-27 13:23:19 UTC (rev 7714)
@@ -105,8 +105,6 @@
 static HICON SecureNotifyIcon = NULL;
 static HICON OldNotifyIcon = NULL;
 
-static HFONT DlgAboutTextFont;
-
 static TInstVar *pvar;
 
 typedef struct {
@@ -2446,21 +2444,13 @@
 static BOOL CALLBACK TTXAboutDlg(HWND dlg, UINT msg, WPARAM wParam,
                                  LPARAM lParam)
 {
+	static HFONT DlgAboutTextFont;
+
 	switch (msg) {
 	case WM_INITDIALOG:
 		// Edit control\x82͓\x99\x95\x9D\x83t\x83H\x83\x93\x83g\x82ŕ\\x8E\xA6\x82\xB5\x82\xBD\x82\xA2\x82̂ŁA\x95ʐݒ\xE8\x8F\xEE\x95񂩂\xE7\x83t\x83H\x83\x93\x83g\x82\xF0\x83Z\x83b\x83g\x82\xB7\x82\xE9\x81B
 		// (2014.5.5. yutaka)
-		if (!UTIL_get_lang_font("DLG_ABOUT_FONT", dlg, NULL, &DlgAboutTextFont, pvar)) {
-			// \x93ǂݍ\x9E\x82߂Ȃ\xA9\x82\xC1\x82\xBD\x8Fꍇ\x82͓\x99\x95\x9D\x83t\x83H\x83\x93\x83g\x82\xF0\x8Ew\x92肷\x82\xE9\x81B
-			// \x83G\x83f\x83B\x83b\x83g\x83R\x83\x93\x83g\x83\x8D\x81[\x83\x8B\x82̓_\x83C\x83A\x83\x8D\x83O\x82Ɠ\xAF\x82\xB6\x83t\x83H\x83\x93\x83g\x82\xF0\x8E\x9D\x82\xC1\x82Ă\xA8\x82\xE8
-			// \x93\x99\x95\x9D\x83t\x83H\x83\x93\x83g\x82ł͂Ȃ\xA2\x82\xBD\x82߁B
-			LOGFONTA logfont = {0};
-			strncpy_s(logfont.lfFaceName, sizeof(logfont.lfFaceName), "Courier New", _TRUNCATE);
-			logfont.lfCharSet = 0;
-			logfont.lfHeight = MulDiv(8, GetDeviceCaps(GetDC(dlg),LOGPIXELSY) * -1, 72);
-			logfont.lfWidth = 0;
-			DlgAboutTextFont = CreateFontIndirect(&logfont);	// \x83G\x83\x89\x81[\x8E\x9E NULL
-		}
+		DlgAboutTextFont = UTIL_get_lang_fixedfont(dlg, pvar->ts->UILanguageFile);
 		if (DlgAboutTextFont != NULL) {
 			SendDlgItemMessage(dlg, IDC_ABOUTTEXT, WM_SETFONT, (WPARAM)DlgAboutTextFont, MAKELPARAM(TRUE,0));
 		}
@@ -2496,16 +2486,10 @@
 		switch (LOWORD(wParam)) {
 		case IDOK:
 			EndDialog(dlg, 1);
-			if (DlgAboutTextFont != NULL) {
-				DeleteObject(DlgAboutTextFont);
-			}
 			return TRUE;
 		case IDCANCEL:			/* there isn't a cancel button, but other Windows
 								   UI things can send this message */
 			EndDialog(dlg, 0);
-			if (DlgAboutTextFont != NULL) {
-				DeleteObject(DlgAboutTextFont);
-			}
 			return TRUE;
 		case IDC_FP_HASH_ALG_MD5:
 			about_dlg_set_abouttext(pvar, dlg, SSH_DIGEST_MD5);
@@ -2515,6 +2499,23 @@
 			return TRUE;
 		}
 		break;
+
+	case WM_DESTROY:
+		if (DlgAboutTextFont != NULL) {
+			DeleteObject(DlgAboutTextFont);
+			DlgAboutTextFont = NULL;
+		}
+		break;
+
+	case WM_DPICHANGED:
+		if (DlgAboutTextFont != NULL) {
+			DeleteObject(DlgAboutTextFont);
+		}
+		DlgAboutTextFont = UTIL_get_lang_fixedfont(dlg, pvar->ts->UILanguageFile);
+		if (DlgAboutTextFont != NULL) {
+			SendDlgItemMessage(dlg, IDC_ABOUTTEXT, WM_SETFONT, (WPARAM)DlgAboutTextFont, MAKELPARAM(TRUE,0));
+		}
+		return FALSE;
 	}
 
 	return FALSE;

Modified: trunk/ttssh2/ttxssh/ttxssh.h
===================================================================
--- trunk/ttssh2/ttxssh/ttxssh.h	2019-05-27 13:23:08 UTC (rev 7713)
+++ trunk/ttssh2/ttxssh/ttxssh.h	2019-05-27 13:23:19 UTC (rev 7714)
@@ -338,6 +338,10 @@
 	char subsystem_name[256];
 
 	BOOL nosession;
+
+	// dialog resource
+	HFONT hFontFixed;		// hosts.c\x93\xE0\x82̃_\x83C\x83A\x83\x8D\x83O\x97p
+
 } TInstVar;
 
 // \x83o\x81[\x83W\x83\x87\x83\x93\x82ɍ\x87\x82킹\x82Ď\xA9\x93\xAE\x95ύX\x82\xB3\x82\xEA\x82\xE9\x81B \x97\xE1: TTSSH_2-81_TS_data

Modified: trunk/ttssh2/ttxssh/util.c
===================================================================
--- trunk/ttssh2/ttxssh/util.c	2019-05-27 13:23:08 UTC (rev 7713)
+++ trunk/ttssh2/ttxssh/util.c	2019-05-27 13:23:19 UTC (rev 7714)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 1998-2001, Robert O'Callahan
- * (C) 2004-2017 TeraTerm Project
+ * (C) 2004-2019 TeraTerm Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -320,21 +320,44 @@
 		def, pvar->ts->UILanguageFile);
 }
 
-int UTIL_get_lang_font(PCHAR key, HWND dlg, PLOGFONT logfont, HFONT *font, PTInstVar pvar)
+/*
+ *	\x93\x99\x95\x9D\x83t\x83H\x83\x93\x83g\x82\xF0\x8E擾
+ *	@retval		\x83t\x83H\x83\x93\x83g\x83n\x83\x93\x83h\x83\x8B
+ *	@retval		NULL(\x83G\x83\x89\x81[)
+ */
+HFONT UTIL_get_lang_fixedfont(HWND hWnd, const char *UILanguageFile)
 {
-	LOGFONT logfont_tmp;
-	if (logfont == NULL) {
-		logfont = &logfont_tmp;
+	HFONT hFont;
+	LOGFONTA logfont;
+	int dpi = GetMonitorDpiFromWindow(hWnd);
+	BOOL result = GetI18nLogfont("TTSSH", "DLG_ABOUT_FONT", &logfont,
+								 dpi, UILanguageFile);
+	if (result == FALSE) {
+		// \x93ǂݍ\x9E\x82߂Ȃ\xA9\x82\xC1\x82\xBD\x8Fꍇ\x82͓\x99\x95\x9D\x83t\x83H\x83\x93\x83g\x82\xF0\x8Ew\x92肷\x82\xE9\x81B
+		// \x83G\x83f\x83B\x83b\x83g\x83R\x83\x93\x83g\x83\x8D\x81[\x83\x8B\x82̓_\x83C\x83A\x83\x8D\x83O\x82Ɠ\xAF\x82\xB6\x83t\x83H\x83\x93\x83g\x82\xF0\x8E\x9D\x82\xC1\x82Ă\xA8\x82\xE8
+		// \x93\x99\x95\x9D\x83t\x83H\x83\x93\x83g\x82ł͂Ȃ\xA2\x82\xBD\x82߁B
+
+		// \x83E\x83B\x83\x93\x83h\x83E(\x83_\x83C\x83A\x83\x8D\x83O)\x82̃t\x83H\x83\x93\x83g\x82\xF0\x8E擾\x81A\x83t\x83H\x83\x93\x83g\x8D\x82\x82\xF0\x8EQ\x8FƂ\xB7\x82\xE9
+		HFONT hFontDlg;
+		LOGFONT logfontDlg;
+		hFontDlg = (HFONT)SendMessage(hWnd, WM_GETFONT, (WPARAM)0, (LPARAM)0);
+		GetObject(hFontDlg, sizeof(logfontDlg), &logfontDlg);
+
+		memset(&logfont, 0, sizeof(logfont));
+		strncpy_s(logfont.lfFaceName, sizeof(logfont.lfFaceName), "Courier New", _TRUNCATE);
+		logfont.lfCharSet = ANSI_CHARSET;	// = 0
+		logfont.lfHeight = logfontDlg.lfHeight;
+		logfont.lfWidth = 0;
 	}
-	if (GetI18nLogfont("TTSSH", key, logfont,
-					   GetDeviceCaps(GetDC(dlg),LOGPIXELSY),
-					   pvar->ts->UILanguageFile) == FALSE) {
-		return FALSE;
+	hFont = CreateFontIndirect(&logfont);	// \x83G\x83\x89\x81[\x8E\x9E NULL
+#if 1
+	if (hFont == NULL) {
+		// \x83t\x83H\x83\x93\x83g\x82\xAA\x90\xB6\x90\xAC\x82ł\xAB\x82Ȃ\xA9\x82\xC1\x82\xBD\x8Fꍇ stock object \x82\xF0\x8Eg\x97p\x82\xB7\x82\xE9
+		// DeleteObject() \x82\xB5\x82Ă\xE0ok\x82̂͂\xB8
+		// It is not necessary (but it is not harmful) to
+		// delete stock objects by calling DeleteObject.
+		hFont = GetStockObject(ANSI_FIXED_FONT);
 	}
-
-	if ((*font = CreateFontIndirect(logfont)) == NULL) {
-		return FALSE;
-	}
-
-	return TRUE;
+#endif
+	return hFont;
 }

Modified: trunk/ttssh2/ttxssh/util.h
===================================================================
--- trunk/ttssh2/ttxssh/util.h	2019-05-27 13:23:08 UTC (rev 7713)
+++ trunk/ttssh2/ttxssh/util.h	2019-05-27 13:23:19 UTC (rev 7714)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 1998-2001, Robert O'Callahan
- * (C) 2004-2017 TeraTerm Project
+ * (C) 2004-2019 TeraTerm Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -85,6 +85,6 @@
 BOOL UTIL_is_sock_deeply_buffered(UTILSockWriteBuf *buf);
 
 void UTIL_get_lang_msg(PCHAR key, PTInstVar pvar, PCHAR def);
-int UTIL_get_lang_font(PCHAR key, HWND dlg, PLOGFONT logfont, HFONT *font, PTInstVar pvar);
+HFONT UTIL_get_lang_fixedfont(HWND hWnd, const char *UILanguageFile);
 
 #endif


Ttssh2-commit メーリングリストの案内
Back to archive index