This commit is contained in:
2024-10-14 00:08:40 +02:00
parent dbfba56f66
commit 1462d52e13
4572 changed files with 2658864 additions and 0 deletions

View File

@@ -0,0 +1,163 @@
package Font::TTF::Kern::ClassArray;
=head1 NAME
Font::TTF::Kern::ClassArray - ClassArray Kern 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::Kern::Subtable);
sub new
{
my ($class) = @_;
my ($self) = {};
$class = ref($class) || $class;
bless $self, $class;
}
=head2 $t->read
Reads the table into memory
=cut
sub read
{
my ($self, $fh) = @_;
my $subtableStart = $fh->tell() - 8;
my $dat;
$fh->read($dat, 8);
my ($rowWidth, $leftClassTable, $rightClassTable, $array) = unpack("nnnn", $dat);
$fh->seek($subtableStart + $leftClassTable, IO::File::SEEK_SET);
$fh->read($dat, 4);
my ($firstGlyph, $nGlyphs) = unpack("nn", $dat);
$fh->read($dat, $nGlyphs * 2);
my $leftClasses = [];
foreach (TTF_Unpack("S*", $dat)) {
push @{$leftClasses->[($_ - $array) / $rowWidth]}, $firstGlyph++;
}
$fh->seek($subtableStart + $rightClassTable, IO::File::SEEK_SET);
$fh->read($dat, 4);
($firstGlyph, $nGlyphs) = unpack("nn", $dat);
$fh->read($dat, $nGlyphs * 2);
my $rightClasses = [];
foreach (TTF_Unpack("S*", $dat)) {
push @{$rightClasses->[$_ / 2]}, $firstGlyph++;
}
$fh->seek($subtableStart + $array, IO::File::SEEK_SET);
$fh->read($dat, $self->{'length'} - $array);
my $offset = 0;
my $kernArray = [];
while ($offset < length($dat)) {
push @$kernArray, [ TTF_Unpack("s*", substr($dat, $offset, $rowWidth)) ];
$offset += $rowWidth;
}
$self->{'leftClasses'} = $leftClasses;
$self->{'rightClasses'} = $rightClasses;
$self->{'kernArray'} = $kernArray;
$fh->seek($subtableStart + $self->{'length'}, IO::File::SEEK_SET);
$self;
}
=head2 $t->out_sub($fh)
Writes the table to a file
=cut
sub out_sub
{
}
=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;
}
sub dumpXML
{
my ($self, $fh) = @_;
my $post = $self->post();
$fh = 'STDOUT' unless defined $fh;
$fh->printf("<leftClasses>\n");
$self->dumpClasses($self->{'leftClasses'}, $fh);
$fh->printf("</leftClasses>\n");
$fh->printf("<rightClasses>\n");
$self->dumpClasses($self->{'rightClasses'}, $fh);
$fh->printf("</rightClasses>\n");
$fh->printf("<kernArray>\n");
my $kernArray = $self->{'kernArray'};
foreach (0 .. $#$kernArray) {
$fh->printf("<row index=\"%s\">\n", $_);
my $row = $kernArray->[$_];
foreach (0 .. $#$row) {
$fh->printf("<val index=\"%s\" v=\"%s\"/>\n", $_, $row->[$_]);
}
$fh->printf("</row>\n");
}
$fh->printf("</kernArray>\n");
}
sub type
{
return 'kernClassArray';
}
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

View File

@@ -0,0 +1,103 @@
package Font::TTF::Kern::CompactClassArray;
=head1 NAME
Font::TTF::Kern::CompactClassArray - Compact Class Array kern subtable for AAT
=head1 METHODS
=cut
use strict;
use vars qw(@ISA);
use Font::TTF::Utils;
use Font::TTF::AATutils;
@ISA = qw(Font::TTF::Kern::Subtable);
sub new
{
my ($class) = @_;
my ($self) = {};
$class = ref($class) || $class;
bless $self, $class;
}
=head2 $t->read
Reads the table into memory
=cut
sub read
{
my ($self, $fh) = @_;
die "incomplete";
$self;
}
=head2 $t->out($fh)
Writes the table to a file
=cut
sub out_sub
{
my ($self, $fh) = @_;
die "incomplete";
$self;
}
=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;
die "incomplete";
}
sub type
{
return 'kernCompactClassArray';
}
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

