Table of Contents

Interface ITextMeasureContext

Namespace
Xui.Core.Canvas
Assembly
Xui.Core.dll

Provides functionality for measuring text and setting font properties. Mirrors the measurement behavior of the HTML5 Canvas 2D context, but returns a full TextMetrics structure for advanced layout.

public interface ITextMeasureContext

Methods

HitTestTextPosition(ReadOnlySpan<char>, NFloat)

Returns the character index (caret position) in text closest to the given x coordinate, using the current font. The result ranges from 0 (before the first character) to text.Length (after the last character). The position snaps to whichever side of a character's midpoint x falls on.

int HitTestTextPosition(ReadOnlySpan<char> text, NFloat x)

Parameters

text ReadOnlySpan<char>

The text to hit-test against.

x NFloat

The horizontal offset to test, relative to the text origin.

Returns

int

The nearest caret position (0 to text.Length).

HitTestTextPosition(string, NFloat)

Returns the character index (caret position) in text closest to the given x coordinate, using the current font. The result ranges from 0 (before the first character) to text.Length (after the last character). The position snaps to whichever side of a character's midpoint x falls on.

int HitTestTextPosition(string text, NFloat x)

Parameters

text string

The text to hit-test against.

x NFloat

The horizontal offset to test, relative to the text origin.

Returns

int

The nearest caret position (0 to text.Length).

MeasureText(ReadOnlySpan<char>)

Measures the layout and bounding box metrics of the specified text without allocating a string.

TextMetrics MeasureText(ReadOnlySpan<char> text)

Parameters

text ReadOnlySpan<char>

The text characters to measure.

Returns

TextMetrics

A TextMetrics structure containing both string-specific and font-wide metrics.

MeasureText(string)

Measures the layout and bounding box metrics of the specified text string using the current font.

TextMetrics MeasureText(string text)

Parameters

text string

The text string to measure.

Returns

TextMetrics

A TextMetrics structure containing both string-specific and font-wide metrics.

SetFont(Font)

Sets the font used for all subsequent text drawing and measurement operations.

void SetFont(Font font)

Parameters

font Font

The font definition to apply.