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

=head1 NAME

Font::TTF::Glyph - Holds a single glyph's information

=head1 DESCRIPTION

This is a single glyph description as held in a TT font. On creation only its
header is read. Thus you can get the bounding box of each glyph without having
to read all the other information.

=head1 INSTANCE VARIABLES

In addition to the named variables in a glyph header (C&lt;xMin&gt; etc.), there are
also all capital instance variables for holding working information, mostly
from the location table.

The standard attributes each glyph has are:

 numberOfContours
 xMin
 yMin
 xMax
 yMax

There are also other, derived, instance variables for each glyph which are read
when the whole glyph is read (via C&lt;read_dat&gt;):

=over 4

=item instLen

Number of bytes in the hinting instructions (Warning this variable is deprecated,
use C&lt;length($g-&gt;{'hints'})&gt; instead).

=item hints

The string containing the hinting code for the glyph

=back

In addition there are other attribute like instance variables for simple glyphs:

=over 4

For each contour there is:

=over 4

=item endPoints

An array of endpoints for each contour in the glyph. There are
C&lt;numberOfContours&gt; contours in a glyph. The number of points in a glyph is
equal to the highest endpoint of a contour.

=back

There are also a number of arrays indexed by point number

=over 4

=item flags

The flags associated with reading this point. The flags for a point are
recalculated for a point when it is C&lt;update&gt;d. Thus the flags are not very
useful. The only important bit is bit 0 which indicates whether the point is
an 'on' curve point, or an 'off' curve point.

=item x

The absolute x co-ordinate of the point.

=item y

The absolute y co-ordinate of the point

=back

=back

For composite glyphs there are other variables

=over 4

=item metric

This holds the component number (not its glyph number) of the component from
which the metrics for this glyph should be taken.

=item comps

This is an array of hashes for each component. Each hash has a number of
elements:

=over 4

=item glyph

The glyph number of the glyph which comprises this component of the composite.
NOTE: In some badly generated fonts, C&lt;glyph&gt; may contain a numerical value
but that glyph might not actually exist in the font file.  This could
occur in any glyph, but is particularly likely for glyphs that have
no strokes, such as SPACE, U+00A0 NO-BREAK SPACE, or 
U+200B ZERO WIDTH SPACE.

=item args

An array of two arguments which may be an x, y co-ordinate or two attachment
points (one on the base glyph the other on the component). See flags for details.

=item flag

The flag for this component

=item scale

A 4 number array for component scaling. This allows stretching, rotating, etc.
Note that scaling applies to placement co-ordinates (rather than attachment points)
before locating rather than after.

=back

=item numPoints

This is a generated value which contains the number of components read in for this
compound glyph.

=back

The private instance variables are:

=over 4

=item INFILE (P)

The input file form which to read any information

=item LOC (P)

Location relative to the start of the glyf table in the read file

=item BASE (P)

The location of the glyf table in the read file

=item LEN (P)

This is the number of bytes required by the glyph. It should be kept up to date
by calling the C&lt;update&gt; method whenever any of the glyph content changes.

=item OUTLOC (P)

Location relative to the start of the glyf table. This variable is only active
whilst the output process is going on. It is used to inform the location table
where the glyph's location is, since the glyf table is output before the loca
table due to alphabetical ordering.

=item OUTLEN (P)

This indicates the length of the glyph data when it is output. This more
accurately reflects the internal memory form than the C&lt;LEN&gt; variable which
only reflects the read file length. The C&lt;OUTLEN&gt; variable is only set after
calling C&lt;out&gt; or C&lt;out_dat&gt;.

=back

=head2 Editing

If you want to edit a glyph in some way, then you should read_dat the glyph, then
make your changes and then update the glyph or set the $g-&gt;{' isdirty'} variable.
It is the application's duty to ensure that the following instance variables are
correct, from which update will calculate the rest, including the bounding box
information.

    numPoints
    numberOfContours
    endPoints
    x, y, flags         (only flags bit 0)
    instLen
    hints

For components, the numPoints, x, y, endPoints &amp; flags are not required but
the following information is required for each component.

    flag                (bits 2, 10, 11, 12)
    glyph
    args
    scale
    metric              (glyph instance variable)
    

=head1 METHODS

=cut

use strict;
use vars qw(%fields @field_info);
use Font::TTF::Utils;
use Font::TTF::Table;

