GUI Font Tool

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

GUI Font Tool

24 Sep 2017, 10:42

I wrote this a few months ago to help with selecting the font options for gui's.

Image

Before I made this script I rarely used anything but the default font, but with this tool I find it much easier to select a font to use on a project.

Notes:

- To use this script you will first need to get the font list from here: https://pastebin.com/uKdFfD1M
then copy it into a .txt file named "Font Family List.txt" saved into the same folder as the script.
When I made the list I only added the default fonts that I had when I got my computer, if you are missing any from my list the script will give you a error when you select
that font. If that happens, just remove that font from the text file and rerun the script.

- If you have fonts that are not on the list you can just add them to the text file

- There are two commented out hotkeys at the bottom of the script that can be used to create a new font list if needed.

- If the font editor is not the active window it will shrink down to about 50x20 pixels in the bottom right corner. I think I did this because I would often have multiple gui's
running at once and this made jumping to the editor quicker. The point is, it can take a few mins to get used to it shrinking.

- If you switch fonts/size/etc too many times the script will crash. When it does, just remember what font options you were at and hit the reload button and continue
from where you were. As far as I have been able to tell, there is nothing else that can be done about this, but after the first few times it happens you will get used to it.

- The script will auto generate the code for your selected font, just copy it and paste it into your script and adjust the "Q" value as needed (1-5)

Code: Select all

