A Million Little Pieces Of My Mind

NamtiraLib

SuperFonts

By: Paul S Cilwa Posted: 4/10/2026 Page Views: 25
Hashtags: #Namtira #VisualBasic #VBNET #ClassLibrary #NamtiraLib #SuperFonts #Font #TrueType #OpenType
Classes for loading, inspecting, and previewing TrueType and OpenType font files.
Estimated reading time: 3 minute(s) (682 words)

.NET can render any installed font, but it offers no convenient way to load a font file from disk, discover which styles it supports, or build a preview. SuperFonts provides two classes that fill this gap: FontFileInfo wraps a single font file and exposes its families and available styles, while FontFileList scans a folder (or the system Fonts directory) and collects the results.

Class FontFileInfo
MemberParametersExample
NewInfo As FileInfoDim ffi As New FontFileInfo(myFile)
NewPath As StringDim ffi As New FontFileInfo("C:\Fonts\Lato.ttf")
DisplayNameffi.DisplayName"Lato (Regular, Bold, Italic)"
IsSystemFontffi.IsSystemFont
AvailableStylesffi.AvailableStylesIReadOnlyList(Of FontStyle)
FontStyleffi.FontStyle (default Regular)
Familiesffi.FamiliesIReadOnlyList(Of FontFamily)
FontFamilyffi.FontFamily → primary family
Tagffi.Tag = "custom"
FileInfoffi.FileInfo → underlying FileInfo
FullNameffi.FullName → full file path
Extensionffi.Extension".ttf"
GetPreviewFontSize As Single, Style As FontStyleffi.GetPreviewFont(14, FontStyle.Bold)
Class FontFileList (Inherits List(Of FontFileInfo))
NewFolderPath As StringDim ffl As New FontFileList("C:\MyFonts")
NewPreloadSystemFonts As Boolean (opt)Dim ffl As New FontFileList(True)
LoadFromSystemffl.LoadFromSystem()

FontFileInfo

Each FontFileInfo wraps a single font file. The constructor loads it via a PrivateFontCollection, detects which styles (Regular, Bold, Italic, etc.) the font supports, and builds a human-readable DisplayName.

Imports System.Drawing.Text Imports System.IO Public Class FontFileInfo Public ReadOnly DisplayName As String Public ReadOnly IsSystemFont As Boolean Public ReadOnly AvailableStyles As IReadOnlyList(Of FontStyle) Public FontStyle As FontStyle = FontStyle.Regular Public ReadOnly Families As IReadOnlyList(Of FontFamily) Public ReadOnly FontFamily As FontFamily Public Tag As String = String.Empty Private ReadOnly MyInfo As FileInfo Private ReadOnly MyFonts As New PrivateFontCollection Public Sub New(Info As FileInfo) MyInfo = Info MyFonts.AddFontFile(MyInfo.FullName) If MyFonts.Families.Length = 0 Then Throw New Exception("No font families found in file: " & MyInfo.FullName) End If FontFamily = MyFonts.Families(0) AvailableStyles = DetectStyles(FontFamily) DisplayName = BuildDisplayName(FontFamily) End Sub Public Sub New(Path As String) Me.New(New FileInfo(Path)) End Sub End Class

The private BuildDisplayName helper joins the family name with a parenthesized list of available styles. DetectStyles iterates every FontStyle enum value and keeps only those the family reports as available.

Private Function BuildDisplayName(Family As FontFamily) As String Dim styleNames = AvailableStyles.Select(Function(s) s.ToString()) Return Family.Name & " (" & String.Join(", ", styleNames) & ")" End Function Private Function DetectStyles(Family As FontFamily) As List(Of FontStyle) Dim Styles As New List(Of FontStyle) For Each s As FontStyle In [Enum].GetValues(GetType(FontStyle)) If Family.IsStyleAvailable(s) Then Styles.Add(s) End If Next Return Styles End Function

Several read-only properties expose the underlying FileInfo, its full path, and extension, keeping the caller from needing to dig into the wrapped object.

Public ReadOnly Property FileInfo As FileInfo Get Return MyInfo End Get End Property Public ReadOnly Property FullName As String Get Return MyInfo.FullName End Get End Property Public ReadOnly Property Extension As String Get Return MyInfo.Extension End Get End Property

GetPreviewFont creates a Font instance from the loaded family at a given size and style—handy for rendering sample text in a UI.

Public Function GetPreviewFont(Size As Single, Style As FontStyle) As Font Return New Font(Me.FontFamily, Size, Style) End Function

FontFileList

FontFileList inherits from List(Of FontFileInfo) and adds the ability to scan a folder for font files (TrueType, OpenType, and TrueType/OpenType Collections). The folder-path constructor loads immediately; the parameterless constructor optionally preloads the Windows system fonts.

Public Class FontFileList Inherits List(Of FontFileInfo) Private Shared ReadOnly FontFileExtensions As String() = {".ttf", ".otf", ".ttc", ".otc"} Public Sub New(FolderPath As String) MyBase.New LoadFromFolder(FolderPath) End Sub Public Sub New(Optional PreloadSystemFonts As Boolean = False) MyBase.New If PreloadSystemFonts Then LoadFromSystem() End Sub Private Sub LoadFromFolder(FolderPath As String) If Directory.Exists(FolderPath) Then For Each F In Directory.GetFiles(FolderPath) If FontFileExtensions.Contains(Path.GetExtension(F).ToLower()) Then Try Add(New FontFileInfo(F)) Catch ex As Exception ' Ignore invalid or unreadable font files End Try End If Next End If End Sub Public Sub LoadFromSystem() LoadFromFolder(Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.Windows), "Fonts")) End Sub End Class