1 package Font::TTF::Mort::Ligature;
5 Font::TTF::Mort::Ligature - Ligature Mort subtable for AAT
14 use Font::TTF::AATutils;
17 @ISA = qw(Font::TTF::Mort::Subtable);
21 my ($class, $direction, $orientation, $subFeatureFlags) = @_;
23 'direction' => $direction,
24 'orientation' => $orientation,
25 'subFeatureFlags' => $subFeatureFlags
28 $class = ref($class) || $class;
34 Reads the table into memory
43 my $stateTableStart = $fh->tell();
44 my ($classes, $states, $entries) = AAT_read_state_table($fh, 0);
46 $fh->seek($stateTableStart, IO::File::SEEK_SET);
48 my ($stateSize, $classTable, $stateArray, $entryTable,
49 $ligActionTable, $componentTable, $ligatureTable) = unpack("nnnnnnn", $dat);
50 my $limits = [$classTable, $stateArray, $entryTable, $ligActionTable, $componentTable, $ligatureTable, $self->{'length'} - 8];
55 my $offset = $_->{'flags'} & 0x3fff;
56 $_->{'flags'} &= ~0x3fff;
58 if (not defined $actions{$offset}) {
59 $fh->seek($stateTableStart + $offset, IO::File::SEEK_SET);
63 my $action = unpack("N", $dat);
64 my ($last, $store, $component) = (($action & 0x80000000) != 0, ($action & 0xC0000000) != 0, ($action & 0x3fffffff));
65 $component -= 0x40000000 if $component > 0x1fffffff;
66 $component -= $componentTable / 2;
67 push @$actionList, { 'store' => $store, 'component' => $component };
70 push @$actionLists, $actionList;
71 $actions{$offset} = $#$actionLists;
73 $_->{'actions'} = $actions{$offset};
77 $self->{'componentTable'} = $componentTable;
78 my $components = [unpack("n*", AAT_read_subtable($fh, $stateTableStart, $componentTable, $limits))];
79 foreach (@$components) {
80 $_ = ($_ - $ligatureTable) . " +" if $_ >= $ligatureTable;
82 $self->{'components'} = $components;
84 $self->{'ligatureTable'} = $ligatureTable;
85 $self->{'ligatures'} = [unpack("n*", AAT_read_subtable($fh, $stateTableStart, $ligatureTable, $limits))];
87 $self->{'classes'} = $classes;
88 $self->{'states'} = $states;
89 $self->{'actionLists'} = $actionLists;
94 =head2 $t->pack_sub($fh)
103 $dat .= pack("nnnnnnn", (0) x 7); # placeholders for stateSize, classTable, stateArray, entryTable, actionLists, components, ligatures
105 my $classTable = length($dat);
106 my $classes = $self->{'classes'};
107 $dat .= AAT_pack_classes($classes);
109 my $stateArray = length($dat);
110 my $states = $self->{'states'};
112 my ($dat1, $stateSize, $entries) = AAT_pack_states($classes, $stateArray, $states,
114 ( $_->{'flags'} & 0xc000, $_->{'actions'} )
119 my $actionLists = $self->{'actionLists'};
120 my %actionListOffset;
121 my $actionListDataLength = 0;
122 my @actionListEntries;
123 foreach (0 .. $#$entries) {
124 my ($nextState, $flags, $offset) = split(/,/, $entries->[$_]);
129 if (defined $actionListOffset{$offset}) {
130 $offset = $actionListOffset{$offset};
133 $actionListOffset{$offset} = $actionListDataLength;
134 my $list = $actionLists->[$offset];
135 $actionListDataLength += 4 * @$list;
136 push @actionListEntries, $list;
137 $offset = $actionListOffset{$offset};
140 $entries->[$_] = [ $nextState, $flags, $offset ];
142 my $entryTable = length($dat);
143 my $ligActionLists = ($entryTable + @$entries * 4 + 3) & ~3;
144 foreach (@$entries) {
145 $_->[2] += $ligActionLists if defined $_->[2];
146 $dat .= pack("nn", $_->[0], $_->[1] + $_->[2]);
148 $dat .= pack("C*", (0) x ($ligActionLists - $entryTable - @$entries * 4));
150 die "internal error" unless length($dat) == $ligActionLists;
152 my $componentTable = length($dat) + $actionListDataLength;
154 foreach $actionList (@actionListEntries) {
155 foreach (0 .. $#$actionList) {
156 my $action = $actionList->[$_];
157 my $val = $action->{'component'} + $componentTable / 2;
158 $val += 0x40000000 if $val < 0;
160 $val |= 0x40000000 if $action->{'store'};
161 $val |= 0x80000000 if $_ == $#$actionList;
162 $dat .= pack("N", $val);
166 die "internal error" unless length($dat) == $componentTable;
168 my $components = $self->{'components'};
169 my $ligatureTable = $componentTable + @$components * 2;
170 $dat .= pack("n*", map { (index($_, '+') >= 0 ? $ligatureTable : 0) + $_ } @$components);
172 my $ligatures = $self->{'ligatures'};
173 $dat .= pack("n*", @$ligatures);
175 $dat1 = pack("nnnnnnn", $stateSize, $classTable, $stateArray, $entryTable, $ligActionLists, $componentTable, $ligatureTable);
176 substr($dat, 0, length($dat1)) = $dat1;
181 =head2 $t->print($fh)
183 Prints a human-readable representation of the table
189 my ($self, $fh) = @_;
191 my $post = $self->post();
193 $fh = 'STDOUT' unless defined $fh;
195 $self->print_classes($fh);
198 my $states = $self->{'states'};
199 foreach (0 .. $#$states) {
200 $fh->printf("\t\tState %d:", $_);
201 my $state = $states->[$_];
204 $flags .= "!" if ($_->{'flags'} & 0x4000);
205 $flags .= "*" if ($_->{'flags'} & 0x8000);
206 $fh->printf("\t(%s%d,%s)", $flags, $_->{'nextState'}, defined $_->{'actions'} ? $_->{'actions'} : "=");
212 my $actionLists = $self->{'actionLists'};
213 foreach (0 .. $#$actionLists) {
214 $fh->printf("\t\tList %d:\t", $_);
215 my $actionList = $actionLists->[$_];
216 $fh->printf("%s\n", join(", ", map { ($_->{'component'} . ($_->{'store'} ? "*" : "") ) } @$actionList));
219 my $ligatureTable = $self->{'ligatureTable'};
222 my $components = $self->{'components'};
223 foreach (0 .. $#$components) {
224 $fh->printf("\t\tComponent %d: %s\n", $_, $components->[$_]);
228 my $ligatures = $self->{'ligatures'};
229 foreach (0 .. $#$ligatures) {
230 $fh->printf("\t\tLigature %d: %d [%s]\n", $_, $ligatures->[$_], $post->{'VAL'}[$ligatures->[$_]]);
242 Jonathan Kew L<Jonathan_Kew@sil.org>. See L<Font::TTF::Font> for copyright and