Jump to content

Recommended Posts

Posted (edited)

Hi all,

I would like to know how to check if a specific font is installed in user's system. If it is not installed, my program needs to install the font. (Don't worry about the copy right of the font. it's free) I have got some points from google which directs me into _WinAPI_AddFontResourceEx function. But help file says that this function is only for current session.  And i also got the _WinAPI_EnumFontFamilies function too. But before trying any of these, i would like to hear from the masters. 

Edited by kcvinu
  Reveal hidden contents

 

Posted

Well, i digged this with a deep search

 

Not bad i think. :)

  Reveal hidden contents

 

Posted

_WinAPI_EnumFontFamilies is perfect to check if a font exists... why didn't you try it ? 

_WinAPI_AddFontResourceEx installs the font only for the current session, but anyway the font gets installed when the script is launched  :)

Posted

Thanks @mikell . I just hesitated because the time it consumes for getting all fonts list. And what do you mean by "script is launched ?. Help file says that it won't work after a restart.

  Reveal hidden contents

 

Posted

_WinAPI_AddFontResourceEx

  Quote

Remarks

This function installs the font only for the current session. When the system restarts, the font will not be present.
To have the font installed even after restarting the system, the font must be listed in the registry.

Expand  

It'll just be removed after a restart, I'm sure there's a way to install it and update the registry ;). Unless you don't wanna add it to the registry, in which case I doubt the time it takes to install the font is noticeable.

Also

#include <WinAPIGdi.au3>
#include <Array.au3>

Local $timer = TimerInit()
Local $font_families = _WinAPI_EnumFontFamilies()
Local $time = TimerDiff($timer) / 1000
_ArrayDisplay($font_families, $time)

1672 fonts installed, .2 second to finish the execution of the function.

Posted

Since my program is portable, i don't want to play with users registry. 

  Reveal hidden contents

 

Posted
  On 2/28/2016 at 6:24 PM, kcvinu said:

Since my program is portable, i don't want to play with users registry. 

Expand  

So on evry starting your programm:

  • test if font exists (_WinAPI_EnumFontFamilies)
  • if not install it for this session (_WinAPI_AddFontResourceEx)
Posted

No @AutoBert , i am planning to write the data to an ini file

  Reveal hidden contents

 

Posted

@InunoTaishou Thank you man. That's not a big delay for my program. Now i am testing Fileinstall 

 

  Reveal hidden contents

 

Posted

Just check for c:\Windows\Fonts\

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

@mLipok & @jguinch I am happy with  _WinAPI_EnumFontFamilies  function for finding if the font is installed or not. Now i need to install the font if  it is not in the system. Is there any method other than FileInstall ?

  Reveal hidden contents

 

Posted (edited)

 

This will install it and save it to the registry so it won't be removed on startup.

Honestly though I've used _WinAPI_AddFontResourceEX in a program I made that I used frequently (close and restart) and there was never any problem or delay to install the three custom fonts I used.

Don't know if you're worried about the overhead or the processing speed but when you're just working with small files (my .ttf files were 12kb, 22kb, and 324kb) and checking checking (not accessing) a lot of files, almost all, modern, machines can do the processing without any any noticeable delay.

#include <WinAPIGdi.au3>
#include <Array.au3>

Local $timer_init = TimerInit()
Local $font_families = _WinAPI_EnumFontFamilies()
Local $time_enum_font_families = TimerDiff($timer_init) / 1000 & "s"
$timer_init = TimerInit()
Local $font_installed = _ArraySearch($font_families, "Futura", 0, 0, 0, 1)
Local $time_array_search = TimerDiff($timer_init) / 1000 & "s"
Local $time_font_install = 0
If ($font_installed = -1) Then
    $timer_init = TimerInit()
    _WinAPI_AddFontResourceEx("Futura Extra Bold.ttf", $FR_PRIVATE)
    $time_font_install = TimerDiff($timer_init) / 1000 & "s"
EndIf

MsgBox("", "Time", "Time to enum font families: " & $time_enum_font_families & @CRLF & _
                    "Time to search through (" & $font_families[0][0] & ") font families: " & $time_array_search & @CRLF & _
                    "Time to add font resource: " & $time_font_install)

Time to enum font families: 0.210863995560568s

Time to search through (1672) font families: 0.0302487330923837s

Time to add font resource: 0.00023872755105527s

It would probably be more efficient to just always install your font on startup, save yourself roughly 1/4 - 1/5 of a second.

Edited by InunoTaishou
Posted

@InunoTaishou Your last point is most important. I just want install the font at once.  And thank you for that link. It is helpful. :)

 

  Reveal hidden contents

 

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
×
×
  • Create New...