<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package Font::TTF::OldMort;

=head1 NAME

Font::TTF::OldMort - Glyph Metamorphosis table in a font

=head1 DESCRIPTION

=head1 INSTANCE VARIABLES

=item version

table version number (Fixed: currently 1.0)

=item chains

list of metamorphosis chains, each of which has its own fields:

=over

=item defaultFlags

chain's default subfeature flags (UInt32)

=item featureEntries

list of feature entries, each of which has fields:

=over

=item type

=item setting

=item enable

=item disable

=back

=item subtables

list of metamorphosis subtables, each of which has fields:

=over

=item type

subtable type (0: rearrangement; 1: contextual substitution; 2: ligature;
4: non-contextual substitution; 5: insertion)

=item direction

processing direction ('LR' or 'RL')

=item orientation

applies to text in which orientation ('VH', 'V', or 'H')

=item subFeatureFlags

the subfeature flags controlling whether the table is used (UInt32)

=back

Further fields depend on the type of subtable:

=over

Rearrangement table:

=over

=item classes

array of lists of glyphs

=item states

array of arrays of hashes{'nextState', 'flags'}

=back

Contextual substitution table:

=over

=item classes

array of lists of glyphs

=item states

array of array of hashes{'nextState', 'flags', 'actions'}, where C&lt;actions&gt;
is an array of two elements which are offsets to be added to [marked, current]
glyph to get index into C&lt;mappings&gt; (or C&lt;undef&gt; if no mapping to be applied)

=item mappings

list of glyph codes mapped to through the state table mappings

=back

Ligature table:

Non-contextual substitution table:

Insertion table:

=back

=back

=head1 METHODS

=cut

use strict;
use vars qw(@ISA);
use Font::TTF::Utils;
use Font::TTF::AATutils;
use IO::File;

@ISA = qw(Font::TTF::Table);

=head2 $t-&gt;read

Reads the table into memory

=cut

