init III
This commit is contained in:
206
Perl OTRS/Kernel/cpan-lib/Font/TTF/Mort/Chain.pm
Normal file
206
Perl OTRS/Kernel/cpan-lib/Font/TTF/Mort/Chain.pm
Normal file
@@ -0,0 +1,206 @@
|
||||
package Font::TTF::Mort::Chain;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Font::TTF::Mort::Chain - Chain Mort subtable for AAT
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use Font::TTF::Utils;
|
||||
use Font::TTF::AATutils;
|
||||
use Font::TTF::Mort::Subtable;
|
||||
use IO::File;
|
||||
|
||||
=head2 $t->new
|
||||
|
||||
=cut
|
||||
|
||||
sub new
|
||||
{
|
||||
my ($class, %parms) = @_;
|
||||
my ($self) = {};
|
||||
my ($p);
|
||||
|
||||
$class = ref($class) || $class;
|
||||
foreach $p (keys %parms)
|
||||
{ $self->{" $p"} = $parms{$p}; }
|
||||
bless $self, $class;
|
||||
}
|
||||
|
||||
=head2 $t->read($fh)
|
||||
|
||||
Reads the chain into memory
|
||||
|
||||
=cut
|
||||
|
||||
sub read
|
||||
{
|
||||
my ($self, $fh) = @_;
|
||||
my ($dat);
|
||||
|
||||
my $chainStart = $fh->tell();
|
||||
$fh->read($dat, 12);
|
||||
my ($defaultFlags, $chainLength, $nFeatureEntries, $nSubtables) = TTF_Unpack("LLSS", $dat);
|
||||
|
||||
my $featureEntries = [];
|
||||
foreach (1 .. $nFeatureEntries) {
|
||||
$fh->read($dat, 12);
|
||||
my ($featureType, $featureSetting, $enableFlags, $disableFlags) = TTF_Unpack("SSLL", $dat);
|
||||
push @$featureEntries, {
|
||||
'type' => $featureType,
|
||||
'setting' => $featureSetting,
|
||||
'enable' => $enableFlags,
|
||||
'disable' => $disableFlags
|
||||
};
|
||||
}
|
||||
|
||||
my $subtables = [];
|
||||
foreach (1 .. $nSubtables) {
|
||||
my $subtableStart = $fh->tell();
|
||||
|
||||
$fh->read($dat, 8);
|
||||
my ($length, $coverage, $subFeatureFlags) = TTF_Unpack("SSL", $dat);
|
||||
my $type = $coverage & 0x0007;
|
||||
|
||||
my $subtable = Font::TTF::Mort::Subtable->create($type, $coverage, $subFeatureFlags, $length);
|
||||
$subtable->read($fh);
|
||||
$subtable->{' PARENT'} = $self;
|
||||
|
||||
push @$subtables, $subtable;
|
||||
$fh->seek($subtableStart + $length, IO::File::SEEK_SET);
|
||||
}
|
||||
|
||||
$self->{'defaultFlags'} = $defaultFlags;
|
||||
$self->{'featureEntries'} = $featureEntries;
|
||||
$self->{'subtables'} = $subtables;
|
||||
|
||||
$fh->seek($chainStart + $chainLength, IO::File::SEEK_SET);
|
||||
|
||||
$self;
|
||||
}
|
||||
|
||||
=head2 $t->out($fh)
|
||||
|
||||
Writes the table to a file either from memory or by copying
|
||||
|
||||
=cut
|
||||
|
||||
sub out
|
||||
{
|
||||
my ($self, $fh) = @_;
|
||||
|
||||
my $chainStart = $fh->tell();
|
||||
my ($featureEntries, $subtables) = ($_->{'featureEntries'}, $_->{'subtables'});
|
||||
$fh->print(TTF_Pack("LLSS", $_->{'defaultFlags'}, 0, scalar @$featureEntries, scalar @$subtables)); # placeholder for length
|
||||
|
||||
foreach (@$featureEntries) {
|
||||
$fh->print(TTF_Pack("SSLL", $_->{'type'}, $_->{'setting'}, $_->{'enable'}, $_->{'disable'}));
|
||||
}
|
||||
|
||||
foreach (@$subtables) {
|
||||
$_->out($fh);
|
||||
}
|
||||
|
||||
my $chainLength = $fh->tell() - $chainStart;
|
||||
$fh->seek($chainStart + 4, IO::File::SEEK_SET);
|
||||
$fh->print(pack("N", $chainLength));
|
||||
$fh->seek($chainStart + $chainLength, IO::File::SEEK_SET);
|
||||
}
|
||||
|
||||
=head2 $t->print($fh)
|
||||
|
||||
Prints a human-readable representation of the chain
|
||||
|
||||
=cut
|
||||
|
||||
sub feat
|
||||
{
|
||||
my ($self) = @_;
|
||||
|
||||
my $feat = $self->{' PARENT'}{' PARENT'}{'feat'};
|
||||
if (defined $feat) {
|
||||
$feat->read;
|
||||
}
|
||||
else {
|
||||
$feat = {};
|
||||
}
|
||||
|
||||
return $feat;
|
||||
}
|
||||
|
||||
sub print
|
||||
{
|
||||
my ($self, $fh) = @_;
|
||||
|
||||
$fh->printf("version %f\n", $self->{'version'});
|
||||
|
||||
my $defaultFlags = $self->{'defaultFlags'};
|
||||
$fh->printf("chain: defaultFlags = %08x\n", $defaultFlags);
|
||||
|
||||
my $feat = $self->feat();
|
||||
my $featureEntries = $self->{'featureEntries'};
|
||||
foreach (@$featureEntries) {
|
||||
$fh->printf("\tfeature %d, setting %d : enableFlags = %08x, disableFlags = %08x # '%s: %s'\n",
|
||||
$_->{'type'}, $_->{'setting'}, $_->{'enable'}, $_->{'disable'},
|
||||
$feat->settingName($_->{'type'}, $_->{'setting'}));
|
||||
}
|
||||
|
||||
my $subtables = $self->{'subtables'};
|
||||
foreach (@$subtables) {
|
||||
my $type = $_->{'type'};
|
||||
my $subFeatureFlags = $_->{'subFeatureFlags'};
|
||||
$fh->printf("\n\t%s table, %s, %s, subFeatureFlags = %08x # %s (%s)\n",
|
||||
subtable_type_($type), $_->{'direction'}, $_->{'orientation'}, $subFeatureFlags,
|
||||
"Default " . ((($subFeatureFlags & $defaultFlags) != 0) ? "On" : "Off"),
|
||||
join(", ",
|
||||
map {
|
||||
join(": ", $feat->settingName($_->{'type'}, $_->{'setting'}) )
|
||||
} grep { ($_->{'enable'} & $subFeatureFlags) != 0 } @$featureEntries
|
||||
) );
|
||||
|
||||
$_->print($fh);
|
||||
}
|
||||
}
|
||||
|
||||
sub subtable_type_
|
||||
{
|
||||
my ($val) = @_;
|
||||
my ($res);
|
||||
|
||||
my @types = (
|
||||
'Rearrangement',
|
||||
'Contextual',
|
||||
'Ligature',
|
||||
undef,
|
||||
'Non-contextual',
|
||||
'Insertion',
|
||||
);
|
||||
$res = $types[$val] or ('Undefined (' . $val . ')');
|
||||
|
||||
$res;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
None known
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Jonathan Kew L<http://scripts.sil.org/FontUtils>.
|
||||
|
||||
|
||||
=head1 LICENSING
|
||||
|
||||
Copyright (c) 1998-2016, SIL International (http://www.sil.org)
|
||||
|
||||
This module is released under the terms of the Artistic License 2.0.
|
||||
For details, see the full text of the license in the file LICENSE.
|
||||
|
||||
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
166
Perl OTRS/Kernel/cpan-lib/Font/TTF/Mort/Contextual.pm
Normal file
166
Perl OTRS/Kernel/cpan-lib/Font/TTF/Mort/Contextual.pm
Normal file
@@ -0,0 +1,166 @@
|
||||
package Font::TTF::Mort::Contextual;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Font::TTF::Mort::Contextual - Contextual Mort subtable for AAT
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use vars qw(@ISA);
|
||||
use Font::TTF::Utils;
|
||||
use Font::TTF::AATutils;
|
||||
use IO::File;
|
||||
|
||||
@ISA = qw(Font::TTF::Mort::Subtable);
|
||||
|
||||
sub new
|
||||
{
|
||||
my ($class, $direction, $orientation, $subFeatureFlags) = @_;
|
||||
my ($self) = {
|
||||
'direction' => $direction,
|
||||
'orientation' => $orientation,
|
||||
'subFeatureFlags' => $subFeatureFlags
|
||||
};
|
||||
|
||||
$class = ref($class) || $class;
|
||||
bless $self, $class;
|
||||
}
|
||||
|
||||
=head2 $t->read
|
||||
|
||||
Reads the table into memory
|
||||
|
||||
=cut
|
||||
|
||||
sub read
|
||||
{
|
||||
my ($self, $fh) = @_;
|
||||
my ($dat);
|
||||
|
||||
my $stateTableStart = $fh->tell();
|
||||
my ($classes, $states, $entries) = AAT_read_state_table($fh, 2);
|
||||
|
||||
$fh->seek($stateTableStart, IO::File::SEEK_SET);
|
||||
$fh->read($dat, 10);
|
||||
my ($stateSize, $classTable, $stateArray, $entryTable, $mappingTables) = unpack("nnnnn", $dat);
|
||||
my $limits = [$classTable, $stateArray, $entryTable, $mappingTables, $self->{'length'} - 8];
|
||||
|
||||
foreach (@$entries) {
|
||||
my $actions = $_->{'actions'};
|
||||
foreach (@$actions) {
|
||||
$_ = $_ ? $_ - ($mappingTables / 2) : undef;
|
||||
}
|
||||
}
|
||||
|
||||
$self->{'classes'} = $classes;
|
||||
$self->{'states'} = $states;
|
||||
$self->{'mappings'} = [unpack("n*", AAT_read_subtable($fh, $stateTableStart, $mappingTables, $limits))];
|
||||
|
||||
$self;
|
||||
}
|
||||
|
||||
=head2 $t->pack_sub()
|
||||
|
||||
=cut
|
||||
|
||||
sub pack_sub
|
||||
{
|
||||
my ($self) = @_;
|
||||
|
||||
my ($dat) = pack("nnnnn", (0) x 5); # placeholders for stateSize, classTable, stateArray, entryTable, mappingTables
|
||||
|
||||
my $classTable = length($dat);
|
||||
my $classes = $self->{'classes'};
|
||||
$dat .= AAT_pack_classes($classes);
|
||||
|
||||
my $stateArray = length($dat);
|
||||
my $states = $self->{'states'};
|
||||
my ($dat1, $stateSize, $entries) = AAT_pack_states($classes, $stateArray, $states,
|
||||
sub {
|
||||
my $actions = $_->{'actions'};
|
||||
( $_->{'flags'}, @$actions )
|
||||
}
|
||||
);
|
||||
$dat .= $dat1;
|
||||
|
||||
my $entryTable = length($dat);
|
||||
my $offset = ($entryTable + 8 * @$entries) / 2;
|
||||
foreach (@$entries) {
|
||||
my ($nextState, $flags, @parts) = split /,/;
|
||||
$dat .= pack("nnnn", $nextState, $flags, map { $_ eq "" ? 0 : $_ + $offset } @parts);
|
||||
}
|
||||
|
||||
my $mappingTables = length($dat);
|
||||
my $mappings = $self->{'mappings'};
|
||||
$dat .= pack("n*", @$mappings);
|
||||
|
||||
$dat1 = pack("nnnnn", $stateSize, $classTable, $stateArray, $entryTable, $mappingTables);
|
||||
substr($dat, 0, length($dat1)) = $dat1;
|
||||
|
||||
return $dat;
|
||||
}
|
||||
|
||||
=head2 $t->print($fh)
|
||||
|
||||
Prints a human-readable representation of the table
|
||||
|
||||
=cut
|
||||
|
||||
sub print
|
||||
{
|
||||
my ($self, $fh) = @_;
|
||||
|
||||
my $post = $self->post();
|
||||
|
||||
$fh = 'STDOUT' unless defined $fh;
|
||||
|
||||
$self->print_classes($fh);
|
||||
|
||||
$fh->print("\n");
|
||||
my $states = $self->{'states'};
|
||||
foreach (0 .. $#$states) {
|
||||
$fh->printf("\t\tState %d:", $_);
|
||||
my $state = $states->[$_];
|
||||
foreach (@$state) {
|
||||
my $flags;
|
||||
$flags .= "!" if ($_->{'flags'} & 0x4000);
|
||||
$flags .= "*" if ($_->{'flags'} & 0x8000);
|
||||
my $actions = $_->{'actions'};
|
||||
$fh->printf("\t(%s%d,%s,%s)", $flags, $_->{'nextState'}, map { defined $_ ? $_ : "=" } @$actions);
|
||||
}
|
||||
$fh->print("\n");
|
||||
}
|
||||
|
||||
$fh->print("\n");
|
||||
my $mappings = $self->{'mappings'};
|
||||
foreach (0 .. $#$mappings) {
|
||||
$fh->printf("\t\tMapping %d: %d [%s]\n", $_, $mappings->[$_], $post->{'VAL'}[$mappings->[$_]]);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
None known
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Jonathan Kew L<http://scripts.sil.org/FontUtils>.
|
||||
|
||||
|
||||
=head1 LICENSING
|
||||
|
||||
Copyright (c) 1998-2016, SIL International (http://www.sil.org)
|
||||
|
||||
This module is released under the terms of the Artistic License 2.0.
|
||||
For details, see the full text of the license in the file LICENSE.
|
||||
|
||||
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
189
Perl OTRS/Kernel/cpan-lib/Font/TTF/Mort/Insertion.pm
Normal file
189
Perl OTRS/Kernel/cpan-lib/Font/TTF/Mort/Insertion.pm
Normal file
@@ -0,0 +1,189 @@
|
||||
package Font::TTF::Mort::Insertion;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Font::TTF::Mort::Insertion - Insertion Mort subtable for AAT
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use vars qw(@ISA);
|
||||
use Font::TTF::Utils;
|
||||
use Font::TTF::AATutils;
|
||||
use IO::File;
|
||||
|
||||
@ISA = qw(Font::TTF::Mort::Subtable);
|
||||
|
||||
sub new
|
||||
{
|
||||
my ($class, $direction, $orientation, $subFeatureFlags) = @_;
|
||||
my ($self) = {
|
||||
'direction' => $direction,
|
||||
'orientation' => $orientation,
|
||||
'subFeatureFlags' => $subFeatureFlags
|
||||
};
|
||||
|
||||
$class = ref($class) || $class;
|
||||
bless $self, $class;
|
||||
}
|
||||
|
||||
=head2 $t->read
|
||||
|
||||
Reads the table into memory
|
||||
|
||||
=cut
|
||||
|
||||
sub read
|
||||
{
|
||||
my ($self, $fh) = @_;
|
||||
my ($dat);
|
||||
|
||||
my $subtableStart = $fh->tell();
|
||||
|
||||
my $stateTableStart = $fh->tell();
|
||||
my ($classes, $states, $entries) = AAT_read_state_table($fh, 2);
|
||||
|
||||
my %insertListHash;
|
||||
my $insertLists;
|
||||
foreach (@$entries) {
|
||||
my $flags = $_->{'flags'};
|
||||
my @insertCount = (($flags & 0x03e0) >> 5, ($flags & 0x001f));
|
||||
my $actions = $_->{'actions'};
|
||||
foreach (0 .. 1) {
|
||||
if ($insertCount[$_] > 0) {
|
||||
$fh->seek($stateTableStart + $actions->[$_], IO::File::SEEK_SET);
|
||||
$fh->read($dat, $insertCount[$_] * 2);
|
||||
if (not defined $insertListHash{$dat}) {
|
||||
push @$insertLists, [unpack("n*", $dat)];
|
||||
$insertListHash{$dat} = $#$insertLists;
|
||||
}
|
||||
$actions->[$_] = $insertListHash{$dat};
|
||||
}
|
||||
else {
|
||||
$actions->[$_] = undef;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$self->{'classes'} = $classes;
|
||||
$self->{'states'} = $states;
|
||||
$self->{'insertLists'} = $insertLists;
|
||||
|
||||
$self;
|
||||
}
|
||||
|
||||
=head2 $t->pack_sub()
|
||||
|
||||
=cut
|
||||
|
||||
sub pack_sub
|
||||
{
|
||||
my ($self) = @_;
|
||||
|
||||
my ($dat) = pack("nnnn", (0) x 4);
|
||||
|
||||
my $classTable = length($dat);
|
||||
my $classes = $self->{'classes'};
|
||||
$dat .= AAT_pack_classes($classes);
|
||||
|
||||
my $stateArray = length($dat);
|
||||
my $states = $self->{'states'};
|
||||
my ($dat1, $stateSize, $entries) = AAT_pack_states($classes, $stateArray, $states,
|
||||
sub {
|
||||
my $actions = $_->{'actions'};
|
||||
( $_->{'flags'}, @$actions )
|
||||
}
|
||||
);
|
||||
$dat .= $dat1;
|
||||
|
||||
my $entryTable = length($dat);
|
||||
my $offset = ($entryTable + 8 * @$entries);
|
||||
my @insListOffsets;
|
||||
my $insertLists = $self->{'insertLists'};
|
||||
foreach (@$insertLists) {
|
||||
push @insListOffsets, $offset;
|
||||
$offset += 2 * scalar @$_;
|
||||
}
|
||||
foreach (@$entries) {
|
||||
my ($nextState, $flags, @lists) = split /,/;
|
||||
$flags &= ~0x03ff;
|
||||
$flags |= (scalar @{$insertLists->[$lists[0]]}) << 5 if $lists[0] ne '';
|
||||
$flags |= (scalar @{$insertLists->[$lists[1]]}) if $lists[1] ne '';
|
||||
$dat .= pack("nnnn", $nextState, $flags,
|
||||
map { $_ eq '' ? 0 : $insListOffsets[$_] } @lists);
|
||||
}
|
||||
|
||||
foreach (@$insertLists) {
|
||||
$dat .= pack("n*", @$_);
|
||||
}
|
||||
|
||||
$dat1 = pack("nnnn", $stateSize, $classTable, $stateArray, $entryTable);
|
||||
substr($dat, 0, length($dat1)) = $dat1;
|
||||
|
||||
return $dat;
|
||||
}
|
||||
|
||||
=head2 $t->print($fh)
|
||||
|
||||
Prints a human-readable representation of the table
|
||||
|
||||
=cut
|
||||
|
||||
sub print
|
||||
{
|
||||
my ($self, $fh) = @_;
|
||||
|
||||
my $post = $self->post();
|
||||
|
||||
$fh = 'STDOUT' unless defined $fh;
|
||||
|
||||
$self->print_classes($fh);
|
||||
|
||||
$fh->print("\n");
|
||||
my $states = $self->{'states'};
|
||||
foreach (0 .. $#$states) {
|
||||
$fh->printf("\t\tState %d:", $_);
|
||||
my $state = $states->[$_];
|
||||
foreach (@$state) {
|
||||
my $flags;
|
||||
$flags .= "!" if ($_->{'flags'} & 0x4000);
|
||||
$flags .= "*" if ($_->{'flags'} & 0x8000);
|
||||
my $actions = $_->{'actions'};
|
||||
$fh->printf("\t(%s%d,%s,%s)", $flags, $_->{'nextState'}, map { defined $_ ? $_ : "=" } @$actions);
|
||||
}
|
||||
$fh->print("\n");
|
||||
}
|
||||
|
||||
$fh->print("\n");
|
||||
my $insertLists = $self->{'insertLists'};
|
||||
foreach (0 .. $#$insertLists) {
|
||||
my $insertList = $insertLists->[$_];
|
||||
$fh->printf("\t\tList %d: %s\n", $_, join(", ", map { $_ . " [" . $post->{'VAL'}[$_] . "]" } @$insertList));
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
None known
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Jonathan Kew L<http://scripts.sil.org/FontUtils>.
|
||||
|
||||
|
||||
=head1 LICENSING
|
||||
|
||||
Copyright (c) 1998-2016, SIL International (http://www.sil.org)
|
||||
|
||||
This module is released under the terms of the Artistic License 2.0.
|
||||
For details, see the full text of the license in the file LICENSE.
|
||||
|
||||
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
256
Perl OTRS/Kernel/cpan-lib/Font/TTF/Mort/Ligature.pm
Normal file
256
Perl OTRS/Kernel/cpan-lib/Font/TTF/Mort/Ligature.pm
Normal file
@@ -0,0 +1,256 @@
|
||||
package Font::TTF::Mort::Ligature;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Font::TTF::Mort::Ligature - Ligature Mort subtable for AAT
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use vars qw(@ISA);
|
||||
use Font::TTF::Utils;
|
||||
use Font::TTF::AATutils;
|
||||
use IO::File;
|
||||
|
||||
@ISA = qw(Font::TTF::Mort::Subtable);
|
||||
|
||||
sub new
|
||||
{
|
||||
my ($class, $direction, $orientation, $subFeatureFlags) = @_;
|
||||
my ($self) = {
|
||||
'direction' => $direction,
|
||||
'orientation' => $orientation,
|
||||
'subFeatureFlags' => $subFeatureFlags
|
||||
};
|
||||
|
||||
$class = ref($class) || $class;
|
||||
bless $self, $class;
|
||||
}
|
||||
|
||||
=head2 $t->read
|
||||
|
||||
Reads the table into memory
|
||||
|
||||
=cut
|
||||
|
||||
sub read
|
||||
{
|
||||
my ($self, $fh) = @_;
|
||||
my ($dat);
|
||||
|
||||
my $stateTableStart = $fh->tell();
|
||||
my ($classes, $states, $entries) = AAT_read_state_table($fh, 0);
|
||||
|
||||
$fh->seek($stateTableStart, IO::File::SEEK_SET);
|
||||
$fh->read($dat, 14);
|
||||
my ($stateSize, $classTable, $stateArray, $entryTable,
|
||||
$ligActionTable, $componentTable, $ligatureTable) = unpack("nnnnnnn", $dat);
|
||||
my $limits = [$classTable, $stateArray, $entryTable, $ligActionTable, $componentTable, $ligatureTable, $self->{'length'} - 8];
|
||||
|
||||
my %actions;
|
||||
my $actionLists;
|
||||
foreach (@$entries) {
|
||||
my $offset = $_->{'flags'} & 0x3fff;
|
||||
$_->{'flags'} &= ~0x3fff;
|
||||
if ($offset != 0) {
|
||||
if (not defined $actions{$offset}) {
|
||||
$fh->seek($stateTableStart + $offset, IO::File::SEEK_SET);
|
||||
my $actionList;
|
||||
while (1) {
|
||||
$fh->read($dat, 4);
|
||||
my $action = unpack("N", $dat);
|
||||
my ($last, $store, $component) = (($action & 0x80000000) != 0, ($action & 0xC0000000) != 0, ($action & 0x3fffffff));
|
||||
$component -= 0x40000000 if $component > 0x1fffffff;
|
||||
$component -= $componentTable / 2;
|
||||
push @$actionList, { 'store' => $store, 'component' => $component };
|
||||
last if $last;
|
||||
}
|
||||
push @$actionLists, $actionList;
|
||||
$actions{$offset} = $#$actionLists;
|
||||
}
|
||||
$_->{'actions'} = $actions{$offset};
|
||||
}
|
||||
}
|
||||
|
||||
$self->{'componentTable'} = $componentTable;
|
||||
my $components = [unpack("n*", AAT_read_subtable($fh, $stateTableStart, $componentTable, $limits))];
|
||||
foreach (@$components) {
|
||||
$_ = ($_ - $ligatureTable) . " +" if $_ >= $ligatureTable;
|
||||
}
|
||||
$self->{'components'} = $components;
|
||||
|
||||
$self->{'ligatureTable'} = $ligatureTable;
|
||||
$self->{'ligatures'} = [unpack("n*", AAT_read_subtable($fh, $stateTableStart, $ligatureTable, $limits))];
|
||||
|
||||
$self->{'classes'} = $classes;
|
||||
$self->{'states'} = $states;
|
||||
$self->{'actionLists'} = $actionLists;
|
||||
|
||||
$self;
|
||||
}
|
||||
|
||||
=head2 $t->pack_sub($fh)
|
||||
|
||||
=cut
|
||||
|
||||
sub pack_sub
|
||||
{
|
||||
my ($self) = @_;
|
||||
my ($dat);
|
||||
|
||||
$dat .= pack("nnnnnnn", (0) x 7); # placeholders for stateSize, classTable, stateArray, entryTable, actionLists, components, ligatures
|
||||
|
||||
my $classTable = length($dat);
|
||||
my $classes = $self->{'classes'};
|
||||
$dat .= AAT_pack_classes($classes);
|
||||
|
||||
my $stateArray = length($dat);
|
||||
my $states = $self->{'states'};
|
||||
|
||||
my ($dat1, $stateSize, $entries) = AAT_pack_states($classes, $stateArray, $states,
|
||||
sub {
|
||||
( $_->{'flags'} & 0xc000, $_->{'actions'} )
|
||||
}
|
||||
);
|
||||
$dat .= $dat1;
|
||||
|
||||
my $actionLists = $self->{'actionLists'};
|
||||
my %actionListOffset;
|
||||
my $actionListDataLength = 0;
|
||||
my @actionListEntries;
|
||||
foreach (0 .. $#$entries) {
|
||||
my ($nextState, $flags, $offset) = split(/,/, $entries->[$_]);
|
||||
if ($offset eq "") {
|
||||
$offset = undef;
|
||||
}
|
||||
else {
|
||||
if (defined $actionListOffset{$offset}) {
|
||||
$offset = $actionListOffset{$offset};
|
||||
}
|
||||
else {
|
||||
$actionListOffset{$offset} = $actionListDataLength;
|
||||
my $list = $actionLists->[$offset];
|
||||
$actionListDataLength += 4 * @$list;
|
||||
push @actionListEntries, $list;
|
||||
$offset = $actionListOffset{$offset};
|
||||
}
|
||||
}
|
||||
$entries->[$_] = [ $nextState, $flags, $offset ];
|
||||
}
|
||||
my $entryTable = length($dat);
|
||||
my $ligActionLists = ($entryTable + @$entries * 4 + 3) & ~3;
|
||||
foreach (@$entries) {
|
||||
$_->[2] += $ligActionLists if defined $_->[2];
|
||||
$dat .= pack("nn", $_->[0], $_->[1] + $_->[2]);
|
||||
}
|
||||
$dat .= pack("C*", (0) x ($ligActionLists - $entryTable - @$entries * 4));
|
||||
|
||||
die "internal error" unless length($dat) == $ligActionLists;
|
||||
|
||||
my $componentTable = length($dat) + $actionListDataLength;
|
||||
my $actionList;
|
||||
foreach $actionList (@actionListEntries) {
|
||||
foreach (0 .. $#$actionList) {
|
||||
my $action = $actionList->[$_];
|
||||
my $val = $action->{'component'} + $componentTable / 2;
|
||||
$val += 0x40000000 if $val < 0;
|
||||
$val &= 0x3fffffff;
|
||||
$val |= 0x40000000 if $action->{'store'};
|
||||
$val |= 0x80000000 if $_ == $#$actionList;
|
||||
$dat .= pack("N", $val);
|
||||
}
|
||||
}
|
||||
|
||||
die "internal error" unless length($dat) == $componentTable;
|
||||
|
||||
my $components = $self->{'components'};
|
||||
my $ligatureTable = $componentTable + @$components * 2;
|
||||
$dat .= pack("n*", map { (index($_, '+') >= 0 ? $ligatureTable : 0) + $_ } @$components);
|
||||
|
||||
my $ligatures = $self->{'ligatures'};
|
||||
$dat .= pack("n*", @$ligatures);
|
||||
|
||||
$dat1 = pack("nnnnnnn", $stateSize, $classTable, $stateArray, $entryTable, $ligActionLists, $componentTable, $ligatureTable);
|
||||
substr($dat, 0, length($dat1)) = $dat1;
|
||||
|
||||
return $dat;
|
||||
}
|
||||
|
||||
=head2 $t->print($fh)
|
||||
|
||||
Prints a human-readable representation of the table
|
||||
|
||||
=cut
|
||||
|
||||
sub print
|
||||
{
|
||||
my ($self, $fh) = @_;
|
||||
|
||||
my $post = $self->post();
|
||||
|
||||
$fh = 'STDOUT' unless defined $fh;
|
||||
|
||||
$self->print_classes($fh);
|
||||
|
||||
$fh->print("\n");
|
||||
my $states = $self->{'states'};
|
||||
foreach (0 .. $#$states) {
|
||||
$fh->printf("\t\tState %d:", $_);
|
||||
my $state = $states->[$_];
|
||||
foreach (@$state) {
|
||||
my $flags;
|
||||
$flags .= "!" if ($_->{'flags'} & 0x4000);
|
||||
$flags .= "*" if ($_->{'flags'} & 0x8000);
|
||||
$fh->printf("\t(%s%d,%s)", $flags, $_->{'nextState'}, defined $_->{'actions'} ? $_->{'actions'} : "=");
|
||||
}
|
||||
$fh->print("\n");
|
||||
}
|
||||
|
||||
$fh->print("\n");
|
||||
my $actionLists = $self->{'actionLists'};
|
||||
foreach (0 .. $#$actionLists) {
|
||||
$fh->printf("\t\tList %d:\t", $_);
|
||||
my $actionList = $actionLists->[$_];
|
||||
$fh->printf("%s\n", join(", ", map { ($_->{'component'} . ($_->{'store'} ? "*" : "") ) } @$actionList));
|
||||
}
|
||||
|
||||
my $ligatureTable = $self->{'ligatureTable'};
|
||||
|
||||
$fh->print("\n");
|
||||
my $components = $self->{'components'};
|
||||
foreach (0 .. $#$components) {
|
||||
$fh->printf("\t\tComponent %d: %s\n", $_, $components->[$_]);
|
||||
}
|
||||
|
||||
$fh->print("\n");
|
||||
my $ligatures = $self->{'ligatures'};
|
||||
foreach (0 .. $#$ligatures) {
|
||||
$fh->printf("\t\tLigature %d: %d [%s]\n", $_, $ligatures->[$_], $post->{'VAL'}[$ligatures->[$_]]);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
None known
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Jonathan Kew L<http://scripts.sil.org/FontUtils>.
|
||||
|
||||
|
||||
=head1 LICENSING
|
||||
|
||||
Copyright (c) 1998-2016, SIL International (http://www.sil.org)
|
||||
|
||||
This module is released under the terms of the Artistic License 2.0.
|
||||
For details, see the full text of the license in the file LICENSE.
|
||||
|
||||
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
105
Perl OTRS/Kernel/cpan-lib/Font/TTF/Mort/Noncontextual.pm
Normal file
105
Perl OTRS/Kernel/cpan-lib/Font/TTF/Mort/Noncontextual.pm
Normal file
@@ -0,0 +1,105 @@
|
||||
package Font::TTF::Mort::Noncontextual;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Font::TTF::Mort::Noncontextual - Noncontextual Mort subtable for AAT
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use vars qw(@ISA);
|
||||
use Font::TTF::Utils;
|
||||
use Font::TTF::AATutils;
|
||||
|
||||
@ISA = qw(Font::TTF::Mort::Subtable);
|
||||
|
||||
sub new
|
||||
{
|
||||
my ($class, $direction, $orientation, $subFeatureFlags) = @_;
|
||||
my ($self) = {
|
||||
'direction' => $direction,
|
||||
'orientation' => $orientation,
|
||||
'subFeatureFlags' => $subFeatureFlags
|
||||
};
|
||||
|
||||
$class = ref($class) || $class;
|
||||
bless $self, $class;
|
||||
}
|
||||
|
||||
=head2 $t->read
|
||||
|
||||
Reads the table into memory
|
||||
|
||||
=cut
|
||||
|
||||
sub read
|
||||
{
|
||||
my ($self, $fh) = @_;
|
||||
my ($dat);
|
||||
|
||||
my ($format, $lookup) = AAT_read_lookup($fh, 2, $self->{'length'} - 8, undef);
|
||||
$self->{'format'} = $format;
|
||||
$self->{'lookup'} = $lookup;
|
||||
|
||||
$self;
|
||||
}
|
||||
|
||||
=head2 $t->pack_sub($fh)
|
||||
|
||||
=cut
|
||||
|
||||
sub pack_sub
|
||||
{
|
||||
my ($self) = @_;
|
||||
|
||||
return AAT_pack_lookup($self->{'format'}, $self->{'lookup'}, 2, undef);
|
||||
}
|
||||
|
||||
=head2 $t->print($fh)
|
||||
|
||||
Prints a human-readable representation of the table
|
||||
|
||||
=cut
|
||||
|
||||
sub print
|
||||
{
|
||||
my ($self, $fh) = @_;
|
||||
|
||||
my $post = $self->post();
|
||||
|
||||
$fh = 'STDOUT' unless defined $fh;
|
||||
|
||||
my $lookup = $self->{'lookup'};
|
||||
$fh->printf("\t\tLookup format %d\n", $self->{'format'});
|
||||
if (defined $lookup) {
|
||||
foreach (sort { $a <=> $b } keys %$lookup) {
|
||||
$fh->printf("\t\t\t%d [%s] -> %d [%s])\n", $_, $post->{'VAL'}[$_], $lookup->{$_}, $post->{'VAL'}[$lookup->{$_}]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
None known
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Jonathan Kew L<http://scripts.sil.org/FontUtils>.
|
||||
|
||||
|
||||
=head1 LICENSING
|
||||
|
||||
Copyright (c) 1998-2016, SIL International (http://www.sil.org)
|
||||
|
||||
This module is released under the terms of the Artistic License 2.0.
|
||||
For details, see the full text of the license in the file LICENSE.
|
||||
|
||||
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
118
Perl OTRS/Kernel/cpan-lib/Font/TTF/Mort/Rearrangement.pm
Normal file
118
Perl OTRS/Kernel/cpan-lib/Font/TTF/Mort/Rearrangement.pm
Normal file
@@ -0,0 +1,118 @@
|
||||
package Font::TTF::Mort::Rearrangement;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Font::TTF::Mort::Rearrangement - Rearrangement Mort subtable for AAT
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use vars qw(@ISA);
|
||||
use Font::TTF::Utils;
|
||||
use Font::TTF::AATutils;
|
||||
|
||||
@ISA = qw(Font::TTF::Mort::Subtable);
|
||||
|
||||
sub new
|
||||
{
|
||||
my ($class, $direction, $orientation, $subFeatureFlags) = @_;
|
||||
my ($self) = {
|
||||
'direction' => $direction,
|
||||
'orientation' => $orientation,
|
||||
'subFeatureFlags' => $subFeatureFlags
|
||||
};
|
||||
|
||||
$class = ref($class) || $class;
|
||||
bless $self, $class;
|
||||
}
|
||||
|
||||
=head2 $t->read
|
||||
|
||||
Reads the table into memory
|
||||
|
||||
=cut
|
||||
|
||||
sub read
|
||||
{
|
||||
my ($self, $fh) = @_;
|
||||
|
||||
my ($classes, $states) = AAT_read_state_table($fh, 0);
|
||||
$self->{'classes'} = $classes;
|
||||
$self->{'states'} = $states;
|
||||
|
||||
$self;
|
||||
}
|
||||
|
||||
=head2 $t->pack_sub()
|
||||
|
||||
=cut
|
||||
|
||||
sub pack_sub
|
||||
{
|
||||
my ($self) = @_;
|
||||
|
||||
return AAT_pack_state_table($self->{'classes'}, $self->{'states'}, 0);
|
||||
}
|
||||
|
||||
=head2 $t->print($fh)
|
||||
|
||||
Prints a human-readable representation of the table
|
||||
|
||||
=cut
|
||||
|
||||
sub print
|
||||
{
|
||||
my ($self, $fh) = @_;
|
||||
|
||||
my $post = $self->post();
|
||||
|
||||
$fh = 'STDOUT' unless defined $fh;
|
||||
|
||||
$self->print_classes($fh);
|
||||
|
||||
$fh->print("\n");
|
||||
my $states = $self->{'states'};
|
||||
my @verbs = ( "0", "Ax->xA", "xD->Dx", "AxD->DxA",
|
||||
"ABx->xAB", "ABx->xBA", "xCD->CDx", "xCD->DCx",
|
||||
"AxCD->CDxA", "AxCD->DCxA", "ABxD->DxAB", "ABxD->DxBA",
|
||||
"ABxCD->CDxAB", "ABxCD->CDxBA", "ABxCD->DCxAB", "ABxCD->DCxBA");
|
||||
foreach (0 .. $#$states) {
|
||||
$fh->printf("\t\tState %d:", $_);
|
||||
my $state = $states->[$_];
|
||||
foreach (@$state) {
|
||||
my $flags;
|
||||
$flags .= "!" if ($_->{'flags'} & 0x4000);
|
||||
$flags .= "<" if ($_->{'flags'} & 0x8000);
|
||||
$flags .= ">" if ($_->{'flags'} & 0x2000);
|
||||
$fh->printf("\t(%s%d,%s)", $flags, $_->{'nextState'}, $verbs[($_->{'flags'} & 0x000f)]);
|
||||
}
|
||||
$fh->print("\n");
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
None known
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Jonathan Kew L<http://scripts.sil.org/FontUtils>.
|
||||
|
||||
|
||||
=head1 LICENSING
|
||||
|
||||
Copyright (c) 1998-2016, SIL International (http://www.sil.org)
|
||||
|
||||
This module is released under the terms of the Artistic License 2.0.
|
||||
For details, see the full text of the license in the file LICENSE.
|
||||
|
||||
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
|
||||
210
Perl OTRS/Kernel/cpan-lib/Font/TTF/Mort/Subtable.pm
Normal file
210
Perl OTRS/Kernel/cpan-lib/Font/TTF/Mort/Subtable.pm
Normal file
@@ -0,0 +1,210 @@
|
||||
package Font::TTF::Mort::Subtable;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Font::TTF::Mort::Subtable - Mort subtable superclass for AAT
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use Font::TTF::Utils;
|
||||
use Font::TTF::AATutils;
|
||||
use IO::File;
|
||||
|
||||
require Font::TTF::Mort::Rearrangement;
|
||||
require Font::TTF::Mort::Contextual;
|
||||
require Font::TTF::Mort::Ligature;
|
||||
require Font::TTF::Mort::Noncontextual;
|
||||
require Font::TTF::Mort::Insertion;
|
||||
|
||||
sub new
|
||||
{
|
||||
my ($class) = @_;
|
||||
my ($self) = {};
|
||||
|
||||
$class = ref($class) || $class;
|
||||
|
||||
bless $self, $class;
|
||||
}
|
||||
|
||||
sub create
|
||||
{
|
||||
my ($class, $type, $coverage, $subFeatureFlags, $length) = @_;
|
||||
|
||||
$class = ref($class) || $class;
|
||||
|
||||
my $subclass;
|
||||
if ($type == 0) {
|
||||
$subclass = 'Font::TTF::Mort::Rearrangement';
|
||||
}
|
||||
elsif ($type == 1) {
|
||||
$subclass = 'Font::TTF::Mort::Contextual';
|
||||
}
|
||||
elsif ($type == 2) {
|
||||
$subclass = 'Font::TTF::Mort::Ligature';
|
||||
}
|
||||
elsif ($type == 4) {
|
||||
$subclass = 'Font::TTF::Mort::Noncontextual';
|
||||
}
|
||||
elsif ($type == 5) {
|
||||
$subclass = 'Font::TTF::Mort::Insertion';
|
||||
}
|
||||
|
||||
my ($self) = $subclass->new(
|
||||
(($coverage & 0x4000) ? 'RL' : 'LR'),
|
||||
(($coverage & 0x2000) ? 'VH' : ($coverage & 0x8000) ? 'V' : 'H'),
|
||||
$subFeatureFlags
|
||||
);
|
||||
|
||||
$self->{'type'} = $type;
|
||||
$self->{'length'} = $length;
|
||||
|
||||
$self;
|
||||
}
|
||||
|
||||
=head2 $t->out($fh)
|
||||
|
||||
Writes the table to a file
|
||||
|
||||
=cut
|
||||
|
||||
sub out
|
||||
{
|
||||
my ($self, $fh) = @_;
|
||||
|
||||
my ($subtableStart) = $fh->tell();
|
||||
my ($type) = $self->{'type'};
|
||||
my ($coverage) = $type;
|
||||
$coverage += 0x4000 if $self->{'direction'} eq 'RL';
|
||||
$coverage += 0x2000 if $self->{'orientation'} eq 'VH';
|
||||
$coverage += 0x8000 if $self->{'orientation'} eq 'V';
|
||||
|
||||
$fh->print(TTF_Pack("SSL", 0, $coverage, $self->{'subFeatureFlags'})); # placeholder for length
|
||||
|
||||
my ($dat) = $self->pack_sub();
|
||||
$fh->print($dat);
|
||||
|
||||
my ($length) = $fh->tell() - $subtableStart;
|
||||
my ($padBytes) = (4 - ($length & 3)) & 3;
|
||||
$fh->print(pack("C*", (0) x $padBytes));
|
||||
$length += $padBytes;
|
||||
$fh->seek($subtableStart, IO::File::SEEK_SET);
|
||||
$fh->print(pack("n", $length));
|
||||
$fh->seek($subtableStart + $length, IO::File::SEEK_SET);
|
||||
}
|
||||
|
||||
=head2 $t->print($fh)
|
||||
|
||||
Prints a human-readable representation of the table
|
||||
|
||||
=cut
|
||||
|
||||
sub post
|
||||
{
|
||||
my ($self) = @_;
|
||||
|
||||
my ($post) = $self->{' PARENT'}{' PARENT'}{' PARENT'}{'post'};
|
||||
if (defined $post) {
|
||||
$post->read;
|
||||
}
|
||||
else {
|
||||
$post = {};
|
||||
}
|
||||
|
||||
return $post;
|
||||
}
|
||||
|
||||
sub feat
|
||||
{
|
||||
my ($self) = @_;
|
||||
|
||||
return $self->{' PARENT'}->feat();
|
||||
}
|
||||
|
||||
sub print
|
||||
{
|
||||
my ($self, $fh) = @_;
|
||||
|
||||
my ($feat) = $self->feat();
|
||||
my ($post) = $self->post();
|
||||
|
||||
$fh = 'STDOUT' unless defined $fh;
|
||||
|
||||
my ($type) = $self->{'type'};
|
||||
my ($subFeatureFlags) = $self->{'subFeatureFlags'};
|
||||
my ($defaultFlags) = $self->{' PARENT'}{'defaultFlags'};
|
||||
my ($featureEntries) = $self->{' PARENT'}{'featureEntries'};
|
||||
$fh->printf("\n\t%s table, %s, %s, subFeatureFlags = %08x # %s (%s)\n",
|
||||
subtable_type_($type), $_->{'direction'}, $_->{'orientation'}, $subFeatureFlags,
|
||||
"Default " . ((($subFeatureFlags & $defaultFlags) != 0) ? "On" : "Off"),
|
||||
join(", ",
|
||||
map {
|
||||
join(": ", $feat->settingName($_->{'type'}, $_->{'setting'}) )
|
||||
} grep { ($_->{'enable'} & $subFeatureFlags) != 0 } @$featureEntries
|
||||
) );
|
||||
}
|
||||
|
||||
sub subtable_type_
|
||||
{
|
||||
my ($val) = @_;
|
||||
my ($res);
|
||||
|
||||
my (@types) = (
|
||||
'Rearrangement',
|
||||
'Contextual',
|
||||
'Ligature',
|
||||
undef,
|
||||
'Non-contextual',
|
||||
'Insertion',
|
||||
);
|
||||
$res = $types[$val] or ('Undefined (' . $val . ')');
|
||||
|
||||
$res;
|
||||
}
|
||||
|
||||
=head2 $t->print_classes($fh)
|
||||
|
||||
Prints a human-readable representation of the table
|
||||
|
||||
=cut
|
||||
|
||||
sub print_classes
|
||||
{
|
||||
my ($self, $fh) = @_;
|
||||
|
||||
my ($post) = $self->post();
|
||||
|
||||
my ($classes) = $self->{'classes'};
|
||||
foreach (0 .. $#$classes) {
|
||||
my $class = $classes->[$_];
|
||||
if (defined $class) {
|
||||
$fh->printf("\t\tClass %d:\t%s\n", $_, join(", ", map { $_ . " [" . $post->{'VAL'}[$_] . "]" } @$class));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
None known
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Jonathan Kew L<http://scripts.sil.org/FontUtils>.
|
||||
|
||||
|
||||
=head1 LICENSING
|
||||
|
||||
Copyright (c) 1998-2016, SIL International (http://www.sil.org)
|
||||
|
||||
This module is released under the terms of the Artistic License 2.0.
|
||||
For details, see the full text of the license in the file LICENSE.
|
||||
|
||||
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
Reference in New Issue
Block a user