Skip to main content

OpenType features

An OpenType font can have optional typographic features in its GSUB (glyph substitution) and GPOS (glyph positioning) tables. Each feature has a four-letter tag, such as smcp for small capitals.

Features that are always on​

The library applies the features that correct text needs, for every run of text:

TagFeature
rvrnRequired variation alternates
ltra, ltrm, rtla, rtlmLeft-to-right and right-to-left alternates and mirrored forms
ccmpGlyph composition and decomposition
loclLocalized forms
rligRequired ligatures
mark, mkmkMark positioning (accents)
caltContextual alternates
cligContextual ligatures
ligaStandard ligatures, such as fi and fl
rcltRequired contextual alternates
cursCursive positioning
kernKerning

In vertical text, vert replaces the horizontal-only features calt, clig, liga, rclt, curs and kern. The complex-script shapers add the features their scripts need, for example init, medi and fina for Arabic.

A feature has an effect only if the font has it. Most fonts have only some of them.

Turn on more features​

Add tags to TextOptions.FeatureTags. The FeatureTags enumeration names the registered features, and Tag.Parse makes a tag from its four letters:

using PinataLabs.Typography;
using PinataLabs.Typography.Tables.AdvancedTypographic;

TextOptions options = new(font)
{
FeatureTags =
[
FeatureTags.SmallCapitals, // smcp
FeatureTags.OldstyleFigures, // onum
Tag.Parse("ss01"), // Stylistic set 1
],
};

FeatureTags values convert to Tag without a cast. Use Tag.Parse for tags that the enumeration does not have, such as the stylistic sets ss01 to ss20 and the character variants cv01 to cv99.

The features apply to the whole text. To apply a feature to only part of the text, measure or render that part with its own TextOptions.

Some features that are often useful:

FeatureTags valueTagEffect
SmallCapitalssmcpLower-case letters as small capitals.
SmallCapitalsFromCapitalsc2scCapital letters as small capitals.
OldstyleFiguresonumFigures that rise and fall like lower-case letters.
LiningFigureslnumFigures that are all the height of capitals.
TabularFigurestnumFigures that are all the same width, for tables of numbers.
ProportionalFigurespnumFigures with their natural widths.
SlashedZerozeroA zero with a slash, to tell it from the letter O.
FractionsfracFractions such as 1/2 set as one fraction glyph or a built-up fraction.
OrdinalsordnOrdinal forms, such as the o in 1º.
DiscretionaryLigaturesdligDecorative ligatures, such as ct and st.
HistoricalLigatureshligHistorical ligatures.
SwashswshSwash forms.
CaseSensitiveFormscasePunctuation moved up to fit capital letters.

The full list of registered tags is in the OpenType feature registry.

Fractions​

When you turn on frac, the library finds the digits on each side of a slash (/) or a fraction slash (U+2044). It applies the numerator (numr) feature to the digits before the slash and the denominator (dnom) feature to the digits after it. Other digits are not changed.

options.FeatureTags = [FeatureTags.Fractions];
TextMeasurer.MeasureSize("Add 3/4 cup of flour", options);

You cannot turn off a feature that is always on​

FeatureTags only adds features. There is no way to turn off a feature from the table at the top of this page, such as liga. Kerning is the exception: use KerningMode.

Kerning​

Kerning adjusts the space between pairs of glyphs, for example to move A and V closer together. The library uses the GPOS kern feature. If the font has no GPOS kerning, the library uses the older kern table.

KerningModeEffect
Standard (default)Apply kerning from the font.
AutoApply kerning when the layout engine chooses. At present this has the same effect as Standard.
NoneDo not apply kerning.
options.KerningMode = KerningMode.None;