Table of Contents

Class FormattedText

Namespace
Avalonia.Media
Assembly
Avalonia.Base.dll

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

public class FormattedText
Inheritance
FormattedText
Inherited Members

Constructors

FormattedText(string, CultureInfo, FlowDirection, Typeface, double, IBrush?)

Construct a FormattedText object.

public FormattedText(string textToFormat, CultureInfo culture, FlowDirection flowDirection, Typeface typeface, double emSize, IBrush? foreground)

Parameters

textToFormat string

String of text to be displayed.

culture CultureInfo

Culture of text.

flowDirection FlowDirection

Flow direction of text.

typeface Typeface

Type face used to display text.

emSize double

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

foreground IBrush

Foreground brush used to render text.

Fields

DefaultIdealToReal

public const double DefaultIdealToReal = 0.0033333333333333335

Field Value

double

DefaultRealToIdeal

public const double DefaultRealToIdeal = 300

Field Value

double

GreatestMultiplierOfEm

public const double GreatestMultiplierOfEm = 100

Field Value

double

IdealInfiniteWidth

public const int IdealInfiniteWidth = 1073741822

Field Value

int

RealInfiniteWidth

public const double RealInfiniteWidth = 3579139.4066666667

Field Value

double

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

FlowDirection

Defines the flow direction

public FlowDirection FlowDirection { get; set; }

Property Value

FlowDirection

Height

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

public double Height { get; }

Property Value

double

LineHeight

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

public double LineHeight { get; set; }

Property Value

double

MaxLineCount

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

Property Value

int

MaxTextHeight

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

Property Value

double

MaxTextWidth

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

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

TextAlignment

Defines the alignment of text within the column

public TextAlignment TextAlignment { get; set; }

Property Value

TextAlignment

Trimming

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 TextTrimming Trimming { get; set; }

Property Value

TextTrimming

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

BuildGeometry(Point)

Obtains geometry for the text, including underlines and strikethroughs.

public Geometry? BuildGeometry(Point origin)

Parameters

origin Point

The left top origin of the resulting geometry.

Returns

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(Point)

Builds a highlight geometry object.

public Geometry? BuildHighlightGeometry(Point origin)

Parameters

origin Point

The origin of the highlight region

Returns

Geometry

Geometry that surrounds the text.

BuildHighlightGeometry(Point, int, int)

Builds a highlight geometry object for a given character range.

public Geometry? BuildHighlightGeometry(Point origin, int startIndex, int count)

Parameters

origin 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

Geometry

Geometry that surrounds the specified character range.

GetMaxTextWidths()

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(CultureInfo)

Sets or changes the culture for the text object.

public void SetCulture(CultureInfo culture)

Parameters

culture CultureInfo

The new culture for the text object.

SetCulture(CultureInfo, int, int)

Sets or changes the culture for the text object.

public void SetCulture(CultureInfo culture, int startIndex, int count)

Parameters

culture 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(FontFamily)

Sets or changes the font family for the text object

public void SetFontFamily(FontFamily fontFamily)

Parameters

fontFamily FontFamily

Font family

SetFontFamily(FontFamily, int, int)

Sets or changes the font family for the text object

public void SetFontFamily(FontFamily fontFamily, int startIndex, int count)

Parameters

fontFamily 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(string)

Sets or changes the font family for the text object

public void SetFontFamily(string fontFamily)

Parameters

fontFamily string

Font family name

SetFontFamily(string, int, int)

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(FontFeatureCollection?)

Sets or changes the font features for the text object

public void SetFontFeatures(FontFeatureCollection? fontFeatures)

Parameters

fontFeatures FontFeatureCollection

Feature collection

SetFontFeatures(FontFeatureCollection?, int, int)

Sets or changes the font features for the text object

public void SetFontFeatures(FontFeatureCollection? fontFeatures, int startIndex, int count)

Parameters

fontFeatures 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(double)

Sets or changes the font em size measured in MIL units

public void SetFontSize(double emSize)

Parameters

emSize double

Font em size

SetFontSize(double, int, int)

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(FontStyle)

Sets or changes the font style

public void SetFontStyle(FontStyle style)

Parameters

style FontStyle

Font style

SetFontStyle(FontStyle, int, int)

Sets or changes the font style

public void SetFontStyle(FontStyle style, int startIndex, int count)

Parameters

style 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(Typeface)

Sets or changes the type face

public void SetFontTypeface(Typeface typeface)

Parameters

typeface Typeface

Typeface

SetFontTypeface(Typeface, int, int)

Sets or changes the type face

public void SetFontTypeface(Typeface typeface, int startIndex, int count)

Parameters

typeface 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(FontWeight)

Sets or changes the font weight

public void SetFontWeight(FontWeight weight)

Parameters

weight FontWeight

Font weight

SetFontWeight(FontWeight, int, int)

Sets or changes the font weight

public void SetFontWeight(FontWeight weight, int startIndex, int count)

Parameters

weight 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(IBrush)

Sets foreground brush used for drawing text

public void SetForegroundBrush(IBrush foregroundBrush)

Parameters

foregroundBrush IBrush

Foreground brush

SetForegroundBrush(IBrush?, int, int)

Sets foreground brush used for drawing text

public void SetForegroundBrush(IBrush? foregroundBrush, int startIndex, int count)

Parameters

foregroundBrush 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(double[])

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(TextDecorationCollection)

Sets or changes the text decorations

public void SetTextDecorations(TextDecorationCollection textDecorations)

Parameters

textDecorations TextDecorationCollection

Text decorations

SetTextDecorations(TextDecorationCollection, int, int)

Sets or changes the text decorations

public void SetTextDecorations(TextDecorationCollection textDecorations, int startIndex, int count)

Parameters

textDecorations 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.