sub read
{
    my ($self) = @_;
    my ($dat, $fh, $numChains);
    
    $self-&gt;SUPER::read or return $self;

    $fh = $self-&gt;{' INFILE'};

    $fh-&gt;read($dat, 8);
    ($self-&gt;{'version'}, $numChains) = TTF_Unpack("fL", $dat);
    
    my $chains = [];
    foreach (1 .. $numChains) {
        my $chainStart = $fh-&gt;tell();
        $fh-&gt;read($dat, 12);
        my ($defaultFlags, $chainLength, $nFeatureEntries, $nSubtables) = TTF_Unpack("LLSS", $dat);
        my $featureEntries = [];
        foreach (1 .. $nFeatureEntries) {
            $fh-&gt;read($dat, 12);
            my ($featureType, $featureSetting, $enableFlags, $disableFlags) = TTF_Unpack("SSLL", $dat);
            push @$featureEntries,    {
                                        'type'        =&gt; $featureType,
                                        'setting'    =&gt; $featureSetting,
                                        'enable'    =&gt; $enableFlags,
                                        'disable'    =&gt; $disableFlags
                                    };
        }
        my $subtables = [];
        foreach (1 .. $nSubtables) {
            my $subtableStart = $fh-&gt;tell();
            $fh-&gt;read($dat, 8);
            my ($length, $coverage, $subFeatureFlags) = TTF_Unpack("SSL", $dat);
            my $type = $coverage &amp; 0x0007;

            my $subtable =    {
                                'type'                =&gt; $type,
                                'direction'            =&gt; (($coverage &amp; 0x4000) ? 'RL' : 'LR'),
                                'orientation'        =&gt; (($coverage &amp; 0x2000) ? 'VH' : ($coverage &amp; 0x8000) ? 'V' : 'H'),
                                'subFeatureFlags'    =&gt; $subFeatureFlags
                            };

            if ($type == 0) {    # rearrangement
                my ($classes, $states) = AAT_read_state_table($fh, 0);
                $subtable-&gt;{'classes'} = $classes;
                $subtable-&gt;{'states'} = $states;
            }

            elsif ($type == 1) {    # contextual
                my $stateTableStart = $fh-&gt;tell();
                my ($classes, $states, $entries) = AAT_read_state_table($fh, 2);

                $fh-&gt;seek($stateTableStart, IO::File::SEEK_SET);
                $fh-&gt;read($dat, 10);
                my ($stateSize, $classTable, $stateArray, $entryTable, $mappingTables) = unpack("nnnnn", $dat);
                my $limits = [$classTable, $stateArray, $entryTable, $mappingTables, $length - 8];

                foreach (@$entries) {
                    my $actions = $_-&gt;{'actions'};
                    foreach (@$actions) {
                        $_ = $_ ? $_ - ($mappingTables / 2) : undef;
                    }
                }
                
                $subtable-&gt;{'classes'} = $classes;
                $subtable-&gt;{'states'} = $states;
                $subtable-&gt;{'mappings'} = [unpack("n*", AAT_read_subtable($fh, $stateTableStart, $mappingTables, $limits))];
            }

            elsif ($type == 2) {    # ligature
                my $stateTableStart = $fh-&gt;tell();
                my ($classes, $states, $entries) = AAT_read_state_table($fh, 0);
                
                $fh-&gt;seek($stateTableStart, IO::File::SEEK_SET);
                $fh-&gt;read($dat, 14);
                my ($stateSize, $classTable, $stateArray, $entryTable,
                    $ligActionTable, $componentTable, $ligatureTable) = unpack("nnnnnnn", $dat);
                my $limits = [$classTable, $stateArray, $entryTable, $ligActionTable, $componentTable, $ligatureTable, $length - 8];
                
                my %actions;
                my $actionLists;
                foreach (@$entries) {
                    my $offset = $_-&gt;{'flags'} &amp; 0x3fff;
                    $_-&gt;{'flags'} &amp;= ~0x3fff;
                    if ($offset != 0) {
                        if (not defined $actions{$offset}) {
                            $fh-&gt;seek($stateTableStart + $offset, IO::File::SEEK_SET);
                            my $actionList;
                            while (1) {
                                $fh-&gt;read($dat, 4);
                                my $action = unpack("N", $dat);
                                my ($last, $store, $component) = (($action &amp; 0x80000000) != 0, ($action &amp; 0xC0000000) != 0, ($action &amp; 0x3fffffff));
                                $component -= 0x40000000 if $component &gt; 0x1fffffff;
                                $component -= $componentTable / 2;
                                push @$actionList, { 'store' =&gt; $store, 'component' =&gt; $component };
                                last if $last;
                            }
                            push @$actionLists, $actionList;
                            $actions{$offset} = $#$actionLists;
                        }
                        $_-&gt;{'actions'} = $actions{$offset};
                    }
                }
                
                $subtable-&gt;{'componentTable'} = $componentTable;
                my $components = [unpack("n*", AAT_read_subtable($fh, $stateTableStart, $componentTable, $limits))];
                foreach (@$components) {
                    $_ = ($_ - $ligatureTable) . " +" if $_ &gt;= $ligatureTable;
                }
                $subtable-&gt;{'components'} = $components;
                
                $subtable-&gt;{'ligatureTable'} = $ligatureTable;
                $subtable-&gt;{'ligatures'} = [unpack("n*", AAT_read_subtable($fh, $stateTableStart, $ligatureTable, $limits))];
                
                $subtable-&gt;{'classes'} = $classes;
                $subtable-&gt;{'states'} = $states;
                $subtable-&gt;{'actionLists'} = $actionLists;
            }

            elsif ($type == 4) {    # non-contextual
                my ($format, $lookup) = AAT_read_lookup($fh, 2, $length - 8, undef);
                $subtable-&gt;{'format'} = $format;
                $subtable-&gt;{'lookup'} = $lookup;
            }

            elsif ($type == 5) {    # insertion
                my $stateTableStart = $fh-&gt;tell();
                my ($classes, $states, $entries) = AAT_read_state_table($fh, 2);
                
                my %insertListHash;
                my $insertLists;
                foreach (@$entries) {
                    my $flags = $_-&gt;{'flags'};
                    my @insertCount = (($flags &amp; 0x03e0) &gt;&gt; 5, ($flags &amp; 0x001f));
                    my $actions = $_-&gt;{'actions'};
                    foreach (0 .. 1) {
                        if ($insertCount[$_] &gt; 0) {
                            $fh-&gt;seek($stateTableStart + $actions-&gt;[$_], IO::File::SEEK_SET);
                            $fh-&gt;read($dat, $insertCount[$_] * 2);
                            if (not defined $insertListHash{$dat}) {
                                push @$insertLists, [unpack("n*", $dat)];
                                $insertListHash{$dat} = $#$insertLists;
                            }
                            $actions-&gt;[$_] = $insertListHash{$dat};
                        }
                        else {
                            $actions-&gt;[$_] = undef;
                        }
                    }
                }

                $subtable-&gt;{'classes'} = $classes;
                $subtable-&gt;{'states'} = $states;
                $subtable-&gt;{'insertLists'} = $insertLists;
            }

            else {
                die "unknown subtable type";
            }
            
            push @$subtables, $subtable;
            $fh-&gt;seek($subtableStart + $length, IO::File::SEEK_SET);
        }
        
        push @$chains,    {
                            'defaultFlags'        =&gt; $defaultFlags,
                            'featureEntries'    =&gt; $featureEntries,
                            'subtables'            =&gt; $subtables
                        };
        $fh-&gt;seek($chainStart + $chainLength, IO::File::SEEK_SET);
    }

    $self-&gt;{'chains'} = $chains;

    $self;
}

