1 package Font::TTF::Maxp;
5 Font::TTF::Maxp - Maximum Profile table in a font
9 A collection of useful instance variables following the TTF standard. Probably
10 the most used being C<numGlyphs>. Note that this particular value is
11 foundational and should be kept up to date by the application, it is not updated
14 Handles table versions 0.5, 1.0
16 =head1 INSTANCE VARIABLES
18 No others beyond those specified in the standard:
41 use vars qw(@ISA %fields @field_info);
44 @ISA = qw(Font::TTF::Table);
49 'maxCompositePoints' => 'S',
50 'maxCompositeContours' => 'S',
52 'maxTwilightPoints' => 'S',
54 'maxFunctionDefs' => 'S',
55 'maxInstructionDefs' => 'S',
56 'maxStackElements' => 'S',
57 'maxSizeOfInstructions' => 'S',
58 'maxComponentElements' => 'S',
59 'maxComponentDepth' => 'S');
64 for ($i = 0; $i < $#field_info; $i += 2)
66 ($k, $v, $c) = TTF_Init_Fields($field_info[$i], $c, $field_info[$i + 1]);
67 next unless defined $k && $k ne "";
75 Reads the table into memory
84 $self->SUPER::read or return $self;
86 init unless defined $fields{'numGlyphs'}; # any key would do
87 $self->{' INFILE'}->read($dat, 4);
88 $self->{'version'} = TTF_Unpack("v", $dat);
90 if ($self->{'version'} == 0.5)
92 $self->{' INFILE'}->read($dat, 2);
93 $self->{'numGlyphs'} = unpack("n", $dat);
96 $self->{' INFILE'}->read($dat, 28);
97 TTF_Read_Fields($self, $dat, \%fields);
105 Writes the table to a file either from memory or by copying.
111 my ($self, $fh) = @_;
113 return $self->SUPER::out($fh) unless $self->{' read'};
114 $fh->print(TTF_Pack("v", $self->{'version'}));
116 if ($self->{'version'} == 0.5)
117 { $fh->print(pack("n", $self->{'numGlyphs'})); }
119 { $fh->print(TTF_Out_Fields($self, \%fields, 28)); }
126 Calculates all the maximum values for a font based on the glyphs in the font.
127 Only those fields which require hinting code interpretation are ignored and
128 left as they were read.
135 my ($i, $num, @n, @m, $j);
136 my (@name) = qw(maxPoints maxContours maxCompositePoints maxCompositeContours
137 maxSizeOfInstructions maxComponentElements maxComponentDepth);
139 return undef unless ($self->SUPER::update);
140 return undef if ($self->{'version'} == 0.5); # only got numGlyphs
141 return undef unless (defined $self->{' PARENT'}{'loca'});
142 $self->{' PARENT'}{'loca'}->update;
143 $num = $self->{'numGlyphs'};
145 for ($i = 0; $i < $num; $i++)
147 my ($g) = $self->{' PARENT'}{'loca'}{'glyphs'}[$i] || next;
151 for ($j = 0; $j <= $#n; $j++)
152 { $m[$j] = $n[$j] if $n[$j] > $m[$j]; }
155 foreach ('prep', 'fpgm')
156 { $m[4] = length($self->{' PARENT'}{$_}{' dat'})
157 if (defined $self->{' PARENT'}{$_}
158 && length($self->{' PARENT'}{$_}{' dat'}) > $m[4]);
161 for ($j = 0; $j <= $#name; $j++)
162 { $self->{$name[$j]} = $m[$j]; }
174 Martin Hosken Martin_Hosken@sil.org. See L<Font::TTF::Font> for copyright and