[Ttssh2-commit] [7379] ダイアログフォント決定方法見直し

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2019年 1月 3日 (木) 01:58:18 JST


Revision: 7379
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/7379
Author:   zmatsuo
Date:     2019-01-03 01:58:18 +0900 (Thu, 03 Jan 2019)
Log Message:
-----------
ダイアログフォント決定方法見直し

Modified Paths:
--------------
    branches/cmake/TTProxy/ProxyWSockHook.h
    branches/cmake/teraterm/common/dlglib.c
    branches/cmake/teraterm/common/i18n.c

-------------- next part --------------
Modified: branches/cmake/TTProxy/ProxyWSockHook.h
===================================================================
--- branches/cmake/TTProxy/ProxyWSockHook.h	2019-01-02 16:58:02 UTC (rev 7378)
+++ branches/cmake/TTProxy/ProxyWSockHook.h	2019-01-02 16:58:18 UTC (rev 7379)
@@ -32,6 +32,7 @@
     GetI18nStrU8("TTProxy", key, buf, buf_len, def, UILanguageFile);
 }
 
+#if 0
 int UTIL_get_lang_font(const char *key, HWND dlg, PLOGFONTA logfont, HFONT *font)
 {
     if (GetI18nLogfont("TTProxy", key, logfont,
@@ -46,6 +47,7 @@
 
     return TRUE;
 }
+#endif
 
 class ProxyWSockHook {
 public:
@@ -741,7 +743,7 @@
         Window conn;
         Window erro;
         Window log;
-        HFONT DlgFont;
+//        HFONT DlgFont;
     protected:
         virtual bool dispatch(int message, int wParam, long lParam) {
             if (message == WM_COMMAND && wParam == MAKEWPARAM(IDC_REFER, BN_CLICKED)) {
@@ -793,11 +795,12 @@
             };
             TCHAR uimsg[MAX_UIMSG];
 //			TCHAR uitmp[MAX_UIMSG];
-            LOGFONTA logfont;
-            HFONT font;
+//            LOGFONTA logfont;
+//            HFONT font;
 
             Dialog::onInitDialog();
 
+#if 0
             font = (HFONT)SendMessage(WM_GETFONT, 0, 0);
             GetObject(font, sizeof(logfont), &logfont);
             if (UTIL_get_lang_font("DLG_TAHOMA_FONT", HWND(), &logfont, &DlgFont)) {
@@ -828,6 +831,7 @@
             else {
                 DlgFont = NULL;
             }
+#endif
 
             HWND hWnd = (HWND)this;
 			hWnd = GetHWND();
@@ -937,15 +941,19 @@
 
             logfile = log.GetWindowTextLength() > 0 ? log.GetWindowText() : NULL;
 
+#if 0
             if (DlgFont != NULL) {
                 DeleteObject(DlgFont);
             }
+#endif
             Dialog::onOK();
         }
         virtual void onCancel() {
+#if 0
             if (DlgFont != NULL) {
                 DeleteObject(DlgFont);
             }
+#endif
             Dialog::onCancel();
         }
     public:
@@ -974,7 +982,7 @@
         EditBoxCtrl  user;
         EditBoxCtrl  pass;
         bool lock;
-        HFONT DlgFont;
+//        HFONT DlgFont;
     protected:
         virtual bool dispatch(int message, int wParam, long lParam) {
             if (message == WM_COMMAND) {
@@ -997,11 +1005,12 @@
         virtual bool onInitDialog() {
             TCHAR uimsg[MAX_UIMSG];
 //			TCHAR uitmp[MAX_UIMSG];
-            LOGFONTA logfont;
-            HFONT font;
+//            LOGFONTA logfont;
+//            HFONT font;
 
             Dialog::onInitDialog();
 
+#if 0
             font = (HFONT)SendMessage(WM_GETFONT, 0, 0);
             GetObject(font, sizeof(logfont), &logfont);
             if (UTIL_get_lang_font("DLG_TAHOMA_FONT", HWND(), &logfont, &DlgFont)) {
@@ -1024,7 +1033,7 @@
             else {
                 DlgFont = NULL;
             }
-
+#endif
             const static DlgTextInfo text_info[] = {
                 { 0, "DLG_SETUP_TITLE" },
                 { IDC_URL_LABEL, "DLG_SETUP_URL" },
@@ -1131,15 +1140,19 @@
                     return;
                 }
             }
+#if 0
             if (DlgFont != NULL) {
                 DeleteObject(DlgFont);
             }
+#endif
             Dialog::onOK();
         }
         virtual void onCancel() {
+#if 0
             if (DlgFont != NULL) {
                 DeleteObject(DlgFont);
             }
+#endif
             Dialog::onCancel();
         }
         void onOptions() {
@@ -1251,6 +1264,7 @@
             const TCHAR *ver;
             int n, a, b, c, d, len;
             TCHAR uimsg[MAX_UIMSG], uimsg2[MAX_UIMSG], uimsg3[MAX_UIMSG];
+#if 0
             LOGFONTA logfont;
             HFONT font;
 
@@ -1263,6 +1277,7 @@
             else {
                 DlgFont = NULL;
             }
+#endif
 
             GetWindowText(uimsg2, _countof(uimsg2));
             UTIL_get_lang_msg("DLG_ABOUT_TITLE", uimsg, _countof(uimsg), uimsg2);

Modified: branches/cmake/teraterm/common/dlglib.c
===================================================================
--- branches/cmake/teraterm/common/dlglib.c	2019-01-02 16:58:02 UTC (rev 7378)
+++ branches/cmake/teraterm/common/dlglib.c	2019-01-02 16:58:18 UTC (rev 7379)
@@ -459,9 +459,8 @@
 	LONG height;
 } DialogFontLists;
 
-DWORD GetDialogFontCandidate(const DialogFontLists **candidate_list)
+const DialogFontLists *GetDialogFontCandidate(BYTE char_set)
 {
-	DWORD char_set = GetCharSet();
 	switch (char_set) {
 	case SHIFTJIS_CHARSET: {
 		static const DialogFontLists list[] = {
@@ -471,8 +470,7 @@
 			{ _T("MS ゴシック"), -9 },	// Windows 3.1以降
 			0
 		};
-		*candidate_list = list;
-		return char_set;
+		return list;
 	}
 	case HANGUL_CHARSET: {
 		// Korean
@@ -481,8 +479,7 @@
 			{ _T("굴림"), -10 },
 			0
 		};
-		*candidate_list = list;
-		return char_set;
+		return list;
 	}
 	case GB2312_CHARSET: {
 		// Simplified Chinese
@@ -491,8 +488,7 @@
 			{ _T("微软雅黑") , -10 },
 			0
 		};
-		*candidate_list = list;
-		return char_set;
+		return list;
 	}
 	case CHINESEBIG5_CHARSET: {
 		// Traditional Chinese
@@ -501,8 +497,7 @@
 			{ _T("新細明體") , -10 },
 			0
 		};
-		*candidate_list = list;
-		return char_set;
+		return list;
 	}
 	default: {
 		static const DialogFontLists list[] = {
@@ -509,8 +504,7 @@
 			{ _T("Tahoma"), -8 },
 			0
 		};
-		*candidate_list = list;
-		return char_set;
+		return list;
 	}
 	}
 }
@@ -520,15 +514,33 @@
  */
 void SetDialogFont(const char *section, const char *UILanguageFile)
 {
+	BYTE char_set = SYMBOL_CHARSET;	// symbolを使うことはないだろう
+
 	// 明示的に指定されている場合はそれに従う
 	{
+		static const char *dlg_font_keys[] = {
+			"DLG_FONT",
+			"DLG_TAHOMA_FONT",
+			"DLG_SYSTEM_FONT",
+		};
 		BOOL result = FALSE;
 		LOGFONTA logfont;
+		int i;
 		if (section != NULL) {
-			result = GetI18nLogfont(section, "DLG_FONT", &logfont, 72, UILanguageFile);
+			for (i = 0; i < _countof(dlg_font_keys); i++) {
+				result = GetI18nLogfont(section, "DLG_FONT", &logfont, 72, UILanguageFile);
+				if (result == TRUE) {
+					break;
+				}
+			}
 		}
 		if (result == FALSE) {
-			result = GetI18nLogfont("Tera Term", "DLG_FONT", &logfont, 72, UILanguageFile);
+			for (i = 0; i < _countof(dlg_font_keys); i++) {
+				result = GetI18nLogfont("Tera Term", "DLG_FONT", &logfont, 72, UILanguageFile);
+				if (result == TRUE) {
+					break;
+				}
+			}
 		}
 		if (result == TRUE) {
 #if defined(UNICODE)
@@ -544,6 +556,9 @@
 				return;
 			}
 #endif
+
+			// 使用したかったフォントのCharSetを取得
+			char_set = logfont.lfCharSet;
 			// TODO フォントが見つからなかったときの処理
 			//	messagebox()出して下へ続くが妥当か?
 		}
@@ -551,14 +566,18 @@
 
 	// 実際に存在するフォントを使用する
 	{
-		DWORD charset;
-		const DialogFontLists *list;
-		charset = GetDialogFontCandidate(&list);
+		if (char_set == SYMBOL_CHARSET) {
+			// 未設定の場合
+			char_set = GetCharSet();
+		}
+		const DialogFontLists *list = GetDialogFontCandidate(char_set);
 		while(list->face != NULL) {
-			if (IsExistFont(list->face, (BYTE)charset, TRUE)) {
-				TTSetDlgFont(list->face, list->height, charset);
+			if (IsExistFont(list->face, char_set, TRUE)) {
+				// 候補内に存在するフォントが存在した
+				TTSetDlgFont(list->face, list->height, char_set);
 				return;
 			}
+			list++;
 		}
 	}
 

Modified: branches/cmake/teraterm/common/i18n.c
===================================================================
--- branches/cmake/teraterm/common/i18n.c	2019-01-02 16:58:02 UTC (rev 7378)
+++ branches/cmake/teraterm/common/i18n.c	2019-01-02 16:58:18 UTC (rev 7379)
@@ -1,4 +1,4 @@
-/*
+/*
  * Copyright (C) 2006-2018 TeraTerm Project
  * All rights reserved.
  *
@@ -52,7 +52,7 @@
 	RestoreNewLine(buf);
 }
 
-// TODO: バッファ不足時の動作
+// TODO: \x83o\x83b\x83t\x83@\x95s\x91\xAB\x8E\x9E\x82̓\xAE\x8D\xEC
 DllExport void GetI18nStrU8(const char *section, const char *key, char *buf, int buf_len, const char *def, const char *iniFile)
 {
 	int r;
@@ -88,8 +88,8 @@
 	static char tmp[MAX_UIMSG];
 	static char font[LF_FACESIZE];
 	int hight, charset;
-	GetPrivateProfileStringA(section, key, "-", tmp, MAX_UIMSG, iniFile);
-	if (strcmp(tmp, "-") == 0) {
+	GetPrivateProfileStringA(section, key, "", tmp, MAX_UIMSG, iniFile);
+	if (tmp[0] == '\0') {
 		return FALSE;
 	}
 


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