| 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: Subtable.pm,v 2.0 2005/11/16 02:16:00 areibens Exp $ | ||
| 25 | # | ||
| 26 | #======================================================================= | ||
| 27 | package PDF::API3::Compat::API2::Basic::TTF::Mort::Subtable; | ||
| 28 | |||
| 29 | =head1 NAME | ||
| 30 | |||
| 31 | PDF::API3::Compat::API2::Basic::TTF::Mort::Subtable | ||
| 32 | |||
| 33 | =head1 METHODS | ||
| 34 | |||
| 35 | =cut | ||
| 36 | |||
| 37 | use strict; | ||
| 38 | use PDF::API3::Compat::API2::Basic::TTF::Utils; | ||
| 39 | use PDF::API3::Compat::API2::Basic::TTF::AATutils; | ||
| 40 | |||
| 41 | require PDF::API3::Compat::API2::Basic::TTF::Mort::Rearrangement; | ||
| 42 | require PDF::API3::Compat::API2::Basic::TTF::Mort::Contextual; | ||
| 43 | require PDF::API3::Compat::API2::Basic::TTF::Mort::Ligature; | ||
| 44 | require PDF::API3::Compat::API2::Basic::TTF::Mort::Noncontextual; | ||
| 45 | require PDF::API3::Compat::API2::Basic::TTF::Mort::Insertion; | ||
| 46 | |||
| 47 | sub new | ||
| 48 | { | ||
| 49 | my ($class) = @_; | ||
| 50 | my ($self) = {}; | ||
| 51 | |||
| 52 | $class = ref($class) || $class; | ||
| 53 | |||
| 54 | bless $self, $class; | ||
| 55 | } | ||
| 56 | |||
| 57 | sub create | ||
| 58 | { | ||
| 59 | my ($class, $type, $coverage, $subFeatureFlags, $length) = @_; | ||
| 60 | |||
| 61 | $class = ref($class) || $class; | ||
| 62 | |||
| 63 | my $subclass; | ||
| 64 | if ($type == 0) { | ||
| 65 | $subclass = 'PDF::API3::Compat::API2::Basic::TTF::Mort::Rearrangement'; | ||
| 66 | } | ||
| 67 | elsif ($type == 1) { | ||
| 68 | $subclass = 'PDF::API3::Compat::API2::Basic::TTF::Mort::Contextual'; | ||
| 69 | } | ||
| 70 | elsif ($type == 2) { | ||
| 71 | $subclass = 'PDF::API3::Compat::API2::Basic::TTF::Mort::Ligature'; | ||
| 72 | } | ||
| 73 | elsif ($type == 4) { | ||
| 74 | $subclass = 'PDF::API3::Compat::API2::Basic::TTF::Mort::Noncontextual'; | ||
| 75 | } | ||
| 76 | elsif ($type == 5) { | ||
| 77 | $subclass = 'PDF::API3::Compat::API2::Basic::TTF::Mort::Insertion'; | ||
| 78 | } | ||
| 79 | |||
| 80 | my ($self) = $subclass->new( | ||
| 81 | (($coverage & 0x4000) ? 'RL' : 'LR'), | ||
| 82 | (($coverage & 0x2000) ? 'VH' : ($coverage & 0x8000) ? 'V' : 'H'), | ||
| 83 | $subFeatureFlags | ||
| 84 | ); | ||
| 85 | |||
| 86 | $self->{'type'} = $type; | ||
| 87 | $self->{'length'} = $length; | ||
| 88 | |||
| 89 | $self; | ||
| 90 | } | ||
| 91 | |||
| 92 | =head2 $t->out($fh) | ||
| 93 | |||
| 94 | Writes the table to a file | ||
| 95 | |||
| 96 | =cut | ||
| 97 | |||
| 98 | sub out | ||
| 99 | { | ||
| 100 | my ($self, $fh) = @_; | ||
| 101 | |||
| 102 | my ($subtableStart) = $fh->tell(); | ||
| 103 | my ($type) = $self->{'type'}; | ||
| 104 | my ($coverage) = $type; | ||
| 105 | $coverage += 0x4000 if $self->{'direction'} eq 'RL'; | ||
| 106 | $coverage += 0x2000 if $self->{'orientation'} eq 'VH'; | ||
| 107 | $coverage += 0x8000 if $self->{'orientation'} eq 'V'; | ||
| 108 | |||
| 109 | $fh->print(TTF_Pack("SSL", 0, $coverage, $self->{'subFeatureFlags'})); # placeholder for length | ||
| 110 | |||
| 111 | my ($dat) = $self->pack_sub(); | ||
| 112 | $fh->print($dat); | ||
| 113 | |||
| 114 | my ($length) = $fh->tell() - $subtableStart; | ||
| 115 | my ($padBytes) = (4 - ($length & 3)) & 3; | ||
| 116 | $fh->print(pack("C*", (0) x $padBytes)); | ||
| 117 | $length += $padBytes; | ||
| 118 | $fh->seek($subtableStart, IO::File::SEEK_SET); | ||
| 119 | $fh->print(pack("n", $length)); | ||
| 120 | $fh->seek($subtableStart + $length, IO::File::SEEK_SET); | ||
| 121 | } | ||
| 122 | |||
| 123 | =head2 $t->print($fh) | ||
| 124 | |||
| 125 | Prints a human-readable representation of the table | ||
| 126 | |||
| 127 | =cut | ||
| 128 | |||
| 129 | sub post | ||
| 130 | { | ||
| 131 | my ($self) = @_; | ||
| 132 | |||
| 133 | my ($post) = $self->{' PARENT'}{' PARENT'}{' PARENT'}{'post'}; | ||
| 134 | if (defined $post) { | ||
| 135 | $post->read; | ||
| 136 | } | ||
| 137 | else { | ||
| 138 | $post = {}; | ||
| 139 | } | ||
| 140 | |||
| 141 | return $post; | ||
| 142 | } | ||
| 143 | |||
| 144 | sub feat | ||
| 145 | { | ||
| 146 | my ($self) = @_; | ||
| 147 | |||
| 148 | return $self->{' PARENT'}->feat(); | ||
| 149 | } | ||
| 150 | |||
| 151 | sub print | ||
| 152 | { | ||
| 153 | my ($self, $fh) = @_; | ||
| 154 | |||
| 155 | my ($feat) = $self->feat(); | ||
| 156 | my ($post) = $self->post(); | ||
| 157 | |||
| 158 | $fh = 'STDOUT' unless defined $fh; | ||
| 159 | |||
| 160 | my ($type) = $self->{'type'}; | ||
| 161 | my ($subFeatureFlags) = $self->{'subFeatureFlags'}; | ||
| 162 | my ($defaultFlags) = $self->{' PARENT'}{'defaultFlags'}; | ||
| 163 | my ($featureEntries) = $self->{' PARENT'}{'featureEntries'}; | ||
| 164 | $fh->printf("\n\t%s table, %s, %s, subFeatureFlags = %08x # %s (%s)\n", | ||
| 165 | subtable_type_($type), $_->{'direction'}, $_->{'orientation'}, $subFeatureFlags, | ||
| 166 | "Default " . ((($subFeatureFlags & $defaultFlags) != 0) ? "On" : "Off"), | ||
| 167 | join(", ", | ||
| 168 | map { | ||
| 169 | join(": ", $feat->settingName($_->{'type'}, $_->{'setting'}) ) | ||
| 170 | } grep { ($_->{'enable'} & $subFeatureFlags) != 0 } @$featureEntries | ||
| 171 | ) ); | ||
| 172 | } | ||
| 173 | |||
| 174 | sub subtable_type_ | ||
| 175 | { | ||
| 176 | my ($val) = @_; | ||
| 177 | my ($res); | ||
| 178 | |||
| 179 | my (@types) = ( | ||
| 180 | 'Rearrangement', | ||
| 181 | 'Contextual', | ||
| 182 | 'Ligature', | ||
| 183 | undef, | ||
| 184 | 'Non-contextual', | ||
| 185 | 'Insertion', | ||
| 186 | ); | ||
| 187 | $res = $types[$val] or ('Undefined (' . $val . ')'); | ||
| 188 | |||
| 189 | $res; | ||
| 190 | } | ||
| 191 | |||
| 192 | =head2 $t->print_classes($fh) | ||
| 193 | |||
| 194 | Prints a human-readable representation of the table | ||
| 195 | |||
| 196 | =cut | ||
| 197 | |||
| 198 | sub print_classes | ||
| 199 | { | ||
| 200 | my ($self, $fh) = @_; | ||
| 201 | |||
| 202 | my ($post) = $self->post(); | ||
| 203 | |||
| 204 | my ($classes) = $self->{'classes'}; | ||
| 205 | foreach (0 .. $#$classes) { | ||
| 206 | my $class = $classes->[$_]; | ||
| 207 | if (defined $class) { | ||
| 208 | $fh->printf("\t\tClass %d:\t%s\n", $_, join(", ", map { $_ . " [" . $post->{'VAL'}[$_] . "]" } @$class)); | ||
| 209 | } | ||
| 210 | } | ||
| 211 | } | ||
| 212 | |||
| 213 | 1; | ||
| 214 | |||
| 215 | =head1 BUGS | ||
| 216 | |||
| 217 | None known | ||
| 218 | |||
| 219 | =head1 AUTHOR | ||
| 220 | |||
| 221 | Jonathan Kew L<Jonathan_Kew@sil.org>. See L<PDF::API3::Compat::API2::Basic::TTF::Font> for copyright and | ||
| 222 | licensing. | ||
| 223 | |||
| 224 | =cut | ||
| 225 |