Font-TTF

 view release on metacpan or  search on metacpan

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

        } else
        {
            $fh->seek($s->{' outloc'} + 4, 0);
            $fh->print(pack("N", $loc - $s->{' outloc'}));
        }
        $fh->seek($base_loc + 8 + ($i << 3), 0);
        $fh->print(pack("N", $s->{' outloc'} - $base_loc));
        $fh->seek($loc, 0);
    }
    $self;
}


=head2 $t->XML_element($context, $depth, $name, $val)

Outputs the elements of the cmap in XML. We only need to process val here

=cut

sub XML_element
{
    my ($self, $context, $depth, $k, $val) = @_;
    my ($fh) = $context->{'fh'};
    my ($i);

    return $self if ($k eq 'LOC');
    return $self->SUPER::XML_element($context, $depth, $k, $val) unless ($k eq 'val');

    $fh->print("$depth<mappings>\n");
    foreach $i (sort {$a <=> $b} keys %{$val})
    { $fh->printf("%s<map code='%04X' glyph='%s'/>\n", $depth . $context->{'indent'}, $i, $val->{$i}); }
    $fh->print("$depth</mappings>\n");
    $self;
}


=head2 $t->minsize()

Returns the minimum size this table can be in bytes. If it is smaller than this, then the table
must be bad and should be deleted or whatever.

=cut

sub minsize
{
    return 4;
}


=head2 $t->update

Tidies the cmap table.

Removes MS Fmt12 cmap if it is no longer needed.

Removes from all cmaps any codepoint that map to GID=0. Note that such entries will
be re-introduced as necessary depending on the cmap format.

=cut

sub update
{
    my ($self) = @_;
    my ($max, $code, $gid, @keep);
    
    return undef unless ($self->SUPER::update);

    foreach my $s (@{$self->{'Tables'}})
    {
        $max = 0;
        while (($code, $gid) = each %{$s->{'val'}})
        {
            if ($gid)
            {
                # remember max USV
                $max = $code if $max < $code;
            }
            else
            {
                # Remove unneeded key
                delete $s->{'val'}{$code};  # nb: this is a safe delete according to perldoc perlfunc.
            }
        }
        push @keep, $s unless $s->{'Platform'} == 3 && $s->{'Encoding'} == 10 && $s->{'Format'} == 12 && $max <= 0xFFFF;
    }
    
    $self->{'Tables'} = [ @keep ];  
    
    delete $self->{' mstable'};     # Force rediscovery of this.
    
    $self;
}

=head2 @map = $t->reverse(%opt)

Returns a reverse map of the Unicode cmap. I.e. given a glyph gives the Unicode value for it. Options are:

=over 4

=item tnum

Table number to use rather than the default Unicode table

=item array

Returns each element of reverse as an array since a glyph may be mapped by more
than one Unicode value. The arrays are unsorted. Otherwise store any one unicode value for a glyph.

=back

=cut

sub reverse
{
    my ($self, %opt) = @_;
    my ($table) = defined $opt{'tnum'} ? $self->{'Tables'}[$opt{'tnum'}] : $self->find_ms;
    my (@res, $code, $gid);

    while (($code, $gid) = each(%{$table->{'val'}}))
    {
        if ($opt{'array'})



( run in 0.693 second using v1.01-cache-2.11-cpan-140bd7fdf52 )