[Ttssh2-commit] [7587] フォントの単位変換関数を追加

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2019年 4月 13日 (土) 01:19:17 JST


Revision: 7587
          https://osdn.net/projects/ttssh2/scm/svn/commits/7587
Author:   zmatsuo
Date:     2019-04-13 01:19:17 +0900 (Sat, 13 Apr 2019)
Log Message:
-----------
フォントの単位変換関数を追加
GetFontPointFromPixel(), GetFontPixelFromPoint()

Modified Paths:
--------------
    trunk/teraterm/common/dlglib.h
    trunk/teraterm/common/dlglib_cpp.cpp
    trunk/teraterm/common/dlglib_tmpl.cpp

-------------- next part --------------
Modified: trunk/teraterm/common/dlglib.h
===================================================================
--- trunk/teraterm/common/dlglib.h	2019-04-12 16:19:05 UTC (rev 7586)
+++ trunk/teraterm/common/dlglib.h	2019-04-12 16:19:17 UTC (rev 7587)
@@ -91,6 +91,8 @@
 HFONT SetDlgFonts(HWND hDlg, const int nIDDlgItems[], int nIDDlgItemCount,
 				  const char *UILanguageFile, PCHAR key);
 BOOL IsExistFontA(const char *face, BYTE charset, BOOL strict);
+int GetFontPointFromPixel(HWND hWnd, int pixel);
+int GetFontPixelFromPoint(HWND hWnd, int point);
 
 #if defined(_UNICODE)
 #define TTSetDlgFont(p1,p2,p3)	TTSetDlgFontW(p1,p2,p3)

Modified: trunk/teraterm/common/dlglib_cpp.cpp
===================================================================
--- trunk/teraterm/common/dlglib_cpp.cpp	2019-04-12 16:19:05 UTC (rev 7586)
+++ trunk/teraterm/common/dlglib_cpp.cpp	2019-04-12 16:19:17 UTC (rev 7587)
@@ -319,6 +319,40 @@
 	{
 		LOGFONT logfont;
 		GetMessageboxFont(&logfont);
+		if (logfont.lfHeight < 0) {
+			logfont.lfHeight = GetFontPointFromPixel(NULL, -logfont.lfHeight);
+		}
 		TTSetDlgFont(logfont.lfFaceName, logfont.lfHeight, logfont.lfCharSet);
 	}
 }
+
+
+/**
+ *	pixel\x90\x94\x82\xF0point\x90\x94\x82ɕϊ\xB7\x82\xB7\x82\xE9(\x83t\x83H\x83\x93\x83g\x97p)
+ *		\x92\x8D 1point = 1/72 inch, \x83t\x83H\x83\x93\x83g\x82̒P\x88\xCA
+ *		\x92\x8D \x83E\x83B\x83\x93\x83h\x83E\x82̕\\x8E\xA6\x8B\x82Ŕ{\x97\xA6\x82\xAA\x95ω\xBB\x82\xB7\x82\xE9\x82̂\xC5 hWnd \x82\xAA\x95K\x97v
+ */
+int GetFontPixelFromPoint(HWND hWnd, int pixel)
+{
+	if (hWnd == NULL) {
+		hWnd = GetDesktopWindow();
+	}
+	HDC DC = GetDC(hWnd);
+	int dpi = GetDeviceCaps(DC, LOGPIXELSY);	// dpi = dot per inch (96DPI)
+	int point = MulDiv(pixel, dpi, 72);			// pixel = point / 72 * dpi
+	ReleaseDC(hWnd, DC);
+	return point;
+}
+
+/**
+ *	point\x90\x94\x82\xF0pixel\x90\x94\x82ɕϊ\xB7\x82\xB7\x82\xE9(\x83t\x83H\x83\x93\x83g\x97p)
+ *		\x92\x8D 1point = 1/72 inch, \x83t\x83H\x83\x93\x83g\x82̒P\x88\xCA
+ */
+int GetFontPointFromPixel(HWND hWnd, int point)
+{
+	HDC DC = GetDC(hWnd);
+	int dpi = GetDeviceCaps(DC, LOGPIXELSY);	// dpi = dot per inch (96DPI)
+	int pixel = MulDiv(point, 72, dpi);			// point = pixel / dpi * 72
+	ReleaseDC(hWnd, DC);
+	return pixel;
+}

Modified: trunk/teraterm/common/dlglib_tmpl.cpp
===================================================================
--- trunk/teraterm/common/dlglib_tmpl.cpp	2019-04-12 16:19:05 UTC (rev 7586)
+++ trunk/teraterm/common/dlglib_tmpl.cpp	2019-04-12 16:19:17 UTC (rev 7587)
@@ -440,6 +440,10 @@
 static LONG FontHeight;
 static BYTE FontCharSet;
 
+/**
+ *	\x83_\x83C\x83A\x83\x8D\x83O\x82̃t\x83H\x83\x93\x83g\x82\xF0\x90ݒ肷\x82\xE9
+ *	height\x82̒P\x88ʂ̓|\x83C\x83\x93\x83g
+ */
 void TTSetDlgFontW(const wchar_t *face, int height, int charset)
 {
 	if (face != NULL) {
@@ -451,6 +455,10 @@
 	FontCharSet = (BYTE)charset;
 }
 
+/**
+ *	\x83_\x83C\x83A\x83\x8D\x83O\x82̃t\x83H\x83\x93\x83g\x82\xF0\x90ݒ肷\x82\xE9
+ *	height\x82̒P\x88ʂ̓|\x83C\x83\x93\x83g
+ */
 void TTSetDlgFontA(const char *face, int height, int charset)
 {
 	if (face != NULL) {


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