Sign in to follow this  
Followers 0
peter1234

How to install font?

15 posts in this topic

Does anyone know how to install a new font using AutoIt? Just adding the font to the font folder using FileInstall does not work.

Share this post


Link to post
Share on other sites



Does anyone know how to install a new font using AutoIt? Just adding the font to the font folder using FileInstall does not work.

You should be able to use FileCopy I think.

INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites

strate,

Thanks for the reply, but that does not work either.

Share this post


Link to post
Share on other sites

hm, usual you need to install a font correctly the install function in the font folder... but it could work with filecopy, either...

file install is for sth. vry different, as you see in the help-file...

Share this post


Link to post
Share on other sites


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

I used a free exe called fontinst.exe from ParaType Software. That requires creating a folder and flashes a message box but works fine. I hope someone who knows DLLs will make a _FontInstall UDF. In the mean time, I recommend fontinst.exe for anyone else wanting to do this.

Share this post


Link to post
Share on other sites

Does anyone know how to install a new font using AutoIt? Just adding the font to the font folder using FileInstall does not work.

Do a search, I've answered this one before


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

see if this works:

#include<file.au3>
$rc = InstallFont("C:\temp\jdeb.ttf","JdeB test Font")
ConsoleWrite('@@ Debug(2) : $rc = ' & $rc & @lf & '>Error code: ' & @error & @lf);### Debug Console
;
Func InstallFont($SourceFile,$FontDescription)
    Local $HWND_BROADCAST = 0xFFFF
    Local $WM_FONTCHANGE = 0x1D
    Local $null, $FontFile, $FontExt
    _PathSplit($SourceFile,$null,$null,$FontFile,$FontExt)
    $FontFile = $FontFile & $FontExt    
    Local $rc = FileCopy($SourceFile,@WindowsDir & "\fonts\" & $FontFile,1)
    If $rc = 0 Then 
        SetError(1)
        Return 0
    EndIf
    Local $res = DllCall("gdi32.dll","Int","AddFontResource","str",@WindowsDir & "\fonts\" & $FontFile)
    If $res[0] > 0 Then
        RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", $FontDescription, "REG_SZ", $FontFile)
        DllCall("user32.dll","Int","SendMessage","HWND",$HWND_BROADCAST,"int", $WM_FONTCHANGE,"int", 0,"int", 0)
        Return 1
    Else
        SetError(2)
        Return 0
    EndIf    
EndFunc
Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

gafrost,

Thanks. When I tried this I got a DllStructDelete($s_p) error. Font was in same folder as script.

;>>>>>> NOTE - REQUIRES BETA AUTOIT AND COMPILER  <<<<<<<<<
#include <GuiConstants.au3>
FileChangeDir (@ScriptDir)
_LoadFont("ariblk.ttf")


Func _LoadFont($Fontname)
    $s_p = DllStructCreate("char[" & StringLen($Fontname) + 1 & "]")
    If @error Then
        Return @error
    EndIf
    DllStructSetData($s_p, 1, $Fontname)
    $msg = DllCall("gdi32.dll", "int", "AddFontResource", "ptr", DllStructGetPtr($s_p))
    DllStructDelete($s_p)
    If @error = 1 Then MsgBox(0, "DLLcall", "unable to use the DLL file")
    If @error = 2 Then MsgBox(0, "DLLcall", "unknown return type")
    Return $msg[0]
    EndFunc ;==>_LoadFont

Share this post


Link to post
Share on other sites

gafrost,

Thanks. When I tried this I got a DllStructDelete($s_p) error. Font was in same folder as script.

;>>>>>> NOTE - REQUIRES BETA AUTOIT AND COMPILER  <<<<<<<<<
#include <GuiConstants.au3>
FileChangeDir (@ScriptDir)
_LoadFont("ariblk.ttf")


Func _LoadFont($Fontname)
    $s_p = DllStructCreate("char[" & StringLen($Fontname) + 1 & "]")
    If @error Then
        Return @error
    EndIf
    DllStructSetData($s_p, 1, $Fontname)
    $msg = DllCall("gdi32.dll", "int", "AddFontResource", "ptr", DllStructGetPtr($s_p))
    DllStructDelete($s_p)
    If @error = 1 Then MsgBox(0, "DLLcall", "unable to use the DLL file")
    If @error = 2 Then MsgBox(0, "DLLcall", "unknown return type")
    Return $msg[0]
    EndFunc;==>_LoadFont

just change

DllStructDelete($s_p)

to

$s_p = 0


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

JdeB,

This works but The Font Thing shows a warning symbol next to font and is not able to uninstall the font, so I think it is not being installed correctly. But it works, thanks. Font was in same folder as script.

#include <GuiConstants.au3>
#include<file.au3>
FileChangeDir (@ScriptDir)

$rc = InstallFont("ariblk.ttf","Arial Black")
ConsoleWrite('@@ Debug(2) : $rc = ' & $rc & @lf & '>Error code: ' & @error & @lf);### Debug Console
MsgBox(0, "Font Installed", "Arial Black   ")
;
Func InstallFont($SourceFile,$FontDescription)
    Local $HWND_BROADCAST = 0xFFFF
    Local $WM_FONTCHANGE = 0x1D
    Local $null, $FontFile, $FontExt
    _PathSplit($SourceFile,$null,$null,$FontFile,$FontExt)
    $FontFile = $FontFile & $FontExt    
    Local $rc = FileCopy($SourceFile,@WindowsDir & "\fonts\" & $FontFile,1)
    If $rc = 0 Then 
        SetError(1)
        Return 0
    EndIf
    Local $res = DllCall("gdi32.dll","Int","AddFontResource","str",@WindowsDir & "\fonts\" & $FontFile)
    If $res[0] > 0 Then
        RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", $FontDescription, "REG_SZ", $FontFile)
        DllCall("user32.dll","Int","SendMessage","HWND",$HWND_BROADCAST,"int", $WM_FONTCHANGE,"int", 0,"int", 0)
        Return 1
    Else
        SetError(2)
        Return 0
    EndIf    
EndFunc

Share this post


Link to post
Share on other sites

gafrost,

Thanks. That works, but font is not installed correctly. Font does show up in Word and can be used in AutoIt scripts, but Font does not appear in Font folder and is not detected by The Font Thing program.

Share this post


Link to post
Share on other sites

I have noticed that if I just copy the font to the font folder and then open and close the Font folder, the font gets registered OK. But I haven't figured out how to get AutoIt to open and close the font folder in a script.

Share this post


Link to post
Share on other sites

I have noticed that if I just copy the font to the font folder and then open and close the Font folder, the font gets registered OK. But I haven't figured out how to get AutoIt to open and close the font folder in a script.

Something like this should work:

Opt("WinTitleMatchMode", 2);match partial titles
Run("explorer " & @WindowsDir & "\Fonts", "", @SW_MINIMIZE)
WinWait("Fonts")
WinClose("Fonts")

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

CyberSlug,

Thanks. This works perfect using Windows XP.

#include <GuiConstants.au3>
FileChangeDir (@ScriptDir)
$FontFile="ariblk.ttf"
_FontInstall ( $FontFile )
MsgBox(0, "Font Installed", $FontFile )

Func _FontInstall ( $FontFile )
    FileCopy ( $FontFile, @WindowsDir & "\Fonts" ,1 )
    Run("explorer " & @WindowsDir & "\Fonts", "", @SW_HIDE)
    WinWait("Fonts")
    WinClose("Fonts")
    EndFunc
Edited by peter1234

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0