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

=head1 NAME

Font::TTF::Bsln - Baseline table in a font

=head1 DESCRIPTION

=head1 INSTANCE VARIABLES

=item version

=item xformat

=item defaultBaseline

=item deltas

=item stdGlyph

=item ctlPoints

=item lookupFormat

=item lookup

=head1 METHODS

=cut

use strict;
use vars qw(@ISA);

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

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

=head2 $t-&gt;read

Reads the table into memory

=cut

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

    $fh = $self-&gt;{' INFILE'};
    $fh-&gt;read($dat, 8);
    my ($version, $format, $defaultBaseline) = TTF_Unpack("vSS", $dat);

    if ($format == 0 or $format == 1) {
        $fh-&gt;read($dat, 64);
        $self-&gt;{'deltas'} = [TTF_Unpack("s*", $dat)];
    }
    elsif ($format == 2 or $format == 3) {
        $fh-&gt;read($dat, 2);
        $self-&gt;{'stdGlyph'} = unpack("n", $dat);
        $fh-&gt;read($dat, 64);
        $self-&gt;{'ctlPoints'} = unpack("n*", $dat);
    }
    else {
        die "unknown table format";
    }
    
    if ($format == 1 or $format == 3) {
        my $len = $self-&gt;{' LENGTH'} - ($fh-&gt;tell() - $self-&gt;{' OFFSET'});
        my ($lookupFormat, $lookup) = AAT_read_lookup($fh, 2, $len, $defaultBaseline);
        $self-&gt;{'lookupFormat'} = $lookupFormat;
        $self-&gt;{'lookup'} = $lookup;
    }

    $self-&gt;{'version'} = $version;
    $self-&gt;{'format'} = $format;
    $self-&gt;{'defaultBaseline'} = $defaultBaseline;

    $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 $format = $self-&gt;{'format'};
    my $defaultBaseline = $self-&gt;{'defaultBaseline'};
    $fh-&gt;print(TTF_Pack("vSS", $self-&gt;{'version'}, $format, $defaultBaseline));

    AAT_write_lookup($fh, $self-&gt;{'lookupFormat'}, $self-&gt;{'lookup'}, 2, $defaultBaseline) if ($format == 1 or $format == 3);
}

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

Prints a human-readable representation of the table

=cut

sub print
{
    my ($self, $fh) = @_;

    $self-&gt;read;
        
    $fh = 'STDOUT' unless defined $fh;
    
    my $format = $self-&gt;{'format'};
    $fh-&gt;printf("version %f\nformat %d\ndefaultBaseline %d\n", $self-&gt;{'version'}, $format, $self-&gt;{'defaultBaseline'});
    if ($format == 0 or $format == 1) {
        $fh-&gt;printf("\tdeltas:\n");
        my $deltas = $self-&gt;{'deltas'};
        foreach (0 .. 31) {
            $fh-&gt;printf("\t\t%d: %d%s\n", $_, $deltas-&gt;[$_], defined baselineName_($_) ? "\t# " . baselineName_($_) : "");
        }
    }
    if ($format == 2 or $format == 3) {
        $fh-&gt;printf("\tstdGlyph = %d\n", $self-&gt;{'stdGlyph'});
        my $ctlPoints = $self-&gt;{'ctlPoints'};
        foreach (0 .. 31) {
            $fh-&gt;printf("\t\t%d: %d%s\n", $_, $ctlPoints-&gt;[$_], defined baselineName_($_) ? "\t# " . baselineName_($_) : "");
        }
    }
    if ($format == 1 or $format == 3) {
        $fh-&gt;printf("lookupFormat %d\n", $self-&gt;{'lookupFormat'});
        my $lookup = $self-&gt;{'lookup'};
        foreach (sort { $a &lt;=&gt; $b } keys %$lookup) {
            $fh-&gt;printf("\tglyph %d: %d%s\n", $_, $lookup-&gt;{$_}, defined baselineName_($_) ? "\t# " . baselineName_($_) : "");
        }
    }
}

sub baselineName_
{
    my ($b) = @_;
    my @baselines = ( 'Roman', 'Ideographic centered', 'Ideographic low', 'Hanging', 'Math' );
    $baselines[$b];
}

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>