Class TextStyle
How a stretch of text looks. Every field is optional: an unset field takes the enclosing builder style's, then the paragraph's DefaultStyle, then Egami's default (16 pixels, black, normal line height, no decoration). Fields that change shaping (fonts, size, style, variations, language, features, letter spacing) split a paragraph into separately shaped runs; the others (colors, paints, background, decoration, shadows) never do, so a color change inside a ligature keeps the ligature.
public sealed record TextStyle : IEquatable<TextStyle>
- Inheritance
-
TextStyle
- 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
Background
Gets the color behind the text, filling each run's line box height.
public Rgba8? Background { get; init; }
Property Value
BackgroundPaint
Gets the paint behind the text; overrides Background.
public ITextPaint? BackgroundPaint { get; init; }
Property Value
BaselineShift
Gets how far the text moves down from the baseline, in canvas units (negative raises it, for superscripts).
public float? BaselineShift { get; init; }
Property Value
Color
Gets the text color, used where Paint is not set. Egami's default is opaque black.
public Rgba8? Color { get; init; }
Property Value
Decoration
Gets the underline, overline or line-through.
public TextDecoration? Decoration { get; init; }
Property Value
Features
Gets the OpenType features to turn on or off, added to the paragraph's.
public IReadOnlyList<FontFeature>? Features { get; init; }
Property Value
FontFamilies
Gets the font families in order of preference; later ones and the paragraph's fallback cover characters the first does not have.
public IReadOnlyList<FontFamily>? FontFamilies { get; init; }
Property Value
FontStyle
Gets the weight, width and slant the families are matched against.
public FontStyle? FontStyle { get; init; }
Property Value
Language
Gets the BCP 47 language of the text, which picks OpenType language systems and line breaking rules.
public string? Language { get; init; }
Property Value
LetterSpacing
Gets the space added after each grapheme cluster, in canvas units (negative tightens). Non-zero spacing turns off optional ligatures, and cursive scripts such as Arabic get none, as CSS.
public float? LetterSpacing { get; init; }
Property Value
LineHeight
Gets the height of the line box this text asks for.
public LineHeight? LineHeight { get; init; }
Property Value
Paint
Gets the paint the text is drawn with, such as an Egami.Drawing gradient; overrides Color.
public ITextPaint? Paint { get; init; }
Property Value
Shadows
Gets the shadows, drawn in order under the text, as CSS's text-shadow list.
public IReadOnlyList<TextShadow>? Shadows { get; init; }
Property Value
Size
Gets the font size in canvas units (pixels when drawn at scale 1).
public float? Size { get; init; }
Property Value
Variations
Gets the variation axis settings for variable fonts.
public IReadOnlyList<FontVariation>? Variations { get; init; }
Property Value
WordSpacing
Gets the space added to each word separator, in canvas units.
public float? WordSpacing { get; init; }