Font/TTF/Kern/ClassArray.pm untested

filter: Statementstmt 0.0% 0 / 77 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 103 CC 3 SCAR 11.7
CC
3
Cov
0%
print
6.0
dumpXML
6.0
new
2.0
CRAP 3.2
1 package Font::TTF::Kern::ClassArray;
2  
3 =head1 NAME
4  
5 Font::TTF::Kern::ClassArray - ClassArray Kern Subtable for AAT
6  
7 =head1 METHODS
8  
9 =cut
10  
11 use strict;
12 use vars qw(@ISA);
13 use Font::TTF::Utils;
14 use Font::TTF::AATutils;
15 use IO::File;
16  
17 @ISA = qw(Font::TTF::Kern::Subtable);
18  
19 sub new
20 {
21 my ($class) = @_;
22 my ($self) = {};
23
24 $class = ref($class) || $class;
25 bless $self, $class;
26 }
27  
28 =head2 $t->read
29  
30 Reads the table into memory
31  
32 =cut
33  
34 sub read
35 {
36 my ($self, $fh) = @_;
37
38 my $subtableStart = $fh->tell() - 8;
39 my $dat;
40 $fh->read($dat, 8);
41 my ($rowWidth, $leftClassTable, $rightClassTable, $array) = unpack("nnnn", $dat);
42  
43 $fh->seek($subtableStart + $leftClassTable, IO::File::SEEK_SET);
44 $fh->read($dat, 4);
45 my ($firstGlyph, $nGlyphs) = unpack("nn", $dat);
46 $fh->read($dat, $nGlyphs * 2);
47 my $leftClasses = [];
48 foreach (TTF_Unpack("S*", $dat)) {
49 push @{$leftClasses->[($_ - $array) / $rowWidth]}, $firstGlyph++;
50 }
51
52 $fh->seek($subtableStart + $rightClassTable, IO::File::SEEK_SET);
53 $fh->read($dat, 4);
54 ($firstGlyph, $nGlyphs) = unpack("nn", $dat);
55 $fh->read($dat, $nGlyphs * 2);
56 my $rightClasses = [];
57 foreach (TTF_Unpack("S*", $dat)) {
58 push @{$rightClasses->[$_ / 2]}, $firstGlyph++;
59 }
60
61 $fh->seek($subtableStart + $array, IO::File::SEEK_SET);
62 $fh->read($dat, $self->{'length'} - $array);
63  
64 my $offset = 0;
65 my $kernArray = [];
66 while ($offset < length($dat)) {
67 push @$kernArray, [ TTF_Unpack("s*", substr($dat, $offset, $rowWidth)) ];
68 $offset += $rowWidth;
69 }
70  
71 $self->{'leftClasses'} = $leftClasses;
72 $self->{'rightClasses'} = $rightClasses;
73 $self->{'kernArray'} = $kernArray;
74
75 $fh->seek($subtableStart + $self->{'length'}, IO::File::SEEK_SET);
76
77 $self;
78 }
79  
80 =head2 $t->out_sub($fh)
81  
82 Writes the table to a file
83  
84 =cut
85  
86 sub out_sub
87 {
88 }
89  
90 =head2 $t->print($fh)
91  
92 Prints a human-readable representation of the table
93  
94 =cut
95  
96 sub print
97 {
98 my ($self, $fh) = @_;
99
100 my $post = $self->post();
101
102 $fh = 'STDOUT' unless defined $fh;
103  
104
105 }
106  
107 sub dumpXML
108 {
109 my ($self, $fh) = @_;
110 my $post = $self->post();
111
112 $fh = 'STDOUT' unless defined $fh;
113 $fh->printf("<leftClasses>\n");
114 $self->dumpClasses($self->{'leftClasses'}, $fh);
115 $fh->printf("</leftClasses>\n");
116  
117 $fh->printf("<rightClasses>\n");
118 $self->dumpClasses($self->{'rightClasses'}, $fh);
119 $fh->printf("</rightClasses>\n");
120
121 $fh->printf("<kernArray>\n");
122 my $kernArray = $self->{'kernArray'};
123 foreach (0 .. $#$kernArray) {
124 $fh->printf("<row index=\"%s\">\n", $_);
125 my $row = $kernArray->[$_];
126 foreach (0 .. $#$row) {
127 $fh->printf("<val index=\"%s\" v=\"%s\"/>\n", $_, $row->[$_]);
128 }
129 $fh->printf("</row>\n");
130 }
131 $fh->printf("</kernArray>\n");
132 }
133  
134 sub type
135 {
136 return 'kernClassArray';
137 }
138  
139  
140  
141 1;
142  
143 =head1 BUGS
144  
145 None known
146  
147 =head1 AUTHOR
148  
149 Jonathan Kew L<http://scripts.sil.org/FontUtils>.
150  
151  
152 =head1 LICENSING
153  
154 Copyright (c) 1998-2016, SIL International (http://www.sil.org)
155  
156 This module is released under the terms of the Artistic License 2.0.
157 For details, see the full text of the license in the file LICENSE.
158  
159  
160  
161 =cut
162  
163