Forum Discussion

lphilippe_macau's avatar
lphilippe_macau
Contributor
13 years ago

Problem with Fonts

Hi everyone, 



I'm currently working on a project that checks to make sure all appropriate files have been installed after a setup. Basically I have an excel driver go through a bunch of files/folders with their paths and I use the "aqfile.Exists()" to verify if the file is installed or not. This works like a charm with everything except with fonts. 



When I try to verify if the fonts exist in the C:\windows\fonts folder, it can't find them. When I look through the folder I can see them but they appear with the actual font name and not the file name. I have to right-click and go to properties to see the filename. Is there a way I can see if the fonts are installed with test complete? 



Thank's

L-P

2 Replies


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