Font-TTF
view release on metacpan or search on metacpan
lib/Font/TTF/OS_2.pm view on Meta::CPAN
{
my ($self) = shift;
my ($context, $depth, $key, $value) = @_;
my ($fh) = $context->{'fh'};
if ($key =~ m/^ul(?:Unicode|CodePage)Range\d$/o)
{ $fh->printf("%s<%s>%08X</%s>\n", $depth, $key, $value, $key); }
elsif ($key eq 'achVendID')
{ $fh->printf("%s<%s name='%s'/>\n", $depth, $key, pack('N', $value)); }
else
{ return $self->SUPER::XML_element(@_); }
$self;
}
=head2 $t->XML_end($context, $tag, %attrs)
Now handle them on the way back in
=cut
sub XML_end
{
my ($self) = shift;
my ($context, $tag, %attrs) = @_;
if ($tag =~ m/^ul(?:Unicode|CodePage)Range\d$/o)
{ return hex($context->{'text'}); }
elsif ($tag eq 'achVendID')
{ return unpack('N', $attrs{'name'}); }
else
{ return $self->SUPER::XML_end(@_); }
}
=head2 $t->minsize()
Returns the minimum size this table can be. If it is smaller than this, then the table
must be bad and should be deleted or whatever.
=cut
sub minsize
{
return 78;
}
=head2 $t->update
Updates the OS/2 table by getting information from other sources:
Updates the C<firstChar> and C<lastChar> values based on the MS table in the
cmap.
Updates the sTypoAscender, sTypoDescender & sTypoLineGap to be the same values
as Ascender, Descender and Linegap from the hhea table (assuming it is dirty)
and also sets usWinAscent to be the sum of Ascender+Linegap and usWinDescent to
be the negative of Descender.
=cut
sub update
{
my ($self) = @_;
my ($map, @keys, $table, $i, $avg, $hmtx);
return undef unless ($self->SUPER::update);
$self->{' PARENT'}{'cmap'}->update;
$map = $self->{' PARENT'}{'cmap'}->find_ms || return undef;
$hmtx = $self->{' PARENT'}{'hmtx'}->read;
@keys = sort {$a <=> $b} grep {$_ < 0x10000} keys %{$map->{'val'}};
$self->{'usFirstCharIndex'} = $keys[0];
$self->{'usLastCharIndex'} = $keys[-1];
$table = $self->{' PARENT'}{'hhea'}->read;
# try any way we can to get some real numbers passed around!
if (($self->{'fsSelection'} & 128) != 0)
{
# assume the user knows what they are doing and has sensible values already
}
elsif ($table->{'Ascender'} != 0 || $table->{'Descender'} != 0)
{
$self->{'sTypoAscender'} = $table->{'Ascender'};
$self->{'sTypoDescender'} = $table->{'Descender'};
$self->{'sTypoLineGap'} = $table->{'LineGap'};
$self->{'usWinAscent'} = $self->{'sTypoAscender'} + $self->{'sTypoLineGap'};
$self->{'usWinDescent'} = -$self->{'sTypoDescender'};
}
elsif ($self->{'sTypoAscender'} != 0 || $self->{'sTypoDescender'} != 0)
{
$table->{'Ascender'} = $self->{'sTypoAscender'};
$table->{'Descender'} = $self->{'sTypoDescender'};
$table->{'LineGap'} = $self->{'sTypoLineGap'};
$self->{'usWinAscent'} = $self->{'sTypoAscender'} + $self->{'sTypoLineGap'};
$self->{'usWinDescent'} = -$self->{'sTypoDescender'};
}
elsif ($self->{'usWinAscent'} != 0 || $self->{'usWinDescent'} != 0)
{
$self->{'sTypoAscender'} = $table->{'Ascender'} = $self->{'usWinAscent'};
$self->{'sTypoDescender'} = $table->{'Descender'} = -$self->{'usWinDescent'};
$self->{'sTypoLineGap'} = $table->{'LineGap'} = 0;
}
if ($self->{'Version'} < 3)
{
for ($i = 0; $i < 26; $i++)
{ $avg += $hmtx->{'advance'}[$map->{'val'}{$i + 0x0061}] * $weights[$i]; }
$avg += $hmtx->{'advance'}[$map->{'val'}{0x0020}] * $weights[-1];
$self->{'xAvgCharWidth'} = $avg / 1000;
}
elsif ($self->{'Version'} > 2)
{
$i = 0; $avg = 0;
foreach (@{$hmtx->{'advance'}})
{
next unless ($_);
$i++;
$avg += $_;
( run in 0.607 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )