« API3/Compat/API2/Basic/TTF/PSNames.pm
↑ Summary
API3/Compat/API2/Resource/ColorSpace/Indexed/Hue.pm »
| 1 | #======================================================================= | ||
| 2 | # ____ ____ _____ _ ____ ___ ____ | ||
| 3 | # | _ \| _ \| ___| _ _ / \ | _ \_ _| |___ \ | ||
| 4 | # | |_) | | | | |_ (_) (_) / _ \ | |_) | | __) | | ||
| 5 | # | __/| |_| | _| _ _ / ___ \| __/| | / __/ | ||
| 6 | # |_| |____/|_| (_) (_) /_/ \_\_| |___| |_____| | ||
| 7 | # | ||
| 8 | # A Perl Module Chain to faciliate the Creation and Modification | ||
| 9 | # of High-Quality "Portable Document Format (PDF)" Files. | ||
| 10 | # | ||
| 11 | #======================================================================= | ||
| 12 | # | ||
| 13 | # THIS IS A REUSED PERL MODULE, FOR PROPER LICENCING TERMS SEE BELOW: | ||
| 14 | # | ||
| 15 | # | ||
| 16 | # Copyright Martin Hosken <Martin_Hosken@sil.org> | ||
| 17 | # | ||
| 18 | # No warranty or expression of effectiveness, least of all regarding | ||
| 19 | # anyone's safety, is implied in this software or documentation. | ||
| 20 | # | ||
| 21 | # This specific module is licensed under the Perl Artistic License. | ||
| 22 | # | ||
| 23 | # | ||
| 24 | # $Id: Maxp.pm,v 2.0 2005/11/16 02:16:00 areibens Exp $ | ||
| 25 | # | ||
| 26 | #======================================================================= | ||
| 27 | package PDF::API3::Compat::API2::Basic::TTF::Maxp; | ||
| 28 | |||
| 29 | =head1 NAME | ||
| 30 | |||
| 31 | PDF::API3::Compat::API2::Basic::TTF::Maxp - Maximum Profile table in a font | ||
| 32 | |||
| 33 | =head1 DESCRIPTION | ||
| 34 | |||
| 35 | A collection of useful instance variables following the TTF standard. Probably | ||
| 36 | the most used being C<numGlyphs>. Note that this particular value is | ||
| 37 | foundational and should be kept up to date by the application, it is not updated | ||
| 38 | by C<update>. | ||
| 39 | |||
| 40 | Handles table versions 0.5, 1.0 | ||
| 41 | |||
| 42 | =head1 INSTANCE VARIABLES | ||
| 43 | |||
| 44 | No others beyond those specified in the standard: | ||
| 45 | |||
| 46 | numGlyphs | ||
| 47 | maxPoints | ||
| 48 | maxContours | ||
| 49 | maxCompositePoints | ||
| 50 | maxCompositeContours | ||
| 51 | maxZones | ||
| 52 | maxTwilightPoints | ||
| 53 | maxStorage | ||
| 54 | maxFunctionDefs | ||
| 55 | maxInstructionDefs | ||
| 56 | maxStackElements | ||
| 57 | maxSizeOfInstructions | ||
| 58 | maxComponentElements | ||
| 59 | maxComponentDepth | ||
| 60 | |||
| 61 | |||
| 62 | =head1 METHODS | ||
| 63 | |||
| 64 | =cut | ||
| 65 | |||
| 66 | use strict; | ||
| 67 | use vars qw(@ISA %fields @field_info); | ||
| 68 | use PDF::API3::Compat::API2::Basic::TTF::Utils; | ||
| 69 | |||
| 70 | @ISA = qw(PDF::API3::Compat::API2::Basic::TTF::Table); | ||
| 71 | @field_info = ( | ||
| 72 | 'numGlyphs' => 'S', | ||
| 73 | 'maxPoints' => 'S', | ||
| 74 | 'maxContours' => 'S', | ||
| 75 | 'maxCompositePoints' => 'S', | ||
| 76 | 'maxCompositeContours' => 'S', | ||
| 77 | 'maxZones' => 'S', | ||
| 78 | 'maxTwilightPoints' => 'S', | ||
| 79 | 'maxStorage' => 'S', | ||
| 80 | 'maxFunctionDefs' => 'S', | ||
| 81 | 'maxInstructionDefs' => 'S', | ||
| 82 | 'maxStackElements' => 'S', | ||
| 83 | 'maxSizeOfInstructions' => 'S', | ||
| 84 | 'maxComponentElements' => 'S', | ||
| 85 | 'maxComponentDepth' => 'S'); | ||
| 86 | |||
| 87 | sub init | ||
| 88 | { | ||
| 89 | my ($k, $v, $c, $i); | ||
| 90 | for ($i = 0; $i < $#field_info; $i += 2) | ||
| 91 | { | ||
| 92 | ($k, $v, $c) = TTF_Init_Fields($field_info[$i], $c, $field_info[$i + 1]); | ||
| 93 | next unless defined $k && $k ne ""; | ||
| 94 | $fields{$k} = $v; | ||
| 95 | } | ||
| 96 | } | ||
| 97 | |||
| 98 | |||
| 99 | =head2 $t->read | ||
| 100 | |||
| 101 | Reads the table into memory | ||
| 102 | |||
| 103 | =cut | ||
| 104 | |||
| 105 | sub read | ||
| 106 | { | ||
| 107 | my ($self) = @_; | ||
| 108 | my ($dat); | ||
| 109 | |||
| 110 | $self->SUPER::read or return $self; | ||
| 111 | |||
| 112 | init unless defined $fields{'numGlyphs'}; # any key would do | ||
| 113 | $self->{' INFILE'}->read($dat, 4); | ||
| 114 | $self->{'version'} = TTF_Unpack("f", $dat); | ||
| 115 | |||
| 116 | if ($self->{'version'} == 0.5) | ||
| 117 | { | ||
| 118 | $self->{' INFILE'}->read($dat, 2); | ||
| 119 | $self->{'numGlyphs'} = unpack("n", $dat); | ||
| 120 | } else | ||
| 121 | { | ||
| 122 | $self->{' INFILE'}->read($dat, 28); | ||
| 123 | TTF_Read_Fields($self, $dat, \%fields); | ||
| 124 | } | ||
| 125 | $self; | ||
| 126 | } | ||
| 127 | |||
| 128 | |||
| 129 | =head2 $t->out($fh) | ||
| 130 | |||
| 131 | Writes the table to a file either from memory or by copying. | ||
| 132 | |||
| 133 | =cut | ||
| 134 | |||
| 135 | sub out | ||
| 136 | { | ||
| 137 | my ($self, $fh) = @_; | ||
| 138 | |||
| 139 | return $self->SUPER::out($fh) unless $self->{' read'}; | ||
| 140 | $fh->print(TTF_Pack("f", $self->{'version'})); | ||
| 141 | |||
| 142 | if ($self->{'version'} == 0.5) | ||
| 143 | { $fh->print(pack("n", $self->{'numGlyphs'})); } | ||
| 144 | else | ||
| 145 | { $fh->print(TTF_Out_Fields($self, \%fields, 28)); } | ||
| 146 | $self; | ||
| 147 | } | ||
| 148 | |||
| 149 | |||
| 150 | =head2 $t->update | ||
| 151 | |||
| 152 | Calculates all the maximum values for a font based on the glyphs in the font. | ||
| 153 | Only those fields which require hinting code interpretation are ignored and | ||
| 154 | left as they were read. | ||
| 155 | |||
| 156 | =cut | ||
| 157 | |||
| 158 | sub update | ||
| 159 | { | ||
| 160 | my ($self) = @_; | ||
| 161 | my ($i, $num, @n, @m, $j); | ||
| 162 | my (@name) = qw(maxPoints maxContours maxCompositePoints maxCompositeContours | ||
| 163 | maxSizeOfInstructions maxComponentElements maxComponentDepth); | ||
| 164 | |||
| 165 | return undef unless ($self->SUPER::update); | ||
| 166 | return undef if ($self->{'version'} == 0.5); # only got numGlyphs | ||
| 167 | return undef unless (defined $self->{' PARENT'}{'loca'}); | ||
| 168 | $self->{' PARENT'}{'loca'}->update; | ||
| 169 | $num = $self->{'numGlyphs'}; | ||
| 170 | |||
| 171 | for ($i = 0; $i < $num; $i++) | ||
| 172 | { | ||
| 173 | my ($g) = $self->{' PARENT'}{'loca'}{'glyphs'}[$i] || next; | ||
| 174 | |||
| 175 | @n = $g->maxInfo($self->{' PARENT'}{'loca'}{'glyphs'}); | ||
| 176 | |||
| 177 | for ($j = 0; $j <= $#n; $j++) | ||
| 178 | { $m[$j] = $n[$j] if $n[$j] > $m[$j]; } | ||
| 179 | } | ||
| 180 | |||
| 181 | foreach ('prep', 'fpgm') | ||
| 182 | { $m[4] = length($self->{' PARENT'}{$_}{' dat'}) | ||
| 183 | if (defined $self->{' PARENT'}{$_} | ||
| 184 | && length($self->{' PARENT'}{$_}{' dat'}) > $m[4]); | ||
| 185 | } | ||
| 186 | |||
| 187 | for ($j = 0; $j <= $#name; $j++) | ||
| 188 | { $self->{$name[$j]} = $m[$j]; } | ||
| 189 | $self; | ||
| 190 | } | ||
| 191 | 1; | ||
| 192 | |||
| 193 | |||
| 194 | =head1 BUGS | ||
| 195 | |||
| 196 | None known | ||
| 197 | |||
| 198 | =head1 AUTHOR | ||
| 199 | |||
| 200 | Martin Hosken Martin_Hosken@sil.org. See L<PDF::API3::Compat::API2::Basic::TTF::Font> for copyright and | ||
| 201 | licensing. | ||
| 202 | |||
| 203 | =cut |