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