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
ITextSourceThe text source.
paragraphProperties
TextParagraphPropertiesThe default text paragraph properties.
textTrimming
TextTrimmingThe text trimming.
maxWidth
doubleThe maximum width.
maxHeight
doubleThe maximum height.
maxLines
intThe 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
stringThe text.
typeface
TypefaceThe typeface.
fontFeatures
FontFeatureCollectionOptional list of turned on/off features.
fontSize
doubleSize of the font.
foreground
IBrushThe foreground.
textAlignment
TextAlignmentThe text alignment.
textWrapping
TextWrappingThe text wrapping.
textTrimming
TextTrimmingThe text trimming.
textDecorations
TextDecorationCollectionThe text decorations.
flowDirection
FlowDirectionThe text flow direction.
maxWidth
doubleThe maximum width.
maxHeight
doubleThe maximum height.
lineHeight
doubleThe height of each line of text.
letterSpacing
doubleThe letter spacing that is applied to rendered glyphs.
maxLines
intThe 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
stringThe text.
typeface
TypefaceThe typeface.
fontSize
doubleSize of the font.
foreground
IBrushThe foreground.
textAlignment
TextAlignmentThe text alignment.
textWrapping
TextWrappingThe text wrapping.
textTrimming
TextTrimmingThe text trimming.
textDecorations
TextDecorationCollectionThe text decorations.
flowDirection
FlowDirectionThe text flow direction.
maxWidth
doubleThe maximum width.
maxHeight
doubleThe maximum height.
lineHeight
doubleThe height of each line of text.
letterSpacing
doubleThe letter spacing that is applied to rendered glyphs.
maxLines
intThe 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
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
Height
The distance from the top of the first line to the bottom of the last line.
public double Height { get; }
Property Value
LetterSpacing
Gets the text spacing.
public double LetterSpacing { get; }
Property Value
LineHeight
Gets or sets the height of each line of text.
public double LineHeight { get; }
Property Value
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
MaxLines
Gets the maximum number of text lines.
public int MaxLines { get; }
Property Value
MaxWidth
Gets the maximum width.
public double MaxWidth { get; }
Property Value
OverhangAfter
The distance from the bottom of the last line to the extent bottom.
public double OverhangAfter { get; }
Property Value
OverhangLeading
The maximum distance from the leading black pixel to the leading alignment point of a line.
public double OverhangLeading { get; }
Property Value
OverhangTrailing
The maximum distance from the trailing black pixel to the trailing alignment point of a line.
public double OverhangTrailing { get; }
Property Value
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
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
Methods
Dispose()
public void Dispose()
Draw(DrawingContext, Point)
Draws the text layout.
public void Draw(DrawingContext context, Point origin)
Parameters
context
DrawingContextThe drawing context.
origin
PointThe origin.
GetLineIndexFromCharacterIndex(int, bool)
public int GetLineIndexFromCharacterIndex(int charIndex, bool trailingEdge)
Parameters
Returns
HitTestPoint(in Point)
public TextHitTestResult HitTestPoint(in Point point)
Parameters
point
Point
Returns
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
intThe text position.
Returns
HitTestTextRange(int, int)
public IEnumerable<Rect> HitTestTextRange(int start, int length)