Skip to content

FreeType » Docs » Extended API » Unicode Variation Sequences

# Unicode Variation Sequences

## Synopsis

Many characters, especially for CJK scripts, have variant forms. They are a sort of grey area somewhere between being totally irrelevant and semantically distinct; for this reason, the Unicode consortium decided to introduce Variation Sequences (VS), consisting of a Unicode base character and a variation selector instead of further extending the already huge number of characters.

Unicode maintains two different sets, namely ‘Standardized Variation Sequences’ and registered ‘Ideographic Variation Sequences’ (IVS), collected in the ‘Ideographic Variation Database’ (IVD).

https://unicode.org/Public/UCD/latest/ucd/StandardizedVariants.txt https://unicode.org/reports/tr37/ https://unicode.org/ivd/

To date (January 2017), the character with the most ideographic variations is U+9089, having 32 such IVS.

Three Mongolian Variation Selectors have the values U+180B-U+180D; 256 generic Variation Selectors are encoded in the ranges U+FE00-U+FE0F and U+E0100-U+E01EF. IVS currently use Variation Selectors from the range U+E0100-U+E01EF only.

A VS consists of the base character value followed by a single Variation Selector. For example, to get the first variation of U+9089, you have to write the character sequence `U+9089 U+E0100`.

Adobe and MS decided to support both standardized and ideographic VS with a new cmap subtable (format 14). It is an odd subtable because it is not a mapping of input code points to glyphs, but contains lists of all variations supported by the font.

A variation may be either ‘default’ or ‘non-default’ for a given font. A default variation is the one you will get for that code point if you look it up in the standard Unicode cmap. A non-default variation is a different glyph.

## FT_Face_GetCharVariantIndex

Defined in FT_FREETYPE_H (freetype/freetype.h).

      FT_EXPORT( FT_UInt )
      FT_Face_GetCharVariantIndex( FT_Face   face,
                                   FT_ULong  charcode,
                                   FT_ULong  variantSelector );

Return the glyph index of a given character code as modified by the variation selector.

#### input

face | A handle to the source face object.
charcode | The character code point in Unicode.
variantSelector | The Unicode code point of the variation selector.

#### return

The glyph index. 0 means either ‘undefined character code’, or ‘undefined selector code’, or ‘no variation selector cmap subtable’, or ‘current CharMap is not Unicode’.

#### note

If you use FreeType to manipulate the contents of font files directly, be aware that the glyph index returned by this function doesn't always correspond to the internal indices used within the file. This is done to ensure that value 0 always corresponds to the ‘missing glyph’.

This function is only meaningful if a) the font has a variation selector cmap sub table, and b) the current charmap has a Unicode encoding.

#### since

2.3.6

## FT_Face_GetCharVariantIsDefault

Defined in FT_FREETYPE_H (freetype/freetype.h).

      FT_EXPORT( FT_Int )
      FT_Face_GetCharVariantIsDefault( FT_Face   face,
                                       FT_ULong  charcode,
                                       FT_ULong  variantSelector );

Check whether this variation of this Unicode character is the one to be found in the charmap.

#### input

face | A handle to the source face object.
charcode | The character codepoint in Unicode.
variantSelector | The Unicode codepoint of the variation selector.

#### return

1 if found in the standard (Unicode) cmap, 0 if found in the variation selector cmap, or -1 if it is not a variation.

#### note

This function is only meaningful if the font has a variation selector cmap subtable.

#### since

2.3.6

## FT_Face_GetVariantSelectors

Defined in FT_FREETYPE_H (freetype/freetype.h).

      FT_EXPORT( FT_UInt32* )
      FT_Face_GetVariantSelectors( FT_Face  face );

Return a zero-terminated list of Unicode variation selectors found in the font.

#### input

face | A handle to the source face object.

#### return

A pointer to an array of selector code points, or `NULL` if there is no valid variation selector cmap subtable.

#### note

The last item in the array is 0; the array is owned by the `FT_Face` object but can be overwritten or released on the next call to a FreeType function.

#### since

2.3.6

## FT_Face_GetVariantsOfChar

Defined in FT_FREETYPE_H (freetype/freetype.h).

      FT_EXPORT( FT_UInt32* )
      FT_Face_GetVariantsOfChar( FT_Face   face,
                                 FT_ULong  charcode );

Return a zero-terminated list of Unicode variation selectors found for the specified character code.

#### input

face | A handle to the source face object.
charcode | The character codepoint in Unicode.

#### return

A pointer to an array of variation selector code points that are active for the given character, or `NULL` if the corresponding list is empty.

#### note

The last item in the array is 0; the array is owned by the `FT_Face` object but can be overwritten or released on the next call to a FreeType function.

#### since

2.3.6

## FT_Face_GetCharsOfVariant

Defined in FT_FREETYPE_H (freetype/freetype.h).

      FT_EXPORT( FT_UInt32* )
      FT_Face_GetCharsOfVariant( FT_Face   face,
                                 FT_ULong  variantSelector );

Return a zero-terminated list of Unicode character codes found for the specified variation selector.

#### input

face | A handle to the source face object.
variantSelector | The variation selector code point in Unicode.

#### return

A list of all the code points that are specified by this selector (both default and non-default codes are returned) or `NULL` if there is no valid cmap or the variation selector is invalid.

#### note

The last item in the array is 0; the array is owned by the `FT_Face` object but can be overwritten or released on the next call to a FreeType function.

#### since

2.3.6