Incidencia #37155

Feature to add hotkey for font resizing

Abrir Fecha: 2017-05-04 18:06 Última actualización: 2017-05-04 18:06

Informador:
Propietario:
(Ninguno)
Estado:
Open
Componente:
Hito:
(Ninguno)
Prioridad:
5 - Medium
Gravedad:
5 - Medium
Resolución:
Ninguno
Fichero:
Ninguno
Vote
Score: 0
No votes
0.0% (0/0)
0.0% (0/0)

Details

I switch back and forth between a high-res, high-dpi monitor and my laptop, having the ability to hotkey the font size up and down would come in very handy, so I added it to teraterm.

Here's the diff. The change does "eat up" two user keys, but I didn't know about the ramifications of changing the NumOfUserKey macro.

ありがとうございます!

Index: teraterm/common/tttypes.h
===================================================================
--- teraterm/common/tttypes.h	(revision 6700)
+++ teraterm/common/tttypes.h	(working copy)
@@ -853,7 +853,9 @@
 #define IdCmdPrevSWin     87
 #define IdCmdLocalEcho    88
 #define IdCmdScrollLock   89
-#define IdUser1           90
+#define IdCmdFontSizeUp   90
+#define IdCmdFontSizeDown 91
+#define IdUser1           92
 #define NumOfUDK          IdUDK20-IdUDK6+1
 #define NumOfUserKey      99
 #define IdKeyMax          IdUser1+NumOfUserKey-1
Index: teraterm/teraterm/vtdisp.c
===================================================================
--- teraterm/teraterm/vtdisp.c	(revision 6700)
+++ teraterm/teraterm/vtdisp.c	(working copy)
@@ -3359,6 +3359,37 @@
   ChangeCaret();
 }
 
+static int fontSizes[] = { 4, 6, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72 };
+#define NUM_FONT_SIZES (sizeof(fontSizes) / sizeof(fontSizes[0]))
+
+void DispBumpFontSize(int dir)
+{
+	// get logpx scale
+	HDC TmpDC = GetDC(NULL);
+	int logpxy = GetDeviceCaps(TmpDC, LOGPIXELSY);
+	ReleaseDC(NULL, TmpDC);
+
+	// clip direction to -1 or 1.
+	dir = dir > 0 ? 1 : -1;
+
+	for (int i = 0; i < NUM_FONT_SIZES; ++i) {
+		int logpx = -MulDiv(fontSizes[i], logpxy, 72);
+		// logpx gets more negative as font sizes grow, so find largest number not less than current size.
+		if (logpx <= ts.VTFontSize.y) {
+			// now go 1 up or 1 down
+			int newSize = i + dir;
+			// still in range?
+			if (newSize < 0 || newSize == NUM_FONT_SIZES) 
+				break;
+			ts.VTFontSize.y = -MulDiv(fontSizes[newSize], logpxy, 72);
+			ChangeFont();
+			DispChangeWinSize(WinWidth, WinHeight);
+			ChangeCaret();
+			return;
+		}
+	}
+}
+
 void DispRestoreWinSize()
 //  Restore window size by double clik on caption bar
 {
Index: teraterm/teraterm/vtdisp.h
===================================================================
--- teraterm/teraterm/vtdisp.h	(revision 6700)
+++ teraterm/teraterm/vtdisp.h	(working copy)
@@ -71,6 +71,7 @@
 void DispHScroll(int Func, int Pos);
 void DispVScroll(int Func, int Pos);
 void DispSetupFontDlg();
+void DispBumpFontSize(int dir);
 void DispRestoreWinSize();
 void DispSetWinPos();
 void DispSetActive(BOOL ActiveFlag);
Index: teraterm/teraterm/vtwin.cpp
===================================================================
--- teraterm/teraterm/vtwin.cpp	(revision 6700)
+++ teraterm/teraterm/vtwin.cpp	(working copy)
@@ -3492,6 +3492,12 @@
 		case IdCmdScrollLock:
 			ScrollLock = ! ScrollLock;
 			break;
+		case IdCmdFontSizeUp:
+			DispBumpFontSize(1);
+			break;
+		case IdCmdFontSizeDown:
+			DispBumpFontSize(-1);
+			break;
 	}
 	return 0;
 }
Index: teraterm/ttpcmn/ttcmn.c
===================================================================
--- teraterm/ttpcmn/ttcmn.c	(revision 6700)
+++ teraterm/ttpcmn/ttcmn.c	(working copy)
@@ -796,6 +796,8 @@
 		case IdCmdPrevSWin:
 		case IdCmdLocalEcho:
 		case IdCmdScrollLock:
+		case IdCmdFontSizeUp:
+		case IdCmdFontSizeDown:
 			PostMessage(HWin,WM_USER_ACCELCOMMAND,KeyCode,0);
 			break;
 		default:
Index: teraterm/ttpset/ttset.c
===================================================================
--- teraterm/ttpset/ttset.c	(revision 6700)
+++ teraterm/ttpset/ttset.c	(working copy)
@@ -3422,6 +3422,10 @@
 
 	GetInt(KeyMap, IdCmdScrollLock, ShortCut, "ScrollLock", FName);
 
+	GetInt(KeyMap, IdCmdFontSizeUp, ShortCut, "FontSizeUp", FName);
+
+	GetInt(KeyMap, IdCmdFontSizeDown, ShortCut, "FontSizeDown", FName);
+
 	/* user keys */
 
 	Ptr = 0;

Ticket History (1/1 Histories)

2017-05-04 18:06 Updated by: pryankster
  • New Ticket "Feature to add hotkey for font resizing" created

Attachment File List

No attachments

Editar

You are not logged in. I you are not logged in, your comment will be treated as an anonymous post. » Entrar