Skip to main content

FormattedText Class

Definition

Namespace:Avalonia.Media
Assembly:Avalonia.Base
Package:Avalonia

The FormattedText class is targeted at programmers needing to add some simple text to a MIL visual.

public class FormattedText

Inheritance: object -> FormattedText

Constructors

NameDescription
FormattedTextConstruct a FormattedText object.

FormattedText Constructor

Construct a FormattedText object.

public FormattedText(string textToFormat, System.Globalization.CultureInfo culture, Avalonia.Media.FlowDirection flowDirection, Avalonia.Media.Typeface typeface, double emSize, Avalonia.Media.IBrush foreground)

Parameters

textToFormat string

String of text to be displayed.

culture System.Globalization.CultureInfo

Culture of text.

flowDirection Avalonia.Media.FlowDirection

Flow direction of text.

typeface Avalonia.Media.Typeface

Type face used to display text.

emSize double

Font em size in visual units (1/96 of an inch).

foreground Avalonia.Media.IBrush

Foreground brush used to render text.

Methods

NameDescription
BuildGeometryObtains geometry for the text, including underlines and strikethroughs.
BuildHighlightGeometry (2 overloads)Builds a highlight geometry object.
GetMaxTextWidthsObtains a copy of the array of lengths, which will be applied to each line of text in turn. If the text covers more lines than there are entries in the length array, the last entry is reused as many times as required. The maxTextWidths array overrides the MaxTextWidth property.
SetCulture (2 overloads)Sets or changes the culture for the text object.
SetFontFamily (4 overloads)Sets or changes the font family for the text object
SetFontFeatures (2 overloads)Sets or changes the font features for the text object
SetFontSize (2 overloads)Sets or changes the font em size measured in MIL units
SetFontStyle (2 overloads)Sets or changes the font style
SetFontTypeface (2 overloads)Sets or changes the type face
SetFontWeight (2 overloads)Sets or changes the font weight
SetForegroundBrush (2 overloads)Sets foreground brush used for drawing text
SetMaxTextWidthsSets the array of lengths, which will be applied to each line of text in turn. If the text covers more lines than there are entries in the length array, the last entry is reused as many times as required. The maxTextWidths array overrides the MaxTextWidth property.
SetTextDecorations (2 overloads)Sets or changes the text decorations

BuildGeometry Method

Obtains geometry for the text, including underlines and strikethroughs.

public Avalonia.Media.Geometry BuildGeometry(Avalonia.Point origin)

Parameters

origin Avalonia.Point

The left top origin of the resulting geometry.

Returns

Avalonia.Media.Geometry

The geometry returned contains the combined geometry of all of the glyphs, underlines and strikeThroughs that represent the formatted text. Overlapping contours are merged by performing a Boolean union operation.

BuildHighlightGeometry overloads

BuildHighlightGeometry Method

Builds a highlight geometry object.

public Avalonia.Media.Geometry BuildHighlightGeometry(Avalonia.Point origin)
Parameters

origin Avalonia.Point

The origin of the highlight region

Returns

Avalonia.Media.Geometry

Geometry that surrounds the text.

BuildHighlightGeometry Method

Builds a highlight geometry object for a given character range.

public Avalonia.Media.Geometry BuildHighlightGeometry(Avalonia.Point origin, int startIndex, int count)
Parameters

origin Avalonia.Point

The origin of the highlight region.

startIndex int

The start index of initial character the bounds should be obtained for.

count int

The number of characters the bounds should be obtained for.

Returns

Avalonia.Media.Geometry

Geometry that surrounds the specified character range.

GetMaxTextWidths Method

Obtains a copy of the array of lengths, which will be applied to each line of text in turn. If the text covers more lines than there are entries in the length array, the last entry is reused as many times as required. The maxTextWidths array overrides the MaxTextWidth property.

public double[] GetMaxTextWidths()

Returns

double[]

The copy of max text width array

SetCulture overloads

SetCulture Method

Sets or changes the culture for the text object.

public void SetCulture(System.Globalization.CultureInfo culture)
Parameters

culture System.Globalization.CultureInfo

The new culture for the text object.

SetCulture Method

Sets or changes the culture for the text object.

public void SetCulture(System.Globalization.CultureInfo culture, int startIndex, int count)
Parameters

culture System.Globalization.CultureInfo

The new culture for the text object.

startIndex int

The start index of initial character to apply the change to.

count int

The number of characters the change should be applied to.

SetFontFamily overloads

SetFontFamily Method

Sets or changes the font family for the text object

public void SetFontFamily(Avalonia.Media.FontFamily fontFamily)
Parameters

fontFamily Avalonia.Media.FontFamily

Font family

SetFontFamily Method

Sets or changes the font family for the text object

public void SetFontFamily(Avalonia.Media.FontFamily fontFamily, int startIndex, int count)
Parameters

