Table of Contents

Struct Placeholder

Namespace
Egami.Fonts.Layout
Assembly
Egami.Fonts.dll

An inline box laid out with the text, such as an icon or an image, which the caller draws: it stands for an object replacement character (U+FFFC) in the text, so bidi, line breaking and indexes treat it as one character.

public readonly record struct Placeholder : IEquatable<Placeholder>
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);

Constructors

Placeholder(float, float, PlaceholderAlignment, float)

An inline box laid out with the text, such as an icon or an image, which the caller draws: it stands for an object replacement character (U+FFFC) in the text, so bidi, line breaking and indexes treat it as one character.

public Placeholder(float Width, float Height, PlaceholderAlignment Alignment = PlaceholderAlignment.Baseline, float BaselineOffset = 0)

Parameters

Width float

The box's width in canvas units.

Height float

The box's height in canvas units.

Alignment PlaceholderAlignment

How the box sits on its line.

BaselineOffset float

For Baseline, the distance from the box's top to the point that sits on the text's baseline.

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

Alignment

How the box sits on its line.

public PlaceholderAlignment Alignment { get; init; }

Property Value

PlaceholderAlignment

BaselineOffset

For Baseline, the distance from the box's top to the point that sits on the text's baseline.

public float BaselineOffset { get; init; }

Property Value

float

Height

The box's height in canvas units.

public float Height { get; init; }

Property Value

float

Width

The box's width in canvas units.

public float Width { get; init; }

Property Value

float