Struct LineHeight
The height a run asks of its line box (CSS line-height): Normal from the font's metrics, a
Multiple(float) of the font size or an Absolute(float) height. The extra over the font's ascent and descent is
split half above and half below.
public readonly record struct LineHeight : IEquatable<LineHeight>
- 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
Kind
Gets how the height is given.
public LineHeightKind Kind { get; }
Property Value
Normal
Gets the font's own line height: its ascent, descent and line gap.
public static LineHeight Normal { get; }
Property Value
Value
Gets the multiple of the font size, or the height in canvas units; 0 for Normal.
public float Value { get; }
Property Value
Methods
Absolute(float)
A height in canvas units.
public static LineHeight Absolute(float height)
Parameters
heightfloatThe height, 0 or more.
Returns
- LineHeight
The line height.
Exceptions
- ArgumentOutOfRangeException
heightis negative or not finite.
Multiple(float)
A height that is a multiple of the font size, as CSS's unitless line-height.
public static LineHeight Multiple(float factor)
Parameters
factorfloatThe multiple, 0 or more.
Returns
- LineHeight
The line height.
Exceptions
- ArgumentOutOfRangeException
factoris negative or not finite.