<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::ClassArray;

=head1 NAME

Font::TTF::Kern::ClassArray - ClassArray Kern Subtable for AAT

=head1 METHODS

=cut

use strict;
use vars qw(@ISA);
use Font::TTF::Utils;
use Font::TTF::AATutils;
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 $subtableStart = $fh-&gt;tell() - 8;
    my $dat;
    $fh-&gt;read($dat, 8);
    my ($rowWidth, $leftClassTable, $rightClassTable, $array) = unpack("nnnn", $dat);

    $fh-&gt;seek($subtableStart + $leftClassTable, IO::File::SEEK_SET);
    $fh-&gt;read($dat, 4);
    my ($firstGlyph, $nGlyphs) = unpack("nn", $dat);
    $fh-&gt;read($dat, $nGlyphs * 2);
    my $leftClasses = [];
    foreach (TTF_Unpack("S*", $dat)) {
        push @{$leftClasses-&gt;[($_ - $array) / $rowWidth]}, $firstGlyph++;
    }
    
    $fh-&gt;seek($subtableStart + $rightClassTable, IO::File::SEEK_SET);
    $fh-&gt;read($dat, 4);
    ($firstGlyph, $nGlyphs) = unpack("nn", $dat);
    $fh-&gt;read($dat, $nGlyphs * 2);
    my $rightClasses = [];
    foreach (TTF_Unpack("S*", $dat)) {
        push @{$rightClasses-&gt;[$_ / 2]}, $firstGlyph++;
    }
    
    $fh-&gt;seek($subtableStart + $array, IO::File::SEEK_SET);
    $fh-&gt;read($dat, $self-&gt;{'length'} - $array);

    my $offset = 0;
    my $kernArray = [];
    while ($offset &lt; length($dat)) {
        push @$kernArray, [ TTF_Unpack("s*", substr($dat, $offset, $rowWidth)) ];
        $offset += $rowWidth;
    }    

    $self-&gt;{'leftClasses'} = $leftClasses;
    $self-&gt;{'rightClasses'} = $rightClasses;
    $self-&gt;{'kernArray'} = $kernArray;
    
    $fh-&gt;seek($subtableStart + $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
{
    my ($self, $fh) = @_;
    
    my $post = $self-&gt;post();
    
    $fh = 'STDOUT' unless defined $fh;

    
}

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

    $fh-&gt;printf("&lt;rightClasses&gt;\n");
    $self-&gt;dumpClasses($self-&gt;{'rightClasses'}, $fh);    
    $fh-&gt;printf("&lt;/rightClasses&gt;\n");
    
    $fh-&gt;printf("&lt;kernArray&gt;\n");
    my $kernArray = $self-&gt;{'kernArray'};
    foreach (0 .. $#$kernArray) {
        $fh-&gt;printf("&lt;row index=\"%s\"&gt;\n", $_);
        my $row = $kernArray-&gt;[$_];
        foreach (0 .. $#$row) {
            $fh-&gt;printf("&lt;val index=\"%s\" v=\"%s\"/&gt;\n", $_, $row-&gt;[$_]);
        }
        $fh-&gt;printf("&lt;/row&gt;\n");
    }
    $fh-&gt;printf("&lt;/kernArray&gt;\n");
}

sub type
{
    return 'kernClassArray';
}



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>