Class Strut
A minimum line box every line has, from a font and a line height (CSS's strut), or with Force the exact line box, for line grids in forms and columns.
public sealed record Strut : IEquatable<Strut>
- Inheritance
-
Strut
- 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
FontFamilies
Gets the families whose first match gives the strut's ascent and descent; the paragraph's default style's when unset.
public IReadOnlyList<FontFamily>? FontFamilies { get; init; }
Property Value
FontStyle
Gets the strut's font style.
public FontStyle? FontStyle { get; init; }
Property Value
Force
Gets whether every line box is exactly the strut's, whatever its text asks for.
public bool Force { get; init; }
Property Value
LineHeight
Gets the strut's line height.
public LineHeight LineHeight { get; init; }
Property Value
Size
Gets the strut's font size; the paragraph's default style's when unset.
public float? Size { get; init; }