Custom font support by specifying file path optionally of font file, rather than font name only

Propose new features and changes
User avatar
Animan8000
Posts: 58
Joined: 11 May 2022, 05:00
Contact:

Custom font support by specifying file path optionally of font file, rather than font name only

18 Oct 2023, 10:48

From my understanding; when changing the font in let's say GUIs, you can specify a font name, but this only considers the name of a font that is specifically present in the fonts directory of the OS. This causes the issue that you either have the script to install the custom font on the user's system... or use a user library for this purpose (there is one for v1.1 only but not for v2 yet). I personally think that allowing a file path to be supported is a good idea to solve this particular problem. No need to install a font, no need for any library (in case you happen to notice that file paths ain't supported unfortunately) if AutoHotkey gave you this functionality out of the box.

And to answer the question in advance why I in particular might wish to use a custom font in a GUI (without the need to install any font because maybe the user doesn't want it on their OS to be visible in other programs, that font): I am planning to make a script for some quality of life stuff for a game, and I thought using a GUI that uses the same font as the game might give some "familiarity" (in terms of aesthetics), if that makes any sense, without wanting to unnecessarily install the font to the OS, and access the font file from a subdirectory of the script for example.

I don't have a computer at the moment to double check that there's 100% no support for font file paths, but if there is, then let me know. Thanks.


Cheers.
geek
Posts: 1054
Joined: 02 Oct 2013, 22:13
Location: GeekDude
Contact:

Re: Custom font support by specifying file path optionally of font file, rather than font name only

18 Oct 2023, 19:13

You specify a font name, and that font must be registered with the operating system, but does not have to be in the operating system's font directory. You can register a font from any directory by calling AddFontResourceEx, preferably with the FR_PRIVATE flag. For example:

Code: Select all

DllCall("AddFontResourceEx", "Str", ".\myFont.ttf", "UInt", 0x10, "Ptr", 0)
Once the font has been registered, it can be used in AHK by referencing it with the same font name you would have used if it had been installed, which unfortunately can differ significantly from the file name. But it should be the same across systems for the same font file being registered.

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 8 guests