Font/TTF/Maxp.pm

filter: Statementstmt 60.0% 33 / 55 Branchbran 33.3% 10 / 30 Conditioncond 12.5% 1 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 75.0% 6 / 8 Podpod 80.0% 4 / 5 totaltotal 48.6% 54 / 111 CC 20 SCAR 42.6
CC
20
Cov
47%
update
156.0
init
4.2
read
4.1
CRAP 71.1
« Font/TTF/Head.pm ↑ Summary Font/TTF/OldCmap.pm »
1 package Font::TTF::Maxp;
2  
3 =head1 NAME
4  
5 Font::TTF::Maxp - Maximum Profile table in a font
6  
7 =head1 DESCRIPTION
8  
9 A collection of useful instance variables following the TTF standard. Probably
10 the most used being C<numGlyphs>. Note that this particular value is
11 foundational and should be kept up to date by the application, it is not updated
12 by C<update>.
13  
14 Handles table versions 0.5, 1.0
15  
16 =head1 INSTANCE VARIABLES
17  
18 No others beyond those specified in the standard:
19  
20 numGlyphs
21 maxPoints
22 maxContours
23 maxCompositePoints
24 maxCompositeContours
25 maxZones
26 maxTwilightPoints
27 maxStorage
28 maxFunctionDefs
29 maxInstructionDefs
30 maxStackElements
31 maxSizeOfInstructions
32 maxComponentElements
33 maxComponentDepth
34  
35  
36 =head1 METHODS
37  
38 =cut
39  
40 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 ▶use vars qw(@ISA %fields @field_info);
Subroutine BEGIN: called CC=1 SCAR=0.0
42 1 ▶use Font::TTF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 1 @ISA = qw(Font::TTF::Table);
45 1 @field_info = (
46 'numGlyphs' => 'S',
47 'maxPoints' => 'S',
48 'maxContours' => 'S',
49 'maxCompositePoints' => 'S',
50 'maxCompositeContours' => 'S',
51 'maxZones' => 'S',
52 'maxTwilightPoints' => 'S',
53 'maxStorage' => 'S',
54 'maxFunctionDefs' => 'S',
55 'maxInstructionDefs' => 'S',
56 'maxStackElements' => 'S',
57 'maxSizeOfInstructions' => 'S',
58 'maxComponentElements' => 'S',
59 'maxComponentDepth' => 'S');
60  
61 sub init
62 1 ▶{
Subroutine init: called CC=4 SCAR=14.5
Pod undocumented
63 1 my ($k, $v, $c, $i);
64 1 ▶ for ($i = 0; $i < $#field_info; $i += 2)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $#Font::TTF::Maxp::field_info) 14 1 15
65 {
66 14 ($k, $v, $c) = TTF_Init_Fields($field_info[$i], $c, $field_info[$i + 1]);
67 14 ▶ next unless defined $k && $k ne "";
Branch: 1 branch
BranchTrueFalseTotal
unless defined $k and $k ne "" 0 14 14
Condition33%1/3
defined $k and $k ne ""
!ll&&!rl&&r
0014
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
68 14 $fields{$k} = $v;
69 }
70 }
71  
72  
73 =head2 $t->read
74  
75 Reads the table into memory
76  
77 =cut
78  
79 sub read
80 4 ▶{
Subroutine read: called CC=4 SCAR=14.0
Pod documented
81 4 my ($self) = @_;
82 4 my ($dat);
83  
84 4 ▶ $self->SUPER::read or return $self;
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::read or return $self 2 2 4
85  
86 2 ▶ init unless defined $fields{'numGlyphs'}; # any key would do
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Font::TTF::Maxp::fields{"numGlyphs"} 1 1 2
87 2 $self->{' INFILE'}->read($dat, 4);
88 2 $self->{'version'} = TTF_Unpack("v", $dat);
89  
90 2 ▶ if ($self->{'version'} == 0.5)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'version'} == 0.5) { } 0 2 2
91 {
92 0 $self->{' INFILE'}->read($dat, 2);
93 0 $self->{'numGlyphs'} = unpack("n", $dat);
94 } else
95 {
96 2 $self->{' INFILE'}->read($dat, 28);
97 2 TTF_Read_Fields($self, $dat, \%fields);
98 }
99 2 $self;
100 }
101  
102  
103 =head2 $t->out($fh)
104  
105 Writes the table to a file either from memory or by copying.
106  
107 =cut
108  
109 sub out
110 2 ▶{
Subroutine out: called CC=3 SCAR=11.6
Pod documented
111 2 my ($self, $fh) = @_;
112  
113 2 ▶ return $self->SUPER::out($fh) unless $self->{' read'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{" read"} 0 2 2
114 2 $fh->print(TTF_Pack("v", $self->{'version'}));
115
116 2 ▶ if ($self->{'version'} == 0.5)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'version'} == 0.5) { } 0 2 2
117 0 { $fh->print(pack("n", $self->{'numGlyphs'})); }
118 else
119 2 { $fh->print(TTF_Out_Fields($self, \%fields, 28)); }
120 2 $self;
121 }
122  
123 =head2 $t->minsize()
124  
125 Returns the minimum size this table can be. If it is smaller than this, then the table
126 must be bad and should be deleted or whatever.
127  
128 =cut
129  
130 sub minsize
131 0 ▶{
Subroutine minsize: not called CC=1 SCAR=6.9
Pod documented
132 0 return 4;
133 }
134  
135  
136 =head2 $t->update
137  
138 Calculates all the maximum values for a font based on the glyphs in the font.
139 Only those fields which require hinting code interpretation are ignored and
140 left as they were read.
141  
142 =cut
143  
144 sub update
145 0 ▶{
Subroutine update: not called CC=12 SCAR=50.5
Pod documented
146 0 my ($self) = @_;
147 0 my ($i, $num, @n, @m, $j);
148 0 my (@name) = qw(maxPoints maxContours maxCompositePoints maxCompositeContours
149 maxSizeOfInstructions maxComponentElements maxComponentDepth);
150  
151 0 ▶ return undef unless ($self->SUPER::update);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->SUPER::update 0 0 0
152 0 ▶ return undef if ($self->{'version'} == 0.5); # only got numGlyphs
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"version"} == "0.5" 0 0 0
153 0 ▶ return undef unless (defined $self->{' PARENT'}{'loca'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{" PARENT"}{"loca"} 0 0 0
154 0 $self->{' PARENT'}{'loca'}->update;
155 0 $num = $self->{'numGlyphs'};
156  
157 0 ▶ for ($i = 0; $i < $num; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $num) 0 0 0
158 {
159 0 ▶ my ($g) = $self->{' PARENT'}{'loca'}{'glyphs'}[$i] || next;
Condition0%0/2
$self->{' PARENT'}{'loca'}{'glyphs'}[$i] || (next)
l!l
00
MC/DC0%0/1
$self->{' PARENT'}{'loca'}{'glyphs'}[$i] || (next)
$self->{' PARENT'}{'loca'}{'glyphs'}[$i]
Truth table0%0/2
A
A= $self->{' PARENT'}{'loca'}{'glyphs'}[$i]
Aresult
11
00
160  
161 0 @n = $g->maxInfo;
162  
163 0 ▶ for ($j = 0; $j <= $#n; $j++)
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $#n) 0 0 0
164 0 ▶ { $m[$j] = $n[$j] if $n[$j] > $m[$j]; }
Branch: 1 branch
BranchTrueFalseTotal
if $n[$j] > $m[$j] 0 0 0
165 }
166  
167 0 foreach ('prep', 'fpgm')
168 { $m[4] = length($self->{' PARENT'}{$_}{' dat'})
169 if (defined $self->{' PARENT'}{$_}
170 0 ▶ && length($self->{' PARENT'}{$_}{' dat'}) > $m[4]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{" PARENT"}{$_} and length $self->{" PARENT"}{$_}{" dat"} > $m[4] 0 0 0
Condition0%0/3
defined $self->{" PARENT"}{$_} and length $self->{" PARENT"}{$_}{" dat"} > $m[4]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{" PARENT"}{$_} and length $self->{" PARENT"}{$_}{" dat"} > $m[4]
defined $self->{" PARENT"}{$_} length $self->{" PARENT"}{$_}{" dat"} > $m[4]
Truth table0%0/3
A and B
A= defined $self->{" PARENT"}{$_}B= length $self->{" PARENT"}{$_}{" dat"} > $m[4]
ABresult
0X0
100
111
171 }
172  
173 0 ▶ for ($j = 0; $j <= $#name; $j++)
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $#name) 0 0 0
174 0 { $self->{$name[$j]} = $m[$j]; }
175 0 $self;
176 }
177 1 1;
178  
179  
180 =head1 BUGS
181  
182 None known
183  
184 =head1 AUTHOR
185  
186 Martin Hosken L<http://scripts.sil.org/FontUtils>.
187  
188  
189 =head1 LICENSING
190  
191 Copyright (c) 1998-2016, SIL International (http://www.sil.org)
192  
193 This module is released under the terms of the Artistic License 2.0.
194 For details, see the full text of the license in the file LICENSE.
195  
196  
197  
198 =cut
199  
« Font/TTF/Head.pm ↑ Summary Font/TTF/OldCmap.pm »