@field_info = (
    'numberOfContours' =&gt; 's', 
    'xMin' =&gt; 's', 
    'yMin' =&gt; 's',
    'xMax' =&gt; 's',
    'yMax' =&gt; 's');

sub init
{
    my ($k, $v, $c, $i);
    for ($i = 0; $i &lt; $#field_info; $i += 2)
    {
        ($k, $v, $c) = TTF_Init_Fields($field_info[$i], $c, $field_info[$i + 1]);
        next unless defined $k &amp;&amp; $k ne "";
        $fields{$k} = $v;
    }
}


=head1 Font::TTF::Glyph-&gt;new(%parms)

Creates a new glyph setting various instance variables

=cut

sub new
{
    my ($class, %parms) = @_;
    my ($self) = {};
    my ($p);

    bless $self, $class;
    foreach $p (keys %parms)
    { $self-&gt;{" $p"} = $parms{$p}; }
    init unless defined $fields{'xMin'};
    $self;
}


=head2 $g-&gt;read

Reads the header component of the glyph (bounding box, etc.) and also the
glyph content, but into a data field rather than breaking it down into
its constituent structures. Use read_dat for this.

=cut

sub read
{
    my ($self) = @_;
    my ($fh) = $self-&gt;{' INFILE'};
    my ($dat);

    return $self if $self-&gt;{' read'};
    $self-&gt;{' read'} = 1;
    $fh-&gt;seek($self-&gt;{' LOC'} + $self-&gt;{' BASE'}, 0);
    $fh-&gt;read($self-&gt;{' DAT'}, $self-&gt;{' LEN'});
    TTF_Read_Fields($self, $self-&gt;{' DAT'}, \%fields);
    $self;
}


=head2 $g-&gt;read_dat

Reads the contents of the glyph (components and curves, etc.) from the memory
store C&lt;DAT&gt; into structures within the object. Then, to indicate where the
master form of the data is, it deletes the C&lt;DAT&gt; instance variable.

=cut

sub read_dat
{
    my ($self) = @_;
    my ($dat, $num, $max, $i, $flag, $len, $val, $val1, $fp);

    return $self if (defined $self-&gt;{' read'} &amp;&amp; $self-&gt;{' read'} &gt; 1);
    $self-&gt;read unless $self-&gt;{' read'};
    $dat = $self-&gt;{' DAT'};
    $fp = 10;
    $num = $self-&gt;{'numberOfContours'};
    if ($num &gt; 0)
    {
        $self-&gt;{'endPoints'} = [unpack("n*", substr($dat, $fp, $num &lt;&lt; 1))];
        $fp += $num &lt;&lt; 1;
        $max = 0;
        foreach (@{$self-&gt;{'endPoints'}})
        { $max = $_ if $_ &gt; $max; }
#        print STDERR join(",", unpack('C*', $self-&gt;{" DAT"}));
#        printf STDERR ("(%d,%d in %d=%d @ %d)", scalar @{$self-&gt;{'endPoints'}}, $max, length($dat), $self-&gt;{' LEN'}, $fp);
        $max++ if (@{$self-&gt;{'endPoints'}});
        $self-&gt;{'numPoints'} = $max;
        $self-&gt;{'instLen'} = unpack("n", substr($dat, $fp));
        $self-&gt;{'hints'} = substr($dat, $fp + 2, $self-&gt;{'instLen'});
        $fp += 2 + $self-&gt;{'instLen'};
# read the flags array
        for ($i = 0; $i &lt; $max; $i++)                   
        {
            $flag = unpack("C", substr($dat, $fp++));
            $self-&gt;{'flags'}[$i] = $flag;
            if ($flag &amp; 8)
            {
                $len = unpack("C", substr($dat, $fp++));
                while ($len-- &gt; 0)
                {
                    $i++;
                    $self-&gt;{'flags'}[$i] = $flag;
                }
            }
        }
#read the x array
        for ($i = 0; $i &lt; $max; $i++)
        {
            $flag = $self-&gt;{'flags'}[$i];
            if ($flag &amp; 2)
            {
                $val = unpack("C", substr($dat, $fp++));
                $val = -$val unless ($flag &amp; 16);
            } elsif ($flag &amp; 16)
            { $val = 0; }
            else
            {
                $val = TTF_Unpack("s", substr($dat, $fp));
                $fp += 2;
            }
            $self-&gt;{'x'}[$i] = $i == 0 ? $val : $self-&gt;{'x'}[$i - 1] + $val;
        }
#read the y array
        for ($i = 0; $i &lt; $max; $i++)
        {
            $flag = $self-&gt;{'flags'}[$i];
            if ($flag &amp; 4)
            {
                $val = unpack("C", substr($dat, $fp++));
                $val = -$val unless ($flag &amp; 32);
            } elsif ($flag &amp; 32)
            { $val = 0; }
            else
            {
                $val = TTF_Unpack("s", substr($dat, $fp));
                $fp += 2;
            }
            $self-&gt;{'y'}[$i] = $i == 0 ? $val : $self-&gt;{'y'}[$i - 1] + $val;
        }
    }
    
# compound glyph
    elsif ($num &lt; 0)
    {
        $flag = 1 &lt;&lt; 5;             # cheat to get the loop going
        for ($i = 0; $flag &amp; 32; $i++)
        {
            ($flag, $self-&gt;{'comps'}[$i]{'glyph'}) = unpack("n2", substr($dat, $fp));
            $fp += 4;
            $self-&gt;{'comps'}[$i]{'flag'} = $flag;
            if ($flag &amp; 1)              # ARGS1_AND_2_ARE_WORDS
            {
                $self-&gt;{'comps'}[$i]{'args'} = [TTF_Unpack("s2", substr($dat, $fp))];
                $fp += 4;
            } else
            {
                $self-&gt;{'comps'}[$i]{'args'} = [unpack("c2", substr($dat, $fp))];
                $fp += 2;
            }
            
            if ($flag &amp; 8)
            {
                $val = TTF_Unpack("F", substr($dat, $fp));
                $fp += 2;
                $self-&gt;{'comps'}[$i]{'scale'} = [$val, 0, 0, $val];
            } elsif ($flag &amp; 64)
            {
                ($val, $val1) = TTF_Unpack("F2", substr($dat, $fp));
                $fp += 4;
                $self-&gt;{'comps'}[$i]{'scale'} = [$val, 0, 0, $val1];
            } elsif ($flag &amp; 128)
            {
                $self-&gt;{'comps'}[$i]{'scale'} = [TTF_Unpack("F4", substr($dat, $fp))];
                $fp += 8;
            }
            $self-&gt;{'metric'} = $i if ($flag &amp; 512);
        }
        $self-&gt;{'numPoints'} = $i;
        if ($flag &amp; 256)            # HAVE_INSTRUCTIONS
        {
            $self-&gt;{'instLen'} = unpack("n", substr($dat, $fp));
            $self-&gt;{'hints'} = substr($dat, $fp + 2, $self-&gt;{'instLen'});
            $fp += 2 + $self-&gt;{'instLen'};
        }
    }
    return undef if ($fp &gt; length($dat));
    $self-&gt;{' read'} = 2;
    $self;
}


=head2 $g-&gt;out($fh)

Writes the glyph data to outfile

=cut

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

    $self-&gt;read unless $self-&gt;{' read'};
    $self-&gt;update if $self-&gt;{' isDirty'};
    $fh-&gt;print($self-&gt;{' DAT'});
    $self-&gt;{' OUTLEN'} = length($self-&gt;{' DAT'});
    $self;
}


