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

=head1 NAME

Font::TTF::Sill - Graphite language mapping table

=head1 DESCRIPTION

=head1 INSTANCE VARIABLES

=over 4

=item version

Table version number.

=item langs

Contains a hash where the key is the language id and the value is an array of
language records

=back

=head2 Language Records

Each language record is itself an array of two values [fid, val]. fid is the
feature id and is held as a long.

=cut

use Font::TTF::Utils;
require Font::TTF::Table;

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

sub read
{
    my ($self) = @_;
    my ($num, $i, $j);

    return $self if ($self-&gt;{' read'});
    $self-&gt;SUPER::read_dat or return $self;

    ($self-&gt;{'version'}, $num) = TTF_Unpack("vS", $self-&gt;{' dat'});

    foreach $i (1 .. $num)        # ignore bogus entry at end
    {
        my ($lid, $numf, $offset) = unpack("A4nn", substr($self-&gt;{' dat'}, $i * 8 + 4));      # 12 - 8 = 4 since i starts at 1. A4 strips nulls
        my (@settings);

        foreach $j (1 .. $numf)
        {
            my ($fid, $val) = TTF_Unpack("Ls", substr($self-&gt;{' dat'}, $offset + $j * 8 - 8));
            push (@settings, [$fid, $val]);
        }
        $self-&gt;{'langs'}{$lid} = [@settings];
    }
    delete $self-&gt;{' dat'};
    $self-&gt;{' read'} = 1;
    $self;
}

sub out
{
    my ($self, $fh) = @_;
    my ($num, $range, $select, $shift) = TTF_bininfo(scalar keys %{$self-&gt;{'langs'}}, 1);
    my ($offset) = $num * 8 + 20;   #header = 12, dummy = 8
    my ($k, $s);

    return $self-&gt;SUPER::out($fh) unless ($self-&gt;{' read'});
    $fh-&gt;print(TTF_Pack("vSSSS", $self-&gt;{'version'}, $num, $range, $select, $shift));
    foreach $k (sort (keys %{$self-&gt;{'langs'}}), '+1')
    {
        my ($numf) = scalar @{$self-&gt;{'langs'}{$k}} unless ($k eq '+1');
        $fh-&gt;print(pack("a4nn", $k, $numf, $offset));
        $offset += $numf * 8;
    }

    foreach $k (sort keys %{$self-&gt;{'langs'}})
    {
        foreach $s (@{$self-&gt;{'langs'}{$k}})
        { $fh-&gt;print(TTF_Pack("LsS", @{$s}, 0)); }
    }
    $self;
}

sub XML_element
{
    my ($self) = shift;
    my ($context, $depth, $key, $dat) = @_;
    my ($fh) = $context-&gt;{'fh'};
    my ($k, $s);

    return $self-&gt;SUPER::XML_element(@_) unless ($key eq 'langs');
    foreach $k (sort keys %{$self-&gt;{'langs'}})
    {
        $fh-&gt;printf("%s&lt;lang id='%s'&gt;\n", $depth, $k);
        foreach $s (@{$self-&gt;{'langs'}{$k}})
        {
            my ($fid) = $s-&gt;[0];
            if ($fid &gt; 0x00FFFFFF)
            { $fid = unpack("A4", pack ("N", $fid)); }
            else
            { $fid = sprintf("%d", $fid); }
            $fh-&gt;printf("%s%s&lt;feature id='%s' value='%d'/&gt;\n",
                $depth, $context-&gt;{'indent'}, $fid, $s-&gt;[1]);
        }
        $fh-&gt;printf("%s&lt;/lang&gt;\n", $depth);
    }
    $self;
}
1;
        
        
</pre></body></html>