1 package Font::TTF::Mort::Contextual;
5 Font::TTF::Mort::Contextual - Contextual Mort subtable for AAT
14 use Font::TTF::AATutils;
15 use Font::TTF::Mort::Subtable;
18 @ISA = qw(Font::TTF::AAT::Mort::Subtable);
22 my ($class, $direction, $orientation, $subFeatureFlags) = @_;
24 'direction' => $direction,
25 'orientation' => $orientation,
26 'subFeatureFlags' => $subFeatureFlags
29 $class = ref($class) || $class;
35 Reads the table into memory
44 my $stateTableStart = $fh->tell();
45 my ($classes, $states, $entries) = AAT_read_state_table($fh, 2);
47 $fh->seek($stateTableStart, IO::File::SEEK_SET);
49 my ($stateSize, $classTable, $stateArray, $entryTable, $mappingTables) = unpack("nnnnn", $dat);
50 my $limits = [$classTable, $stateArray, $entryTable, $mappingTables, $self->{'length'} - 8];
53 my $actions = $_->{'actions'};
55 $_ = $_ ? $_ - ($mappingTables / 2) : undef;
59 $self->{'classes'} = $classes;
60 $self->{'states'} = $states;
61 $self->{'mappings'} = [unpack("n*", AAT_read_subtable($fh, $stateTableStart, $mappingTables, $limits))];
74 my ($dat) = pack("nnnnn", (0) x 5); # placeholders for stateSize, classTable, stateArray, entryTable, mappingTables
76 my $classTable = length($dat);
77 my $classes = $self->{'classes'};
78 $dat .= AAT_pack_classes($classes);
80 my $stateArray = length($dat);
81 my $states = $self->{'states'};
82 my ($dat1, $stateSize, $entries) = AAT_pack_states($classes, $stateArray, $states,
84 my $actions = $_->{'actions'};
85 ( $_->{'flags'}, @$actions )
90 my $entryTable = length($dat);
91 my $offset = ($entryTable + 8 * @$entries) / 2;
93 my ($nextState, $flags, @parts) = split /,/;
94 $dat .= pack("nnnn", $nextState, $flags, map { $_ eq "" ? 0 : $_ + $offset } @parts);
97 my $mappingTables = length($dat);
98 my $mappings = $self->{'mappings'};
99 $dat .= pack("n*", @$mappings);
101 $dat1 = pack("nnnnn", $stateSize, $classTable, $stateArray, $entryTable, $mappingTables);
102 substr($dat, 0, length($dat1)) = $dat1;
107 =head2 $t->print($fh)
109 Prints a human-readable representation of the table
115 my ($self, $fh) = @_;
117 my $post = $self->post();
119 $fh = 'STDOUT' unless defined $fh;
121 $self->print_classes($fh);
124 my $states = $self->{'states'};
125 foreach (0 .. $#$states) {
126 $fh->printf("\t\tState %d:", $_);
127 my $state = $states->[$_];
130 $flags .= "!" if ($_->{'flags'} & 0x4000);
131 $flags .= "*" if ($_->{'flags'} & 0x8000);
132 my $actions = $_->{'actions'};
133 $fh->printf("\t(%s%d,%s,%s)", $flags, $_->{'nextState'}, map { defined $_ ? $_ : "=" } @$actions);
139 my $mappings = $self->{'mappings'};
140 foreach (0 .. $#$mappings) {
141 $fh->printf("\t\tMapping %d: %d [%s]\n", $_, $mappings->[$_], $post->{'VAL'}[$mappings->[$_]]);
153 Jonathan Kew L<Jonathan_Kew@sil.org>. See L<Font::TTF::Font> for copyright and