Class DynamicFontAtlas
Represents a dynamic texture atlas for storing font glyphs.
public class DynamicFontAtlas : IFontAtlas
- Inheritance
-
DynamicFontAtlas
- Implements
- Inherited Members
- Extension Methods
Constructors
DynamicFontAtlas(IRenderContext, uint)
Initializes a new instance of the DynamicFontAtlas class.
public DynamicFontAtlas(IRenderContext context, uint maxPages = 4)
Parameters
contextIRenderContextAn instance of the IRenderContext to create textures from.
maxPagesuintThe maximum number of texture pages to create.
Properties
Glyphs
Gets all glyphs stored in the atlas.
public IReadOnlyDictionary<StyledGlyphDefinition, FontGlyph> Glyphs { get; }
Property Value
PageCount
Gets the number of texture pages.
public int PageCount { get; }
Property Value
Textures
Gets the font textures.
public IReadOnlyCollection<ITexture> Textures { get; }
Property Value
Methods
AddEmptyGlyph(FontGlyph, FontInfo)
Adds an empty glyph for rendering purposes.
public void AddEmptyGlyph(FontGlyph glyph, FontInfo fontInfo)
Parameters
glyphFontGlyphAn instance of the FontGlyph to add to a font.
fontInfoFontInfoInfo about the font to store font-specific glyph info for.
Remarks
This method can be used for non-rendered glyphs that represent some unique spacings or kernings. The most common example of an "empty" glyph is a whitespace. These glyphs are not saved to the atlas so they don't affect textures. However, they're used in calculations.
Clear()
Clears all atlas data by removing all the pages and glyphs data.
public void Clear()
GetGlyph(StyledGlyphDefinition)
Gets the glyph for a codepoint.
public FontGlyph? GetGlyph(StyledGlyphDefinition codepoint)
Parameters
codepointStyledGlyphDefinition
Returns
GetGlyphPage(in FontGlyph)
Gets a page for the glyph with the specified codepoint.
public ITexture GetGlyphPage(in FontGlyph glyph)
Parameters
glyphFontGlyphGlyph to get atlas page for.
Returns
- ITexture
A texture page for the specified glyph.
TryAddGlyph(FontGlyph, Memory<byte>, FontInfo)
Tries to add a glyph to this atlas instance.
public FontGlyph TryAddGlyph(FontGlyph glyph, Memory<byte> pixels, FontInfo fontInfo)
Parameters
glyphFontGlyphA glyph to add to the atlas.
pixelsMemory<byte>Pixels buffer to add to the texture.
fontInfoFontInfoInfo about the font that adds a glyph.
Returns
- FontGlyph
Modified glyph instance with page index and texture region set.