Hi Louis-Philippe,
Information about the fonts installed in the system is stored in Windows Registry in the
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Fonts branch. To learn more about fonts in Windows Registry, please see the
Fonts article.
Use the sample script below to accomplish your task:
Sub ListOfAvailableFonts()
' Defines the branch of the registry with the fonts
Dim arrFonts
Set arrFonts = Storages.Registry("Software\Microsoft\Windows NT\CurrentVersion\Fonts", HKEY_LOCAL_MACHINE)
' Posts all available fonts to the log
For i = 0 To arrFonts.OptionCount - 1
Log.Message(arrFonts.GetOptionName(i))
Next
End Sub
Function IsFontInstalled(strInput)
' Defines the branch of the registry with the fonts
Dim arrFonts
Set arrFonts = Storages.Registry("Software\Microsoft\Windows NT\CurrentVersion\Fonts", HKEY_LOCAL_MACHINE)
' Checks whether the target font exists
If arrFonts.OptionExists(strInput) Then
IsFontInstalled = True
Else
IsFontInstalled = False
End If
End Function
Sub Test()
' Posts the names of all installed fonts to the Test Log
Call ListOfAvailableFonts()
' Checks whether the 'Times New Roman' font is installed in the system
strFont = "Times new Roman (TrueType)"
Dim fExists
fExists = IsFontInstalled(strFont)
If fExists Then
Log.Message strFont & " is installed"
Else
Log.Message strFont & " is not installed"
End If
End Sub
The ListOfAvailableFonts routine posts the names of all installed fonts found in Windows Registry.
The IsFontInstalled function checks whether the target font is installed in the system.
Please refer to the
Storages.Registry article - it explains how to work with the registry in TestComplete.
Please let me know if you need anymore assistance.