Struct FontFeature
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
TagFontTagThe feature tag, such as
liga,kernorss01.ValueuintThe value: 0 off, 1 on, 2 and up an alternate.
StartintThe first UTF-16 index the setting applies to.
EndintThe 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
IsGlobal
Gets whether the setting applies to the whole text.
public bool IsGlobal { get; }
Property Value
NoKerning
Gets the setting for kerning (kern) off.
public static FontFeature NoKerning { get; }
Property Value
SmallCaps
Gets the setting for small capitals (smcp).
public static FontFeature SmallCaps { get; }
Property Value
Start
The first UTF-16 index the setting applies to.
public int Start { get; init; }
Property Value
TabularFigures
Gets the setting for tabular figures (tnum): digits of one width, for columns.
public static FontFeature TabularFigures { get; }
Property Value
Tag
The feature tag, such as liga, kern or ss01.
public FontTag Tag { get; init; }
Property Value
Value
The value: 0 off, 1 on, 2 and up an alternate.
public uint Value { get; init; }
Property Value
Methods
Ligatures(bool)
Turns standard ligatures (liga) on or off.
public static FontFeature Ligatures(bool enabled)
Parameters
enabledboolWhether 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
textstringThe setting.
Returns
- FontFeature
The feature setting.
Exceptions
- ArgumentNullException
textis null.- FormatException
textis not a feature setting.
StylisticSet(int)
Turns on a stylistic set, ss01 to ss20.
public static FontFeature StylisticSet(int number)
Parameters
numberintThe set, 1 to 20.
Returns
- FontFeature
The setting.
Exceptions
- ArgumentOutOfRangeException
numberis 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
textstringThe setting.
featureFontFeatureThe feature setting, or the default value.