1 package Font::TTF::Hhea;
5 Font::TTF::Hhea - Horizontal Header table
9 This is a simplte table with just standards specified instance variables
11 =head1 INSTANCE VARIABLES
32 use vars qw(@ISA %fields @field_info);
34 require Font::TTF::Table;
37 @ISA = qw(Font::TTF::Table);
43 'advanceWidthMax' => 'S',
44 'minLeftSideBearing' => 's',
45 'minRightSideBearing' => 's',
47 'caretSlopeRise' => 's',
48 'caretSlopeRun' => 's',
49 'metricDataFormat' => '+10s',
50 'numberOfHMetrics' => 'S');
55 for ($i = 0; $i < $#field_info; $i += 2)
57 ($k, $v, $c) = TTF_Init_Fields($field_info[$i], $c, $field_info[$i + 1]);
58 next unless defined $k && $k ne "";
66 Reads the table into memory as instance variables
75 $self->SUPER::read or return $self;
76 init unless defined $fields{'Ascender'};
77 $self->{' INFILE'}->read($dat, 36);
79 TTF_Read_Fields($self, $dat, \%fields);
86 Writes the table to a file either from memory or by copying.
94 return $self->SUPER::out($fh) unless $self->{' read'};
96 $self->{'numberOfHMetrics'} = $self->{' PARENT'}{'hmtx'}->numMetrics || $self->{'numberOfHMetrics'};
97 $fh->print(TTF_Out_Fields($self, \%fields, 36));
104 Updates various parameters in the hhea table from the hmtx table.
111 my ($hmtx) = $self->{' PARENT'}{'hmtx'};
114 my ($i, $maw, $mlsb, $mrsb, $mext, $aw, $lsb, $ext);
116 return undef unless ($self->SUPER::update);
117 return undef unless (defined $hmtx && defined $self->{' PARENT'}{'loca'});
120 $self->{' PARENT'}{'loca'}->read->update;
121 $glyphs = $self->{' PARENT'}{'loca'}{'glyphs'};
122 $num = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
124 for ($i = 0; $i < $num; $i++)
126 $aw = $hmtx->{'advance'}[$i];
127 $lsb = $hmtx->{'lsb'}[$i];
128 if (defined $glyphs->[$i])
129 { $ext = $lsb + $glyphs->[$i]->read->{'xMax'} - $glyphs->[$i]{'xMin'}; }
132 $maw = $aw if ($aw > $maw);
133 $mlsb = $lsb if ($lsb < $mlsb or $i == 0);
134 $mrsb = $aw - $ext if ($aw - $ext < $mrsb or $i == 0);
135 $mext = $ext if ($ext > $mext);
137 $self->{'advanceWidthMax'} = $maw;
138 $self->{'minLeftSideBearing'} = $mlsb;
139 $self->{'minRightSideBearing'} = $mrsb;
140 $self->{'xMaxExtent'} = $mext;
141 $self->{'numberOfHMetrics'} = $hmtx->numMetrics;
155 Martin Hosken Martin_Hosken@sil.org. See L<Font::TTF::Font> for copyright and