[Ttssh2-commit] [8518] TSPECIAL1.TTF のロードを layer for unicode を使用するようにした

scmno****@osdn***** scmno****@osdn*****
2020年 1月 31日 (金) 08:42:48 JST


Revision: 8518
          https://osdn.net/projects/ttssh2/scm/svn/commits/8518
Author:   zmatsuo
Date:     2020-01-31 08:42:47 +0900 (Fri, 31 Jan 2020)
Log Message:
-----------
TSPECIAL1.TTF のロードを layer for unicode を使用するようにした

Modified Paths:
--------------
    trunk/teraterm/common/compat_win.cpp
    trunk/teraterm/common/compat_win.h
    trunk/teraterm/common/layer_for_unicode.cpp
    trunk/teraterm/common/layer_for_unicode.h
    trunk/teraterm/teraterm/teraterm.cpp

-------------- next part --------------
Modified: trunk/teraterm/common/compat_win.cpp
===================================================================
--- trunk/teraterm/common/compat_win.cpp	2020-01-30 23:42:44 UTC (rev 8517)
+++ trunk/teraterm/common/compat_win.cpp	2020-01-30 23:42:47 UTC (rev 8518)
@@ -56,10 +56,6 @@
 BOOL (WINAPI *pIsValidDpiAwarenessContext)(DPI_AWARENESS_CONTEXT dpiContext);
 UINT (WINAPI *pGetDpiForWindow)(HWND hwnd);
 BOOL (WINAPI *pSetLayeredWindowAttributes)(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);
-int (WINAPI *pAddFontResourceExA)(LPCSTR name, DWORD fl, PVOID res);
-int (WINAPI *pAddFontResourceExW)(LPCWSTR name, DWORD fl, PVOID res);
-BOOL (WINAPI *pRemoveFontResourceExA)(LPCSTR name, DWORD fl, PVOID pdv);
-BOOL (WINAPI *pRemoveFontResourceExW)(LPCWSTR name, DWORD fl, PVOID pdv);
 HRESULT (WINAPI *pGetDpiForMonitor)(HMONITOR hmonitor, MONITOR_DPI_TYPE dpiType, UINT *dpiX, UINT *dpiY);
 BOOL (WINAPI *pAdjustWindowRectEx)(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle);
 BOOL (WINAPI *pAdjustWindowRectExForDpi)(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle, UINT dpi);
@@ -67,6 +63,11 @@
 int (WINAPI *pMessageBoxW)(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType);
 INT_PTR (WINAPI *pDialogBoxIndirectParamW)(HINSTANCE hInstance, LPCDLGTEMPLATEW hDialogTemplate, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam);
 
+// gdi32.lib
+int (WINAPI *pAddFontResourceExW)(LPCWSTR name, DWORD fl, PVOID res);
+BOOL (WINAPI *pRemoveFontResourceExW)(LPCWSTR name, DWORD fl, PVOID pdv);
+
+// htmlhelp.ocx
 HWND (WINAPI *pHtmlHelpW)(HWND hwndCaller, LPCWSTR pszFile, UINT uCommand, DWORD_PTR dwData);
 HWND (WINAPI *pHtmlHelpA)(HWND hwndCaller, LPCSTR pszFile, UINT uCommand, DWORD_PTR dwData);
 
@@ -147,8 +148,6 @@
 };
 
 static const APIInfo Lists_gdi32[] = {
-	{ "AddFontResourceExA", (void **)&pAddFontResourceExA },
-	{ "RemoveFontResourceExA", (void **)&pRemoveFontResourceExA },
 	{ "AddFontResourceExW", (void **)&pAddFontResourceExW },
 	{ "RemoveFontResourceExW", (void **)&pRemoveFontResourceExW },
 	{},

Modified: trunk/teraterm/common/compat_win.h
===================================================================
--- trunk/teraterm/common/compat_win.h	2020-01-30 23:42:44 UTC (rev 8517)
+++ trunk/teraterm/common/compat_win.h	2020-01-30 23:42:47 UTC (rev 8518)
@@ -93,9 +93,7 @@
 extern BOOL (WINAPI *pAdjustWindowRectEx)(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle);
 extern BOOL (WINAPI *pAdjustWindowRectExForDpi)(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle, UINT dpi);
 extern BOOL (WINAPI *pSetLayeredWindowAttributes)(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);
-extern int (WINAPI *pAddFontResourceExA)(LPCSTR name, DWORD fl, PVOID res);
 extern int (WINAPI *pAddFontResourceExW)(LPCWSTR name, DWORD fl, PVOID res);
-extern BOOL (WINAPI *pRemoveFontResourceExA)(LPCSTR name, DWORD fl, PVOID pdv);
 extern BOOL (WINAPI *pRemoveFontResourceExW)(LPCWSTR name, DWORD fl, PVOID pdv);
 extern HWND (WINAPI *pGetConsoleWindow)(void);
 extern int (WINAPI *pMessageBoxW)(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType);
@@ -110,14 +108,6 @@
 extern BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR hMonitor, LPMONITORINFO lpmi);
 
 
