Font-TTF

 view release on metacpan or  search on metacpan

lib/Font/TTF/Ttopen.pm  view on Meta::CPAN

}

=head2 $t->maxContext

Returns the length of the longest opentype rule in this table.

=cut

sub maxContext
{
    my ($self) = @_;
    
    # Make sure table is read
    $self->read;

    # Calculate my contribution to OS/2 usMaxContext
    
    my ($maxcontext, $l, $s, $r, $m);
   
    for $l (@{$self->{'LOOKUP'}})        # Examine each lookup
    {
        for $s (@{$l->{'SUB'}})         # Multiple possible subtables for this lookup
        {
            for $r (@{$s->{'RULES'}})   # One ruleset for each covered glyph
            {
                for $m (@{$r})          # Multiple possible matches for this covered glyph 
                {
                    my $lgt;
                    $lgt++ if exists $s->{'COVERAGE'};  # Count 1 for the coverage table if it exists
                    for (qw(MATCH POST))                # only Input and Lookahead sequences count (Lookbehind doesn't) -- see OT spec.
                    {
                        $lgt += @{$m->{$_}} if exists $m->{$_};
                    }
                    $maxcontext = $lgt if $lgt > $maxcontext;
                }
            }
            
        }
    }
    
    $maxcontext;    
}    


=head2 $t->update

Perform various housekeeping items:

For all lookups, set/clear 0x0010 bit of flag words based on 'FILTER' value.

Sort COVERAGE table and RULES for all lookups.

Unless $t->{' PARENT'}{' noharmony'} is true, update will make sure that GPOS and GSUB include 
the same scripts and languages. Any added scripts and languages will have empty feature sets.

=cut

# Assumes we are called on both GSUB and GPOS. So simply ADDS scripts and languages to $self that it finds
# in the other table.

sub update
{
    my ($self) = @_;
    
    return undef unless ($self->SUPER::update);
    
    if (defined ($self->{'LOOKUP'}))
    {
            
        # make flag word agree with mark filter setting:
        for my $l (@{$self->{'LOOKUP'}})
        {
            if (defined $l->{'FILTER'})
            { $l->{'FLAG'} |= 0x0010; }
            else
            { $l->{'FLAG'} &= ~0x0010; }
        }
        
        unless ($Font::TTF::Coverage::dontsort)
        {
            # Sort coverage tables and rules of all lookups by glyphID
            # The lookup types that need to be sorted are:
            #    GSUB: 1.2 2 3 4 5.1 6.1 8    (However GSUB type 8 lookups are not yet supported by Font::TTF)
            #    GPOS: 1.2 2.1 3 4 5 6 7.1 8.1
            
            for my $l (@{$self->{'LOOKUP'}})
            {
                next unless defined $l->{'SUB'};
                for my $sub (@{$l->{'SUB'}})
                {
                    if (defined $sub->{'COVERAGE'} and $sub->{'COVERAGE'}{'cover'} and !$sub->{'COVERAGE'}{'dontsort'})
                    {
                        # OK! Found a lookup with coverage table:
                        my @map = $sub->{'COVERAGE'}->sort();
                        if (defined $sub->{'RULES'} and ($sub->{'MATCH_TYPE'} =~ /g/ or $sub->{'ACTION_TYPE'} =~ /[gvea]/))
                        {
                            # And also a RULES table which now needs to be re-sorted
                            my $newrules = [];
                            foreach (0 .. $#map)
                            { push @{$newrules}, $sub->{'RULES'}[$map[$_]]; }
                            $sub->{'RULES'} = $newrules;
                        }
                    }
                        
                    # Special case for Mark positioning -- need to also sort the MarkArray
                    if (exists($sub->{'MARKS'}) and ref($sub->{'MATCH'}[0]) =~ /Cover/ and $sub->{'MATCH'}[0]{'cover'} and !$sub->{'MATCH'}[0]{'dontsort'})
                    {
                        my @map = $sub->{'MATCH'}[0]->sort();
                        my $newmarks = [];
                        foreach (0 .. $#map)
                        { push @{$newmarks}, $sub->{'MARKS'}[$map[$_]]; }
                        $sub->{'MARKS'} = $newmarks;
                    }
                }
            }
        }
    }

    # Enforce script/lang congruence unless asked not to:
    return $self if $self->{' PARENT'}{' noharmony'};



( run in 0.756 second using v1.01-cache-2.11-cpan-817d5f8af8b )