=head2 $g-&gt;out_xml($context, $depth)

Outputs an XML description of the glyph

=cut

sub out_xml
{
    my ($self, $context, $depth) = @_;
    my ($addr) = ($self =~ m/\((.+)\)$/o);
    my ($k, $ndepth);

    if ($context-&gt;{'addresses'}{$addr})
    {
        $context-&gt;{'fh'}-&gt;printf("%s&lt;glyph gid='%s' id_ref='%s'/&gt;\n", $depth, $context-&gt;{'gid'}, $addr);
        return $self;
    }
    else
    {
        $context-&gt;{'fh'}-&gt;printf("%s&lt;glyph gid='%s' id='%s'&gt;\n", $depth, $context-&gt;{'gid'}, $addr);
    }
    
    $ndepth = $depth . $context-&gt;{'indent'};
    $self-&gt;read_dat;
    foreach $k (sort grep {$_ !~ m/^\s/o} keys %{$self})
    {
        $self-&gt;XML_element($context, $ndepth, $k, $self-&gt;{$k});
    }
    $context-&gt;{'fh'}-&gt;print("$depth&lt;/glyph&gt;\n");
    delete $context-&gt;{'done_points'};
    $self;
}
    

sub XML_element
{
    my ($self, $context, $depth, $key, $val) = @_;
    my ($fh) = $context-&gt;{'fh'};
    my ($dind) = $depth . $context-&gt;{'indent'};
    my ($i);
    
    if ($self-&gt;{'numberOfContours'} &gt;= 0 &amp;&amp; ($key eq 'x' || $key eq 'y' || $key eq 'flags'))
    {
        return $self if ($context-&gt;{'done_points'});
        $context-&gt;{'done_points'} = 1;

        $fh-&gt;print("$depth&lt;points&gt;\n");
        for ($i = 0; $i &lt;= $#{$self-&gt;{'flags'}}; $i++)
        { $fh-&gt;printf("%s&lt;point x='%s' y='%s' flags='0x%02X'/&gt;\n", $dind,
                $self-&gt;{'x'}[$i], $self-&gt;{'y'}[$i], $self-&gt;{'flags'}[$i]); }
        $fh-&gt;print("$depth&lt;/points&gt;\n");
    }
    elsif ($key eq 'hints')
    {
        my ($dat);
        $fh-&gt;print("$depth&lt;hints&gt;\n");
#        Font::TTF::Utils::XML_hexdump($context, $depth . $context-&gt;{'indent'}, $self-&gt;{'hints'});
        $dat = Font::TTF::Utils::XML_binhint($self-&gt;{'hints'}) || "";
        $dat =~ s/\n(?!$)/\n$depth$context-&gt;{'indent'}/mg;
        $fh-&gt;print("$depth$context-&gt;{'indent'}$dat");
        $fh-&gt;print("$depth&lt;/hints&gt;\n");
    }
    else
    { return Font::TTF::Table::XML_element(@_); }

    $self;    
}


=head2 $g-&gt;update

Generates a C&lt;$self-&gt;{'DAT'}&gt; from the internal structures, if the data has
been read into structures in the first place. If you are building a glyph
from scratch you will need to set the instance variable C&lt;' read'&gt; to 2 (or
something &gt; 1) for the update to work.

=cut

sub update
{
    my ($self) = @_;
    my ($dat, $loc, $len, $flag, $x, $y, $i, $comp, $num);

    return $self unless (defined $self-&gt;{' read'} &amp;&amp; $self-&gt;{' read'} &gt; 1);
    $self-&gt;update_bbox;
    $self-&gt;{' DAT'} = TTF_Out_Fields($self, \%fields, 10);
    $num = $self-&gt;{'numberOfContours'};
    if ($num &gt; 0)
    {
        $self-&gt;{' DAT'} .= pack("n*", @{$self-&gt;{'endPoints'}});
        $len = $self-&gt;{'instLen'};
        $self-&gt;{' DAT'} .= pack("n", $len);
        $self-&gt;{' DAT'} .= pack("a" . $len, substr($self-&gt;{'hints'}, 0, $len)) if ($len &gt; 0);
        for ($i = 0; $i &lt; $self-&gt;{'numPoints'}; $i++)
        {
            $flag = $self-&gt;{'flags'}[$i] &amp; 1;
            if ($i == 0)
            {
                $x = $self-&gt;{'x'}[$i];
                $y = $self-&gt;{'y'}[$i];
            } else
            {
                $x = $self-&gt;{'x'}[$i] - $self-&gt;{'x'}[$i - 1];
                $y = $self-&gt;{'y'}[$i] - $self-&gt;{'y'}[$i - 1];
            }
            $flag |= 16 if ($x == 0);
            $flag |= 32 if ($y == 0);
            if (($flag &amp; 16) == 0 &amp;&amp; $x &lt; 256 &amp;&amp; $x &gt; -256)
            {
                $flag |= 2;
                $flag |= 16 if ($x &gt;= 0);
            }
            if (($flag &amp; 32) == 0 &amp;&amp; $y &lt; 256 &amp;&amp; $y &gt; -256)
            {
                $flag |= 4;
                $flag |= 32 if ($y &gt;= 0);
            }
            $self-&gt;{' DAT'} .= pack("C", $flag);                    # sorry no repeats
            $self-&gt;{'flags'}[$i] = $flag;
        }
        for ($i = 0; $i &lt; $self-&gt;{'numPoints'}; $i++)
        {
            $flag = $self-&gt;{'flags'}[$i];
            $x = $self-&gt;{'x'}[$i] - (($i == 0) ? 0 : $self-&gt;{'x'}[$i - 1]);
            if (($flag &amp; 18) == 0)
            { $self-&gt;{' DAT'} .= TTF_Pack("s", $x); }
            elsif (($flag &amp; 18) == 18)
            { $self-&gt;{' DAT'} .= pack("C", $x); }
            elsif (($flag &amp; 18) == 2)
            { $self-&gt;{' DAT'} .= pack("C", -$x); }
        }
        for ($i = 0; $i &lt; $self-&gt;{'numPoints'}; $i++)
        {
            $flag = $self-&gt;{'flags'}[$i];
            $y = $self-&gt;{'y'}[$i] - (($i == 0) ? 0 : $self-&gt;{'y'}[$i - 1]);
            if (($flag &amp; 36) == 0)
            { $self-&gt;{' DAT'} .= TTF_Pack("s", $y); }
            elsif (($flag &amp; 36) == 36)
            { $self-&gt;{' DAT'} .= pack("C", $y); }
            elsif (($flag &amp; 36) == 4)
            { $self-&gt;{' DAT'} .= pack("C", -$y); }
        }
    }

    elsif ($num &lt; 0)
    {
        for ($i = 0; $i &lt;= $#{$self-&gt;{'comps'}}; $i++)
        {
            $comp = $self-&gt;{'comps'}[$i];
            $flag = $comp-&gt;{'flag'} &amp; 7158;        # bits 2,10,11,12
            $flag |= 1 unless ($comp-&gt;{'args'}[0] &gt; -129 &amp;&amp; $comp-&gt;{'args'}[0] &lt; 128
                    &amp;&amp; $comp-&gt;{'args'}[1] &gt; -129 &amp;&amp; $comp-&gt;{'args'}[1] &lt; 128);
            if (defined $comp-&gt;{'scale'})
            {
                if ($comp-&gt;{'scale'}[1] == 0 &amp;&amp; $comp-&gt;{'scale'}[2] == 0)
                {
                    if ($comp-&gt;{'scale'}[0] == $comp-&gt;{'scale'}[3])
                    { $flag |= 8 unless ($comp-&gt;{'scale'}[0] == 0
                                    || $comp-&gt;{'scale'}[0] == 1); }
                    else
                    { $flag |= 64; }
                } else
                { $flag |= 128; }
            }
            
            $flag |= 512 if (defined $self-&gt;{'metric'} &amp;&amp; $self-&gt;{'metric'} == $i);
            if ($i == $#{$self-&gt;{'comps'}})
            { $flag |= 256 if (defined $self-&gt;{'instLen'} &amp;&amp; $self-&gt;{'instLen'} &gt; 0); }
            else
            { $flag |= 32; }
            
            $self-&gt;{' DAT'} .= pack("n", $flag);
            $self-&gt;{' DAT'} .= pack("n", $comp-&gt;{'glyph'});
            $comp-&gt;{'flag'} = $flag;

            if ($flag &amp; 1)
            { $self-&gt;{' DAT'} .= TTF_Pack("s2", @{$comp-&gt;{'args'}}); }
            else
            { $self-&gt;{' DAT'} .= pack("CC", @{$comp-&gt;{'args'}}); }

            if ($flag &amp; 8)
            { $self-&gt;{' DAT'} .= TTF_Pack("F", $comp-&gt;{'scale'}[0]); }
            elsif ($flag &amp; 64)
            { $self-&gt;{' DAT'} .= TTF_Pack("F2", $comp-&gt;{'scale'}[0], $comp-&gt;{'scale'}[3]); }
            elsif ($flag &amp; 128)
            { $self-&gt;{' DAT'} .= TTF_Pack("F4", @{$comp-&gt;{'scale'}}); }
        }
        if (defined $self-&gt;{'instLen'} &amp;&amp; $self-&gt;{'instLen'} &gt; 0)
        {
            $len = $self-&gt;{'instLen'};
            $self-&gt;{' DAT'} .= pack("n", $len);
            $self-&gt;{' DAT'} .= pack("a" . $len, substr($self-&gt;{'hints'}, 0, $len));
        }
    }
    my ($olen) = length($self-&gt;{' DAT'});
    $self-&gt;{' DAT'} .= ("\000") x (4 - ($olen &amp; 3)) if ($olen &amp; 3);
    $self-&gt;{' OUTLEN'} = length($self-&gt;{' DAT'});
    $self-&gt;{' read'} = 2;           # changed from 1 to 2 so we don't read_dat() again
# we leave numPoints and instLen since maxp stats use this
    $self;
}


=head2 $g-&gt;update_bbox

Updates the bounding box for this glyph according to the points in the glyph

=cut

sub update_bbox
{
    my ($self) = @_;
    my ($num, $maxx, $minx, $maxy, $miny, $i, $comp, $x, $y, $compg);

    return $self unless $self-&gt;{' read'} &gt; 1;       # only if read_dat done
    $miny = $minx = 65537; $maxx = $maxy = -65537;
    $num = $self-&gt;{'numberOfContours'};
    if ($num &gt; 0)
    {
        for ($i = 0; $i &lt; $self-&gt;{'numPoints'}; $i++)
        {
            ($x, $y) = ($self-&gt;{'x'}[$i], $self-&gt;{'y'}[$i]);

            $maxx = $x if ($x &gt; $maxx);
            $minx = $x if ($x &lt; $minx);
            $maxy = $y if ($y &gt; $maxy);
            $miny = $y if ($y &lt; $miny);
        }
    }

    elsif ($num &lt; 0)
    {
        foreach $comp (@{$self-&gt;{'comps'}})
        {
            my ($gnx, $gny, $gxx, $gxy);
            my ($sxx, $sxy, $syx, $syy);
            
            my $otherg = $self-&gt;{' PARENT'}{'loca'}{'glyphs'}[$comp-&gt;{'glyph'}];
            # work around bad fonts: see documentation for 'comps' above
            next unless (defined $otherg);
            $compg = $otherg-&gt;read-&gt;update_bbox;
            ($gnx, $gny, $gxx, $gxy) = @{$compg}{'xMin', 'yMin', 'xMax', 'yMax'};
            if (defined $comp-&gt;{'scale'})
            {
                ($sxx, $sxy, $syx, $syy) = @{$comp-&gt;{'scale'}};
                ($gnx, $gny, $gxx, $gxy) = ($gnx*$sxx+$gny*$syx + $comp-&gt;{'args'}[0],
                                            $gnx*$sxy+$gny*$syy + $comp-&gt;{'args'}[1],
                                            $gxx*$sxx+$gxy*$syx + $comp-&gt;{'args'}[0],
                                            $gxx*$sxy+$gxy*$syy + $comp-&gt;{'args'}[1]);
            } elsif ($comp-&gt;{'args'}[0] || $comp-&gt;{'args'}[1])
            {
                $gnx += $comp-&gt;{'args'}[0];
                $gny += $comp-&gt;{'args'}[1];
                $gxx += $comp-&gt;{'args'}[0];
                $gxy += $comp-&gt;{'args'}[1];
            }
            ($gnx, $gxx) = ($gxx, $gnx) if $gnx &gt; $gxx;
            ($gny, $gxy) = ($gxy, $gny) if $gny &gt; $gxy;
            $maxx = $gxx if $gxx &gt; $maxx;
            $minx = $gnx if $gnx &lt; $minx;
            $maxy = $gxy if $gxy &gt; $maxy;
            $miny = $gny if $gny &lt; $miny;
        }
    }
    $self-&gt;{'xMax'} = $maxx;
    $self-&gt;{'xMin'} = $minx;
    $self-&gt;{'yMax'} = $maxy;
    $self-&gt;{'yMin'} = $miny;
    $self;
}

            
=head2 $g-&gt;maxInfo

Returns lots of information about a glyph so that the C&lt;maxp&gt; table can update
itself. Returns array containing contributions of this glyph to maxPoints, maxContours, 
maxCompositePoints, maxCompositeContours, maxSizeOfInstructions, maxComponentElements, 
and maxComponentDepth.

=cut

sub maxInfo
{
    my ($self) = @_;
    my (@res, $i, @n);

    $self-&gt;read_dat;            # make sure we've read some data
    $res[4] = length($self-&gt;{'hints'}) if defined $self-&gt;{'hints'};
    $res[6] = 1;
    if ($self-&gt;{'numberOfContours'} &gt; 0)
    {
        $res[0] = $self-&gt;{'numPoints'};
        $res[1] = $self-&gt;{'numberOfContours'};
    } elsif ($self-&gt;{'numberOfContours'} &lt; 0)
    {
        for ($i = 0; $i &lt;= $#{$self-&gt;{'comps'}}; $i++)
        {
            my $otherg = 
                $self-&gt;{' PARENT'}{'loca'}{'glyphs'}
                    [$self-&gt;{'comps'}[$i]{'glyph'}];
            
            # work around bad fonts: see documentation for 'comps' above
            next unless (defined $otherg );
            
            @n = $otherg-&gt;maxInfo;

            $res[2] += $n[2] == 0 ? $n[0] : $n[2];
            $res[3] += $n[3] == 0 ? $n[1] : $n[3];
            $res[5]++;
            $res[6] = $n[6] + 1 if ($n[6] &gt;= $res[6]);
        }
    }
    @res;
}

=head2 $g-&gt;empty

Empties the glyph of all information to the level of not having been read.
Useful for saving memory in apps with many glyphs being read

=cut

sub empty
{
    my ($self) = @_;
    my (%keep) = map {(" $_" =&gt; 1)} ('LOC', 'OUTLOC', 'PARENT', 'INFILE', 'BASE',
                                'OUTLEN', 'LEN');
    map {delete $self-&gt;{$_} unless $keep{$_}} keys %$self;
    
    $self;
}


=head2 $g-&gt;get_points

This method creates point information for a compound glyph. The information is
stored in the same place as if the glyph was not a compound, but since
numberOfContours is negative, the glyph is still marked as being a compound

=cut

sub get_points
{
    my ($self) = @_;
    my ($comp, $compg, $nump, $e, $i);

    $self-&gt;read_dat;
    return undef unless ($self-&gt;{'numberOfContours'} &lt; 0);

    foreach $comp (@{$self-&gt;{'comps'}})
    {
        $compg = $self-&gt;{' PARENT'}{'loca'}{'glyphs'}[$comp-&gt;{'glyph'}];
        # work around bad fonts: see documentation for 'comps' above
        next unless (defined $compg );
        $compg-&gt;get_points;

        for ($i = 0; $i &lt; $compg-&gt;{'numPoints'}; $i++)
        {
            my ($x, $y) = ($compg-&gt;{'x'}[$i], $compg-&gt;{'y'}[$i]);
            if (defined $comp-&gt;{'scale'})
            {
                ($x, $y) = ($x * $comp-&gt;{'scale'}[0] + $y * $comp-&gt;{'scale'}[2],
                            $x * $comp-&gt;{'scale'}[1] + $y * $comp-&gt;{'scale'}[3]);
            }
            if (defined $comp-&gt;{'args'})
            { ($x, $y) = ($x + $comp-&gt;{'args'}[0], $y + $comp-&gt;{'args'}[1]); }
            push (@{$self-&gt;{'x'}}, $x);
            push (@{$self-&gt;{'y'}}, $y);
            push (@{$self-&gt;{'flags'}}, $compg-&gt;{'flags'}[$i]);
        }
        foreach $e (@{$compg-&gt;{'endPoints'}})
        { push (@{$self-&gt;{'endPoints'}}, $e + $nump); }
        $nump += $compg-&gt;{'numPoints'};
    }
    $self-&gt;{'numPoints'} = $nump;
    $self;
}


=head2 $g-&gt;get_refs

Returns an array of all the glyph ids that are used to make up this glyph. That
is all the compounds and their references and so on. If this glyph is not a
compound, then returns an empty array.

Please note the warning about bad fonts that reference nonexistant glyphs
under INSTANCE VARIABLES above.  This function will not attempt to 
filter out nonexistant glyph numbers.

=cut

sub get_refs
{
    my ($self) = @_;
    my (@res, $g);

    $self-&gt;read_dat;
    return unless ($self-&gt;{'numberOfContours'} &lt; 0);
    foreach $g (@{$self-&gt;{'comps'}})
    {
        push (@res, $g-&gt;{'glyph'});
        my $otherg = $self-&gt;{' PARENT'}{'loca'}{'glyphs'}[$g-&gt;{'glyph'}];
        # work around bad fonts: see documentation for 'comps' above
        next unless (defined $otherg);
        my @list = $otherg-&gt;get_refs;
        push(@res, @list);
    }
    return @res;
}

1;

=head1 BUGS

=over 4

=item *

The instance variables used here are somewhat clunky and inconsistent with
the other tables.

=item *

C&lt;update&gt; doesn't re-calculate the bounding box or C&lt;numberOfContours&gt;.

=back

=head1 AUTHOR

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

=cut
</pre></body></html>