=head2 $t-&gt;out($fh)

Writes the table to a file either from memory or by copying

=cut

sub out
{
    my ($self, $fh) = @_;
    
    return $self-&gt;SUPER::out($fh) unless $self-&gt;{' read'};

    my $chains = $self-&gt;{'chains'};
    $fh-&gt;print(TTF_Pack("fL", $self-&gt;{'version'}, scalar @$chains));

    foreach (@$chains) {
        my $chainStart = $fh-&gt;tell();
        my ($featureEntries, $subtables) = ($_-&gt;{'featureEntries'}, $_-&gt;{'subtables'});
        $fh-&gt;print(TTF_Pack("LLSS", $_-&gt;{'defaultFlags'}, 0, scalar @$featureEntries, scalar @$subtables)); # placeholder for length
        
        foreach (@$featureEntries) {
            $fh-&gt;print(TTF_Pack("SSLL", $_-&gt;{'type'}, $_-&gt;{'setting'}, $_-&gt;{'enable'}, $_-&gt;{'disable'}));
        }
        
        foreach (@$subtables) {
            my $subtableStart = $fh-&gt;tell();
            my $type = $_-&gt;{'type'};
            my $coverage = $type;
            $coverage += 0x4000 if $_-&gt;{'direction'} eq 'RL';
            $coverage += 0x2000 if $_-&gt;{'orientation'} eq 'VH';
            $coverage += 0x8000 if $_-&gt;{'orientation'} eq 'V';
            
            $fh-&gt;print(TTF_Pack("SSL", 0, $coverage, $_-&gt;{'subFeatureFlags'}));    # placeholder for length
            
            if ($type == 0) {    # rearrangement
                AAT_write_state_table($fh, $_-&gt;{'classes'}, $_-&gt;{'states'}, 0);
            }
            
            elsif ($type == 1) {    # contextual
                my $stHeader = $fh-&gt;tell();
                $fh-&gt;print(pack("nnnnn", (0) x 5));    # placeholders for stateSize, classTable, stateArray, entryTable, mappingTables
                
                my $classTable = $fh-&gt;tell() - $stHeader;
                my $classes = $_-&gt;{'classes'};
                AAT_write_classes($fh, $classes);
                
                my $stateArray = $fh-&gt;tell() - $stHeader;
                my $states = $_-&gt;{'states'};
                my ($stateSize, $entries) = AAT_write_states($fh, $classes, $stateArray, $states, 
                        sub {
                            my $actions = $_-&gt;{'actions'};
                            ( $_-&gt;{'flags'}, @$actions )
                        }
                    );

                my $entryTable = $fh-&gt;tell() - $stHeader;
                my $offset = ($entryTable + 8 * @$entries) / 2;
                foreach (@$entries) {
                    my ($nextState, $flags, @parts) = split /,/;
                    $fh-&gt;print(pack("nnnn", $nextState, $flags, map { $_ eq "" ? 0 : $_ + $offset } @parts));
                }

                my $mappingTables = $fh-&gt;tell() - $stHeader;
                my $mappings = $_-&gt;{'mappings'};
                $fh-&gt;print(pack("n*", @$mappings));
                
                my $loc = $fh-&gt;tell();
                $fh-&gt;seek($stHeader, IO::File::SEEK_SET);
                $fh-&gt;print(pack("nnnnn", $stateSize, $classTable, $stateArray, $entryTable, $mappingTables));
                $fh-&gt;seek($loc, IO::File::SEEK_SET);
            }
            
            elsif ($type == 2) {    # ligature
                my $stHeader = $fh-&gt;tell();
                $fh-&gt;print(pack("nnnnnnn", (0) x 7));    # placeholders for stateSize, classTable, stateArray, entryTable, actionLists, components, ligatures
            
                my $classTable = $fh-&gt;tell() - $stHeader;
                my $classes = $_-&gt;{'classes'};
                AAT_write_classes($fh, $classes);
                
                my $stateArray = $fh-&gt;tell() - $stHeader;
                my $states = $_-&gt;{'states'};
                
                my ($stateSize, $entries) = AAT_write_states($fh, $classes, $stateArray, $states,
                        sub {
                            ( $_-&gt;{'flags'} &amp; 0xc000, $_-&gt;{'actions'} )
                        }
                    );
                
                my $actionLists = $_-&gt;{'actionLists'};
                my %actionListOffset;
                my $actionListDataLength = 0;
                my @actionListEntries;
                foreach (0 .. $#$entries) {
                    my ($nextState, $flags, $offset) = split(/,/, $entries-&gt;[$_]);
                    if ($offset eq "") {
                        $offset = undef;
                    }
                    else {
                        if (defined $actionListOffset{$offset}) {
                            $offset = $actionListOffset{$offset};
                        }
                        else {
                            $actionListOffset{$offset} = $actionListDataLength;
                            my $list = $actionLists-&gt;[$offset];
                            $actionListDataLength += 4 * @$list;
                            push @actionListEntries, $list;
                            $offset = $actionListOffset{$offset};
                        }
                    }
                    $entries-&gt;[$_] = [ $nextState, $flags, $offset ];
                }
                my $entryTable = $fh-&gt;tell() - $stHeader;
                my $ligActionLists = ($entryTable + @$entries * 4 + 3) &amp; ~3;
                foreach (@$entries) {
                    $_-&gt;[2] += $ligActionLists if defined $_-&gt;[2];
                    $fh-&gt;print(pack("nn", $_-&gt;[0], $_-&gt;[1] + $_-&gt;[2]));
                }
                $fh-&gt;print(pack("C*", (0) x ($ligActionLists - $entryTable - @$entries * 4)));
                
                die "internal error" if $fh-&gt;tell() != $ligActionLists + $stHeader;
                
                my $componentTable = $fh-&gt;tell() - $stHeader + $actionListDataLength;
                my $actionList;
                foreach $actionList (@actionListEntries) {
                    foreach (0 .. $#$actionList) {
                        my $action = $actionList-&gt;[$_];
                        my $val = $action-&gt;{'component'} + $componentTable / 2;
                        $val += 0x40000000 if $val &lt; 0;
                        $val &amp;= 0x3fffffff;
                        $val |= 0x40000000 if $action-&gt;{'store'};
                        $val |= 0x80000000 if $_ == $#$actionList;
                        $fh-&gt;print(pack("N", $val));
                    }
                }

                die "internal error" if $fh-&gt;tell() != $componentTable + $stHeader;

                my $components = $_-&gt;{'components'};
                my $ligatureTable = $componentTable + @$components * 2;
                $fh-&gt;print(pack("n*", map { (index($_, '+') &gt;= 0 ? $ligatureTable : 0) + $_ } @$components));
                
                my $ligatures = $_-&gt;{'ligatures'};
                $fh-&gt;print(pack("n*", @$ligatures));
                
                my $loc = $fh-&gt;tell();
                $fh-&gt;seek($stHeader, IO::File::SEEK_SET);
                $fh-&gt;print(pack("nnnnnnn", $stateSize, $classTable, $stateArray, $entryTable, $ligActionLists, $componentTable, $ligatureTable));
                $fh-&gt;seek($loc, IO::File::SEEK_SET);
            }
            
            elsif ($type == 4) {    # non-contextual
                AAT_write_lookup($fh, $_-&gt;{'format'}, $_-&gt;{'lookup'}, 2, undef);
            }
            
            elsif ($type == 5) {    # insertion
            }
            
            else {
                die "unknown subtable type";
            }
            
            my $length = $fh-&gt;tell() - $subtableStart;
            my $padBytes = (4 - ($length &amp; 3)) &amp; 3;
            $fh-&gt;print(pack("C*", (0) x $padBytes));
            $length += $padBytes;
            $fh-&gt;seek($subtableStart, IO::File::SEEK_SET);
            $fh-&gt;print(pack("n", $length));
            $fh-&gt;seek($subtableStart + $length, IO::File::SEEK_SET);
        }
        
        my $chainLength = $fh-&gt;tell() - $chainStart;
        $fh-&gt;seek($chainStart + 4, IO::File::SEEK_SET);
        $fh-&gt;print(pack("N", $chainLength));
        $fh-&gt;seek($chainStart + $chainLength, IO::File::SEEK_SET);
    }
}

