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

=head1 NAME

Font::TTF::Maxp - Maximum Profile table in a font

=head1 DESCRIPTION

A collection of useful instance variables following the TTF standard. Probably
the most used being C&lt;numGlyphs&gt;. Note that this particular value is
foundational and should be kept up to date by the application, it is not updated
by C&lt;update&gt;.

Handles table versions 0.5, 1.0

=head1 INSTANCE VARIABLES

No others beyond those specified in the standard:

    numGlyphs
    maxPoints
    maxContours
    maxCompositePoints
    maxCompositeContours
    maxZones
    maxTwilightPoints
    maxStorage
    maxFunctionDefs
    maxInstructionDefs
    maxStackElements
    maxSizeOfInstructions
    maxComponentElements
    maxComponentDepth


=head1 METHODS

=cut

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

@ISA = qw(Font::TTF::Table);
@field_info = (
    'numGlyphs' =&gt; 'S',
    'maxPoints' =&gt; 'S',
    'maxContours' =&gt; 'S',
    'maxCompositePoints' =&gt; 'S',
    'maxCompositeContours' =&gt; 'S',
    'maxZones' =&gt; 'S',
    'maxTwilightPoints' =&gt; 'S',
    'maxStorage' =&gt; 'S',
    'maxFunctionDefs' =&gt; 'S',
    'maxInstructionDefs' =&gt; 'S',
    'maxStackElements' =&gt; 'S',
    'maxSizeOfInstructions' =&gt; 'S',
    'maxComponentElements' =&gt; 'S',
    'maxComponentDepth' =&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;
    }
}


=head2 $t-&gt;read

Reads the table into memory

=cut

sub read
{
    my ($self) = @_;
    my ($dat);

    $self-&gt;SUPER::read or return $self;

    init unless defined $fields{'numGlyphs'};    # any key would do
    $self-&gt;{' INFILE'}-&gt;read($dat, 4);
    $self-&gt;{'version'} = TTF_Unpack("v", $dat);

    if ($self-&gt;{'version'} == 0.5)
    {
        $self-&gt;{' INFILE'}-&gt;read($dat, 2);
        $self-&gt;{'numGlyphs'} = unpack("n", $dat);
    } else
    {
        $self-&gt;{' INFILE'}-&gt;read($dat, 28);
        TTF_Read_Fields($self, $dat, \%fields);
    }
    $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'};
    $fh-&gt;print(TTF_Pack("v", $self-&gt;{'version'}));
    
    if ($self-&gt;{'version'} == 0.5)
    { $fh-&gt;print(pack("n", $self-&gt;{'numGlyphs'})); }
    else
    { $fh-&gt;print(TTF_Out_Fields($self, \%fields, 28)); }
    $self;
}


=head2 $t-&gt;update

Calculates all the maximum values for a font based on the glyphs in the font.
Only those fields which require hinting code interpretation are ignored and
left as they were read.

=cut

sub update
{
    my ($self) = @_;
    my ($i, $num, @n, @m, $j);
    my (@name) = qw(maxPoints maxContours maxCompositePoints maxCompositeContours
                    maxSizeOfInstructions maxComponentElements maxComponentDepth);

    return undef unless ($self-&gt;SUPER::update);
    return undef if ($self-&gt;{'version'} == 0.5);        # only got numGlyphs
    return undef unless (defined $self-&gt;{' PARENT'}{'loca'});
    $self-&gt;{' PARENT'}{'loca'}-&gt;update;
    $num = $self-&gt;{'numGlyphs'};

    for ($i = 0; $i &lt; $num; $i++)
    {
        my ($g) = $self-&gt;{' PARENT'}{'loca'}{'glyphs'}[$i] || next;

        @n = $g-&gt;maxInfo;

        for ($j = 0; $j &lt;= $#n; $j++)
        { $m[$j] = $n[$j] if $n[$j] &gt; $m[$j]; }
    }

    foreach ('prep', 'fpgm')
    { $m[4] = length($self-&gt;{' PARENT'}{$_}{' dat'})
            if (defined $self-&gt;{' PARENT'}{$_} 
                &amp;&amp; length($self-&gt;{' PARENT'}{$_}{' dat'}) &gt; $m[4]);
    }

    for ($j = 0; $j &lt;= $#name; $j++)
    { $self-&gt;{$name[$j]} = $m[$j]; }
    $self;
}
1;


=head1 BUGS

None known

=head1 AUTHOR

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

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