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

filter: Statementstmt 0.0% 0 / 74 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 99 CC 3 SCAR 12.0
CC
3
Cov
0%
print
6.0
dumpXML
6.0
new
2.0
CRAP 3.3
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: ClassArray.pm,v 2.0 2005/11/16 02:16:00 areibens Exp $
25 #
26 #=======================================================================
27 package PDF::API3::Compat::API2::Basic::TTF::Kern::ClassArray;
28
29 =head1 NAME
30
31 PDF::API3::Compat::API2::Basic::TTF::Kern::ClassArray
32
33 =head1 METHODS
34
35 =cut
36
37 use strict;
38 use vars qw(@ISA);
39 use PDF::API3::Compat::API2::Basic::TTF::Utils;
40 use PDF::API3::Compat::API2::Basic::TTF::AATutils;
41
42 @ISA = qw(PDF::API3::Compat::API2::Basic::TTF::Kern::Subtable);
43
44 sub new
45 {
46 my ($class) = @_;
47 my ($self) = {};
48
49 $class = ref($class) || $class;
50 bless $self, $class;
51 }
52
53 =head2 $t->read
54
55 Reads the table into memory
56
57 =cut
58
59 sub read
60 {
61 my ($self, $fh) = @_;
62
63 my $subtableStart = $fh->tell() - 8;
64 my $dat;
65 $fh->read($dat, 8);
66 my ($rowWidth, $leftClassTable, $rightClassTable, $array) = unpack("nnnn", $dat);
67
68 $fh->seek($subtableStart + $leftClassTable, IO::File::SEEK_SET);
69 $fh->read($dat, 4);
70 my ($firstGlyph, $nGlyphs) = unpack("nn", $dat);
71 $fh->read($dat, $nGlyphs * 2);
72 my $leftClasses = [];
73 foreach (TTF_Unpack("S*", $dat)) {
74 push @{$leftClasses->[($_ - $array) / $rowWidth]}, $firstGlyph++;
75 }
76
77 $fh->seek($subtableStart + $rightClassTable, IO::File::SEEK_SET);
78 $fh->read($dat, 4);
79 ($firstGlyph, $nGlyphs) = unpack("nn", $dat);
80 $fh->read($dat, $nGlyphs * 2);
81 my $rightClasses = [];
82 foreach (TTF_Unpack("S*", $dat)) {
83 push @{$rightClasses->[$_ / 2]}, $firstGlyph++;
84 }
85
86 $fh->seek($subtableStart + $array, IO::File::SEEK_SET);
87 $fh->read($dat, $self->{'length'} - $array);
88
89 my $offset = 0;
90 my $kernArray = [];
91 while ($offset < length($dat)) {
92 push @$kernArray, [ TTF_Unpack("s*", substr($dat, $offset, $rowWidth)) ];
93 $offset += $rowWidth;
94 }
95
96 $self->{'leftClasses'} = $leftClasses;
97 $self->{'rightClasses'} = $rightClasses;
98 $self->{'kernArray'} = $kernArray;
99
100 $fh->seek($subtableStart + $self->{'length'}, IO::File::SEEK_SET);
101
102 $self;
103 }
104
105 =head2 $t->out_sub($fh)
106
107 Writes the table to a file
108
109 =cut
110
111 sub out_sub
112 {
113 }
114
115 =head2 $t->print($fh)
116
117 Prints a human-readable representation of the table
118
119 =cut
120
121 sub print
122 {
123 my ($self, $fh) = @_;
124
125 my $post = $self->post();
126
127 $fh = 'STDOUT' unless defined $fh;
128
129
130 }
131
132 sub dumpXML
133 {
134 my ($self, $fh) = @_;
135 my $post = $self->post();
136
137 $fh = 'STDOUT' unless defined $fh;
138 $fh->printf("<leftClasses>\n");
139 $self->dumpClasses($self->{'leftClasses'}, $fh);
140 $fh->printf("</leftClasses>\n");
141
142 $fh->printf("<rightClasses>\n");
143 $self->dumpClasses($self->{'rightClasses'}, $fh);
144 $fh->printf("</rightClasses>\n");
145
146 $fh->printf("<kernArray>\n");
147 my $kernArray = $self->{'kernArray'};
148 foreach (0 .. $#$kernArray) {
149 $fh->printf("<row index=\"%s\">\n", $_);
150 my $row = $kernArray->[$_];
151 foreach (0 .. $#$row) {
152 $fh->printf("<val index=\"%s\" v=\"%s\"/>\n", $_, $row->[$_]);
153 }
154 $fh->printf("</row>\n");
155 }
156 $fh->printf("</kernArray>\n");
157 }
158
159 sub type
160 {
161 return 'kernClassArray';
162 }
163
164
165
166 1;
167
168 =head1 BUGS
169
170 None known
171
172 =head1 AUTHOR
173
174 Jonathan Kew L<Jonathan_Kew@sil.org>. See L<PDF::API3::Compat::API2::Basic::TTF::Font> for copyright and
175 licensing.
176
177 =cut
178