Table of Contents

Class ShapingOptions

Namespace
Egami.Fonts.Shaping
Assembly
Egami.Fonts.dll

How Shape(string, Font, ShapingOptions?) shapes text: the paragraph direction, the language, script and features of the whole text, the fonts that take characters the font lacks, the cluster level, and styled spans.

public sealed record ShapingOptions : IEquatable<ShapingOptions>
Inheritance
ShapingOptions
Implements
Inherited Members

Examples

// Whole text: lines at hard breaks, bidi levels, script runs, fallback fonts, runs in display order.
var font = new Font(face, 24);
var options = new ShapingOptions { Fallback = new FontFallback(fonts.Families) };
ShapedText shaped = TextShaper.Shape("Shalom: \u05E9\u05DC\u05D5\u05DD!", font, options);

float x = 0;
foreach (ShapedRun run in shaped.Lines[0].Runs)
{
    GlyphRun glyphs = run.ToGlyphRun(new System.Numerics.Vector2(x, 0), shaped.Text); // what a canvas draws
    x += run.Advance;
}

Properties

ClusterLevel

Gets how characters group into clusters.

public ClusterLevel ClusterLevel { get; init; }

Property Value

ClusterLevel

Default

Gets the default options: direction from the text, no language, the script from the text, the font's default features, no fallback beyond the font, monotone grapheme clusters.

public static ShapingOptions Default { get; }

Property Value

ShapingOptions

Direction

Gets the paragraph direction; Auto takes it from the first strong character of each paragraph, and TopToBottom shapes each line as one vertical column.

public TextDirection Direction { get; init; }

Property Value

TextDirection

Fallback

Gets where characters the font does not map go: None (the default) keeps them in the font, as .notdef.

public FontFallback Fallback { get; init; }

Property Value

FontFallback

Features

Gets the feature settings applied to the whole text, in order; a span's features follow them.

public IReadOnlyList<FontFeature>? Features { get; init; }

Property Value

IReadOnlyList<FontFeature>

Language

Gets the BCP 47 language tag of the text, such as ur or sr-Latn, or null for the fonts' default forms (never the machine's culture).

public string? Language { get; init; }

Property Value

string

ProduceSafeToInsertTatweel

Gets whether glyphs say where a tatweel can lengthen a word (SafeToInsertTatweel), as HarfBuzz's HB_BUFFER_FLAG_PRODUCE_SAFE_TO_INSERT_TATWEEL.

public bool ProduceSafeToInsertTatweel { get; init; }

Property Value

bool

Script

Gets the script every run is shaped as, or null to itemize the text into script runs.

public Script? Script { get; init; }

Property Value

Script?

Spans

Gets styled ranges of the text, each overriding the font, language or features for its range; they must not overlap.

public IReadOnlyList<TextSpan>? Spans { get; init; }

Property Value

IReadOnlyList<TextSpan>