Table of Contents

Interface IFont

Namespace
Icy.Rendering.Fonts
Assembly
IcyUI.dll

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

IReadOnlyDictionary<int, FontGlyph>

Info

Gets the info about this font.

FontInfo Info { get; }

Property Value

FontInfo

Metrics

Gets the calculated font metrics.

FontMetrics Metrics { get; }

Property Value

FontMetrics

Methods

CalculateBounds(string, in FontRenderingOptions)

Calculates estimated bounds for the string to render.

Rectangle CalculateBounds(string text, in FontRenderingOptions options)

Parameters

text string

Text to calculate bounds.

options FontRenderingOptions

Options 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

context IRenderContext

An instance of the render context to draw font.

text string

Text to draw.

options FontRenderingOptions

Options for the rendering.

GetGlyph(int)

Gets the glyph for the specified character codepoint.

FontGlyph GetGlyph(int codepoint)

Parameters

codepoint int

Codepoint 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

text string

Text to enumerate glyphs for.

options FontRenderingOptions

Rendering 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

text string

Text to measure.

options FontRenderingOptions

Options for the measurement.

Returns

Vector2

The cursor's total displacement from Position.

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

text string

The text to measure.

options FontRenderingOptions

Options 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

codepoint int

The Unicode codepoint for the character to use.

Returns

bool

true if this font instance can render specified character; otherwise false.