-#ifdef UNICODE
-#define pAddFontResourceEx		pAddFontResourceExW
-#define pRemoveFontResourceEx	pRemoveFontResourceExW
-#else
-#define pAddFontResourceEx		pAddFontResourceExA
-#define pRemoveFontResourceEx	pRemoveFontResourceExA
-#endif // !UNICODE
-
 void WinCompatInit();
 
 #ifdef __cplusplus

Modified: trunk/teraterm/common/layer_for_unicode.cpp
===================================================================
--- trunk/teraterm/common/layer_for_unicode.cpp	2020-01-30 23:42:44 UTC (rev 8517)
+++ trunk/teraterm/common/layer_for_unicode.cpp	2020-01-30 23:42:47 UTC (rev 8518)
@@ -318,3 +318,37 @@
 	free(itemA);
 	return result;
 }
+
+int  _AddFontResourceExW(LPCWSTR name, DWORD fl, PVOID res)
+{
+	if (pAddFontResourceExW != NULL) {
+		/* Windows 2000\x88ȍ~\x82͎g\x82\xA6\x82\xE9\x82͂\xB8 */
+		return pAddFontResourceExW(name, fl, res);
+	}
+	return 0;
+}
+
+BOOL _RemoveFontResourceExW(LPCWSTR name, DWORD fl, PVOID pdv)
+{
+	if (pRemoveFontResourceExW != NULL) {
+		/* Windows 2000\x88ȍ~\x82͎g\x82\xA6\x82\xE9\x82͂\xB8 */
+		return pRemoveFontResourceExW(name, fl, pdv);
+	}
+	return FALSE;
+}
+
+int _AddFontResourceW(LPCWSTR lpFileName)
+{
+	char *filenameA = ToCharW(lpFileName);
+	int result = AddFontResourceA(filenameA);
+	free(filenameA);
+	return result;
+}
+
+BOOL _RemoveFontResourceW(LPCWSTR lpFileName)
+{
+	char *filenameA = ToCharW(lpFileName);
+	int result = RemoveFontResourceA(filenameA);
+	free(filenameA);
+	return result;
+}

Modified: trunk/teraterm/common/layer_for_unicode.h
===================================================================
--- trunk/teraterm/common/layer_for_unicode.h	2020-01-30 23:42:44 UTC (rev 8517)
+++ trunk/teraterm/common/layer_for_unicode.h	2020-01-30 23:42:47 UTC (rev 8518)
@@ -56,6 +56,12 @@
 BOOL _AppendMenuW(HMENU hMenu, UINT uFlags, UINT_PTR uIDNewItem, LPCWSTR lpNewItem);
 HWND _HtmlHelpW(HWND hwndCaller, LPCWSTR pszFile, UINT uCommand, DWORD_PTR dwData);
 
+// gdi32.lib
+int _AddFontResourceW(LPCWSTR lpFileName);
+BOOL _RemoveFontResourceW(LPCWSTR lpFileName);
+int _AddFontResourceExW(LPCWSTR name, DWORD fl, PVOID res);
+BOOL _RemoveFontResourceExW(LPCWSTR name, DWORD fl, PVOID pdv);
+
 // Comctl32.lib
 HPROPSHEETPAGE _CreatePropertySheetPageW(LPCPROPSHEETPAGEW_V1 constPropSheetPagePointer);
 INT_PTR _PropertySheetW(PROPSHEETHEADERW *constPropSheetHeaderPointer);

Modified: trunk/teraterm/teraterm/teraterm.cpp
===================================================================
--- trunk/teraterm/teraterm/teraterm.cpp	2020-01-30 23:42:44 UTC (rev 8517)
+++ trunk/teraterm/teraterm/teraterm.cpp	2020-01-30 23:42:47 UTC (rev 8518)
@@ -59,6 +59,7 @@
 #if UNICODE_INTERNAL_BUFF
 #include "sendmem.h"
 #endif
