1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 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<Jonathan_Kew@sil.org>.
=head1 LICENSING
Copyright (c) 1998-2013, 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
|