Font/TTF/Head.pm

filter: Statementstmt 33.3% 29 / 87 Branchbran 17.5% 7 / 40 Conditioncond 6.6% 1 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 54.5% 6 / 11 Podpod 87.5% 7 / 8 totaltotal 29.2% 50 / 171 CC 26 SCAR 42.6
CC
26
Cov
26%
update
182.0
getdate
20.0
XML_element
12.0
CRAP 70.9
« Font/TTF/Font.pm ↑ Summary Font/TTF/Maxp.pm »
1 package Font::TTF::Head;
2  
3 =head1 NAME
4  
5 Font::TTF::Head - The head table for a TTF Font
6  
7 =head1 DESCRIPTION
8  
9 This is a very basic table with just instance variables as described in the
10 TTF documentation, using the same names. One of the most commonly used is
11 C<unitsPerEm>.
12  
13 =head1 INSTANCE VARIABLES
14  
15 The C<head> table has no internal instance variables beyond those common to all
16 tables and those specified in the standard:
17  
18 version
19 fontRevision
20 checkSumAdjustment
21 magicNumber
22 flags
23 unitsPerEm
24 created
25 modified
26 xMin
27 yMin
28 xMax
29 yMax
30 macStyle
31 lowestRecPPEM
32 fontDirectionHint
33 indexToLocFormat
34 glyphDataFormat
35  
36 The two dates are held as an array of two unsigned longs (32-bits)
37  
38 =head1 METHODS
39  
40 =cut
41  
42 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 1 ▶use vars qw(@ISA %fields @field_info);
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 1 require Font::TTF::Table;
46 1 ▶use Font::TTF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 1 @ISA = qw(Font::TTF::Table);
49 1 @field_info = (
50 'version' => 'v',
51 'fontRevision' => 'f',
52 'checkSumAdjustment' => 'L',
53 'magicNumber' => 'L',
54 'flags' => 'S',
55 'unitsPerEm' => 'S',
56 'created' => 'L2',
57 'modified' => 'L2',
58 'xMin' => 's',
59 'yMin' => 's',
60 'xMax' => 's',
61 'yMax' => 's',
62 'macStyle' => 'S',
63 'lowestRecPPEM' => 'S',
64 'fontDirectionHint' => 's',
65 'indexToLocFormat' => 's',
66 'glyphDataFormat' => 's');
67  
68 sub init
69 2 ▶{
Subroutine init: called CC=4 SCAR=14.5
Pod undocumented
70 2 my ($k, $v, $c, $i);
71 2 ▶ for ($i = 0; $i < $#field_info; $i += 2)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $#Font::TTF::Head::field_info) 34 2 36
72 {
73 34 ($k, $v, $c) = TTF_Init_Fields($field_info[$i], $c, $field_info[$i + 1]);
74 34 ▶ next unless defined $k && $k ne "";
Branch: 1 branch
BranchTrueFalseTotal
unless defined $k and $k ne "" 0 34 34
Condition33%1/3
defined $k and $k ne ""
!ll&&!rl&&r
0034
MC/DC0%0/2
defined $k and $k ne ""
defined $k $k ne ""
Truth table33%1/3
A and B
A= defined $kB= $k ne ""
ABresult
0X0
100
111
75 34 $fields{$k} = $v;
76 }
77 }
78  
79  
80 =head2 $t->read
81  
82 Reads the table into memory thanks to some utility functions
83  
84 =cut
85  
86 sub read
87 4 ▶{
Subroutine read: called CC=3 SCAR=11.0
Pod documented
88 4 my ($self) = @_;
89 4 my ($dat);
90  
91 4 ▶ $self->SUPER::read || return $self;
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::read or return $self 2 2 4
92  
93 2 ▶ init unless defined $fields{'Ascender'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Font::TTF::Head::fields{"Ascender"} 2 0 2
94 2 $self->{' INFILE'}->read($dat, 54);
95  
96 2 TTF_Read_Fields($self, $dat, \%fields);
97 2 $self;
98 }
99  
100  
101 =head2 $t->out($fh)
102  
103 Writes the table to a file either from memory or by copying. If in memory
104 (which is usually) the checkSumAdjustment field is set to 0 as per the default
105 if the file checksum is not to be considered.
106  
107 =cut
108  
109 sub out
110 2 ▶{
Subroutine out: called CC=2 SCAR=7.0
Pod documented
111 2 my ($self, $fh) = @_;
112  
113 2 ▶ return $self->SUPER::out($fh) unless $self->{' read'}; # this is never true
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{" read"} 0 2 2
114 # $self->{'checkSumAdjustment'} = 0 unless $self->{' PARENT'}{' wantsig'};
115 2 $fh->print(TTF_Out_Fields($self, \%fields, 54));
116 2 $self;
117 }
118  
119  
120 =head2 $t->minsize()
121  
122 Returns the minimum size this table can be. If it is smaller than this, then the table
123 must be bad and should be deleted or whatever.
124  
125 =cut
126  
127 sub minsize
128 0 ▶{
Subroutine minsize: not called CC=1 SCAR=6.9
Pod documented
129 0 return 54;
130 }
131  
132  
133 =head2 $t->XML_element($context, $depth, $key, $value)
134  
135 Handles date process for the XML exporter
136  
137 =cut
138  
139 sub XML_element
140 0 ▶{
Subroutine XML_element: not called CC=3 SCAR=24.8
Pod documented
141 0 my ($self) = shift;
142 0 my ($context, $depth, $key, $value) = @_;
143 0 my ($fh) = $context->{'fh'};
144 0 my ($output, @time);
145 0 my (@month) = qw(JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC);
146  
147 0 ▶ return $self->SUPER::XML_element(@_) unless ($key eq 'created' || $key eq 'modified');
Branch: 1 branch
BranchTrueFalseTotal
unless $key eq "created" or $key eq "modified" 0 0 0
Condition0%0/3
$key eq "created" or $key eq "modified"
l!l&&r!l&&!r
000
MC/DC0%0/2
$key eq "created" or $key eq "modified"
$key eq "created" $key eq "modified"
Truth table0%0/3
A or B
A= $key eq "created"B= $key eq "modified"
ABresult
1X1
011
000
148  
149 0 @time = gmtime($self->getdate($key eq 'created'));
150 0 $output = sprintf("%d/%s/%d %d:%d:%d", $time[3], $month[$time[4]], $time[5] + 1900,
151 $time[2], $time[1], $time[0]);
152 0 $fh->print("$depth<$key>$output</$key>\n");
153 0 $self;
154 }
155
156  
157 =head2 $t->update
158  
159 Updates the head table based on the glyph data and the hmtx table
160  
161 =cut
162  
163 sub update
164 0 ▶{
Subroutine update: not called CC=13 SCAR=52.0
Pod documented
165 0 my ($self) = @_;
166 0 my ($num, $i, $loc, $hmtx);
167 0 my ($xMin, $yMin, $xMax, $yMax, $lsbx);
168  
169 0 ▶ return undef unless ($self->SUPER::update);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->SUPER::update 0 0 0
170  
171 0 $num = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
172 0 ▶ return undef unless (defined $self->{' PARENT'}{'hmtx'} && defined $self->{' PARENT'}{'loca'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{" PARENT"}{"hmtx"} and defined $self->{" PARENT"}{"loca"} 0 0 0
Condition0%0/3
defined $self->{" PARENT"}{"hmtx"} and defined $self->{" PARENT"}{"loca"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{" PARENT"}{"hmtx"} and defined $self->{" PARENT"}{"loca"}
defined $self->{" PARENT"}{"hmtx"} defined $self->{" PARENT"}{"loca"}
Truth table0%0/3
A and B
A= defined $self->{" PARENT"}{"hmtx"}B= defined $self->{" PARENT"}{"loca"}
ABresult
0X0
100
111
173 0 $hmtx = $self->{' PARENT'}{'hmtx'}->read;
174
175 0 $self->{' PARENT'}{'loca'}->update;
176 0 $hmtx->update; # if we updated, then the flags will be set anyway.
177 0 $lsbx = 1;
178 0 ▶ for ($i = 0; $i < $num; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $num) 0 0 0
179 {
180 0 $loc = $self->{' PARENT'}{'loca'}{'glyphs'}[$i];
181 0 ▶ next unless defined $loc;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $loc 0 0 0
182 0 $loc->read->update_bbox;
183 0 ▶ $xMin = $loc->{'xMin'} if ($loc->{'xMin'} < $xMin || $i == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $loc->{"xMin"} < $xMin or $i == 0 0 0 0
Condition0%0/3
$loc->{"xMin"} < $xMin or $i == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$loc->{"xMin"} < $xMin or $i == 0
$loc->{"xMin"} < $xMin $i == 0
Truth table0%0/3
A or B
A= $loc->{"xMin"} < $xMinB= $i == 0
ABresult
1X1
011
000
184 0 ▶ $yMin = $loc->{'yMin'} if ($loc->{'yMin'} < $yMin || $i == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $loc->{"yMin"} < $yMin or $i == 0 0 0 0
Condition0%0/3
$loc->{"yMin"} < $yMin or $i == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$loc->{"yMin"} < $yMin or $i == 0
$loc->{"yMin"} < $yMin $i == 0
Truth table0%0/3
A or B
A= $loc->{"yMin"} < $yMinB= $i == 0
ABresult
1X1
011
000
185 0 ▶ $xMax = $loc->{'xMax'} if ($loc->{'xMax'} > $xMax);
Branch: 1 branch
BranchTrueFalseTotal
if $loc->{"xMax"} > $xMax 0 0 0
186 0 ▶ $yMax = $loc->{'yMax'} if ($loc->{'yMax'} > $yMax);
Branch: 1 branch
BranchTrueFalseTotal
if $loc->{"yMax"} > $yMax 0 0 0
187 0 $lsbx &= ($loc->{'xMin'} == $hmtx->{'lsb'}[$i]);
188 }
189 0 $self->{'xMin'} = $xMin;
190 0 $self->{'yMin'} = $yMin;
191 0 $self->{'xMax'} = $xMax;
192 0 $self->{'yMax'} = $yMax;
193 0 ▶ if ($lsbx)
Branch: 1 branch
BranchTrueFalseTotal
if ($lsbx) { } 0 0 0
194 0 { $self->{'flags'} |= 2; }
195 else
196 0 { $self->{'flags'} &= ~2; }
197 0 $self;
198 }
199  
200  
201 =head2 $t->getdate($is_create)
202  
203 Converts font modification time (or creation time if $is_create is set) to a 32-bit integer as returned
204 from time(). Returns undef if the value is out of range, either before the epoch or after the maximum
205 storable time.
206  
207 =cut
208  
209 sub getdate
210 0 ▶{
Subroutine getdate: not called CC=4 SCAR=30.0
Pod documented
211 0 my ($self, $is_create) = @_;
212 0 ▶ my (@arr) = (@{$self->{$is_create ? 'created' : 'modified'}});
Branch: 1 branch
BranchTrueFalseTotal
$is_create ? : 0 0 0
213  
214 0 $arr[1] -= 2082844800; # seconds between 1/Jan/1904 and 1/Jan/1970 (midnight)
215 0 ▶ if ($arr[1] < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($arr[1] < 0) 0 0 0
216 {
217 0 $arr[1] += 0xFFFFFFF; $arr[1]++;
218 0 $arr[0]--;
219 }
220 0 ▶ return undef if $arr[0] != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $arr[0] != 0 0 0 0
221 0 return $arr[1];
222 }
223  
224  
225 =head2 $t->setdate($time, $is_create)
226  
227 Sets the time information for modification (or creation time if $is_create is set) according to the 32-bit
228 time information.
229  
230 =cut
231  
232 sub setdate
233 0 ▶{
Subroutine setdate: not called CC=3 SCAR=24.8
Pod documented
234 0 my ($self, $time, $is_create) = @_;
235 0 my (@arr);
236  
237 0 $arr[1] = $time;
238 0 ▶ if ($arr[1] >= 0x83DA4F80)
Branch: 1 branch
BranchTrueFalseTotal
if ($arr[1] >= 2212122496) 0 0 0
239 {
240 0 $arr[1] -= 0xFFFFFFFF;
241 0 $arr[1]--;
242 0 $arr[0]++;
243 }
244 0 $arr[1] += 2082844800;
245 0 ▶ $self->{$is_create ? 'created' : 'modified'} = \@arr;
Branch: 1 branch
BranchTrueFalseTotal
$is_create ? : 0 0 0
246 0 $self;
247 }
248
249  
250 1 1;
251  
252  
253 =head1 BUGS
254  
255 None known
256  
257 =head1 AUTHOR
258  
259 Martin Hosken L<http://scripts.sil.org/FontUtils>.
260  
261  
262 =head1 LICENSING
263  
264 Copyright (c) 1998-2016, SIL International (http://www.sil.org)
265  
266 This module is released under the terms of the Artistic License 2.0.
267 For details, see the full text of the license in the file LICENSE.
268  
269  
270  
271 =cut
272  
273  
« Font/TTF/Font.pm ↑ Summary Font/TTF/Maxp.pm »