System.FontAt

From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!
Method

System.FontAt() As String

New in 2019r2

Supported on Desktop, Web, Console.

Used to access the names the installed fonts.

Usage

result = Font(index)

Part Type Description
result String The name of the font whose index number is passed. Result is in the appropriate WorldScript encoding.
index Integer The number of the font.

Exceptions

Exception Reason
OutOfBoundsException Raised if index is less than 0 or greater than FontCount - 1.

Notes

Fonts are accessed in alphabetical order where font 0 is the first font. Use the System.FontCount property to determine the number of fonts.

Under macOS, FontAt returns font families instead of fonts. This is closer to the older Carbon behavior, but it does not return identical results.

Using Custom Fonts in your Applications

Both macOS and Windows have techniques for loading fonts for a specific application.

On macOS, you can use ATSApplicationFontsPath key in Info.plist. You add this key, specifying the relative path of the fonts in the Resources folder of your app bundle.

For Windows, the open-source Windows Functionality Suite provides a method (TemporarilyInstallFont) to do this.

Sample Code

This is a function that determines if the font named passed is installed on the user's computer:

Function FontAvailable(FontName As String) As Boolean
For i As Integer = 0 To System.LastFontIndex
If System.FontAt(i) = FontName Then
Return True
End If
Next
Return False
End Function

Compatibility

All project types on all supported operating systems.

See Also

System.FontCount property; System.LastFontIndex; UserGuide:Mac UI Tips#Font Display topic