Font/TTF/Vhea.pm untested

filter: Statementstmt 0.0% 0 / 65 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 127 CC 11 SCAR 34.9
CC
11
Cov
0%
update
72.0
init
6.0
read
6.0
CRAP 32.7
1 package Font::TTF::Vhea;
2  
3 =head1 NAME
4  
5 Font::TTF::Vhea - Vertical Header table
6  
7 =head1 DESCRIPTION
8  
9 This is a simple table with just standards specified instance variables
10  
11 =head1 INSTANCE VARIABLES
12  
13 version
14 Ascender
15 Descender
16 LineGap
17 advanceHeightMax
18 minTopSideBearing
19 minBottomSideBearing
20 yMaxExtent
21 caretSlopeRise
22 caretSlopeRun
23 metricDataFormat
24 numberOfVMetrics
25  
26  
27 =head1 METHODS
28  
29 =cut
30  
31 use strict;
32 use vars qw(@ISA %fields @field_info);
33  
34 require Font::TTF::Table;
35 use Font::TTF::Utils;
36  
37 @ISA = qw(Font::TTF::Table);
38 @field_info = (
39 'version' => 'v',
40 'Ascender' => 's',
41 'Descender' => 's',
42 'LineGap' => 's',
43 'advanceHeightMax' => 'S',
44 'minTopSideBearing' => 's',
45 'minBottomSideBearing' => 's',
46 'yMaxExtent' => 's',
47 'caretSlopeRise' => 's',
48 'caretSlopeRun' => 's',
49 'metricDataFormat' => '+10s',
50 'numberOfVMetrics' => 's');
51  
52 sub init
53 {
54 my ($k, $v, $c, $i);
55 for ($i = 0; $i < $#field_info; $i += 2)
56 {
57 ($k, $v, $c) = TTF_Init_Fields($field_info[$i], $c, $field_info[$i + 1]);
58 next unless defined $k && $k ne "";
59 $fields{$k} = $v;
60 }
61 }
62  
63  
64 =head2 $t->read
65  
66 Reads the table into memory as instance variables
67  
68 =cut
69  
70 sub read
71 {
72 my ($self) = @_;
73 my ($dat);
74  
75 $self->SUPER::read or return $self;
76 init unless defined $fields{'Ascender'};
77 $self->{' INFILE'}->read($dat, 36);
78  
79 TTF_Read_Fields($self, $dat, \%fields);
80 $self;
81 }
82  
83  
84 =head2 $t->out($fh)
85  
86 Writes the table to a file either from memory or by copying.
87  
88 =cut
89  
90 sub out
91 {
92 my ($self, $fh) = @_;
93  
94 return $self->SUPER::out($fh) unless $self->{' read'};
95  
96 $self->{'numberOfVMetrics'} = $self->{' PARENT'}{'vmtx'}->numMetrics || $self->{'numberOfVMetrics'};
97 $fh->print(TTF_Out_Fields($self, \%fields, 36));
98 $self;
99 }
100  
101 =head2 $t->minsize()
102  
103 Returns the minimum size this table can be. If it is smaller than this, then the table
104 must be bad and should be deleted or whatever.
105  
106 =cut
107  
108 sub minsize
109 {
110 return 36;
111 }
112  
113  
114 =head2 $t->update
115  
116 Updates various parameters in the hhea table from the hmtx table, assuming
117 the C<hmtx> table is dirty.
118  
119 =cut
120  
121 sub update
122 {
123 my ($self) = @_;
124 my ($vmtx) = $self->{' PARENT'}{'vmtx'};
125 my ($glyphs);
126 my ($num);
127 my ($i, $maw, $mlsb, $mrsb, $mext, $aw, $lsb, $ext);
128  
129 return undef unless ($self->SUPER::update);
130 return undef unless (defined $vmtx && defined $self->{' PARENT'}{'loca'});
131 $vmtx->read->update;
132 $self->{' PARENT'}{'loca'}->read->update;
133 $glyphs = $self->{' PARENT'}{'loca'}{'glyphs'};
134 $num = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
135  
136 for ($i = 0; $i < $num; $i++)
137 {
138 $aw = $vmtx->{'advance'}[$i];
139 $lsb = $vmtx->{'top'}[$i];
140 if (defined $glyphs->[$i])
141 { $ext = $lsb + $glyphs->[$i]->read->{'yMax'} - $glyphs->[$i]{'yMin'}; }
142 else
143 { $ext = $aw; }
144 $maw = $aw if ($aw > $maw);
145 $mlsb = $lsb if ($lsb < $mlsb or $i == 0);
146 $mrsb = $aw - $ext if ($aw - $ext < $mrsb or $i == 0);
147 $mext = $ext if ($ext > $mext);
148 }
149 $self->{'advanceHeightMax'} = $maw;
150 $self->{'minTopSideBearing'} = $mlsb;
151 $self->{'minBottomSideBearing'} = $mrsb;
152 $self->{'yMaxExtent'} = $mext;
153 $self->{'numberOfVMetrics'} = $vmtx->numMetrics;
154 $self;
155 }
156  
157  
158 1;
159  
160  
161 =head1 BUGS
162  
163 None known
164  
165 =head1 AUTHOR
166  
167 Martin Hosken L<http://scripts.sil.org/FontUtils>.
168  
169  
170 =head1 LICENSING
171  
172 Copyright (c) 1998-2016, SIL International (http://www.sil.org)
173  
174 This module is released under the terms of the Artistic License 2.0.
175 For details, see the full text of the license in the file LICENSE.
176  
177  
178  
179 =cut
180  
181