Class DynamicSpriteFont
Represents a dynamic font that can render glyphs at any size at runtime.
public class DynamicSpriteFont : SpriteFont, ISpanDrawableFont, IFont
- Inheritance
-
DynamicSpriteFont
- Implements
- Inherited Members
- Extension Methods
Constructors
DynamicSpriteFont(FontInfo, IGlyphRasterizer, DynamicFontAtlas, IFallbackFontResolver?)
Initializes a new instance of the DynamicSpriteFont class.
public DynamicSpriteFont(FontInfo info, IGlyphRasterizer rasterizer, DynamicFontAtlas atlas, IFallbackFontResolver? resolver = null)
Parameters
infoFontInfoInformation about the font.
rasterizerIGlyphRasterizerThe glyph rasterizer to use.
atlasDynamicFontAtlasThe texture atlas to store glyphs in.
resolverIFallbackFontResolverAn instance of the service that helps with getting glyphs that are not presented in this font.
Methods
ClearCache()
Clears the glyph cache.
public void ClearCache()
GetGlyph(int)
Gets the glyph for the specified character codepoint.
public override FontGlyph GetGlyph(int codepoint)
Parameters
codepointintCodepoint to get glyph for.
Returns
- FontGlyph
Glyph info to use with this font.
Remarks
If the requested codepoint is not found in the font, this method will attempt to return the glyph for DefaultCodepoint. If that also fails, it returns None.
GetKerning(FontGlyph, FontGlyph)
Gets the kerning between two glyphs.
protected override float GetKerning(FontGlyph current, FontGlyph previous)
Parameters
Returns
- float
Kerning value in pixels.
Remarks
Kerning adjusts the spacing between specific pairs of glyphs to improve visual appearance. For example, in "VA", the 'A' might be moved slightly left to tuck under the 'V'.
SupportsCharacter(int)
Checks if a font supports specified codepoint instance.
public override bool SupportsCharacter(int codepoint)
Parameters
codepointintThe Unicode codepoint for the character to use.
Returns
TryGetDeviceGlyph(int, float, out FontGlyph)
Tries to get a glyph rasterized for the specified device scale, so text drawn under a scaling transform stays crisp.
protected override bool TryGetDeviceGlyph(int codepoint, float deviceScale, out FontGlyph glyph)
Parameters
codepointintThe codepoint to get the glyph for.
deviceScalefloatThe device scale, as returned by GetDeviceScale(in Transform2D).
glyphFontGlyphThe device-resolution glyph, with its size, bearing and texture region in device pixels.
Returns
- bool
true if the font can rasterize at arbitrary sizes and produced a glyph; otherwise false. The base implementation returns false (bitmap fonts are simply scaled).
Remarks
Rasterizes at Size × into the same shared atlas,
which keys glyphs by size, so device-size glyphs are cached alongside the logical ones.deviceScale