How to compile custom font?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
fiendhunter
Posts: 134
Joined: 24 Jul 2019, 15:27

How to compile custom font?

Post by fiendhunter » 13 Aug 2022, 07:36

hi, all. I build a timer and I want to use digital style font named, "digital clock font.ttf".
its working well at my computer, but at diffrent computers, the font is not working.
I found 3 solutions with DllCall. the font was in the working dir. I couldnt make it work.

Code: Select all

F1::
; DllCall("Gdi32.dll\AddFontResourceEx", "Str","digital clock font.ttf", "UInt", 0x10, "UInt", 0)
; DllCall( "AddFontResource", Str,"digital clock font.ttf" )
; DllCall("GDI32.DLL\AddFontResource", str, "digital clock font.ttf")
; tried 3 diffrent dllcall but cant make it work.

StartTime := A_TickCount
EndTime := ctd
EndTimeNow := ctd
SetTimer, SCountdownNow, 100
Gui, Destroy
Gui, -Caption +ToolWindow +AlwaysOnTop
Gui, Font, s30 , digital clock font
Gui, Add, Text,x75 y27 w300 BackGroundTrans c01083d , 88:88:88
Gui, Add, Text,x75 y27 w300 BackGroundTrans cAqua vSCountdown , 
Gui, Color, c000524
Gui, Show, x800 y300 w305 h100
return

SCountdownNow:
; doing counting things.....
return
Last edited by fiendhunter on 14 Aug 2022, 06:30, edited 1 time in total.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to compile costume font?

Post by swagfag » 13 Aug 2022, 08:09

u need to pass a full path to AddFontResource

fiendhunter
Posts: 134
Joined: 24 Jul 2019, 15:27

Re: How to compile costume font?

Post by fiendhunter » 14 Aug 2022, 04:13

swagfag wrote:
13 Aug 2022, 08:09
u need to pass a full path to AddFontResource
"digital clock font.ttf" -> "C:\digital clock font.ttf"

still not working.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to compile costume font?

Post by swagfag » 14 Aug 2022, 05:03

then check the dllcall return value and errorlevel. also, ensure the font name/family is "digital clock font"(maybe its called something else)

fiendhunter
Posts: 134
Joined: 24 Jul 2019, 15:27

Re: How to compile costume font?

Post by fiendhunter » 14 Aug 2022, 05:35

Im not familiar with dllcalls...
I think [ DllCall( "AddFontResource", Str,"C:\digital clock font.ttf" ) ] means; store this file as a font, in the program exe? And exe can use the font in any pc?

note: font name/family are same.

I also tried "C:\Windows\Fonts" path with "digital clock font.ttf" and "digital clock font Normal.ttf" ; at this path it shows additional "Normal". Still not working at difrent PCs.

fiendhunter
Posts: 134
Joined: 24 Jul 2019, 15:27

Re: How to compile costume font?

Post by fiendhunter » 14 Aug 2022, 06:14

@swagfag
I also tried with diffrent font, named "alarm clock.ttf"
Results are same.

Code: Select all

Loop, %A_WinDir%\Fonts\*.ttf
{
if A_LoopFileName = alarm clock.ttf
{
MsgBox, found %A_LoopFileName%
break
}
}
I also check file name with this code. it returns with msgbox; found alarm clock.ttf
resim_2022-08-14_142807310.png
resim_2022-08-14_142807310.png (141.57 KiB) Viewed 921 times

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to compile costume font?

Post by swagfag » 14 Aug 2022, 07:09

fiendhunter wrote:
14 Aug 2022, 05:35
Im not familiar with dllcalls...
I think [ DllCall( "AddFontResource", Str,"C:\digital clock font.ttf" ) ] means; store this file as a font, in the program exe? And exe can use the font in any pc?
no, it means:
MSND wrote:The AddFontResource function adds the font resource from the specified file to the system font table. The font can subsequently be used for text output by any application.
in other words: locate a font file on ur computer, then load it into font table for use(until the computer is rebooted or RemoveFontResource is called)

fiendhunter
Posts: 134
Joined: 24 Jul 2019, 15:27

Re: How to compile costume font?

Post by fiendhunter » 14 Aug 2022, 07:21

