Table of Contents

Struct LineBreakOptions

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

How text may break into lines, as CSS Text 3 sets it: word-break, overflow-wrap, line-break and the content language. The default is CSS's default: Unicode's line breaking algorithm (UAX #14) with breaks before small kana, as browsers break.

public readonly record struct LineBreakOptions : IEquatable<LineBreakOptions>
Implements
Inherited Members

Examples

// Where lines may end: after spaces and hyphens, and always at the end; a line must end after a newline.
List<int> breaks = [];
foreach (LineBreak b in LineBreaks.Enumerate("A well-known fact.\nNext"))
{
    breaks.Add(b.Index);                       // 2, 7, 13, 19 (mandatory), 23
}

// CSS switches: break-all lets letters break like ideographs.
LineBreakOptions breakAll = new(WordBreak: WordBreak.BreakAll);
int count = 0;
foreach (LineBreak b in LineBreaks.Enumerate("word", breakAll))
{
    count++;                                   // 4: after every letter
}

Constructors

LineBreakOptions(WordBreak, OverflowWrap, LineBreakStrictness, string?)

How text may break into lines, as CSS Text 3 sets it: word-break, overflow-wrap, line-break and the content language. The default is CSS's default: Unicode's line breaking algorithm (UAX #14) with breaks before small kana, as browsers break.

public LineBreakOptions(WordBreak WordBreak = WordBreak.Normal, OverflowWrap OverflowWrap = OverflowWrap.Normal, LineBreakStrictness Strictness = LineBreakStrictness.Auto, string? Language = null)

Parameters

WordBreak WordBreak

Whether letters break like ideographs (BreakAll) or ideographs keep together like words (KeepAll).

OverflowWrap OverflowWrap

Whether a piece too wide for its line may break between any two grapheme clusters; line filling uses it, Enumerate(ReadOnlySpan<char>, LineBreakOptions) does not.

Strictness LineBreakStrictness

How strictly Chinese and Japanese punctuation, small kana and iteration marks keep with their neighbours, or Anywhere to break between any two grapheme clusters.

Language string

The BCP 47 language of the text, such as ja; Chinese and Japanese turn on CSS's language-specific strictness rules.

Examples

// Where lines may end: after spaces and hyphens, and always at the end; a line must end after a newline.
List<int> breaks = [];
foreach (LineBreak b in LineBreaks.Enumerate("A well-known fact.\nNext"))
{
    breaks.Add(b.Index);                       // 2, 7, 13, 19 (mandatory), 23
}

// CSS switches: break-all lets letters break like ideographs.
LineBreakOptions breakAll = new(WordBreak: WordBreak.BreakAll);
int count = 0;
foreach (LineBreak b in LineBreaks.Enumerate("word", breakAll))
{
    count++;                                   // 4: after every letter
}

Properties

Language

The BCP 47 language of the text, such as ja; Chinese and Japanese turn on CSS's language-specific strictness rules.

public string? Language { get; init; }

Property Value

string

OverflowWrap

Whether a piece too wide for its line may break between any two grapheme clusters; line filling uses it, Enumerate(ReadOnlySpan<char>, LineBreakOptions) does not.

public OverflowWrap OverflowWrap { get; init; }

Property Value

OverflowWrap

Strictness

How strictly Chinese and Japanese punctuation, small kana and iteration marks keep with their neighbours, or Anywhere to break between any two grapheme clusters.

public LineBreakStrictness Strictness { get; init; }

Property Value

LineBreakStrictness

WordBreak

Whether letters break like ideographs (BreakAll) or ideographs keep together like words (KeepAll).

public WordBreak WordBreak { get; init; }

Property Value

WordBreak