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

=head1 NAME

Font::TTF::Ttc - Truetype Collection class

=head1 DESCRIPTION

A TrueType collection is a collection of TrueType fonts in one file in which
tables may be shared between different directories. In order to support this,
the TTC introduces the concept of a table being shared by different TrueType
fonts. This begs the question of what should happen to the ' PARENT' property
of a particular table. It is made to point to the first directory object which
refers to it. It is therefore up to the application to sort out any confusion.
Confusion only occurs if shared tables require access to non-shared tables.
This should not happen since the shared tables are dealing with glyph
information only and the private tables are dealing with encoding and glyph
identification. Thus the general direction is from identification to glyph and
not the other way around (at least not without knowledge of the particular
context).

=head1 INSTANCE VARIABLES

The following instance variables are preceded by a space

=over 4

=item fname (P)

Filename for this TrueType Collection

=item INFILE (P)

The filehandle of this collection

=back

The following instance variable does not start with a space

=over 4

=item directs

An array of directories (Font::TTF::Font objects) for each sub-font in the directory

=back

=head1 METHODS

=cut

use strict;
use vars qw($VERSION);

use IO::File;

$VERSION = 0.0001;

=head2 Font::TTF::Ttc-&gt;open($fname)

Opens and reads the given filename as a TrueType Collection. Reading a collection
involves reading each of the directories which go to make up the collection.

=cut

sub open
{
    my ($class, $fname) = @_;
    my ($self) = {};
    my ($fh);

    unless (ref($fname))
    {
        $fh = IO::File-&gt;new($fname) or return undef;
        binmode $fh;
    } else
    { $fh = $fname; }
    
    bless $self, $class;
    $self-&gt;{' INFILE'} = $fh;
    $self-&gt;{' fname'} = $fname;
    $fh-&gt;seek(0, 0);
    $self-&gt;read;
}


=head2 $c-&gt;read

Reads a Collection by reading all the directories in the collection

=cut

sub read
{
    my ($self) = @_;
    my ($fh) = $self-&gt;{' INFILE'};
    my ($dat, $ttc, $ver, $num, $i, $loc);

    $fh-&gt;read($dat, 12);
    ($ttc, $ver, $num) = unpack("A4N2", $dat);

    return undef unless $ttc eq "ttcf";
    $fh-&gt;read($dat, $num &lt;&lt; 2);
    for ($i = 0; $i &lt; $num; $i++)
    {
        $loc = unpack("N", substr($dat, $i &lt;&lt; 2, 4));       
        $self-&gt;{'directs'}[$i] = Font::TTF::Font-&gt;new('INFILE' =&gt; $fh,
                                                'PARENT' =&gt; $self,
                                                'OFFSET' =&gt; $loc) || return undef;
    }
    for ($i = 0; $i &lt; $num; $i++)
    { $self-&gt;{'directs'}[$i]-&gt;read; }
    $self;
}


=head2 $c-&gt;find($direct, $name, $check, $off, $len)

Hunts around to see if a table with the given characteristics of name, checksum,
offset and length has been associated with a directory earlier in the list.
Actually on checks the offset since no two tables can share the same offset in
a TrueType font, collection or otherwise.

=cut

sub find
{
    my ($self, $direct, $name, $check, $off, $len) = @_;
    my ($d);

    foreach $d (@{$self-&gt;{'directs'}})
    {
        return undef if $d eq $direct;
        next unless defined $d-&gt;{$name};
        return $d-&gt;{$name} if ($d-&gt;{$name}{' OFFSET'} == $off);
    }
    undef;              # wierd that the font passed is not in the list!
}


=head2 $c-&gt;DESTROY

Closees any opened files by us

=cut

sub DESTROY
{
    my ($self) = @_;
    close ($self-&gt;{' INFILE'});
    undef;
}

=head1 BUGS

No known bugs, but then not ever executed!

=head1 AUTHOR

Martin Hosken Martin_Hosken@sil.org. See L&lt;Font::TTF::Font&gt; for copyright and
licensing.

=cut

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