The Perl Advent Calendar needs more articles for 2022. Submit your idea today!


Font::TTF::OpenTypeLigatures - Transforms OpenType glyphs based on GSUB tables


Version 0.01


    use Font::TTF::OpenTypeLigatures;

    my $foo = Font::TTF::OpenTypeLigatures->new($fontfile, %options);
    @glyph_ids = $foo->substitute(@glyph_ids);


This module is a building block for fine typography systems implemented in Perl. It reads the GSUB table of OpenType fonts to transform glyphs based on selected OpenType features. The most common use of this is to implement ligatures, but OpenType supports a variety of features such as alternates, old-style numbers, non-Roman contextual substitutions and so on.



The constructor takes a font file path and a set of options. The options will determine which substitutions are performed. The default options will substitute ligatures in Latin-script texts. You may supply:


Four-letter code for the script in which your text is written. (See for a list of these.)


Three-letter language tag. If this is not given, or there are no special features for this language, the default language for the script is used.


This is a regular expression matching the features you want to support. The default is liga.

If there are any problems, the constructor will die with an error message.


This performs contextual substitution on a list of numeric glyph IDs, returning a substituted list.


    my $substitutor = $self->stream( \&output );
    for (@glyphids) { $substitutor->($_) }

This creates a stateful closure subroutine which acts as a glyph-by-glyph substitution stream. Once a substitution is processed, or no substitution is needed for the glyph ID stream, the closure calls the provided output subroutine.

This allows you to interpose the stream in between an input and output mechanism, and not worry about maintaining ligature substitution state yourself.

Passing -1 to the substitutor drains the stream.


Simon Cozens, <simon at>


Please report any bugs or feature requests to bug-font-ttf-opentypeligatures at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc Font::TTF::OpenTypeLigatures

You can also look for information at:



Copyright 2011 Simon Cozens.

This program is released under the following license: Perl