API3/Compat/API2/Basic/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 #=======================================================================
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: Bsln.pm,v 2.0 2005/11/16 02:16:00 areibens Exp $
25 #
26 #=======================================================================
27 package PDF::API3::Compat::API2::Basic::TTF::Bsln;
28
29 =head1 NAME
30
31 PDF::API3::Compat::API2::Basic::TTF::Bsln - Baseline table in a font
32
33 =head1 DESCRIPTION
34
35 =head1 INSTANCE VARIABLES
36
37 =item version
38
39 =item xformat
40
41 =item defaultBaseline
42
43 =item deltas
44
45 =item stdGlyph
46
47 =item ctlPoints
48
49 =item lookupFormat
50
51 =item lookup
52
53 =head1 METHODS
54
55 =cut
56
57 use strict;
58 use vars qw(@ISA);
59
60 use PDF::API3::Compat::API2::Basic::TTF::AATutils;
61 use PDF::API3::Compat::API2::Basic::TTF::Utils;
62 require PDF::API3::Compat::API2::Basic::TTF::Table;
63
64 @ISA = qw(PDF::API3::Compat::API2::Basic::TTF::Table);
65
66 =head2 $t->read
67
68 Reads the table into memory
69
70 =cut
71
72 sub read
73 {
74 my ($self) = @_;
75 my ($dat, $fh);
76
77 $self->SUPER::read or return $self;
78
79 $fh = $self->{' INFILE'};
80 $fh->read($dat, 8);
81 my ($version, $format, $defaultBaseline) = TTF_Unpack("fSS", $dat);
82
83 if ($format == 0 or $format == 1) {
84 $fh->read($dat, 64);
85 $self->{'deltas'} = [TTF_Unpack("s*", $dat)];
86 }
87 elsif ($format == 2 or $format == 3) {
88 $fh->read($dat, 2);
89 $self->{'stdGlyph'} = unpack("n", $dat);
90 $fh->read($dat, 64);
91 $self->{'ctlPoints'} = unpack("n*", $dat);
92 }
93 else {
94 die "unknown table format";
95 }
96
97 if ($format == 1 or $format == 3) {
98 my $len = $self->{' LENGTH'} - ($fh->tell() - $self->{' OFFSET'});
99 my ($lookupFormat, $lookup) = AAT_read_lookup($fh, 2, $len, $defaultBaseline);
100 $self->{'lookupFormat'} = $lookupFormat;
101 $self->{'lookup'} = $lookup;
102 }
103
104 $self->{'version'} = $version;
105 $self->{'format'} = $format;
106 $self->{'defaultBaseline'} = $defaultBaseline;
107
108 $self;
109 }
110
111 =head2 $t->out($fh)
112
113 Writes the table to a file either from memory or by copying
114
115 =cut
116
117 sub out
118 {
119 my ($self, $fh) = @_;
120
121 return $self->SUPER::out($fh) unless $self->{' read'};
122
123 my $format = $self->{'format'};
124 my $defaultBaseline = $self->{'defaultBaseline'};
125 $fh->print(TTF_Pack("fSS", $self->{'version'}, $format, $defaultBaseline));
126
127 AAT_write_lookup($fh, $self->{'lookupFormat'}, $self->{'lookup'}, 2, $defaultBaseline) if ($format == 1 or $format == 3);
128 }
129
130 =head2 $t->print($fh)
131
132 Prints a human-readable representation of the table
133
134 =cut
135
136 sub print
137 {
138 my ($self, $fh) = @_;
139
140 $self->read;
141
142 $fh = 'STDOUT' unless defined $fh;
143
144 my $format = $self->{'format'};
145 $fh->printf("version %f\nformat %d\ndefaultBaseline %d\n", $self->{'version'}, $format, $self->{'defaultBaseline'});
146 if ($format == 0 or $format == 1) {
147 $fh->printf("\tdeltas:\n");
148 my $deltas = $self->{'deltas'};
149 foreach (0 .. 31) {
150 $fh->printf("\t\t%d: %d%s\n", $_, $deltas->[$_], defined baselineName_($_) ? "\t# " . baselineName_($_) : "");
151 }
152 }
153 if ($format == 2 or $format == 3) {
154 $fh->printf("\tstdGlyph = %d\n", $self->{'stdGlyph'});
155 my $ctlPoints = $self->{'ctlPoints'};
156 foreach (0 .. 31) {
157 $fh->printf("\t\t%d: %d%s\n", $_, $ctlPoints->[$_], defined baselineName_($_) ? "\t# " . baselineName_($_) : "");
158 }
159 }
160 if ($format == 1 or $format == 3) {
161 $fh->printf("lookupFormat %d\n", $self->{'lookupFormat'});
162 my $lookup = $self->{'lookup'};
163 foreach (sort { $a <=> $b } keys %$lookup) {
164 $fh->printf("\tglyph %d: %d%s\n", $_, $lookup->{$_}, defined baselineName_($_) ? "\t# " . baselineName_($_) : "");
165 }
166 }
167 }
168
169 sub baselineName_
170 {
171 my ($b) = @_;
172 my @baselines = ( 'Roman', 'Ideographic centered', 'Ideographic low', 'Hanging', 'Math' );
173 $baselines[$b];
174 }
175
176 1;
177
178
179 =head1 BUGS
180
181 None known
182
183 =head1 AUTHOR
184
185 Jonathan Kew L<Jonathan_Kew@sil.org>. See L<PDF::API3::Compat::API2::Basic::TTF::Font> for copyright and
186 licensing.
187
188 =cut
189