Class TextLine
One line of a laid-out paragraph: the text it holds, its line box and its runs in visual order. Coordinates are the layout box's, or for a line from a LineFlow, the line's own box with its top at 0.
public sealed class TextLine
- Inheritance
-
TextLine
- Inherited Members
Examples
ParagraphStyle style = new() { DefaultStyle = new TextStyle { FontFamilies = [family], Size = 16 } };
Paragraph paragraph = Paragraph.Create("A paragraph is shaped once and laid out at any width.", style);
// Each width gives an immutable layout: lines of glyph runs, positioned from the box's top-left corner.
TextLayout narrow = paragraph.Layout(120);
TextLayout wide = paragraph.Layout(400);
foreach (TextLine line in narrow.Lines)
{
string text = paragraph.Text[line.Start..line.End]; // the line's text, its trailing space included
float baseline = line.Baseline; // y of the baseline
foreach (LayoutRun run in line.Runs)
{
GlyphRun? glyphs = run.Glyphs; // glyphs at their layout positions
}
}
// No wrapping: the box is as wide as the longest line.
TextLayout unbounded = paragraph.Layout(float.PositiveInfinity);
Properties
Ascent
Gets the distance from the line box's top to the baseline.
public float Ascent { get; }
Property Value
Baseline
Gets the baseline's y.
public float Baseline { get; }
Property Value
Bottom
Gets the bottom of the line box.
public float Bottom { get; }
Property Value
Descent
Gets the distance from the baseline to the line box's bottom.
public float Descent { get; }
Property Value
Ellipsized
Gets whether the line ends with an ellipsis for text cut by a line limit.
public bool Ellipsized { get; }
Property Value
End
Gets the index just past the line's last character.
public int End { get; }
Property Value
HardBreak
Gets whether the line ends at a hard break (a newline or another mandatory break).
public bool HardBreak { get; }
Property Value
Height
Gets the line box's height.
public float Height { get; }
Property Value
Left
Gets the x where the line's content starts on the left, hanging spaces aside.
public float Left { get; }
Property Value
Length
Gets the number of UTF-16 units on the line, its trailing spaces and hard break included.
public int Length { get; }
Property Value
Runs
Gets the runs in visual order, left to right.
public IReadOnlyList<LayoutRun> Runs { get; }
Property Value
Start
Gets the UTF-16 index of the line's first character.
public int Start { get; }
Property Value
Top
Gets the top of the line box; in vertical layouts, its left edge.
public float Top { get; }
Property Value
Width
Gets the width of the line's content, without hanging trailing spaces.
public float Width { get; }