Class ParagraphStyle
How a paragraph is laid out: its default text style, direction, alignment, line breaking, line filling, hyphens, ellipsis and line limits, line box rules, tabs and writing mode. The defaults follow CSS: start-aligned, greedy filling, normal line height, tab stops every 8 spaces, horizontal lines.
public sealed record ParagraphStyle : IEquatable<ParagraphStyle>
- Inheritance
-
ParagraphStyle
- Implements
- Inherited Members
Examples
// Font families come from a collection; later families cover what the first lacks.
FontCollection fonts = new();
fonts.AddFile(System.IO.Path.Combine(folder, "NotoSans-Regular.ttf"));
fonts.AddFile(System.IO.Path.Combine(folder, "NotoSansArabic-Regular.ttf"));
fonts.TryGetFamily("Noto Sans", out FontFamily latin);
fonts.TryGetFamily("Noto Sans Arabic", out FontFamily arabic);
// Styles nest: the inner span keeps the outer one's size and adds a color and an underline.
RichText text = new RichTextBuilder()
.Append("Peace is ")
.Push(new TextStyle { Size = 20 })
.Append("\u0633\u0644\u0627\u0645 ")
.Push(new TextStyle { Color = new Rgba8(200, 30, 30, 255), Decoration = new TextDecoration() })
.Append("in Arabic")
.Pop()
.Pop()
.AddPlaceholder(new Placeholder(16, 16, PlaceholderAlignment.Middle))
.ToRichText();
ParagraphStyle style = new()
{
DefaultStyle = new TextStyle { FontFamilies = [latin, arabic], Size = 16, LineHeight = LineHeight.Multiple(1.4f) },
Align = TextAlign.Justify,
LineBreaking = new LineBreakOptions(WordBreak: WordBreak.Normal),
};
// Shaped once: lay it out at any width later.
Paragraph paragraph = Paragraph.Create(text, style);
Properties
Align
Gets how lines align in the layout width.
public TextAlign Align { get; init; }
Property Value
AlignLast
Gets how the last line, and lines before a hard break, align.
public TextAlignLast AlignLast { get; init; }
Property Value
Default
Gets the default paragraph style.
public static ParagraphStyle Default { get; }
Property Value
DefaultStyle
Gets the text style spans inherit unset fields from; its FontFamilies must be set when a span's are not.
public TextStyle DefaultStyle { get; init; }
Property Value
Direction
Gets the paragraph direction; Auto takes each paragraph's from its first strong character (UAX #9 rules P2 and P3).
public TextDirection Direction { get; init; }
Property Value
Ellipsis
Gets the text that ends the last line when MaxLines or MaxHeight cuts text: U+2026, a custom string, or null to cut without one.
public string? Ellipsis { get; init; }
Property Value
Fallback
Gets the families and resolver tried after a style's own families.
public FontFallback Fallback { get; init; }
Property Value
Hyphen
Gets the text drawn where a line ends at a soft hyphen: U+2010 (U+002D when the font has none), a custom string, or null for none.
public string? Hyphen { get; init; }
Property Value
Justify
Gets how justified lines stretch.
public TextJustify Justify { get; init; }
Property Value
Kashida
Gets how far Kashida lengthens words before word spaces take the rest.
public KashidaLevel Kashida { get; init; }
Property Value
LineBreaking
Gets where lines may break.
public LineBreakOptions LineBreaking { get; init; }
Property Value
LineFill
Gets how lines are filled.
public LineFill LineFill { get; init; }
Property Value
MaxHeight
Gets the height the lines must fit in, in canvas units, or null for no limit.
public float? MaxHeight { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is negative or not a number.
MaxLines
Gets the most lines laid out, or null for no limit.
public int? MaxLines { get; init; }
Property Value
- int?
Exceptions
- ArgumentOutOfRangeException
The value is less than 1.
Strut
Gets the minimum (or, with Force, exact) line box every line has.
public Strut? Strut { get; init; }
Property Value
TabSize
Gets the distance between default tab stops, in spaces of the default font.
public float TabSize { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is negative or not finite.
TabStops
Gets explicit tab stops; past the last one, tabs fall back to TabSize.
public IReadOnlyList<TabStop>? TabStops { get; init; }
Property Value
TextOrientation
Gets how characters stand in vertical lines.
public TextOrientation TextOrientation { get; init; }
Property Value
TrimEdges
Gets whether the first line's space above its ascent and the last line's below its descent are dropped
(CSS text-box-trim).
public bool TrimEdges { get; init; }
Property Value
WritingMode
Gets whether lines run horizontally or vertically.
public WritingMode WritingMode { get; init; }