swagfag wrote:
14 Aug 2022, 07:09
fiendhunter wrote:
14 Aug 2022, 05:35
Im not familiar with dllcalls...
I think [ DllCall( "AddFontResource", Str,"C:\digital clock font.ttf" ) ] means; store this file as a font, in the program exe? And exe can use the font in any pc?
no, it means:
MSND wrote:The AddFontResource function adds the font resource from the specified file to the system font table. The font can subsequently be used for text output by any application.
in other words: locate a font file on ur computer, then load it into font table for use(until the computer is rebooted or RemoveFontResource is called)
Total misunderstood :) . Thanks for explaniton. So, I need to send the font, to all other computers. Ill share the "compiled.exe" not the font. Is there any option to include the font in "exe"?
I ll try ";@Ahk2Exe-AddResource" if there any suggestion, I'd be happy :)

User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: How to compile costume font?

Post by boiler » 14 Aug 2022, 07:53

fiendhunter wrote: Is there any option to include the font in "exe"?
I ll try ";@Ahk2Exe-AddResource" if there any suggestion, I'd be happy :)
See FileInstall.

fiendhunter
Posts: 134
Joined: 24 Jul 2019, 15:27

Re: How to compile costume font?

Post by fiendhunter » 14 Aug 2022, 08:06

boiler wrote:
14 Aug 2022, 07:53
fiendhunter wrote: Is there any option to include the font in "exe"?
I ll try ";@Ahk2Exe-AddResource" if there any suggestion, I'd be happy :)
See FileInstall.
I checked its okey, but after installing, it searchs (to be sure) again, but it cannot locate the font in the installed fonts. It cause endless loop. Restart PC is not solve the problem.
I can see the alarm clock.ttf in the "C:\Windows\Fonts" but if A_LoopFileName = alarm clock.ttf sections return false.
if I use "install for all users" option, its okey, working well. But there is no "RunWait, forallusers, alarm clock.ttf" :)
its wierd :)

Code: Select all

ttfSearch:
Loop, %A_WinDir%\Fonts\*.ttf
{
if A_LoopFileName = alarm clock.ttf
{
goto, ttfFound
}
}
FileInstall, alarm clock.ttf, %A_WorkingDir%\alarm clock.ttf,0
RunWait, alarm clock.ttf
while WinExist("ahk_exe fontview.exe")
{
sleep 1000
}
sleep 2000
goto, ttfSearch
ttfFound:
....
....

User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: How to compile custom font?

Post by boiler » 14 Aug 2022, 08:41

FileInstall just places the file where you tell it. It has nothing to do with installing the font. I was answering just the specific question that I quoted.

fiendhunter
Posts: 134
Joined: 24 Jul 2019, 15:27

Re: How to compile custom font?

Post by fiendhunter » 14 Aug 2022, 09:58

Code: Select all

F1::
ttfSearch:
EnvGet, A_LocalAppData, LocalAppData
Loop, %A_LocalAppData%\microsoft\windows\fonts\*.ttf                   ; check fonts
{
if A_LoopFileName = alarm clock.ttf
{
goto, ttfFound                                                                     ; if found = pass
}
}
if !FileExist("%A_WorkingDir%\alarm clock.ttf")                                     ; if not found = check font in ".exe" folder
{
FileInstall, C:\Users\fiend\AppData\Local\Microsoft\Windows\Fonts\alarm clock.ttf, %A_WorkingDir%\alarm clock.ttf,1                           ; if font not in ".exe" folder, install the file
}
Run, %A_WorkingDir%\alarm clock.ttf                                   ; run the font file
while !WinExist("ahk_exe fontview.exe")
{
sleep 500
}
while WinExist("ahk_exe fontview.exe")                                       ; while the file is activ,....
{
sleep 1000
Loop, %A_LocalAppData%\microsoft\windows\fonts\*.ttf                              ; ..... check installed fonts
{
if A_LoopFileName = alarm clock.ttf
{
goto, checkfontwinexistagain                                                               ; break, if the font installition complate
}
}
}
checkfontwinexistagain:
sleep 1000
if WinExist("ahk_exe fontview.exe")                                    ; close font installion window
{
WinClose
goto, checkfontwinexistagain
}
sleep 1000
FileRecycle, %A_WorkingDir%\alarm clock.ttf    ;  delete the font file in ".exe" folder
goto, ttfSearch
ttfFound:
....
....
....

Post Reply

Return to “Ask for Help (v1)”