View File

@@ -0,0 +1,118 @@
package Font::TTF::Kern::OrderedList;
=head1 NAME
Font::TTF::Kern::OrderedList - Ordered List Kern subtable for AAT
=head1 METHODS
=cut
use strict;
use vars qw(@ISA);
use Font::TTF::Utils;
use Font::TTF::AATutils;
@ISA = qw(Font::TTF::Kern::Subtable);
sub new
{
my ($class, @options) = @_;
my ($self) = {};
$class = ref($class) || $class;
bless $self, $class;
}
=head2 $t->read
Reads the table into memory
=cut
sub read
{
my ($self, $fh) = @_;
my $dat;
$fh->read($dat, 8);
my ($nPairs, $searchRange, $entrySelector, $rangeShift) = unpack("nnnn", $dat);
my $pairs = [];
foreach (1 .. $nPairs) {
$fh->read($dat, 6);
my ($left, $right, $kern) = TTF_Unpack("SSs", $dat);
push @$pairs, { 'left' => $left, 'right' => $right, 'kern' => $kern } if $kern != 0;
}
$self->{'kernPairs'} = $pairs;
$self;
}
=head2 $t->out_sub($fh)
Writes the table to a file
=cut
sub out_sub
{
my ($self, $fh) = @_;
my $pairs = $self->{'kernPairs'};
$fh->print(pack("nnnn", TTF_bininfo(scalar @$pairs, 6)));
foreach (sort { $a->{'left'} <=> $b->{'left'} or $a->{'right'} <=> $b->{'right'} } @$pairs) {
$fh->print(TTF_Pack("SSs", $_->{'left'}, $_->{'right'}, $_->{'kern'}));
}
}
=head2 $t->print($fh)
Prints a human-readable representation of the table
=cut
sub out_xml
{
my ($self, $context, $depth, $k, $val) = @_;
my ($fh) = $context->{'fh'};
my $postVal = $self->post()->{'VAL'};
$fh = 'STDOUT' unless defined $fh;
foreach (@{$self->{'kernPairs'}}) {
$fh->printf("$depth$context->{'indent'}<pair l=\"%s\" r=\"%s\" v=\"%s\"/>\n", $postVal->[$_->{'left'}], $postVal->[$_->{'right'}], $_->{'kern'});
}
}
sub type
{
return 'kernOrderedList';
}
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

View File

@@ -0,0 +1,153 @@
package Font::TTF::Kern::StateTable;
=head1 NAME
Font::TTF::Kern::StateTable - State Table Kern subtable for AAT
=head1 METHODS
=cut
use strict;
use vars qw(@ISA);
use Font::TTF::Utils;
use Font::TTF::AATutils;
use Font::TTF::Kern::Subtable;
use IO::File;
@ISA = qw(Font::TTF::Kern::Subtable);
sub new
{
my ($class) = @_;
my ($self) = {};
$class = ref($class) || $class;
bless $self, $class;
}
=head2 $t->read
Reads the table into memory
=cut
sub read
{
my ($self, $fh) = @_;
my ($dat);
my $stTableStart = $fh->tell();
my ($classes, $states, $entries) = AAT_read_state_table($fh, 0);
foreach (@$entries) {
my $flags = $_->{'flags'};
delete $_->{'flags'};
$_->{'push'} = 1 if $flags & 0x8000;
$_->{'noAdvance'} = 1 if $flags & 0x4000;
$flags &= ~0xC000;
if ($flags != 0) {
my $kernList = [];
$fh->seek($stTableStart + $flags, IO::File::SEEK_SET);
while (1) {
$fh->read($dat, 2);
my $k = TTF_Unpack("s", $dat);
push @$kernList, ($k & ~1);
last if ($k & 1) != 0;
}
$_->{'kernList'} = $kernList;
}
}
$self->{'classes'} = $classes;
$self->{'states'} = $states;
$self->{'entries'} = $entries;
$fh->seek($stTableStart - 8 + $self->{'length'}, IO::File::SEEK_SET);
$self;
}
=head2 $t->out_sub($fh)
Writes the table to a file
=cut
sub out_sub
{
}
=head2 $t->print($fh)
Prints a human-readable representation of the table
=cut
sub print
{
}
sub dumpXML
{
my ($self, $fh) = @_;
$fh->printf("<classes>\n");
$self->dumpClasses($self->{'classes'}, $fh);
$fh->printf("</classes>\n");
$fh->printf("<states>\n");
my $states = $self->{'states'};
foreach (0 .. $#$states) {
$fh->printf("<state index=\"%s\">\n", $_);
my $members = $states->[$_];
foreach (0 .. $#$members) {
my $m = $members->[$_];
$fh->printf("<m index=\"%s\" nextState=\"%s\"", $_, $m->{'nextState'});
$fh->printf(" push=\"1\"") if $m->{'push'};
$fh->printf(" noAdvance=\"1\"") if $m->{'noAdvance'};
if (exists $m->{'kernList'}) {
$fh->printf(">");
foreach (@{$m->{'kernList'}}) {
$fh->printf("<kern v=\"%s\"/>", $_);
}
$fh->printf("</m>\n");
}
else {
$fh->printf("/>\n");
}
}
$fh->printf("</state>\n");
}
$fh->printf("</states>\n");
}
sub type
{
return 'kernStateTable';
}
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