=head2 $t-&gt;print($fh)

Prints a human-readable representation of the table

=cut

sub print
{
    my ($self, $fh) = @_;
    
    $self-&gt;read;
    my $feat = $self-&gt;{' PARENT'}-&gt;{'feat'};
    $feat-&gt;read;
    my $post = $self-&gt;{' PARENT'}-&gt;{'post'};
    $post-&gt;read;
    
    $fh = 'STDOUT' unless defined $fh;

    $fh-&gt;printf("version %f\n", $self-&gt;{'version'});
    
    my $chains = $self-&gt;{'chains'};
    foreach (@$chains) {
        my $defaultFlags = $_-&gt;{'defaultFlags'};
        $fh-&gt;printf("chain: defaultFlags = %08x\n", $defaultFlags);
        
        my $featureEntries = $_-&gt;{'featureEntries'};
        foreach (@$featureEntries) {
            $fh-&gt;printf("\tfeature %d, setting %d : enableFlags = %08x, disableFlags = %08x # '%s: %s'\n",
                        $_-&gt;{'type'}, $_-&gt;{'setting'}, $_-&gt;{'enable'}, $_-&gt;{'disable'},
                        $feat-&gt;settingName($_-&gt;{'type'}, $_-&gt;{'setting'}));
        }
        
        my $subtables = $_-&gt;{'subtables'};
        foreach (@$subtables) {
            my $type = $_-&gt;{'type'};
            my $subFeatureFlags = $_-&gt;{'subFeatureFlags'};
            $fh-&gt;printf("\n\t%s table, %s, %s, subFeatureFlags = %08x # %s (%s)\n",
                        subtable_type_($type), $_-&gt;{'direction'}, $_-&gt;{'orientation'}, $subFeatureFlags,
                        "Default " . ((($subFeatureFlags &amp; $defaultFlags) != 0) ? "On" : "Off"),
                        join(", ",
                            map {
                                join(": ", $feat-&gt;settingName($_-&gt;{'type'}, $_-&gt;{'setting'}) )
                            } grep { ($_-&gt;{'enable'} &amp; $subFeatureFlags) != 0 } @$featureEntries
                        ) );
            
            if ($type == 0) {    # rearrangement
                print_classes_($fh, $_, $post);

                $fh-&gt;print("\n");
                my $states = $_-&gt;{'states'};
                my @verbs = (    "0", "Ax-&gt;xA", "xD-&gt;Dx", "AxD-&gt;DxA",
                                "ABx-&gt;xAB", "ABx-&gt;xBA", "xCD-&gt;CDx", "xCD-&gt;DCx",
                                "AxCD-&gt;CDxA", "AxCD-&gt;DCxA", "ABxD-&gt;DxAB", "ABxD-&gt;DxBA",
                                "ABxCD-&gt;CDxAB", "ABxCD-&gt;CDxBA", "ABxCD-&gt;DCxAB", "ABxCD-&gt;DCxBA");
                foreach (0 .. $#$states) {
                    $fh-&gt;printf("\t\tState %d:", $_);
                    my $state = $states-&gt;[$_];
                    foreach (@$state) {
                        my $flags;
                        $flags .= "!" if ($_-&gt;{'flags'} &amp; 0x4000);
                        $flags .= "&lt;" if ($_-&gt;{'flags'} &amp; 0x8000);
                        $flags .= "&gt;" if ($_-&gt;{'flags'} &amp; 0x2000);
                        $fh-&gt;printf("\t(%s%d,%s)", $flags, $_-&gt;{'nextState'}, $verbs[($_-&gt;{'flags'} &amp; 0x000f)]);
                    }
                    $fh-&gt;print("\n");
                }
            }
            
            elsif ($type == 1) {    # contextual
                print_classes_($fh, $_, $post);
                
                $fh-&gt;print("\n");
                my $states = $_-&gt;{'states'};
                foreach (0 .. $#$states) {
                    $fh-&gt;printf("\t\tState %d:", $_);
                    my $state = $states-&gt;[$_];
                    foreach (@$state) {
                        my $flags;
                        $flags .= "!" if ($_-&gt;{'flags'} &amp; 0x4000);
                        $flags .= "*" if ($_-&gt;{'flags'} &amp; 0x8000);
                        my $actions = $_-&gt;{'actions'};
                        $fh-&gt;printf("\t(%s%d,%s,%s)", $flags, $_-&gt;{'nextState'}, map { defined $_ ? $_ : "=" } @$actions);
                    }
                    $fh-&gt;print("\n");
                }

                $fh-&gt;print("\n");
                my $mappings = $_-&gt;{'mappings'};
                foreach (0 .. $#$mappings) {
                    $fh-&gt;printf("\t\tMapping %d: %d [%s]\n", $_, $mappings-&gt;[$_], $post-&gt;{'VAL'}[$mappings-&gt;[$_]]);
                }
            }
            
            elsif ($type == 2) {    # ligature
                print_classes_($fh, $_, $post);
                
                $fh-&gt;print("\n");
                my $states = $_-&gt;{'states'};
                foreach (0 .. $#$states) {
                    $fh-&gt;printf("\t\tState %d:", $_);
                    my $state = $states-&gt;[$_];
                    foreach (@$state) {
                        my $flags;
                        $flags .= "!" if ($_-&gt;{'flags'} &amp; 0x4000);
                        $flags .= "*" if ($_-&gt;{'flags'} &amp; 0x8000);
                        $fh-&gt;printf("\t(%s%d,%s)", $flags, $_-&gt;{'nextState'}, defined $_-&gt;{'actions'} ? $_-&gt;{'actions'} : "=");
                    }
                    $fh-&gt;print("\n");
                }

                $fh-&gt;print("\n");
                my $actionLists = $_-&gt;{'actionLists'};
                foreach (0 .. $#$actionLists) {
                    $fh-&gt;printf("\t\tList %d:\t", $_);
                    my $actionList = $actionLists-&gt;[$_];
                    $fh-&gt;printf("%s\n", join(", ", map { ($_-&gt;{'component'} . ($_-&gt;{'store'} ? "*" : "") ) } @$actionList));
                }

                my $ligatureTable = $_-&gt;{'ligatureTable'};

                $fh-&gt;print("\n");
                my $components = $_-&gt;{'components'};
                foreach (0 .. $#$components) {
                    $fh-&gt;printf("\t\tComponent %d: %s\n", $_, $components-&gt;[$_]);
                }
                
                $fh-&gt;print("\n");
                my $ligatures = $_-&gt;{'ligatures'};
                foreach (0 .. $#$ligatures) {
                    $fh-&gt;printf("\t\tLigature %d: %d [%s]\n", $_, $ligatures-&gt;[$_], $post-&gt;{'VAL'}[$ligatures-&gt;[$_]]);
                }
            }
            
            elsif ($type == 4) {    # non-contextual
                my $lookup = $_-&gt;{'lookup'};
                $fh-&gt;printf("\t\tLookup format %d\n", $_-&gt;{'format'});
                if (defined $lookup) {
                    foreach (sort { $a &lt;=&gt; $b } keys %$lookup) {
                        $fh-&gt;printf("\t\t\t%d [%s] -&gt; %d [%s])\n", $_, $post-&gt;{'VAL'}[$_], $lookup-&gt;{$_}, $post-&gt;{'VAL'}[$lookup-&gt;{$_}]);
                    }
                }
            }
            
            elsif ($type == 5) {    # insertion
                print_classes_($fh, $_, $post);
                
                $fh-&gt;print("\n");
                my $states = $_-&gt;{'states'};
                foreach (0 .. $#$states) {
                    $fh-&gt;printf("\t\tState %d:", $_);
                    my $state = $states-&gt;[$_];
                    foreach (@$state) {
                        my $flags;
                        $flags .= "!" if ($_-&gt;{'flags'} &amp; 0x4000);
                        $flags .= "*" if ($_-&gt;{'flags'} &amp; 0x8000);
                        my $actions = $_-&gt;{'actions'};
                        $fh-&gt;printf("\t(%s%d,%s,%s)", $flags, $_-&gt;{'nextState'}, map { defined $_ ? $_ : "=" } @$actions);
                    }
                    $fh-&gt;print("\n");
                }

                $fh-&gt;print("\n");
                my $insertLists = $_-&gt;{'insertLists'};
                foreach (0 .. $#$insertLists) {
                    my $insertList = $insertLists-&gt;[$_];
                    $fh-&gt;printf("\t\tList %d: %s\n", $_, join(", ", map { $_ . " [" . $post-&gt;{'VAL'}[$_] . "]" } @$insertList));
                }
            }
            
            else {
                # unknown
            }
        }
    }
}

sub print_classes_
{
    my ($fh, $subtable, $post) = @_;
    
    my $classes = $subtable-&gt;{'classes'};
    foreach (0 .. $#$classes) {
        my $class = $classes-&gt;[$_];
        if (defined $class) {
            $fh-&gt;printf("\t\tClass %d:\t%s\n", $_, join(", ", map { $_ . " [" . $post-&gt;{'VAL'}[$_] . "]" } @$class));
        }
    }
}

sub subtable_type_
{
    my ($val) = @_;
    my ($res);
    
    my @types =    (
                    'Rearrangement',
                    'Contextual',
                    'Ligature',
                    undef,
                    'Non-contextual',
                    'Insertion',
                );
    $res = $types[$val] or ('Undefined (' . $val . ')');
    
    $res;
}

1;

=head1 BUGS

None known

=head1 AUTHOR

Jonathan Kew L&lt;Jonathan_Kew@sil.org&gt;. See L&lt;Font::TTF::Font&gt; for copyright and
licensing.

=cut

</pre></body></html>