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

=head1 NAME

Font::TTF::Kern::StateTable - State Table Kern subtable for AAT

=head1 METHODS

=cut

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

@ISA = qw(Font::TTF::Kern::Subtable);

sub new
{
    my ($class) = @_;
    my ($self) = {};
    
    $class = ref($class) || $class;
    bless $self, $class;
}

=head2 $t-&gt;read

Reads the table into memory

=cut

sub read
{
    my ($self, $fh) = @_;
    my ($dat);
    
    my $stTableStart = $fh-&gt;tell();

    my ($classes, $states, $entries) = AAT_read_state_table($fh, 0);

    foreach (@$entries) {
        my $flags = $_-&gt;{'flags'};
        delete $_-&gt;{'flags'};
        $_-&gt;{'push'} = 1        if $flags &amp; 0x8000;
        $_-&gt;{'noAdvance'} = 1    if $flags &amp; 0x4000;
        $flags &amp;= ~0xC000;
        if ($flags != 0) {
            my $kernList = [];
            $fh-&gt;seek($stTableStart + $flags, IO::File::SEEK_SET);
            while (1) {
                $fh-&gt;read($dat, 2);
                my $k = TTF_Unpack("s", $dat);
                push @$kernList, ($k &amp; ~1);
                last if ($k &amp; 1) != 0;
            }
            $_-&gt;{'kernList'} = $kernList;
        }
    }

    $self-&gt;{'classes'} = $classes;
    $self-&gt;{'states'} = $states;
    $self-&gt;{'entries'} = $entries;

    $fh-&gt;seek($stTableStart - 8 + $self-&gt;{'length'}, IO::File::SEEK_SET);
    
    $self;
}

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

Writes the table to a file

=cut

sub out_sub
{
}

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

Prints a human-readable representation of the table

=cut

sub print
{
}

sub dumpXML
{
    my ($self, $fh) = @_;
    
    $fh-&gt;printf("&lt;classes&gt;\n");
    $self-&gt;dumpClasses($self-&gt;{'classes'}, $fh);
    $fh-&gt;printf("&lt;/classes&gt;\n");

    $fh-&gt;printf("&lt;states&gt;\n");
    my $states = $self-&gt;{'states'};
    foreach (0 .. $#$states) {
        $fh-&gt;printf("&lt;state index=\"%s\"&gt;\n", $_);
        my $members = $states-&gt;[$_];
        foreach (0 .. $#$members) {
            my $m = $members-&gt;[$_];
            $fh-&gt;printf("&lt;m index=\"%s\" nextState=\"%s\"", $_, $m-&gt;{'nextState'});
            $fh-&gt;printf(" push=\"1\"")        if $m-&gt;{'push'};
            $fh-&gt;printf(" noAdvance=\"1\"")    if $m-&gt;{'noAdvance'};
            if (exists $m-&gt;{'kernList'}) {
                $fh-&gt;printf("&gt;");
                foreach (@{$m-&gt;{'kernList'}}) {
                    $fh-&gt;printf("&lt;kern v=\"%s\"/&gt;", $_);
                }
                $fh-&gt;printf("&lt;/m&gt;\n");
            }
            else {
                $fh-&gt;printf("/&gt;\n");
            }
        }
        $fh-&gt;printf("&lt;/state&gt;\n");
    }
    $fh-&gt;printf("&lt;/states&gt;\n");
}

sub type
{
    return 'kernStateTable';
}

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>