View File

@@ -0,0 +1,185 @@
package Font::TTF::Kern::Subtable;
=head1 NAME
Font::TTF::Kern::Subtable - Kern Subtable superclass for AAT
=head1 METHODS
=cut
use strict;
use Font::TTF::Utils;
use Font::TTF::AATutils;
use IO::File;
require Font::TTF::Kern::OrderedList;
require Font::TTF::Kern::StateTable;
require Font::TTF::Kern::ClassArray;
require Font::TTF::Kern::CompactClassArray;
sub new
{
my ($class) = @_;
my ($self) = {};
$class = ref($class) || $class;
bless $self, $class;
}
sub create
{
my ($class, $type, $coverage, $length) = @_;
$class = ref($class) || $class;
my $subclass;
if ($type == 0) {
$subclass = 'Font::TTF::Kern::OrderedList';
}
elsif ($type == 1) {
$subclass = 'Font::TTF::Kern::StateTable';
}
elsif ($type == 2) {
$subclass = 'Font::TTF::Kern::ClassArray';
}
elsif ($type == 3) {
$subclass = 'Font::TTF::Kern::CompactClassArray';
}
my @options;
push @options,'vertical' if ($coverage & 0x8000) != 0;
push @options,'crossStream' if ($coverage & 0x4000) != 0;
push @options,'variation' if ($coverage & 0x2000) != 0;
my ($subTable) = $subclass->new(@options);
map { $subTable->{$_} = 1 } @options;
$subTable->{'type'} = $type;
$subTable->{'length'} = $length;
$subTable;
}
=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 += 0x8000 if $self->{'vertical'};
$coverage += 0x4000 if $self->{'crossStream'};
$coverage += 0x2000 if $self->{'variation'};
$fh->print(TTF_Pack("LSS", 0, $coverage, $self->{'tupleIndex'})); # placeholder for length
$self->out_sub($fh);
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'}{'post'};
if (defined $post) {
$post->read;
}
else {
$post = {};
}
return $post;
}
sub print
{
my ($self, $fh) = @_;
my $post = $self->post();
$fh = 'STDOUT' unless defined $fh;
}
=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));
}
}
}
sub dumpClasses
{
my ($self, $classes, $fh) = @_;
my $post = $self->post();
foreach (0 .. $#$classes) {
my $c = $classes->[$_];
if ($#$c > -1) {
$fh->printf("<class n=\"%s\">\n", $_);
foreach (@$c) {
$fh->printf("<g index=\"%s\" name=\"%s\"/>\n", $_, $post->{'VAL'}[$_]);
}
$fh->printf("</class>\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