API3/Compat/API2/Basic/TTF/Hhea.pm untested

filter: Statementstmt 0.0% 0 / 65 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 132 CC 12 SCAR 38.1
CC
12
Cov
0%
update
90.0
init
6.0
read
6.0
CRAP 44.9
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 Martin Hosken <Martin_Hosken@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: Hhea.pm,v 2.0 2005/11/16 02:16:00 areibens Exp $
25 #
26 #=======================================================================
27 package PDF::API3::Compat::API2::Basic::TTF::Hhea;
28
29 =head1 NAME
30
31 PDF::API3::Compat::API2::Basic::TTF::Hhea - Horizontal Header table
32
33 =head1 DESCRIPTION
34
35 This is a simplte table with just standards specified instance variables
36
37 =head1 INSTANCE VARIABLES
38
39 version
40 Ascender
41 Descender
42 LineGap
43 advanceWidthMax
44 minLeftSideBearing
45 minRightSideBearing
46 xMaxExtent
47 caretSlopeRise
48 caretSlopeRun
49 metricDataFormat
50 numberOfHMetrics
51
52
53 =head1 METHODS
54
55 =cut
56
57 use strict;
58 use vars qw(@ISA %fields @field_info);
59
60 require PDF::API3::Compat::API2::Basic::TTF::Table;
61 use PDF::API3::Compat::API2::Basic::TTF::Utils;
62
63 @ISA = qw(PDF::API3::Compat::API2::Basic::TTF::Table);
64 @field_info = (
65 'version' => 'f',
66 'Ascender' => 's',
67 'Descender' => 's',
68 'LineGap' => 's',
69 'advanceWidthMax' => 'S',
70 'minLeftSideBearing' => 's',
71 'minRightSideBearing' => 's',
72 'xMaxExtent' => 's',
73 'caretSlopeRise' => 's',
74 'caretSlopeRun' => 's',
75 'metricDataFormat' => '+10s',
76 'numberOfHMetrics' => 'S');
77
78 sub init
79 {
80 my ($k, $v, $c, $i);
81 for ($i = 0; $i < $#field_info; $i += 2)
82 {
83 ($k, $v, $c) = TTF_Init_Fields($field_info[$i], $c, $field_info[$i + 1]);
84 next unless defined $k && $k ne "";
85 $fields{$k} = $v;
86 }
87 }
88
89
90 =head2 $t->read
91
92 Reads the table into memory as instance variables
93
94 =cut
95
96 sub read
97 {
98 my ($self) = @_;
99 my ($dat);
100
101 $self->SUPER::read or return $self;
102 init unless defined $fields{'Ascender'};
103 $self->{' INFILE'}->read($dat, 36);
104
105 TTF_Read_Fields($self, $dat, \%fields);
106 $self;
107 }
108
109
110 =head2 $t->out($fh)
111
112 Writes the table to a file either from memory or by copying.
113
114 =cut
115
116 sub out
117 {
118 my ($self, $fh) = @_;
119
120 return $self->SUPER::out($fh) unless $self->{' read'};
121
122 $self->{'numberOfHMetrics'} = $self->{' PARENT'}{'hmtx'}->numMetrics || $self->{'numberOfHMetrics'};
123 $fh->print(TTF_Out_Fields($self, \%fields, 36));
124 $self;
125 }
126
127
128 =head2 $t->update
129
130 Updates various parameters in the hhea table from the hmtx table, assuming
131 the C<hmtx> table is dirty.
132
133 =cut
134
135 sub update
136 {
137 my ($self) = @_;
138 my ($hmtx) = $self->{' PARENT'}{'hmtx'};
139 my ($glyphs);
140 my ($num);
141 my ($i, $maw, $mlsb, $mrsb, $mext, $aw, $lsb, $ext);
142
143 return undef unless ($self->SUPER::update);
144 return undef unless (defined $hmtx && defined $self->{' PARENT'}{'loca'});
145
146 $hmtx->read->update;
147 $self->{' PARENT'}{'loca'}->read->update;
148 $glyphs = $self->{' PARENT'}{'loca'}{'glyphs'};
149 $num = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
150
151 return undef unless ($hmtx->{' isDirty'} || $self->{' PARENT'}{'loca'}{' isDirty'});
152
153 for ($i = 0; $i < $num; $i++)
154 {
155 $aw = $hmtx->{'advance'}[$i];
156 $lsb = $hmtx->{'lsb'}[$i];
157 if (defined $glyphs->[$i])
158 { $ext = $lsb + $glyphs->[$i]->read->{'xMax'} - $glyphs->[$i]{'xMin'}; }
159 else
160 { $ext = $aw; }
161 $maw = $aw if ($aw > $maw);
162 $mlsb = $lsb if ($lsb < $mlsb or $i == 0);
163 $mrsb = $aw - $ext if ($aw - $ext < $mrsb or $i == 0);
164 $mext = $ext if ($ext > $mext);
165 }
166 $self->{'advanceWidthMax'} = $maw;
167 $self->{'minLeftSideBearing'} = $mlsb;
168 $self->{'minRightSideBearing'} = $mrsb;
169 $self->{'xMaxExtent'} = $mext;
170 $self->{'numberOfHMetrics'} = $hmtx->numMetrics;
171 $self;
172 }
173
174
175 1;
176
177
178 =head1 BUGS
179
180 None known
181
182 =head1 AUTHOR
183
184 Martin Hosken Martin_Hosken@sil.org. See L<PDF::API3::Compat::API2::Basic::TTF::Font> for copyright and
185 licensing.
186
187 =cut
188