Table of Contents

Class TextBlock

Namespace
SixLabors.Fonts
Assembly
SixLabors.Fonts.dll

Represents text prepared for repeated line layout, measurement, and rendering.

public sealed class TextBlock
Inheritance
TextBlock
Inherited Members

Constructors

TextBlock(ReadOnlySpan<char>, TextOptions)

Initializes a new instance of the TextBlock class.

public TextBlock(ReadOnlySpan<char> text, TextOptions options)

Parameters

text ReadOnlySpan<char>

The text to prepare.

options TextOptions

The text options used to prepare, measure, and render the block.

Remarks

WrappingLength is ignored while preparing the block; pass the wrapping length to the measurement or rendering method. Use -1 there to disable wrapping.

TextBlock(string, TextOptions)

Initializes a new instance of the TextBlock class.

public TextBlock(string text, TextOptions options)

Parameters

text string

The text to prepare.

options TextOptions

The text options used to prepare, measure, and render the block.

Remarks

WrappingLength is ignored while preparing the block; pass the wrapping length to the measurement or rendering method. Use -1 there to disable wrapping.

Methods

CountLines(float)

Gets the number of laid-out lines at the supplied wrapping length.

public int CountLines(float wrappingLength)

Parameters

wrappingLength float

The wrapping length in pixels. Use -1 to disable wrapping.

Returns

int

The laid-out line count.

EnumerateLineLayouts()

Creates an enumerator that lays out this block one line at a time.

public LineLayoutEnumerator EnumerateLineLayouts()

Returns

LineLayoutEnumerator

A line layout enumerator for this block.

GetGlyphMetrics(float)

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

public ReadOnlyMemory<GlyphMetrics> GetGlyphMetrics(float wrappingLength)

Parameters

wrappingLength float

The wrapping length in pixels. Use -1 to disable wrapping.

Returns

ReadOnlyMemory<GlyphMetrics>

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

GetGraphemeMetrics(float)

Gets the positioned metrics of each laid-out grapheme.

public ReadOnlyMemory<GraphemeMetrics> GetGraphemeMetrics(float wrappingLength)

Parameters

wrappingLength float

The wrapping length in pixels. Use -1 to disable wrapping.

Returns

ReadOnlyMemory<GraphemeMetrics>

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

GetLineLayouts(float)

Gets visual line layouts for this block at the supplied wrapping length.

public ReadOnlyMemory<LineLayout> GetLineLayouts(float wrappingLength)

Parameters

wrappingLength float

The wrapping length in pixels. Use -1 to disable wrapping.

Returns

ReadOnlyMemory<LineLayout>

A read-only memory region containing LineLayout entries in final layout order.

Remarks

The returned memory contains every laid-out line, including lines produced by hard line breaks.

GetLineMetrics(float)

Gets per-line layout metrics at the supplied wrapping length.

public ReadOnlyMemory<LineMetrics> GetLineMetrics(float wrappingLength)

Parameters

wrappingLength float

The wrapping length in pixels. Use -1 to disable wrapping.

Returns

ReadOnlyMemory<LineMetrics>

A read-only memory region containing LineMetrics in pixel units.

GetWordMetrics(float)

Gets the positioned metrics of each Unicode word-boundary segment.

public ReadOnlyMemory<WordMetrics> GetWordMetrics(float wrappingLength)

Parameters

wrappingLength float

The wrapping length in pixels. Use -1 to disable wrapping.

Returns

ReadOnlyMemory<WordMetrics>

A read-only memory region containing per-word-boundary segment metrics entries.

Measure(float)

Measures the full set of layout metrics for this block at the supplied wrapping length.

public TextMetrics Measure(float wrappingLength)

Parameters

wrappingLength float

The wrapping length in pixels. Use -1 to disable wrapping.

Returns

TextMetrics

A TextMetrics instance containing every measurement for the laid-out text.

MeasureAdvance(float)

Measures the logical advance of this block at the supplied wrapping length.

public FontRectangle MeasureAdvance(float wrappingLength)

Parameters

wrappingLength float

The wrapping length in pixels. Use -1 to disable wrapping.

Returns

FontRectangle

The logical advance rectangle.

MeasureBounds(float)

Measures the rendered glyph bounds of this block at the supplied wrapping length.

public FontRectangle MeasureBounds(float wrappingLength)

Parameters

wrappingLength float

The wrapping length in pixels. Use -1 to disable wrapping.

Returns

FontRectangle

The rendered glyph bounds.

MeasureRenderableBounds(float)

Measures the union of logical advance and rendered glyph bounds at the supplied wrapping length.

public FontRectangle MeasureRenderableBounds(float wrappingLength)

Parameters

wrappingLength float

The wrapping length in pixels. Use -1 to disable wrapping.

Returns

FontRectangle

The full renderable bounds.

RenderTo(IGlyphRenderer, float)

Renders this block to the supplied glyph renderer at the supplied wrapping length.

public void RenderTo(IGlyphRenderer renderer, float wrappingLength)

Parameters

renderer IGlyphRenderer

The target renderer.

wrappingLength float

The wrapping length in pixels. Use -1 to disable wrapping.