Font/TTF/Bsln.pm untested

filter: Statementstmt 0.0% 0 / 70 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 23 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 145 CC 13 SCAR 35.1
CC
13
Cov
0%
print
72.0
read
20.0
out
12.0
CRAP 33.5
1 package Font::TTF::Bsln;
2  
3 =head1 NAME
4  
5 Font::TTF::Bsln - Baseline table in a font
6  
7 =head1 DESCRIPTION
8  
9 =head1 INSTANCE VARIABLES
10  
11 =over
12  
13 =item version
14  
15 =item xformat
16  
17 =item defaultBaseline
18  
19 =item deltas
20  
21 =item stdGlyph
22  
23 =item ctlPoints
24  
25 =item lookupFormat
26  
27 =item lookup
28  
29 =back
30  
31 =head1 METHODS
32  
33 =cut
34  
35 use strict;
36 use vars qw(@ISA);
37  
38 use Font::TTF::AATutils;
39 use Font::TTF::Utils;
40 require Font::TTF::Table;
41  
42 @ISA = qw(Font::TTF::Table);
43  
44 =head2 $t->read
45  
46 Reads the table into memory
47  
48 =cut
49  
50 sub read
51 {
52 my ($self) = @_;
53 my ($dat, $fh);
54
55 $self->SUPER::read or return $self;
56  
57 $fh = $self->{' INFILE'};
58 $fh->read($dat, 8);
59 my ($version, $format, $defaultBaseline) = TTF_Unpack("vSS", $dat);
60  
61 if ($format == 0 or $format == 1) {
62 $fh->read($dat, 64);
63 $self->{'deltas'} = [TTF_Unpack("s*", $dat)];
64 }
65 elsif ($format == 2 or $format == 3) {
66 $fh->read($dat, 2);
67 $self->{'stdGlyph'} = unpack("n", $dat);
68 $fh->read($dat, 64);
69 $self->{'ctlPoints'} = unpack("n*", $dat);
70 }
71 else {
72 die "unknown table format";
73 }
74
75 if ($format == 1 or $format == 3) {
76 my $len = $self->{' LENGTH'} - ($fh->tell() - $self->{' OFFSET'});
77 my ($lookupFormat, $lookup) = AAT_read_lookup($fh, 2, $len, $defaultBaseline);
78 $self->{'lookupFormat'} = $lookupFormat;
79 $self->{'lookup'} = $lookup;
80 }
81  
82 $self->{'version'} = $version;
83 $self->{'format'} = $format;
84 $self->{'defaultBaseline'} = $defaultBaseline;
85  
86 $self;
87 }
88  
89 =head2 $t->out($fh)
90  
91 Writes the table to a file either from memory or by copying
92  
93 =cut
94  
95 sub out
96 {
97 my ($self, $fh) = @_;
98
99 return $self->SUPER::out($fh) unless $self->{' read'};
100  
101 my $format = $self->{'format'};
102 my $defaultBaseline = $self->{'defaultBaseline'};
103 $fh->print(TTF_Pack("vSS", $self->{'version'}, $format, $defaultBaseline));
104  
105 AAT_write_lookup($fh, $self->{'lookupFormat'}, $self->{'lookup'}, 2, $defaultBaseline) if ($format == 1 or $format == 3);
106 }
107  
108 =head2 $t->print($fh)
109  
110 Prints a human-readable representation of the table
111  
112 =cut
113  
114 sub print
115 {
116 my ($self, $fh) = @_;
117  
118 $self->read;
119
120 $fh = 'STDOUT' unless defined $fh;
121
122 my $format = $self->{'format'};
123 $fh->printf("version %f\nformat %d\ndefaultBaseline %d\n", $self->{'version'}, $format, $self->{'defaultBaseline'});
124 if ($format == 0 or $format == 1) {
125 $fh->printf("\tdeltas:\n");
126 my $deltas = $self->{'deltas'};
127 foreach (0 .. 31) {
128 $fh->printf("\t\t%d: %d%s\n", $_, $deltas->[$_], defined baselineName_($_) ? "\t# " . baselineName_($_) : "");
129 }
130 }
131 if ($format == 2 or $format == 3) {
132 $fh->printf("\tstdGlyph = %d\n", $self->{'stdGlyph'});
133 my $ctlPoints = $self->{'ctlPoints'};
134 foreach (0 .. 31) {
135 $fh->printf("\t\t%d: %d%s\n", $_, $ctlPoints->[$_], defined baselineName_($_) ? "\t# " . baselineName_($_) : "");
136 }
137 }
138 if ($format == 1 or $format == 3) {
139 $fh->printf("lookupFormat %d\n", $self->{'lookupFormat'});
140 my $lookup = $self->{'lookup'};
141 foreach (sort { $a <=> $b } keys %$lookup) {
142 $fh->printf("\tglyph %d: %d%s\n", $_, $lookup->{$_}, defined baselineName_($_) ? "\t# " . baselineName_($_) : "");
143 }
144 }
145 }
146  
147 sub baselineName_
148 {
149 my ($b) = @_;
150 my @baselines = ( 'Roman', 'Ideographic centered', 'Ideographic low', 'Hanging', 'Math' );
151 $baselines[$b];
152 }
153  
154 1;
155  
156  
157 =head1 BUGS
158  
159 None known
160  
161 =head1 AUTHOR
162  
163 Jonathan Kew L<http://scripts.sil.org/FontUtils>.
164  
165  
166 =head1 LICENSING
167  
168 Copyright (c) 1998-2016, SIL International (http://www.sil.org)
169  
170 This module is released under the terms of the Artistic License 2.0.
171 For details, see the full text of the license in the file LICENSE.
172  
173  
174  
175 =cut
176