Table of Contents

Class TextLayout

Namespace
Avalonia.Media.TextFormatting
Assembly
Avalonia.Base.dll

Represents a multi line text layout.

public class TextLayout : IDisposable
Inheritance
TextLayout
Implements
Inherited Members

Constructors

TextLayout(ITextSource, TextParagraphProperties, TextTrimming?, double, double, int)

Initializes a new instance of the TextLayout class.

public TextLayout(ITextSource textSource, TextParagraphProperties paragraphProperties, TextTrimming? textTrimming = null, double maxWidth = Infinity, double maxHeight = Infinity, int maxLines = 0)

Parameters

textSource ITextSource

The text source.

paragraphProperties TextParagraphProperties

The default text paragraph properties.

textTrimming TextTrimming

The text trimming.

maxWidth double

The maximum width.

maxHeight double

The maximum height.

maxLines int

The maximum number of text lines.

TextLayout(string?, Typeface, FontFeatureCollection?, double, IBrush?, TextAlignment, TextWrapping, TextTrimming?, TextDecorationCollection?, FlowDirection, double, double, double, double, int, IReadOnlyList<ValueSpan<TextRunProperties>>?)

Initializes a new instance of the TextLayout class.

public TextLayout(string? text, Typeface typeface, FontFeatureCollection? fontFeatures, double fontSize, IBrush? foreground, TextAlignment textAlignment = TextAlignment.Left, TextWrapping textWrapping = TextWrapping.NoWrap, TextTrimming? textTrimming = null, TextDecorationCollection? textDecorations = null, FlowDirection flowDirection = FlowDirection.LeftToRight, double maxWidth = Infinity, double maxHeight = Infinity, double lineHeight = NaN, double letterSpacing = 0, int maxLines = 0, IReadOnlyList<ValueSpan<TextRunProperties>>? textStyleOverrides = null)

Parameters

text string

The text.

typeface Typeface

The typeface.

fontFeatures FontFeatureCollection

Optional list of turned on/off features.

fontSize double

Size of the font.

foreground IBrush

The foreground.

textAlignment TextAlignment

The text alignment.

textWrapping TextWrapping

The text wrapping.

textTrimming TextTrimming

The text trimming.

textDecorations TextDecorationCollection

The text decorations.

flowDirection FlowDirection

The text flow direction.

maxWidth double

The maximum width.

maxHeight double

The maximum height.

lineHeight double

The height of each line of text.

letterSpacing double

The letter spacing that is applied to rendered glyphs.

maxLines int

The maximum number of text lines.

textStyleOverrides IReadOnlyList<ValueSpan<TextRunProperties>>

The text style overrides.

TextLayout(string?, Typeface, double, IBrush?, TextAlignment, TextWrapping, TextTrimming?, TextDecorationCollection?, FlowDirection, double, double, double, double, int, IReadOnlyList<ValueSpan<TextRunProperties>>?)

Initializes a new instance of the TextLayout class.

public TextLayout(string? text, Typeface typeface, double fontSize, IBrush? foreground, TextAlignment textAlignment = TextAlignment.Left, TextWrapping textWrapping = TextWrapping.NoWrap, TextTrimming? textTrimming = null, TextDecorationCollection? textDecorations = null, FlowDirection flowDirection = FlowDirection.LeftToRight, double maxWidth = Infinity, double maxHeight = Infinity, double lineHeight = NaN, double letterSpacing = 0, int maxLines = 0, IReadOnlyList<ValueSpan<TextRunProperties>>? textStyleOverrides = null)

Parameters

text string

The text.

typeface Typeface

The typeface.

fontSize double

Size of the font.

foreground IBrush

The foreground.

textAlignment TextAlignment

The text alignment.

textWrapping TextWrapping

The text wrapping.

textTrimming TextTrimming

The text trimming.

textDecorations TextDecorationCollection

The text decorations.

flowDirection FlowDirection

The text flow direction.

maxWidth double

The maximum width.

maxHeight double

The maximum height.

lineHeight double

The height of each line of text.

letterSpacing double

The letter spacing that is applied to rendered glyphs.

maxLines int

The maximum number of text lines.

textStyleOverrides IReadOnlyList<ValueSpan<TextRunProperties>>

The text style overrides.

Properties

Baseline

The distance from the top of the first line to the baseline of the first line.

public double Baseline { get; }

Property Value

double

Extent

The distance from the topmost black pixel of the first line to the bottommost black pixel of the last line.

public double Extent { get; }

Property Value

double

Height

The distance from the top of the first line to the bottom of the last line.

public double Height { get; }

Property Value

double

LetterSpacing

Gets the text spacing.

public double LetterSpacing { get; }

Property Value

double

LineHeight

Gets or sets the height of each line of text.

public double LineHeight { get; }

Property Value

double

Remarks

A value of NaN (equivalent to an attribute value of "Auto") indicates that the line height is determined automatically from the current font characteristics. The default is NaN.

MaxHeight

Gets the maximum height.

public double MaxHeight { get; }

Property Value

double

MaxLines

Gets the maximum number of text lines.

public int MaxLines { get; }

Property Value

int

MaxWidth

Gets the maximum width.

public double MaxWidth { get; }

Property Value

double

OverhangAfter

The distance from the bottom of the last line to the extent bottom.

public double OverhangAfter { get; }

Property Value

double

OverhangLeading

The maximum distance from the leading black pixel to the leading alignment point of a line.

public double OverhangLeading { get; }

Property Value

double

OverhangTrailing

The maximum distance from the trailing black pixel to the trailing alignment point of a line.

public double OverhangTrailing { get; }

Property Value

double

TextLines

Gets the text lines.

public IReadOnlyList<TextLine> TextLines { get; }

Property Value

IReadOnlyList<TextLine>

The text lines.

Width

The maximum advance width between the leading and trailing alignment points of a line, excluding the width of whitespace characters at the end of the line.

public double Width { get; }

Property Value

double

WidthIncludingTrailingWhitespace

The maximum advance width between the leading and trailing alignment points of a line, including the width of whitespace characters at the end of the line.

public double WidthIncludingTrailingWhitespace { get; }

Property Value

double

Methods

Dispose()

public void Dispose()

Draw(DrawingContext, Point)

Draws the text layout.

public void Draw(DrawingContext context, Point origin)

Parameters

context DrawingContext

The drawing context.

origin Point

The origin.

GetLineIndexFromCharacterIndex(int, bool)

public int GetLineIndexFromCharacterIndex(int charIndex, bool trailingEdge)

Parameters

charIndex int
trailingEdge bool

Returns

int

HitTestPoint(in Point)

public TextHitTestResult HitTestPoint(in Point point)

Parameters

point Point

Returns

TextHitTestResult

HitTestTextPosition(int)

Get the pixel location relative to the top-left of the layout box given the text position.

public Rect HitTestTextPosition(int textPosition)

Parameters

textPosition int

The text position.

Returns

Rect

HitTestTextRange(int, int)

public IEnumerable<Rect> HitTestTextRange(int start, int length)

Parameters

start int
length int

Returns

IEnumerable<Rect>