fontFamily Avalonia.Media.FontFamily

Font family

startIndex int

The start index of initial character to apply the change to.

count int

The number of characters the change should be applied to.

SetFontFamily Method

Sets or changes the font family for the text object

public void SetFontFamily(string fontFamily)
Parameters

fontFamily string

Font family name

SetFontFamily Method

Sets or changes the font family for the text object

public void SetFontFamily(string fontFamily, int startIndex, int count)
Parameters

fontFamily string

Font family name

startIndex int

The start index of initial character to apply the change to.

count int

The number of characters the change should be applied to.

SetFontFeatures overloads

SetFontFeatures Method

Sets or changes the font features for the text object

public void SetFontFeatures(Avalonia.Media.FontFeatureCollection fontFeatures)
Parameters

fontFeatures Avalonia.Media.FontFeatureCollection

Feature collection

SetFontFeatures Method

Sets or changes the font features for the text object

public void SetFontFeatures(Avalonia.Media.FontFeatureCollection fontFeatures, int startIndex, int count)
Parameters

fontFeatures Avalonia.Media.FontFeatureCollection

Feature collection

startIndex int

The start index of initial character to apply the change to.

count int

The number of characters the change should be applied to.

SetFontSize overloads

SetFontSize Method

Sets or changes the font em size measured in MIL units

public void SetFontSize(double emSize)
Parameters

emSize double

Font em size

SetFontSize Method

Sets or changes the font em size measured in MIL units

public void SetFontSize(double emSize, int startIndex, int count)
Parameters

emSize double

Font em size

startIndex int

The start index of initial character to apply the change to.

count int

The number of characters the change should be applied to.

SetFontStyle overloads

SetFontStyle Method

Sets or changes the font style

public void SetFontStyle(Avalonia.Media.FontStyle style)
Parameters

style Avalonia.Media.FontStyle

Font style

SetFontStyle Method

Sets or changes the font style

public void SetFontStyle(Avalonia.Media.FontStyle style, int startIndex, int count)
Parameters

style Avalonia.Media.FontStyle

Font style

startIndex int

The start index of initial character to apply the change to.

count int

The number of characters the change should be applied to.

SetFontTypeface overloads

SetFontTypeface Method

Sets or changes the type face

public void SetFontTypeface(Avalonia.Media.Typeface typeface)
Parameters

typeface Avalonia.Media.Typeface

Typeface

SetFontTypeface Method

Sets or changes the type face

public void SetFontTypeface(Avalonia.Media.Typeface typeface, int startIndex, int count)
Parameters

typeface Avalonia.Media.Typeface

Typeface

startIndex int

The start index of initial character to apply the change to.

count int

The number of characters the change should be applied to.

SetFontWeight overloads

SetFontWeight Method

Sets or changes the font weight

public void SetFontWeight(Avalonia.Media.FontWeight weight)
Parameters

weight Avalonia.Media.FontWeight

Font weight

SetFontWeight Method

Sets or changes the font weight

public void SetFontWeight(Avalonia.Media.FontWeight weight, int startIndex, int count)
Parameters

weight Avalonia.Media.FontWeight

Font weight

startIndex int

The start index of initial character to apply the change to.

count int

The number of characters the change should be applied to.

SetForegroundBrush overloads

SetForegroundBrush Method

Sets foreground brush used for drawing text

public void SetForegroundBrush(Avalonia.Media.IBrush foregroundBrush)
Parameters

foregroundBrush Avalonia.Media.IBrush

Foreground brush

SetForegroundBrush Method

Sets foreground brush used for drawing text

public void SetForegroundBrush(Avalonia.Media.IBrush foregroundBrush, int startIndex, int count)
Parameters

foregroundBrush Avalonia.Media.IBrush

Foreground brush

startIndex int

The start index of initial character to apply the change to.

count int

The number of characters the change should be applied to.

SetMaxTextWidths Method

Sets the array of lengths, which will be applied to each line of text in turn. If the text covers more lines than there are entries in the length array, the last entry is reused as many times as required. The maxTextWidths array overrides the MaxTextWidth property.

public void SetMaxTextWidths(double[] maxTextWidths)

Parameters

maxTextWidths double[]

The max text width array

SetTextDecorations overloads

SetTextDecorations Method

Sets or changes the text decorations

public void SetTextDecorations(Avalonia.Media.TextDecorationCollection textDecorations)
Parameters

textDecorations Avalonia.Media.TextDecorationCollection

Text decorations

SetTextDecorations Method

Sets or changes the text decorations

public void SetTextDecorations(Avalonia.Media.TextDecorationCollection textDecorations, int startIndex, int count)
Parameters

textDecorations Avalonia.Media.TextDecorationCollection

Text decorations

startIndex int

The start index of initial character to apply the change to.

count int

The number of characters the change should be applied to.

Properties

