Jump to content

Recommended Posts

Posted

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...
Posted

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...

Posted

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.

  • Developers
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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

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
Posted

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.

 

Posted

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
Posted

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.

Posted

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.

Posted

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!
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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...