Interface IFont
Represents an interface for the text fonts.
public interface IFont
- Extension Methods
Properties
Glyphs
Gets the info about loaded font glyphs.
IReadOnlyDictionary<int, FontGlyph> Glyphs { get; }
Property Value
Info
Gets the info about this font.
FontInfo Info { get; }
Property Value
Metrics
Gets the calculated font metrics.
FontMetrics Metrics { get; }
Property Value
Methods
CalculateBounds(string, in FontRenderingOptions)
Calculates estimated bounds for the string to render.
Rectangle CalculateBounds(string text, in FontRenderingOptions options)
Parameters
textstringText to calculate bounds.
optionsFontRenderingOptionsOptions for the calculations.
Returns
- Rectangle
Estimated bounds required for drawing.
DrawString(IRenderContext, string, in FontRenderingOptions)
Draws specified text using this font instance.
void DrawString(IRenderContext context, string text, in FontRenderingOptions options)
Parameters
contextIRenderContextAn instance of the render context to draw font.
textstringText to draw.
optionsFontRenderingOptionsOptions for the rendering.
GetGlyph(int)
Gets the glyph for the specified character codepoint.
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 default codepoint. If that also fails, it returns None.
We recommend you to use this method instead of calling Glyphs by indexer because this method can have additional logic for the glyphs preparation. For instance, the DynamicSpriteFont rasterizes glyphs only when this method is called.
GetRenderGlyphs(string, in FontRenderingOptions)
Enumerates glyphs to render for the specified text.
List<RenderGlyph> GetRenderGlyphs(string text, in FontRenderingOptions options)
Parameters
textstringText to enumerate glyphs for.
optionsFontRenderingOptionsRendering options to apply.
Returns
- List<RenderGlyph>
An enumeration for all the rendered glyphs.
MeasureAdvance(string, in FontRenderingOptions)
Measures the raw cursor advance for the specified text - how far the text cursor (caret) moves after "typing" every character, including trailing whitespace that has no visible ink of its own.
Vector2 MeasureAdvance(string text, in FontRenderingOptions options)
Parameters
textstringText to measure.
optionsFontRenderingOptionsOptions for the measurement.
Returns
Remarks
Unlike MeasureString(string, in FontRenderingOptions)/CalculateBounds(string, in FontRenderingOptions) - which report the tightest box containing actual glyph ink, appropriate for auto-sizing content to what's visually drawn - this always reflects the true pen position, even past a glyph whose own ink extends beyond its own advance width. Caret placement and "reserve room for what was typed" sizing (e.g. TextBox) must use this, not the ink-based measurements: a glyph that overhangs its advance can otherwise make a trailing, inkless character (like a space) appear to not move the cursor at all, because the ink-based bounds were already wider than the true cursor position.
MeasureString(string, in FontRenderingOptions)
Gets the space required to draw string with this font.
Vector2 MeasureString(string text, in FontRenderingOptions options)
Parameters
textstringThe text to measure.
optionsFontRenderingOptionsOptions for the measure.
Returns
- Vector2
Maximal size in pixels to draw the string with current font parameters.
SupportsCharacter(int)
Checks if a font supports specified codepoint instance.
bool SupportsCharacter(int codepoint)
Parameters
codepointintThe Unicode codepoint for the character to use.