;Written By: Hellbent aka. CivReborn
;Written For: The CivReborn YouTube Channel (https://www.youtube.com/user/CivReborn/featured)
;Date Written: May 1st, 2017
;PasteBin Link Of Script: https://pastebin.com/E9tLF47g
;PasteBin Link Of Font Text Doc:https://pastebin.com/uKdFfD1M




#SingleInstance,Force
SetWorkingDir,%A_ScriptDir%
OnMessage(0x201, "WM_LBUTTONDOWN")
Edit_Color:= "White"
Set_Window_Size:=0
Family:=0
;Loading Font Faimly Dir
;-------------------------------
FileRead,Temp,Font Family List.txt
Font_Family_Index := 0
loop, read,Font Family List.txt 
	{
		Font_Family%A_Index% :=A_LoopReadLine 
		Font_Family0 = %A_Index%
	}

Loop,%Font_Family0%
	{
		if A_Index = 1
			List2 .= Font_Family%A_Index%  . "||" 
		else if A_Index != 1
			List2 .= Font_Family%A_Index%  . "|" 
	}	
;-------------------------------------------------------
;Loading Font Favourites Dir
;-------------------------------
FileRead,Temp,Font Favourites.txt
	Font_Favorites_Index := 0
	loop, read,Font Favourites.txt
		{
		Font_Favorites%A_Index% :=A_LoopReadLine 
		Font_Favorites0 = %A_Index%
		}

	Loop,%Font_Favorites0%
		{
			if A_Index = 2
			List1 .= Font_Favorites%A_Index%  . "||" 
			
			else 
				List1 .= Font_Favorites%A_Index%  . "|" 
		}
;-------------------------------------------------------		
Gui, 1:Color,Gray,
Gui, 1:Add, Groupbox, xm ym-5 w830 h150 center Section,Options
Gui, 1:Add, Groupbox, xs+10 ym+20 w220 h55  Section,Font Family 
Gui, 1:Add, DropDownList,xs+5 ys+20  w200 r20 Sort vFont_Family_Selected gCheck ,%List2% 
Gui, 1:Add, Groupbox, xs  w220 h55 Section,Favourites 
Gui, 1:Add, DropDownList,xs+10 ys+20  w200 r20 Sort vFont_Favorites gCheck1,%List1%
Gui, 1:Add, Groupbox, x250 ym+20 w120 h117 Section,Save / Delete
Gui, 1:Add, Button, xs+10 ys+20 w100 h30  gAdd_To_Favourites,Add To Favourites
Gui, 1:Add, Button, xp yp+55 w100 h30  gRemove_From_Favourites,Remove From Favourites
Gui, 1:Add, Groupbox, x380 ym+20 w220 h55  Section,Type Colour 
Gui, 1:Add, DropDownList,xs+10 ys+20  w200 r20 vFont_Color gUpdate_Font,Black||Silver|Gray|White|Maroon|Red|Purple|Fuchsia|Green|Lime|Olive|Yellow|Navy|Blue|Teal|Aqua|
Gui, 1:Add, Groupbox, xs  w220 h55  Section,Type Size 
Gui, 1:Font,cBlack s16 Bold
Gui, 1:Add, Edit, xs+10 ys+20 w180 h30  vFont_Size gUpdate_Font
Gui, 1:Add, UpDown, range1-200,12
Gui, 1:Font,
Gui, 1:Add, Groupbox,x610 ym+20  w220 h55  Section,Background Colour
Gui, 1:Add, DropDownList,xs+10 ys+20  w200 r20 vEdit_Color gUpdate_Edit,Black|Silver|Gray|White||Maroon|Red|Purple|Fuchsia|Green|Lime|Olive|Yellow|Navy|Blue|Teal|Aqua|
Gui, 1:Add, Checkbox, xs ys+65 w100 BackgroundTrans vBold_Font gUpdate_Font,Bold
Gui, 1:Add, Checkbox, x+20 ys+65 BackgroundTrans vUnderline_Font gUpdate_Font,Underline
Gui, 1:Add, Checkbox, xs yp+30  w100 BackgroundTrans vItalic_Font gUpdate_Font,Italic
Gui, 1:Add, Checkbox, x+20   w100 BackgroundTrans vStrike_Font gUpdate_Font,Strike
Gui, 1:Color,Gray,%Edit_Color% 
Gui, 1:Add, Edit, xm w830 h270 vFont_Display,Sample Text`n1 2 3 4 5 6 7 8 9 0`na A b B c C d D e E f F g G h H i I j J k K l L m M n N o O p P q Q r R s S t T u U v V w W x X y Y z Z
Gui, 1:Add, Edit, xm w730 h20 vGui_Display,
Gui, 1:Add, Button, x+10 w90 h20 gReload,Reload
Gui,1:+AlwaysOnTop 
Gui,1:-Caption ;+Owner 
Gui, 1:Show, x500 y100 w850 h470,Font Tool
SetTimer,Watch_Window,400
return
Watch_Window:
	WinGetTitle,Active_Window,A
	if(Active_Window!="Font Tool"&&Set_Window_Size==0)
		{
			WinGetTitle,New_Active_Window,A
			Gui,1:Show,x1300 y700 w50 h20,Font Tool
			WinActivate,%New_Active_Window%
			Set_Window_Size:=1
		}
	if(Active_Window=="Font Tool"&&Set_Window_Size==1)
		{
			Gui, 1:Show,x500 y100 w850 h470,Font Tool
			Set_Window_Size:=2
		}
	if(Set_Window_Size==2&&Active_Window!="Font Tool")
		{
			Set_Window_Size:=0
		}
	return
GuiClose:
	ExitApp
Reload:
	Reload
	return
Check:
	Family:=0
	gosub, Update_Font
	return
Check1:
	Family:=1
	gosub, Update_Font
	return
Update_Edit:
	Gui, 1:Submit,NoHide
	Gui, 1:Color,,%Edit_Color%
	return
Update_Font:
	Gui, 1:Submit,NoHide
	Gui,1:Font,
	if(Font_Size>200)
		{
			Font_Size:=200
			GuiControl,1:,Font_Size,200
		}
	if(Font_Size<1)
		{
			Font_Size:=1
			GuiControl,1:,Font_Size,1
		}	
	if(Bold_Font==1)
		Bold1:="Bold"
	if(Bold_Font==0)
		{
			Gui,1:Font,
			Bold1:=""
		}
	if(Underline_Font==1)
		Underline1:="Underline"
	if(Underline_Font==0)
		{
			Gui,1:Font,
			Underline1:=""
		}
	if(Italic_Font==1)
		Italic1:= "Italic"
	if(Italic_Font==0)
		{
			Gui,1:Font,
			Italic1:=""
		}
	if(Strike_Font==1)
		Strike1:="Strike"
	if(Strike_Font==0)
		{
			Gui,1:Font,
			Strike1:=""
		}
	if(Family==0)
		{
			Gui,1:Font,
			Gui, 1:Font,c%Font_Color% s%Font_Size% %Underline1% %Bold1% %Italic1% %Strike1% Q4,%Font_Family_Selected%	
			Gui_Out := Font_Family_Selected
		}
	if(Family==1)
		{
			Gui,1:Font
			Gui, 1:Font,c%Font_Color% s%Font_Size% %Underline1% %Bold1% %Italic1% %Strike1% Q4,%Font_Favorites%	
			Gui_Out := Font_Favorites
		}
	GuiControl,1:Font,Font_Display 
	Gui,1:Font,
	Gui,1:Font,c%Font_Color%
	GuiControl,1:Font,Gui_Display
	Gui,1:Font,s16
	GuiControl,1:Font,Font_Size
	GuiControl,1:,Gui_Display,% "Gui,Font,c" Font_Color " s" Font_Size " " Underline1 " " Bold1 " " Italic1 " " Strike1 " Q4," Gui_Out
	Gui,1:Font,
	return
Add_To_Favourites:
	FileAppend,%Font_Family_Selected%`n,Font Favourites.txt
	GuiControl,1:,Font_Favorites,%Font_Family_Selected%
	return
Remove_From_Favourites:
	MsgBox, 262144, Remove Font Family From Favourites, Open the file called Font Favourites.txt and delete the one you don't want anymore.`n`nDid you think I was going to do everything for you? For free? `nlol you are funny lol`n`nNo really just delete the font family from the text doc and you are good to go.
	Run, Font Favourites.txt
	return
WM_LBUTTONDOWN() {
   IfWinActive,Font Tool
			PostMessage, 0xA1, 2  
}
;~ ~Up::
	;~ MouseGetPos,,,Active_Window,Ctrl 
	;~ ControlGetText, TUM , %Ctrl%, ahk_id %Active_Window%
	;~ FileAppend,%TUM%`n,Temp text file to test.txt
	;~ return
;~ ~Down::
	;~ MouseGetPos,,,Active_Window,Ctrl
	;~ ControlGetText, TUM , %Ctrl%, ahk_id %Active_Window%
	;~ FileAppend,%TUM%`n,Temp text file to test.txt
	;~ return
Esc::ExitApp
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: GUI Font Tool

24 Sep 2017, 11:54

Nicely done!
Pairing this with my color tool, and if (and when) I make my AHK command helper and organizer, this little "package" will be highly useful!

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: GUI Font Tool

24 Sep 2017, 12:15

Delta Pythagorean wrote:Nicely done!
Pairing this with my color tool, and if (and when) I make my AHK command helper and organizer, this little "package" will be highly useful!
I needed a quick way to launch the tools that I have/make so I made my own toolbar for Scite4AutoHotkey

Image

Still a work in progress, but it does make things easier. I plan on expanding this for multiple different programs, each with their own options etc.

The way I have set this up is that the toolbar only shows up when Scite is the active window so it never gets in the way of other things.
User avatar
lmstearn
Posts: 694
Joined: 11 Aug 2016, 02:32
Contact:

Re: GUI Font Tool

27 Dec 2019, 01:07

Thanks for the script. :)
Bit out of left field so here goes: when one is presented with the option of a font, would his choice be affected if he knew it was already used by the system? Here's a standalone script which covers two defaults, there may be a number more (untested for non-default- sry):

