| 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 Jonathan Kew L<Jonathan_Kew@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: Feat.pm,v 2.0 2005/11/16 02:16:00 areibens Exp $ | ||
| 25 | # | ||
| 26 | #======================================================================= | ||
| 27 | package PDF::API3::Compat::API2::Basic::TTF::Feat; | ||
| 28 | |||
| 29 | =head1 NAME | ||
| 30 | |||
| 31 | PDF::API3::Compat::API2::Basic::TTF::Feat - Font Features | ||
| 32 | |||
| 33 | =head1 DESCRIPTION | ||
| 34 | |||
| 35 | =head1 INSTANCE VARIABLES | ||
| 36 | |||
| 37 | =over 4 | ||
| 38 | |||
| 39 | =item version | ||
| 40 | |||
| 41 | =item features | ||
| 42 | |||
| 43 | An array of hashes of the following form | ||
| 44 | |||
| 45 | =over 8 | ||
| 46 | |||
| 47 | =item feature | ||
| 48 | |||
| 49 | feature id number | ||
| 50 | |||
| 51 | =item name | ||
| 52 | |||
| 53 | name index in name table | ||
| 54 | |||
| 55 | =item exclusive | ||
| 56 | |||
| 57 | exclusive flag | ||
| 58 | |||
| 59 | =item settings | ||
| 60 | |||
| 61 | hash of setting number against name string index | ||
| 62 | |||
| 63 | =back | ||
| 64 | |||
| 65 | =back | ||
| 66 | |||
| 67 | =head1 METHODS | ||
| 68 | |||
| 69 | =cut | ||
| 70 | |||
| 71 | use strict; | ||
| 72 | use vars qw(@ISA); | ||
| 73 | |||
| 74 | use PDF::API3::Compat::API2::Basic::TTF::Utils; | ||
| 75 | |||
| 76 | require PDF::API3::Compat::API2::Basic::TTF::Table; | ||
| 77 | |||
| 78 | @ISA = qw(PDF::API3::Compat::API2::Basic::TTF::Table); | ||
| 79 | |||
| 80 | =head2 $t->read | ||
| 81 | |||
| 82 | Reads the features from the TTF file into memory | ||
| 83 | |||
| 84 | =cut | ||
| 85 | |||
| 86 | sub read | ||
| 87 | { | ||
| 88 | my ($self) = @_; | ||
| 89 | my ($featureCount, $features); | ||
| 90 | |||
| 91 | $self->SUPER::read_dat or return $self; | ||
| 92 | |||
| 93 | ($self->{'version'}, $featureCount) = TTF_Unpack("fS", $self->{' dat'}); | ||
| 94 | |||
| 95 | $features = []; | ||
| 96 | foreach (1 .. $featureCount) { | ||
| 97 | my ($feature, $nSettings, $settingTable, $featureFlags, $nameIndex) | ||
| 98 | = TTF_Unpack("SSLSS", substr($self->{' dat'}, $_ * 12, 12)); | ||
| 99 | push @$features, | ||
| 100 | { | ||
| 101 | 'feature' => $feature, | ||
| 102 | 'name' => $nameIndex, | ||
| 103 | 'exclusive' => (($featureFlags & 0x8000) != 0), | ||
| 104 | 'settings' => { TTF_Unpack("S*", substr($self->{' dat'}, $settingTable, $nSettings * 4)) } | ||
| 105 | }; | ||
| 106 | } | ||
| 107 | $self->{'features'} = $features; | ||
| 108 | |||
| 109 | delete $self->{' dat'}; # no longer needed, and may become obsolete | ||
| 110 | |||
| 111 | $self; | ||
| 112 | } | ||
| 113 | |||
| 114 | =head2 $t->out($fh) | ||
| 115 | |||
| 116 | Writes the features to a TTF file | ||
| 117 | |||
| 118 | =cut | ||
| 119 | |||
| 120 | sub out | ||
| 121 | { | ||
| 122 | my ($self, $fh) = @_; | ||
| 123 | my ($features, $numFeatures, $settings, $featuresData, $settingsData); | ||
| 124 | |||
| 125 | return $self->SUPER::out($fh) unless $self->{' read'}; | ||
| 126 | |||
| 127 | $features = $self->{'features'}; | ||
| 128 | $numFeatures = @$features; | ||
| 129 | |||
| 130 | foreach (@$features) { | ||
| 131 | $settings = $_->{'settings'}; | ||
| 132 | $featuresData .= TTF_Pack("SSLSS", | ||
| 133 | $_->{'feature'}, | ||
| 134 | scalar keys %$settings, | ||
| 135 | 12 + 12 * $numFeatures + length $settingsData, | ||
| 136 | ($_->{'exclusive'} ? 0x8000 : 0x0000), | ||
| 137 | $_->{'name'}); | ||
| 138 | foreach (sort {$a <=> $b} keys %$settings) { | ||
| 139 | $settingsData .= TTF_Pack("SS", $_, $settings->{$_}); | ||
| 140 | } | ||
| 141 | } | ||
| 142 | |||
| 143 | $fh->print(TTF_Pack("fSSL", $self->{'version'}, $numFeatures, 0, 0)); | ||
| 144 | $fh->print($featuresData); | ||
| 145 | $fh->print($settingsData); | ||
| 146 | |||
| 147 | $self; | ||
| 148 | } | ||
| 149 | |||
| 150 | =head2 $t->print($fh) | ||
| 151 | |||
| 152 | Prints a human-readable representation of the table | ||
| 153 | |||
| 154 | =cut | ||
| 155 | |||
| 156 | sub print | ||
| 157 | { | ||
| 158 | my ($self, $fh) = @_; | ||
| 159 | my ($names, $features, $settings); | ||
| 160 | |||
| 161 | $self->read; | ||
| 162 | |||
| 163 | $names = $self->{' PARENT'}->{'name'}; | ||
| 164 | $names->read; | ||
| 165 | |||
| 166 | $fh = 'STDOUT' unless defined $fh; | ||
| 167 | |||
| 168 | $features = $self->{'features'}; | ||
| 169 | foreach (@$features) { | ||
| 170 | $fh->printf("Feature %d, %s, name %d # '%s'\n", | ||
| 171 | $_->{'feature'}, | ||
| 172 | ($_->{'exclusive'} ? "exclusive" : "additive"), | ||
| 173 | $_->{'name'}, | ||
| 174 | $names->{'strings'}[$_->{'name'}][1][0]{0}); | ||
| 175 | $settings = $_->{'settings'}; | ||
| 176 | foreach (sort { $a <=> $b } keys %$settings) { | ||
| 177 | $fh->printf("\tSetting %d, name %d # '%s'\n", | ||
| 178 | $_, $settings->{$_}, $names->{'strings'}[$settings->{$_}][1][0]{0}); | ||
| 179 | } | ||
| 180 | } | ||
| 181 | |||
| 182 | $self; | ||
| 183 | } | ||
| 184 | |||
| 185 | sub settingName | ||
| 186 | { | ||
| 187 | my ($self, $feature, $setting) = @_; | ||
| 188 | |||
| 189 | $self->read; | ||
| 190 | |||
| 191 | my $names = $self->{' PARENT'}->{'name'}; | ||
| 192 | $names->read; | ||
| 193 | |||
| 194 | my $features = $self->{'features'}; | ||
| 195 | my ($featureEntry) = grep { $_->{'feature'} == $feature } @$features; | ||
| 196 | my $featureName = $names->{'strings'}[$featureEntry->{'name'}][1][0]{0}; | ||
| 197 | my $settingName = $featureEntry->{'exclusive'} | ||
| 198 | ? $names->{'strings'}[$featureEntry->{'settings'}->{$setting}][1][0]{0} | ||
| 199 | : $names->{'strings'}[$featureEntry->{'settings'}->{$setting & ~1}][1][0]{0} | ||
| 200 | . (($setting & 1) == 0 ? " On" : " Off"); | ||
| 201 | |||
| 202 | ($featureName, $settingName); | ||
| 203 | } | ||
| 204 | |||
| 205 | 1; | ||
| 206 | |||
| 207 | =head1 BUGS | ||
| 208 | |||
| 209 | None known | ||
| 210 | |||
| 211 | =head1 AUTHOR | ||
| 212 | |||
| 213 | Jonathan Kew L<Jonathan_Kew@sil.org>. See L<PDF::API3::Compat::API2::Basic::TTF::Font> for copyright and | ||
| 214 | licensing. | ||
| 215 | |||
| 216 | =cut | ||
| 217 |