KernSmith.KniGum
Runtime bitmap font generation for KNI + Gum games.
Install
dotnet add package KernSmith.KniGum
Target: net8.0
Setup
One-line initialization in your game's Initialize() or LoadContent():
using KernSmith.Gum;
using RenderingLibrary;
CustomSetPropertyOnRenderable.InMemoryFontCreator =
new KernSmithFontCreator(GraphicsDevice);
The KernSmithFontCreator class and namespace are the same as the MonoGame package -- only the underlying framework dependencies differ.
Registering Fonts
Some KNI targets (such as Blazor WASM) may not have access to system fonts. Registering font data explicitly is recommended for all platforms to ensure consistent cross-platform rendering. Register font data before initializing KernSmithFontCreator:
using KernSmith.Gum;
// Recommended — uses TitleContainer.OpenStream, works on all platforms
KernSmithFontCreator.RegisterFont("Roboto", "Content/Fonts/Roboto-Regular.ttf");
KernSmithFontCreator.RegisterFont("Roboto", "Content/Fonts/Roboto-Bold.ttf", style: "Bold");
The file-path overload uses TitleContainer.OpenStream internally, so the path is relative to the title container root (typically the Content directory). This is the simplest approach and works on all KNI platforms.
For fonts loaded from embedded resources, archives, or HTTP, use the byte[] overload instead:
using KernSmith.Gum;
byte[] fontData = LoadEmbeddedResource("Fonts.Roboto-Regular.ttf");
KernSmithFontCreator.RegisterFont("Roboto", fontData);
With fonts registered, GenerateFromSystem() (used internally by KernSmithFontCreator) will find them by family name. Registered fonts take priority over system fonts, with automatic fallback to the OS font store on platforms that support it.
Register all font families and style variants your Gum layouts reference. A typical setup covers Regular, Bold, Italic, and Bold Italic:
KernSmithFontCreator.RegisterFont("Roboto", "Content/Fonts/Roboto-Regular.ttf");
KernSmithFontCreator.RegisterFont("Roboto", "Content/Fonts/Roboto-Bold.ttf", style: "Bold");
KernSmithFontCreator.RegisterFont("Roboto", "Content/Fonts/Roboto-Italic.ttf", style: "Italic");
KernSmithFontCreator.RegisterFont("Roboto", "Content/Fonts/Roboto-BoldItalic.ttf", style: "Bold Italic");
On Blazor WASM this is required -- without registration, font generation will fail because there are no system fonts to discover. On desktop platforms it is recommended for consistency so that every build renders identical fonts regardless of what is installed on the OS.
Dependencies
This package automatically pulls in:
KernSmith.GumCommon(shared generation logic)KernSmith(core library)Gum.KNInkast.Xna.Framework
See Integrations Overview for channel configuration and option customization.