Table of Contents

Class TextMetrics

Namespace
SixLabors.Fonts
Assembly
SixLabors.Fonts.dll

Encapsulates the full set of measurement results for laid-out text.

public sealed class TextMetrics
Inheritance
TextMetrics
Inherited Members

Properties

Advance

Gets the logical advance rectangle of the text in pixel units.

public FontRectangle Advance { get; }

Property Value

FontRectangle

Remarks

Reflects line-box height and horizontal or vertical text advance from the layout model. Does not guarantee that all rendered glyph pixels fit within the returned rectangle.

Bounds

Gets the rendered glyph bounds of the text in pixel units.

public FontRectangle Bounds { get; }

Property Value

FontRectangle

Remarks

This is the tight ink bounds enclosing all rendered glyphs and may be smaller or larger than the logical advance. May have a non-zero origin.

GraphemeMetrics

Gets the grapheme metrics entries in final layout order.

public ReadOnlySpan<GraphemeMetrics> GraphemeMetrics { get; }

Property Value

ReadOnlySpan<GraphemeMetrics>

LineCount

Gets the number of laid-out lines in the text.

public int LineCount { get; }

Property Value

int

LineMetrics

Gets the per-line layout metrics for the text.

public ReadOnlySpan<LineMetrics> LineMetrics { get; }

Property Value

ReadOnlySpan<LineMetrics>

RenderableBounds

Gets the union of the logical advance rectangle (positioned at the text options origin) and the rendered glyph bounds in pixel units.

public FontRectangle RenderableBounds { get; }

Property Value

FontRectangle

Remarks

Use this rectangle when both typographic advance and rendered glyph overshoot must fit within the same bounding box.

WordMetrics

Gets the word-boundary segment metrics in source order.

public ReadOnlySpan<WordMetrics> WordMetrics { get; }

Property Value

ReadOnlySpan<WordMetrics>

Methods

GetCaret(CaretPlacement)

Gets an absolute caret position in the laid-out text.

public CaretPosition GetCaret(CaretPlacement placement)

Parameters

placement CaretPlacement

The absolute caret placement.

Returns

CaretPosition

The caret position in pixel units.

GetCaretPosition(TextHit)

Gets the caret position for the supplied hit.

public CaretPosition GetCaretPosition(TextHit hit)

Parameters

hit TextHit

The hit-tested grapheme position.

Returns

CaretPosition

The caret position in pixel units.

GetGlyphMetrics()

Gets the positioned metrics of each laid-out glyph entry.

public ReadOnlyMemory<GlyphMetrics> GetGlyphMetrics()

Returns

ReadOnlyMemory<GlyphMetrics>

A read-only memory region containing per-glyph metrics entries.

GetSelectionBounds(CaretPosition, CaretPosition)

Gets selection bounds between two caret positions.

public ReadOnlyMemory<FontRectangle> GetSelectionBounds(CaretPosition anchor, CaretPosition focus)

Parameters

anchor CaretPosition

The fixed selection endpoint.

focus CaretPosition

The active selection endpoint.

Returns

ReadOnlyMemory<FontRectangle>

A read-only memory region containing the selection bounds in visual order and pixel units.

GetSelectionBounds(GraphemeMetrics)

Gets selection bounds for the supplied grapheme metrics.

public ReadOnlyMemory<FontRectangle> GetSelectionBounds(GraphemeMetrics metrics)

Parameters

metrics GraphemeMetrics

The grapheme metrics to select.

Returns

ReadOnlyMemory<FontRectangle>

A read-only memory region containing the selection bounds in visual order and pixel units.

GetSelectionBounds(TextHit, TextHit)

Gets selection bounds between two hit-tested grapheme positions.

public ReadOnlyMemory<FontRectangle> GetSelectionBounds(TextHit anchor, TextHit focus)

Parameters

anchor TextHit

The fixed selection endpoint.

focus TextHit

The active selection endpoint.

Returns

ReadOnlyMemory<FontRectangle>

A read-only memory region containing the selection bounds in visual order and pixel units.

GetSelectionBounds(WordMetrics)

Gets selection bounds for the supplied word metrics.

public ReadOnlyMemory<FontRectangle> GetSelectionBounds(WordMetrics metrics)

Parameters

metrics WordMetrics

The word metrics to select.

Returns

ReadOnlyMemory<FontRectangle>

A read-only memory region containing the selection bounds in visual order and pixel units.

GetWordMetrics(CaretPosition)

Gets the word metrics for the word-boundary segment containing the supplied caret position.

public WordMetrics GetWordMetrics(CaretPosition caret)

Parameters

caret CaretPosition

The caret position.

Returns

WordMetrics

The word metrics containing the caret's grapheme insertion index.

GetWordMetrics(TextHit)

Gets the word metrics for the word-boundary segment containing the supplied hit-tested grapheme position.

public WordMetrics GetWordMetrics(TextHit hit)

Parameters

hit TextHit

The hit-tested grapheme position.

Returns

WordMetrics

The word metrics containing the hit grapheme.

HitTest(Vector2)

Hit tests the supplied point against the laid-out grapheme advance bounds.

public TextHit HitTest(Vector2 point)

Parameters

point Vector2

The point in pixel units.

Returns

TextHit

The hit-tested grapheme position.

MoveCaret(CaretPosition, CaretMovement)

Moves the supplied caret by the requested operation.

public CaretPosition MoveCaret(CaretPosition caret, CaretMovement movement)

Parameters

caret CaretPosition

The current caret position.

movement CaretMovement

The movement operation.

Returns

CaretPosition

The moved caret position in pixel units.