Table of Contents

Struct FontFeature

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

An OpenType feature setting: a feature tag, a value and the range of UTF-16 units it applies to, in HarfBuzz's model. A value of 0 turns a feature off (such as default ligatures), 1 turns it on, and higher values pick an alternate.

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

Examples

// HarfBuzz's feature syntax, or the presets.
FontFeature noLigatures = FontFeature.Parse("liga=0");
FontFeature figures = FontFeature.TabularFigures;
FontFeature alternates = FontFeature.StylisticSet(1);
FontFeature someKerning = FontFeature.Parse("kern[0:3]=0"); // off for the first three characters only

var properties = new RunProperties { Features = [noLigatures, figures] };
TextShaper.ShapeRun(text, 0, text.Length, font, properties, glyphs);

Constructors

FontFeature(FontTag, uint, int, int)

An OpenType feature setting: a feature tag, a value and the range of UTF-16 units it applies to, in HarfBuzz's model. A value of 0 turns a feature off (such as default ligatures), 1 turns it on, and higher values pick an alternate.

public FontFeature(FontTag Tag, uint Value = 1, int Start = 0, int End = 2147483647)

Parameters

Tag FontTag

The feature tag, such as liga, kern or ss01.

Value uint

The value: 0 off, 1 on, 2 and up an alternate.

Start int

The first UTF-16 index the setting applies to.

End int

The index just past the last one it applies to; MaxValue for the end of the text.

Examples

// HarfBuzz's feature syntax, or the presets.
FontFeature noLigatures = FontFeature.Parse("liga=0");
FontFeature figures = FontFeature.TabularFigures;
FontFeature alternates = FontFeature.StylisticSet(1);
FontFeature someKerning = FontFeature.Parse("kern[0:3]=0"); // off for the first three characters only

var properties = new RunProperties { Features = [noLigatures, figures] };
TextShaper.ShapeRun(text, 0, text.Length, font, properties, glyphs);

Properties

End

The index just past the last one it applies to; MaxValue for the end of the text.

public int End { get; init; }

Property Value

int

IsGlobal

Gets whether the setting applies to the whole text.

public bool IsGlobal { get; }

Property Value

bool

NoKerning

Gets the setting for kerning (kern) off.

public static FontFeature NoKerning { get; }

Property Value

FontFeature

SmallCaps

Gets the setting for small capitals (smcp).

public static FontFeature SmallCaps { get; }

Property Value

FontFeature

Start

The first UTF-16 index the setting applies to.

public int Start { get; init; }

Property Value

int

TabularFigures

Gets the setting for tabular figures (tnum): digits of one width, for columns.

public static FontFeature TabularFigures { get; }

Property Value

FontFeature

Tag

The feature tag, such as liga, kern or ss01.

public FontTag Tag { get; init; }

Property Value

FontTag

Value

The value: 0 off, 1 on, 2 and up an alternate.

public uint Value { get; init; }

Property Value

uint

Methods

Ligatures(bool)

Turns standard ligatures (liga) on or off.

public static FontFeature Ligatures(bool enabled)

Parameters

enabled bool

Whether ligatures are formed.

Returns

FontFeature

The setting.

Parse(string)

Parses HarfBuzz's feature syntax: kern, +kern, -liga, aalt=2, ss01=on, kern[3:5]=0.

public static FontFeature Parse(string text)

Parameters

text string

The setting.

Returns

FontFeature

The feature setting.

Exceptions

ArgumentNullException

text is null.

FormatException

text is not a feature setting.

StylisticSet(int)

Turns on a stylistic set, ss01 to ss20.

public static FontFeature StylisticSet(int number)

Parameters

number int

The set, 1 to 20.

Returns

FontFeature

The setting.

Exceptions

ArgumentOutOfRangeException

number is outside 1 to 20.

ToString()

Returns the setting in HarfBuzz's syntax, such as liga=0 or kern[3:5]=0.

public override string ToString()

Returns

string

The text.

TryParse(string?, out FontFeature)

Parses HarfBuzz's feature syntax, returning false instead of throwing.

public static bool TryParse(string? text, out FontFeature feature)

Parameters

text string

The setting.

feature FontFeature

The feature setting, or the default value.

Returns

bool

true when text is a feature setting.