Code: Select all

Gui, New
Gui,-MaximizeBox -MinimizeBox +OwnDialogs
Gui, thisGui: New, -MaximizeBox -MinimizeBox +OwnDialogs +LastFound HWNDthisGuiHwnd
thisguiW := floor(A_ScreenWidth/6)
thisguiH := floor(A_ScreenHeight/9)

Gui, thisGui: Add, Button, center Default w%thisguiW% h%thisguiH% gFontinfo vFontinfo,Get Font Info
Gui, thisGui: Default 
GuiControl, thisGui: Move, Fontinfo, x%thisguiW% y%thisguiH%


thisguiW := floor(A_ScreenWidth/2)
thisguiH := floor(A_ScreenHeight/3)

Gui, Show, Hide
Gui, thisGui: Show, w%thisguiW% h%thisguiH%
Return


Fontinfo:

A_GuiFont := GuiDefaultFont()
A_GuiFontSize := A_LastError

msgbox % "The font used in explorer is " . A_GuiFont . ", with size " .  A_GuiFontSize . ".`n`nSegoe UI is " . IsFont("Segoe UI") . "."

Return

Esc::
thisguiGuiClose:
ExitApp

IsFont(FontName)
{
strRetVal := ""

(A_PtrSize = 8)? 64bit := 1: 64bit := 0
	if (64bit)
	SetRegView 32

	Loop, Reg, HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts
	{
	If (RegExMatch(A_LoopRegName, "^" . FontName . " \(") > 0)
	strRetVal := "the default Windows font"
	}

	if (!strRetVal)
	{
	FntMatchList := Object()
		Loop, Reg, HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontSubstitutes
		FntMatchList.Push(A_LoopRegName)

		Loop, Reg, HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts
		{
		foundFlg := 0
		ALoopRegName := A_LoopRegName
				For i in FntMatchList
				{
					if (A_Loopfield = ALoopRegName)
					{
					foundFlg := A_Index
					Break
					}
				}
			if (!foundFlg)
			{
			strRetVal := "not the default Windows font, but " ALoopRegName " is."
			Break
			}
		}
	if (!strRetval)	
	strRetVal := "not the default Windows font, but nothing else is, so apparently there is an error"
	}

Return strRetVal
}

GuiDefaultFont()
{
;https://autohotkey.com/board/topic/7984-ahk-functions-incache-cache-list-of-recent-items/://autohotkey.com/board/topic/7984-ahk-functions-incache-cache-list-of-recent-items/page-10?&#entry443622
hwnd := 0 ; entire screen
hFont := DllCall("GetStockObject", "UInt", 17) ; DEFAULT_GUI_FONT
VarSetCapacity(LF, szLF := 60*((A_IsUnicode)? 2:1))
DllCall("GetObject", "UInt", hFont, "Int", szLF, "UInt",&LF)
hDC := DllCall("GetDC", "UInt", hwnd ), DPI := DllCall( "GetDeviceCaps", "UInt", hDC, "Int", 90)
DllCall( "ReleaseDC", "Int", 0, "UInt", hDC ), S := Round((-NumGet(LF,0, "Int") * 72) / DPI) ; S is fonstsize
Return DllCall( "MulDiv", "Int", &LF+28, "Int", 1, "Int", 1, "Str"), DllCall( "SetLastError", "UInt", S ) ; sneaky way of returning a second value without using function parameters
}
Might there room to squeeze a couple of checks in after the underline and strike? :D
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: crossgamma and 153 guests