Font-TTF
view release on metacpan or search on metacpan
lib/Font/TTF/Hmtx.pm view on Meta::CPAN
here. Returns undef if the table has not been read.
=cut
sub numMetrics
{
my ($self) = @_;
my ($numg) = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
my ($i);
return undef unless $self->{' read'};
for ($i = $numg - 2; $i >= 0; $i--)
{ last if ($self->{'advance'}[$i] != $self->{'advance'}[$i + 1]); }
return $i + 2;
}
=head2 $t->out($fh)
Writes the metrics to a TTF file. Assumes that the C<hhea> has updated the
numHMetrics from here
=cut
sub out
{
my ($self, $fh) = @_;
my ($numg) = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
my ($numh) = $self->{' PARENT'}{'hhea'}->read->{'numberOfHMetrics'};
$self->_out($fh, $numg, $numh, "advance", "lsb");
}
sub _out
{
my ($self, $fh, $numg, $numh, $tAdv, $tLsb) = @_;
my ($i, $lsb);
return $self->SUPER::out($fh) unless ($self->{' read'});
for ($i = 0; $i < $numg; $i++)
{
$lsb = $self->{$tLsb}[$i];
$lsb += 65536 if $lsb < 0;
if ($i >= $numh)
{ $fh->print(pack("n", $lsb)); }
else
{ $fh->print(pack("n2", $self->{$tAdv}[$i], $lsb)); }
}
$self;
}
=head2 $t->update
Updates the lsb values from the xMin from the each glyph
=cut
sub update
{
my ($self) = @_;
my ($numg) = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
my ($i);
return undef unless ($self->SUPER::update);
# lsb & xMin must always be the same, regardless of any flags!
# return $self unless ($self->{' PARENT'}{'head'}{'flags'} & 2); # lsb & xMin the same
$self->{' PARENT'}{'loca'}->update;
for ($i = 0; $i < $numg; $i++)
{
my ($g) = $self->{' PARENT'}{'loca'}{'glyphs'}[$i];
if ($g)
{ $self->{'lsb'}[$i] = $g->read->update_bbox->{'xMin'}; }
else
{ $self->{'lsb'}[$i] = 0; }
}
$self->{' PARENT'}{'head'}{'flags'} |= 2;
$self;
}
=head2 $t->out_xml($context, $depth)
Outputs the table in XML
=cut
sub out_xml
{
my ($self, $context, $depth) = @_;
my ($fh) = $context->{'fh'};
my ($numg) = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
my ($addr) = ($self =~ m/\((.+)\)$/o);
my ($i);
if ($context->{'addresses'}{$addr})
{
$fh->printf("%s<%s id_ref='%s'/>\n", $depth, $context->{'name'}, $addr);
return $self;
}
else
{ $fh->printf("%s<%s id='%s'>\n", $depth, $context->{'name'}, $addr); }
$self->read;
for ($i = 0; $i < $numg; $i++)
{ $fh->print("$depth$context->{'indent'}<width gid='$i' adv='$self->{'advance'}[$i]' lsb='$self->{'lsb'}[$i]'/>\n"); }
$fh->print("$depth</$context->{'name'}>\n");
$self;
}
1;
=head1 BUGS
None known
( run in 1.927 second using v1.01-cache-2.11-cpan-b9db842bd85 )