DirectWrite Rasterizer
DirectWrite rasterizer backend using TerraFX.Interop.Windows bindings. Provides access to Windows' modern text rendering APIs, including ClearType-hinted grayscale rendering and system font loading.
Installation
dotnet add package KernSmith.Rasterizers.DirectWrite.TerraFX
Platform: Windows only (net10.0-windows)
Usage
The rasterizer auto-registers via [ModuleInitializer] -- referencing the package is sufficient. Select it in options:
var options = new FontGeneratorOptions
{
Size = 32,
Backend = RasterizerBackend.DirectWrite
};
var result = BmFont.Generate("path/to/font.ttf", options);
For system fonts, use GenerateFromSystem:
var result = BmFont.GenerateFromSystem("Segoe UI", new FontGeneratorOptions
{
Size = 32,
Backend = RasterizerBackend.DirectWrite
});
Note
Color font (ColorPaletteIndex) and variable font (VariationAxes) options are not yet honored by this backend -- see Limitations. Use FreeType for COLR/CPAL and fvar today.
Capabilities
- ClearType-hinted grayscale rendering
- System font loading by family name
- Synthetic bold and italic
- TTF, OTF, WOFF, WOFF2 input
- Fractional font sizes (e.g.
Size = 32.5f) honored natively
Limitations
- Color fonts (COLR/CPAL) are not yet implemented -- the capability is currently stubbed (
SupportsColorFontsreturnsfalse; there is noTranslateColorGlyphRunimplementation yet). Use FreeType for color glyphs. - Variable font axes (fvar) are not yet implemented -- the capability is currently stubbed (
SupportsVariableFontsreturnsfalse; there is noIDWriteFontFace5axis implementation yet). Use FreeType for variable fonts. - Windows only -- will not load on Linux or macOS
- Requires net10.0-windows (not net8.0-windows)
- No SDF rendering support -- use FreeType for SDF
- No vector outlines (
OutlineMode.Vectorfalls back to core's bitmap outline effect, which works as usual), and noWidthPercentor non-defaultItalicAngle(NotSupportedException)
Implementation
Uses an isolated IDWriteFactory5 instance and loads fonts into memory via IDWriteInMemoryFontFileLoader. All COM interop is handled internally.
When to Use
Use DirectWrite when you want Windows' ClearType-hinted grayscale rendering or need to load system-installed fonts by family name on Windows. For color fonts (COLR/CPAL) or variable font axes (fvar), use FreeType -- those DirectWrite code paths are currently stubbed and not yet functional.