| 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: Contextual.pm,v 2.0 2005/11/16 02:16:00 areibens Exp $ | ||
| 25 | # | ||
| 26 | #======================================================================= | ||
| 27 | package PDF::API3::Compat::API2::Basic::TTF::Mort::Contextual; | ||
| 28 | |||
| 29 | =head1 NAME | ||
| 30 | |||
| 31 | PDF::API3::Compat::API2::Basic::TTF::Mort::Contextual | ||
| 32 | |||
| 33 | =head1 METHODS | ||
| 34 | |||
| 35 | =cut | ||
| 36 | |||
| 37 | use strict; | ||
| 38 | use vars qw(@ISA); | ||
| 39 | use PDF::API3::Compat::API2::Basic::TTF::Utils; | ||
| 40 | use PDF::API3::Compat::API2::Basic::TTF::AATutils; | ||
| 41 | use PDF::API3::Compat::API2::Basic::TTF::Mort::Subtable; | ||
| 42 | |||
| 43 | @ISA = qw(PDF::API3::Compat::API2::Basic::TTF::AAT::Mort::Subtable); | ||
| 44 | |||
| 45 | sub new | ||
| 46 | { | ||
| 47 | my ($class, $direction, $orientation, $subFeatureFlags) = @_; | ||
| 48 | my ($self) = { | ||
| 49 | 'direction' => $direction, | ||
| 50 | 'orientation' => $orientation, | ||
| 51 | 'subFeatureFlags' => $subFeatureFlags | ||
| 52 | }; | ||
| 53 | |||
| 54 | $class = ref($class) || $class; | ||
| 55 | bless $self, $class; | ||
| 56 | } | ||
| 57 | |||
| 58 | =head2 $t->read | ||
| 59 | |||
| 60 | Reads the table into memory | ||
| 61 | |||
| 62 | =cut | ||
| 63 | |||
| 64 | sub read | ||
| 65 | { | ||
| 66 | my ($self, $fh) = @_; | ||
| 67 | my ($dat); | ||
| 68 | |||
| 69 | my $stateTableStart = $fh->tell(); | ||
| 70 | my ($classes, $states, $entries) = AAT_read_state_table($fh, 2); | ||
| 71 | |||
| 72 | $fh->seek($stateTableStart, IO::File::SEEK_SET); | ||
| 73 | $fh->read($dat, 10); | ||
| 74 | my ($stateSize, $classTable, $stateArray, $entryTable, $mappingTables) = unpack("nnnnn", $dat); | ||
| 75 | my $limits = [$classTable, $stateArray, $entryTable, $mappingTables, $self->{'length'} - 8]; | ||
| 76 | |||
| 77 | foreach (@$entries) { | ||
| 78 | my $actions = $_->{'actions'}; | ||
| 79 | foreach (@$actions) { | ||
| 80 | $_ = $_ ? $_ - ($mappingTables / 2) : undef; | ||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 84 | $self->{'classes'} = $classes; | ||
| 85 | $self->{'states'} = $states; | ||
| 86 | $self->{'mappings'} = [unpack("n*", AAT_read_subtable($fh, $stateTableStart, $mappingTables, $limits))]; | ||
| 87 | |||
| 88 | $self; | ||
| 89 | } | ||
| 90 | |||
| 91 | =head2 $t->pack_sub() | ||
| 92 | |||
| 93 | =cut | ||
| 94 | |||
| 95 | sub pack_sub | ||
| 96 | { | ||
| 97 | my ($self) = @_; | ||
| 98 | |||
| 99 | my ($dat) = pack("nnnnn", (0) x 5); # placeholders for stateSize, classTable, stateArray, entryTable, mappingTables | ||
| 100 | |||
| 101 | my $classTable = length($dat); | ||
| 102 | my $classes = $self->{'classes'}; | ||
| 103 | $dat .= AAT_pack_classes($classes); | ||
| 104 | |||
| 105 | my $stateArray = length($dat); | ||
| 106 | my $states = $self->{'states'}; | ||
| 107 | my ($dat1, $stateSize, $entries) = AAT_pack_states($classes, $stateArray, $states, | ||
| 108 | sub { | ||
| 109 | my $actions = $_->{'actions'}; | ||
| 110 | ( $_->{'flags'}, @$actions ) | ||
| 111 | } | ||
| 112 | ); | ||
| 113 | $dat .= $dat1; | ||
| 114 | |||
| 115 | my $entryTable = length($dat); | ||
| 116 | my $offset = ($entryTable + 8 * @$entries) / 2; | ||
| 117 | foreach (@$entries) { | ||
| 118 | my ($nextState, $flags, @parts) = split /,/; | ||
| 119 | $dat .= pack("nnnn", $nextState, $flags, map { $_ eq "" ? 0 : $_ + $offset } @parts); | ||
| 120 | } | ||
| 121 | |||
| 122 | my $mappingTables = length($dat); | ||
| 123 | my $mappings = $self->{'mappings'}; | ||
| 124 | $dat .= pack("n*", @$mappings); | ||
| 125 | |||
| 126 | $dat1 = pack("nnnnn", $stateSize, $classTable, $stateArray, $entryTable, $mappingTables); | ||
| 127 | substr($dat, 0, length($dat1)) = $dat1; | ||
| 128 | |||
| 129 | return $dat; | ||
| 130 | } | ||
| 131 | |||
| 132 | =head2 $t->print($fh) | ||
| 133 | |||
| 134 | Prints a human-readable representation of the table | ||
| 135 | |||
| 136 | =cut | ||
| 137 | |||
| 138 | sub print | ||
| 139 | { | ||
| 140 | my ($self, $fh) = @_; | ||
| 141 | |||
| 142 | my $post = $self->post(); | ||
| 143 | |||
| 144 | $fh = 'STDOUT' unless defined $fh; | ||
| 145 | |||
| 146 | $self->print_classes($fh); | ||
| 147 | |||
| 148 | $fh->print("\n"); | ||
| 149 | my $states = $self->{'states'}; | ||
| 150 | foreach (0 .. $#$states) { | ||
| 151 | $fh->printf("\t\tState %d:", $_); | ||
| 152 | my $state = $states->[$_]; | ||
| 153 | foreach (@$state) { | ||
| 154 | my $flags; | ||
| 155 | $flags .= "!" if ($_->{'flags'} & 0x4000); | ||
| 156 | $flags .= "*" if ($_->{'flags'} & 0x8000); | ||
| 157 | my $actions = $_->{'actions'}; | ||
| 158 | $fh->printf("\t(%s%d,%s,%s)", $flags, $_->{'nextState'}, map { defined $_ ? $_ : "=" } @$actions); | ||
| 159 | } | ||
| 160 | $fh->print("\n"); | ||
| 161 | } | ||
| 162 | |||
| 163 | $fh->print("\n"); | ||
| 164 | my $mappings = $self->{'mappings'}; | ||
| 165 | foreach (0 .. $#$mappings) { | ||
| 166 | $fh->printf("\t\tMapping %d: %d [%s]\n", $_, $mappings->[$_], $post->{'VAL'}[$mappings->[$_]]); | ||
| 167 | } | ||
| 168 | } | ||
| 169 | |||
| 170 | 1; | ||
| 171 | |||
| 172 | =head1 BUGS | ||
| 173 | |||
| 174 | None known | ||
| 175 | |||
| 176 | =head1 AUTHOR | ||
| 177 | |||
| 178 | Jonathan Kew L<Jonathan_Kew@sil.org>. See L<PDF::API3::Compat::API2::Basic::TTF::Font> for copyright and | ||
| 179 | licensing. | ||
| 180 | |||
| 181 | =cut | ||
| 182 |