API3/Compat/API2/Basic/TTF/Kern/Subtable.pm untested

filter: Statementstmt 0.0% 0 / 85 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 144 CC 15 SCAR 32.5
CC
15
Cov
0%
create
72.0
out
20.0
post
6.0
CRAP 25.7
1 #=======================================================================
2 # ____ ____ _____ _ ____ ___ ____
3 # | _ \| _ \| ___| _ _ / \ | _ \_ _| |___ \
4 # | |_) | | | | |_ (_) (_) / _ \ | |_) | | __) |
5 # | __/| |_| | _| _ _ / ___ \| __/| | / __/
6 # |_| |____/|_| (_) (_) /_/ \_\_| |___| |_____|
7 #
8 # A Perl Module Chain to faciliate the Creation and Modification
9 # of High-Quality "Portable Document Format (PDF)" Files.
10 #
11 #=======================================================================
12 #
13 # THIS IS A REUSED PERL MODULE, FOR PROPER LICENCING TERMS SEE BELOW:
14 #
15 #
16 # Copyright Jonathan Kew L<Jonathan_Kew@sil.org>
17 #
18 # No warranty or expression of effectiveness, least of all regarding
19 # anyone's safety, is implied in this software or documentation.
20 #
21 # This specific module is licensed under the Perl Artistic License.
22 #
23 #
24 # $Id: Subtable.pm,v 2.0 2005/11/16 02:16:00 areibens Exp $
25 #
26 #=======================================================================
27 package PDF::API3::Compat::API2::Basic::TTF::Kern::Subtable;
28
29 =head1 NAME
30
31 PDF::API3::Compat::API2::Basic::TTF::Kern::Subtable
32
33 =head1 METHODS
34
35 =cut
36
37 use strict;
38 use PDF::API3::Compat::API2::Basic::TTF::Utils;
39 use PDF::API3::Compat::API2::Basic::TTF::AATutils;
40
41 require PDF::API3::Compat::API2::Basic::TTF::Kern::OrderedList;
42 require PDF::API3::Compat::API2::Basic::TTF::Kern::StateTable;
43 require PDF::API3::Compat::API2::Basic::TTF::Kern::ClassArray;
44 require PDF::API3::Compat::API2::Basic::TTF::Kern::CompactClassArray;
45
46 sub new
47 {
48 my ($class) = @_;
49 my ($self) = {};
50
51 $class = ref($class) || $class;
52
53 bless $self, $class;
54 }
55
56 sub create
57 {
58 my ($class, $type, $coverage, $length) = @_;
59
60 $class = ref($class) || $class;
61
62 my $subclass;
63 if ($type == 0) {
64 $subclass = 'PDF::API3::Compat::API2::Basic::TTF::Kern::OrderedList';
65 }
66 elsif ($type == 1) {
67 $subclass = 'PDF::API3::Compat::API2::Basic::TTF::Kern::StateTable';
68 }
69 elsif ($type == 2) {
70 $subclass = 'PDF::API3::Compat::API2::Basic::TTF::Kern::ClassArray';
71 }
72 elsif ($type == 3) {
73 $subclass = 'PDF::API3::Compat::API2::Basic::TTF::Kern::CompactClassArray';
74 }
75
76 my @options;
77 push @options,'vertical' if ($coverage & 0x8000) != 0;
78 push @options,'crossStream' if ($coverage & 0x4000) != 0;
79 push @options,'variation' if ($coverage & 0x2000) != 0;
80
81 my ($subTable) = $subclass->new(@options);
82
83 map { $subTable->{$_} = 1 } @options;
84
85 $subTable->{'type'} = $type;
86 $subTable->{'length'} = $length;
87
88 $subTable;
89 }
90
91 =head2 $t->out($fh)
92
93 Writes the table to a file
94
95 =cut
96
97 sub out
98 {
99 my ($self, $fh) = @_;
100
101 my $subtableStart = $fh->tell();
102 my $type = $self->{'type'};
103 my $coverage = $type;
104 $coverage += 0x4000 if $self->{'direction'} eq 'RL';
105 $coverage += 0x2000 if $self->{'orientation'} eq 'VH';
106 $coverage += 0x8000 if $self->{'orientation'} eq 'V';
107
108 $fh->print(TTF_Pack("SSL", 0, $coverage, $self->{'subFeatureFlags'})); # placeholder for length
109
110 $self->out_sub($fh);
111
112 my $length = $fh->tell() - $subtableStart;
113 my $padBytes = (4 - ($length & 3)) & 3;
114 $fh->print(pack("C*", (0) x $padBytes));
115 $length += $padBytes;
116 $fh->seek($subtableStart, IO::File::SEEK_SET);
117 $fh->print(pack("n", $length));
118 $fh->seek($subtableStart + $length, IO::File::SEEK_SET);
119 }
120
121 =head2 $t->print($fh)
122
123 Prints a human-readable representation of the table
124
125 =cut
126
127 sub post
128 {
129 my ($self) = @_;
130
131 my $post = $self->{' PARENT'}{' PARENT'}{'post'};
132 if (defined $post) {
133 $post->read;
134 }
135 else {
136 $post = {};
137 }
138
139 return $post;
140 }
141
142 sub print
143 {
144 my ($self, $fh) = @_;
145
146 my $post = $self->post();
147 $fh = 'STDOUT' unless defined $fh;
148 }
149
150 =head2 $t->print_classes($fh)
151
152 Prints a human-readable representation of the table
153
154 =cut
155
156 sub print_classes
157 {
158 my ($self, $fh) = @_;
159
160 my $post = $self->post();
161
162 my $classes = $self->{'classes'};
163 foreach (0 .. $#$classes) {
164 my $class = $classes->[$_];
165 if (defined $class) {
166 $fh->printf("\t\tClass %d:\t%s\n", $_, join(", ", map { $_ . " [" . $post->{'VAL'}[$_] . "]" } @$class));
167 }
168 }
169 }
170
171 sub dumpClasses
172 {
173 my ($self, $classes, $fh) = @_;
174 my $post = $self->post();
175
176 foreach (0 .. $#$classes) {
177 my $c = $classes->[$_];
178 if ($#$c > -1) {
179 $fh->printf("<class n=\"%s\">\n", $_);
180 foreach (@$c) {
181 $fh->printf("<g index=\"%s\" name=\"%s\"/>\n", $_, $post->{'VAL'}[$_]);
182 }
183 $fh->printf("</class>\n");
184 }
185 }
186 }
187
188 1;
189
190 =head1 BUGS
191
192 None known
193
194 =head1 AUTHOR
195
196 Jonathan Kew L<Jonathan_Kew@sil.org>. See L<PDF::API3::Compat::API2::Basic::TTF::Font> for copyright and
197 licensing.
198
199 =cut
200