+#include "layer_for_unicode.h"
 
 #if defined(_DEBUG) && defined(_MSC_VER)
 #define new ::new(_NORMAL_BLOCK, __FILE__, __LINE__)
@@ -65,45 +66,46 @@
 #endif
 
 static BOOL AddFontFlag;
-static TCHAR TSpecialFont[MAX_PATH];
+static wchar_t TSpecialFont[MAX_PATH];
 static CVTWindow* pVTWin;
 
 static void LoadSpecialFont()
 {
-	if (!IsExistFontA("Tera Special", SYMBOL_CHARSET, TRUE)) {
-		int r;
+	if (IsExistFontA("Tera Special", SYMBOL_CHARSET, TRUE)) {
+		// \x82\xB7\x82łɑ\xB6\x8D݂\xB7\x82\xE9\x82̂Ń\x8D\x81[\x83h\x82\xB5\x82Ȃ\xA2
+		return;
+	}
 
-		if (GetModuleFileName(NULL, TSpecialFont,_countof(TSpecialFont)) == 0) {
-			AddFontFlag = FALSE;
-			return;
-		}
-		*_tcsrchr(TSpecialFont, _T('\\')) = 0;
-		_tcscat_s(TSpecialFont, _T("\\TSPECIAL1.TTF"));
+	if (GetModuleFileNameW(NULL, TSpecialFont, _countof(TSpecialFont)) == 0) {
+		AddFontFlag = FALSE;
+		return;
+	}
+	*wcsrchr(TSpecialFont, L'\\') = 0;
+	wcscat_s(TSpecialFont, L"\\TSPECIAL1.TTF");
 
-		if (pAddFontResourceEx != NULL) {
-			// teraterm.exe\x82݂̂ŗL\x8C\xF8\x82ȃt\x83H\x83\x93\x83g\x82ƂȂ\xE9\x81B
-			// remove\x82\xB5\x82Ȃ\xAD\x82Ă\xE0\x8FI\x97\xB9\x82\xB7\x82\xE9\x82\xC6OS\x82\xA9\x82\xE7\x82Ȃ\xAD\x82Ȃ\xE9
-			r = pAddFontResourceEx(TSpecialFont, FR_PRIVATE, NULL);
-		} else {
-			// \x83V\x83X\x83e\x83\x80\x91S\x91̂Ŏg\x82\xA6\x82\xE9\x83t\x83H\x83\x93\x83g\x82ƂȂ\xE9
-			// remove\x82\xB5\x82Ȃ\xA2\x82\xC6OS\x82\xAA\x92͂񂾂܂܂ƂȂ\xE9
-			r = AddFontResource(TSpecialFont);
-		}
-		if (r != 0) {
-			AddFontFlag = TRUE;
-		}
+	// teraterm.exe\x82݂̂ŗL\x8C\xF8\x82ȃt\x83H\x83\x93\x83g\x82ƂȂ\xE9\x81B
+	// remove\x82\xB5\x82Ȃ\xAD\x82Ă\xE0\x8FI\x97\xB9\x82\xB7\x82\xE9\x82\xC6OS\x82\xA9\x82\xE7\x82Ȃ\xAD\x82Ȃ\xE9
+	int r = _AddFontResourceExW(TSpecialFont, FR_PRIVATE, NULL);
+	if (r == 0) {
+		// AddFontResourceEx() \x82\xAA\x8Eg\x82\xA6\x82Ȃ\xA9\x82\xC1\x82\xBD
+		// \x83V\x83X\x83e\x83\x80\x91S\x91̂Ŏg\x82\xA6\x82\xE9\x83t\x83H\x83\x93\x83g\x82ƂȂ\xE9
+		// remove\x82\xB5\x82Ȃ\xA2\x82\xC6OS\x82\xAA\x92͂񂾂܂܂ƂȂ\xE9
+		r = _AddFontResourceW(TSpecialFont);
 	}
+	if (r != 0) {
+		AddFontFlag = TRUE;
+	}
 }
 
 static void UnloadSpecialFont()
 {
-	if (AddFontFlag) {
-		if (pRemoveFontResourceEx != NULL) {
-			pRemoveFontResourceEx(TSpecialFont, FR_PRIVATE, NULL);
-		} else {
-			RemoveFontResource(TSpecialFont);
-		}
+	if (!AddFontFlag) {
+		return;
 	}
+	int r = _RemoveFontResourceExW(TSpecialFont, FR_PRIVATE, NULL);
+	if (r == 0) {
+		_RemoveFontResourceW(TSpecialFont);
+	}
 }
 
 static void init()


Ttssh2-commit メーリングリストの案内