/usr/share/perl5/Font/TTF/Hmtx.pm is in libfont-ttf-perl 1.04-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | package Font::TTF::Hmtx;
=head1 NAME
Font::TTF::Hmtx - Horizontal Metrics
=head1 DESCRIPTION
Contains the advance width and left side bearing for each glyph. Given the
compressability of the data onto disk, this table uses information from
other tables, and thus must do part of its output during the output of
other tables
=head1 INSTANCE VARIABLES
The horizontal metrics are kept in two arrays by glyph id. The variable names
do not start with a space
=over 4
=item advance
An array containing the advance width for each glyph
=item lsb
An array containing the left side bearing for each glyph
=back
=head1 METHODS
=cut
use strict;
use vars qw(@ISA);
require Font::TTF::Table;
@ISA = qw(Font::TTF::Table);
=head2 $t->read
Reads the horizontal metrics from the TTF file into memory
=cut
sub read
{
my ($self) = @_;
my ($numh, $numg);
$numh = $self->{' PARENT'}{'hhea'}->read->{'numberOfHMetrics'};
$numg = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
$self->_read($numg, $numh, "advance", "lsb");
}
sub _read
{
my ($self, $numg, $numh, $tAdv, $tLsb) = @_;
$self->SUPER::read or return $self;
my ($fh) = $self->{' INFILE'};
my ($i, $dat);
for ($i = 0; $i < $numh; $i++)
{
$fh->read($dat, 4);
($self->{$tAdv}[$i], $self->{$tLsb}[$i]) = unpack("nn", $dat);
$self->{$tLsb}[$i] -= 65536 if ($self->{$tLsb}[$i] >= 32768);
}
$i--;
while (++$i < $numg)
{
$fh->read($dat, 2);
$self->{$tAdv}[$i] = $self->{$tAdv}[$numh - 1];
$self->{$tLsb}[$i] = unpack("n", $dat);
$self->{$tLsb}[$i] -= 65536 if ($self->{$tLsb}[$i] >= 32768);
}
$self;
}
=head2 $t->numMetrics
Calculates again the number of long metrics required to store the information
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
=head1 AUTHOR
Martin Hosken L<Martin_Hosken@sil.org>.
=head1 LICENSING
Copyright (c) 1998-2013, SIL International (http://www.sil.org)
This module is released under the terms of the Artistic License 2.0.
For details, see the full text of the license in the file LICENSE.
=cut
|