NameDescription
BaselineThe distance from the top of the first line to the baseline of the first line.
ExtentThe distance from the topmost black pixel of the first line to the bottommost black pixel of the last line.
FlowDirectionDefines the flow direction
HeightThe distance from the top of the first line to the bottom of the last line.
LineHeightGets or sets the height of, or the spacing between, each line where zero represents the default line height.
MaxLineCountDefines the maximum number of lines to display. The last line of text displayed is the lineCount-1'th line, or the last whole line that will fit within the count set by MaxTextHeight, whichever occurs first. Use the Trimming property to control how the omission of text is indicated
MaxTextHeightSets the maximum length of a column of text. The last line of text displayed is the last whole line that will fit within this limit, or the nth line as specified by MaxLineCount, whichever occurs first. Use the Trimming property to control how the omission of text is indicated.
MaxTextWidthThe MaxTextWidth property defines the alignment edges for the FormattedText. For example, left aligned text is wrapped such that the leftmost glyph alignment point on each line falls exactly on the left edge of the rectangle. Note that for many fonts, especially in italic style, some glyph strokes may extend beyond the edges of the alignment rectangle. For this reason, it is recommended that clients draw text with at least 1/6 em (i.e of the font size) unused margin space either side. Zero value of MaxTextWidth is equivalent to the maximum possible paragraph width.
OverhangAfterThe distance from the bottom of the last line to the extent bottom.
OverhangLeadingThe maximum distance from the leading black pixel to the leading alignment point of a line.
OverhangTrailingThe maximum distance from the trailing black pixel to the trailing alignment point of a line.
TextAlignmentDefines the alignment of text within the column
TrimmingDefines how omission of text is indicated. CharacterEllipsis trimming allows partial words to be displayed, while WordEllipsis removes whole words to fit. Both guarantee to include an ellipsis ('...') at the end of the lines where text has been trimmed as a result of line and column limits.
WidthThe 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.
WidthIncludingTrailingWhitespaceThe 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.

Baseline Property

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

public double Baseline { get; set; }

Extent Property

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

public double Extent { get; set; }

FlowDirection Property

Defines the flow direction

public Avalonia.Media.FlowDirection FlowDirection { get; set; }

Height Property

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

public double Height { get; set; }

LineHeight Property

Gets or sets the height of, or the spacing between, each line where zero represents the default line height.

public double LineHeight { get; set; }

MaxLineCount Property

Defines the maximum number of lines to display. The last line of text displayed is the lineCount-1'th line, or the last whole line that will fit within the count set by MaxTextHeight, whichever occurs first. Use the Trimming property to control how the omission of text is indicated

public int MaxLineCount { get; set; }

MaxTextHeight Property

Sets the maximum length of a column of text. The last line of text displayed is the last whole line that will fit within this limit, or the nth line as specified by MaxLineCount, whichever occurs first. Use the Trimming property to control how the omission of text is indicated.

public double MaxTextHeight { get; set; }

MaxTextWidth Property

The MaxTextWidth property defines the alignment edges for the FormattedText. For example, left aligned text is wrapped such that the leftmost glyph alignment point on each line falls exactly on the left edge of the rectangle. Note that for many fonts, especially in italic style, some glyph strokes may extend beyond the edges of the alignment rectangle. For this reason, it is recommended that clients draw text with at least 1/6 em (i.e of the font size) unused margin space either side. Zero value of MaxTextWidth is equivalent to the maximum possible paragraph width.

public double MaxTextWidth { get; set; }

OverhangAfter Property

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

public double OverhangAfter { get; set; }

OverhangLeading Property

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

public double OverhangLeading { get; set; }

OverhangTrailing Property

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

public double OverhangTrailing { get; set; }

TextAlignment Property

Defines the alignment of text within the column

public Avalonia.Media.TextAlignment TextAlignment { get; set; }

Trimming Property

Defines how omission of text is indicated. CharacterEllipsis trimming allows partial words to be displayed, while WordEllipsis removes whole words to fit. Both guarantee to include an ellipsis ('...') at the end of the lines where text has been trimmed as a result of line and column limits.

public Avalonia.Media.TextTrimming Trimming { get; set; }

Width Property

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; set; }

WidthIncludingTrailingWhitespace Property

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; set; }

Fields

NameDescription
DefaultIdealToRealNo summary available.
DefaultRealToIdealNo summary available.
GreatestMultiplierOfEmNo summary available.
IdealInfiniteWidthNo summary available.
RealInfiniteWidthNo summary available.

DefaultIdealToReal Field

public double DefaultIdealToReal

DefaultRealToIdeal Field

public double DefaultRealToIdeal

GreatestMultiplierOfEm Field

public double GreatestMultiplierOfEm

IdealInfiniteWidth Field

public int IdealInfiniteWidth

RealInfiniteWidth Field

public double RealInfiniteWidth