Class RuntimeFontProvider
Provides runtime registration and loading of fonts from the file system.
public class RuntimeFontProvider
- Inheritance
-
objectRuntimeFontProvider
Remarks
This provider allows loading custom TrueType fonts (.ttf) at runtime without going through the content pipeline. Fonts registered through this provider are immediately available for use with LoadRuntimeFont(string, float, FontStyle).
Memory Management: All registered fonts remain in memory for the lifetime of the application. There is no mechanism to unload individual fonts once registered. For applications with dynamic font requirements or memory constraints, consider the total memory footprint of all registered fonts.
Methods
IsRegistered(string, FontStyle)
Checks if a font is registered for runtime loading.
public bool IsRegistered(string fontName, FontStyle style = FontStyle.Regular)
Parameters
Returns
- bool
True if registered, false otherwise.
RegisterFont(string, string, FontStyle)
Registers a font file for runtime loading.
public void RegisterFont(string fontName, string filePath, FontStyle style = FontStyle.Regular)
Parameters
fontNamestringThe name to use when loading the font (e.g., "MyFont").
filePathstringThe absolute or relative path to the .ttf file.
styleFontStyleThe font style.
Remarks
Once registered, fonts are loaded into memory and cached for the lifetime of the font system. Individual fonts cannot be unregistered or unloaded - they remain in memory until the application exits or the font system is disposed.
Attempting to register the same font name and style with a different file path will throw an exception.
Exceptions
- ArgumentNullException
Thrown when
fontNameis null or empty.- FileNotFoundException
Thrown when the font file does not exist.
- InvalidOperationException
Thrown when attempting to register the same font name and style with a different file path.