API2/Resource/Font.pm

filter: Statementstmt 60.1% 80 / 133 Branchbran 41.6% 10 / 24 Conditioncond 66.6% 32 / 48 MC/DCmcdc 24.1% 7 / 29 Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 3 totaltotal 55.2% 136 / 246 SCAR 50.7
CC
42
Cov
60%
automap
132.0
encodeByData
36.9
remap
12.0
CRAP 159.1
« API2/Resource/XObject/Image/TIFF/File.pm ↑ Summary API2/NamedDestination.pm »
1 package PDF::API2::Resource::Font;
2  
3 9 ▶use base 'PDF::API2::Resource::BaseFont';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 9 our $VERSION = '2.044'; # VERSION
9  
10 9 ▶use Encode qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 9 ▶use PDF::API2::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 9 ▶use PDF::API2::Basic::PDF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 sub encodeByData {
16 53 ▶ my ($self, $encoding) = @_;
Subroutine encodeByData: called CC=30 SCAR=36.1
Pod undocumented
17 53 my $data = $self->data();
18  
19 53 my ($firstChar, $lastChar);
20  
21 53 ▶ if ($self->issymbol()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->issymbol) 5 48 53
22 5 $encoding = undef;
23 }
24  
25 53 ▶ if (defined $encoding and $encoding =~ /^uni(\d+)$/) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $encoding and $encoding =~ /^uni(\d+)$/) { } 1 52 53
elsif (defined $encoding) { } 1 51 52
elsif (defined $data->{'uni'}) { } 51 0 51
Condition100%3/3
defined $encoding and $encoding =~ /^uni(\d+)$/
!ll&&!rl&&r
5111
MC/DC100%2/2
defined $encoding and $encoding =~ /^uni(\d+)$/
defined $encoding $encoding =~ /^uni(\d+)$/
Truth table100%3/3
A and B
A= defined $encodingB= $encoding =~ /^uni(\d+)$/
ABresult
0X0
100
111
26 1 my $blk = $1;
27 1 $data->{'e2u'} = [ map { $blk * 256 + $_ } (0 .. 255) ];
28 1 ▶ $data->{'e2n'} = [ map { nameByUni($_) or '.notdef' } @{$data->{'e2u'}} ];
Branch: 1 branch
BranchTrueFalseTotal
nameByUni($_) or ".notdef" 0 256 256
29 1 $data->{'firstchar'} = 0;
30 }
31 elsif (defined $encoding) {
32 1 $data->{'e2u'} = [ unpack('U*', decode($encoding, pack('C*', 0 .. 255))) ];
33 1 ▶ $data->{'e2n'} = [ map { nameByUni($_) or '.notdef' } @{$data->{'e2u'}} ];
Branch: 1 branch
BranchTrueFalseTotal
nameByUni($_) or ".notdef" 0 256 256
34 }
35 elsif (defined $data->{'uni'}) {
36 51 $data->{'e2u'} = [ @{$data->{'uni'}} ];
37 51 ▶ $data->{'e2n'} = [ map { $_ or '.notdef' } @{$data->{'char'}} ];
Branch: 1 branch
BranchTrueFalseTotal
$_ or ".notdef" 0 13056 13056
38 }
39 else {
40 0 $data->{'e2u'} = [ map { uniByName($_) } @{$data->{'char'}} ];
41 0 ▶ $data->{'e2n'} = [ map { $_ or '.notdef' } @{$data->{'char'}} ];
Branch: 1 branch
BranchTrueFalseTotal
$_ or ".notdef" 0 0 0
42 }
43  
44 53 $data->{'u2c'} = {};
45 53 $data->{'u2e'} = {};
46 53 $data->{'u2n'} = {};
47 53 $data->{'n2c'} = {};
48 53 $data->{'n2e'} = {};
49 53 $data->{'n2u'} = {};
50  
51 53 foreach my $n (0 .. 255) {
52 13568 my $xchar;
53 my $xuni;
54  
55 13568 ▶ $xchar = $data->{'char'}->[$n] // '.notdef';
Condition50%1/2
$data->{"char"}[$n] // ".notdef"
l!l
135680
MC/DC0%0/1
$data->{"char"}[$n] // ".notdef"
$data->{"char"}[$n]
Truth table50%1/2
A
A= $data->{"char"}[$n]
Aresult
11
00
56 13568 ▶ $data->{'n2c'}->{$xchar} //= $n;
Condition66%2/3
$data->{"n2c"}{$xchar} //= $n
l!l&&r!l&&!r
2110114580
MC/DC0%0/2
$data->{"n2c"}{$xchar} //= $n
$data->{"n2c"}{$xchar} $n
Truth table66%2/3
A //= B
A= $data->{"n2c"}{$xchar}B= $n
ABresult
1X1
011
000
57  
58 13568 ▶ $xchar = $data->{'e2n'}->[$n] // '.notdef';
Condition50%1/2
$data->{"e2n"}[$n] // ".notdef"
l!l
135680
MC/DC0%0/1
$data->{"e2n"}[$n] // ".notdef"
$data->{"e2n"}[$n]
Truth table50%1/2
A
A= $data->{"e2n"}[$n]
Aresult
11
00
59 13568 ▶ $data->{'n2e'}->{$xchar} //= $n;
Condition66%2/3
$data->{"n2e"}{$xchar} //= $n
l!l&&r!l&&!r
2046115220
MC/DC0%0/2
$data->{"n2e"}{$xchar} //= $n
$data->{"n2e"}{$xchar} $n
Truth table66%2/3
A //= B
A= $data->{"n2e"}{$xchar}B= $n
ABresult
1X1
011
000
60  
61 13568 ▶ $data->{'n2u'}->{$xchar} //= $data->{'e2u'}->[$n];
Condition100%3/3
$data->{"n2u"}{$xchar} //= $data->{"e2u"}[$n]
l!l&&r!l&&!r
20481144872
MC/DC100%2/2
$data->{"n2u"}{$xchar} //= $data->{"e2u"}[$n]
$data->{"n2u"}{$xchar} $data->{"e2u"}[$n]
Truth table100%3/3
A //= B
A= $data->{"n2u"}{$xchar}B= $data->{"e2u"}[$n]
ABresult
1X1
011
000
62  
63 13568 ▶ $xchar = $data->{'char'}->[$n] // '.notdef';
Condition50%1/2
$data->{"char"}[$n] // ".notdef"
l!l
135680
MC/DC0%0/1
$data->{"char"}[$n] // ".notdef"
$data->{"char"}[$n]
Truth table50%1/2
A
A= $data->{"char"}[$n]
Aresult
11
00
64 13568 ▶ $xuni = $data->{'uni'}->[$n] // 0;
Condition100%2/2
$data->{"uni"}[$n] // 0
l!l
118001768
MC/DC100%1/1
$data->{"uni"}[$n] // 0
$data->{"uni"}[$n]
Truth table100%2/2
A
A= $data->{"uni"}[$n]
Aresult
11
00
65 13568 ▶ $data->{'n2u'}->{$xchar} //= $xuni;
Condition66%2/3
$data->{"n2u"}{$xchar} //= $xuni
l!l&&r!l&&!r
132852830
MC/DC0%0/2
$data->{"n2u"}{$xchar} //= $xuni
$data->{"n2u"}{$xchar} $xuni
Truth table66%2/3
A //= B
A= $data->{"n2u"}{$xchar}B= $xuni
ABresult
1X1
011
000
66  
67 13568 ▶ $data->{'u2c'}->{$xuni} //= $n;
Condition66%2/3
$data->{"u2c"}{$xuni} //= $n
l!l&&r!l&&!r
2100114680
MC/DC0%0/2
$data->{"u2c"}{$xuni} //= $n
$data->{"u2c"}{$xuni} $n
Truth table66%2/3
A //= B
A= $data->{"u2c"}{$xuni}B= $n
ABresult
1X1
011
000
68  
69 13568 ▶ $xuni = $data->{'e2u'}->[$n] // 0;
Condition100%2/2
$data->{"e2u"}[$n] // 0
l!l
118641704
MC/DC100%1/1
$data->{"e2u"}[$n] // 0
$data->{"e2u"}[$n]
Truth table100%2/2
A
A= $data->{"e2u"}[$n]
Aresult
11
00
70 13568 ▶ $data->{'u2e'}->{$xuni} //= $n;
Condition66%2/3
$data->{"u2e"}{$xuni} //= $n
l!l&&r!l&&!r
2022115460
MC/DC0%0/2
$data->{"u2e"}{$xuni} //= $n
$data->{"u2e"}{$xuni} $n
Truth table66%2/3
A //= B
A= $data->{"u2e"}{$xuni}B= $n
ABresult
1X1
011
000
71  
72 13568 ▶ $xchar = $data->{'e2n'}->[$n] // '.notdef';
Condition50%1/2
$data->{"e2n"}[$n] // ".notdef"
l!l
135680
MC/DC0%0/1
$data->{"e2n"}[$n] // ".notdef"
$data->{"e2n"}[$n]
Truth table50%1/2
A
A= $data->{"e2n"}[$n]
Aresult
11
00
73 13568 ▶ $data->{'u2n'}->{$xuni} //= $xchar;
Condition66%2/3
$data->{"u2n"}{$xuni} //= $xchar
l!l&&r!l&&!r
2023115450
MC/DC0%0/2
$data->{"u2n"}{$xuni} //= $xchar
$data->{"u2n"}{$xuni} $xchar
Truth table66%2/3
A //= B
A= $data->{"u2n"}{$xuni}B= $xchar
ABresult
1X1
011
000
74  
75 13568 ▶ $xchar = $data->{'char'}->[$n] // '.notdef';
Condition50%1/2
$data->{"char"}[$n] // ".notdef"
l!l
135680
MC/DC0%0/1
$data->{"char"}[$n] // ".notdef"
$data->{"char"}[$n]
Truth table50%1/2
A
A= $data->{"char"}[$n]
Aresult
11
00
76 13568 ▶ $xuni = $data->{'uni'}->[$n] // 0;
Condition100%2/2
$data->{"uni"}[$n] // 0
l!l
118001768
MC/DC100%1/1
$data->{"uni"}[$n] // 0
$data->{"uni"}[$n]
Truth table100%2/2
A
A= $data->{"uni"}[$n]
Aresult
11
00
77 13568 ▶ $data->{'u2n'}->{$xuni} //= $xchar;
Condition66%2/3
$data->{"u2n"}{$xuni} //= $xchar
l!l&&r!l&&!r
133312370
MC/DC0%0/2
$data->{"u2n"}{$xuni} //= $xchar
$data->{"u2n"}{$xuni} $xchar
Truth table66%2/3
A //= B
A= $data->{"u2n"}{$xuni}B= $xchar
ABresult
1X1
011
000
78 }
79  
80 53 my $en = PDFDict();
81 53 $self->{'Encoding'} = $en;
82  
83 53 $en->{'Type'} = PDFName('Encoding');
84 53 $en->{'BaseEncoding'} = PDFName('WinAnsiEncoding');
85  
86 53 $en->{'Differences'} = PDFArray(PDFNum(0));
87 53 foreach my $n (0 .. 255) {
88 13568 ▶ my $element = ($self->glyphByEnc($n) or '.notdef');
Condition50%1/2
$self->glyphByEnc($n) || '.notdef'
l!l
135680
MC/DC0%0/1
$self->glyphByEnc($n) || '.notdef'
$self->glyphByEnc($n)
Truth table50%1/2
A
A= $self->glyphByEnc($n)
Aresult
11
00
89 13568 $en->{'Differences'}->add_elements(PDFName($element));
90 }
91  
92 53 $self->{'FirstChar'} = PDFNum($data->{'firstchar'});
93 53 $self->{'LastChar'} = PDFNum($data->{'lastchar'});
94  
95 53 $self->{'Widths'} = PDFArray();
96 53 foreach my $n ($data->{'firstchar'} .. $data->{'lastchar'}) {
97 11904 $self->{'Widths'}->add_elements(PDFNum($self->wxByEnc($n)));
98 }
99  
100 53 return $self;
101 }
102  
103 sub automap {
104 0 ▶ my $self = shift();
Subroutine automap: not called CC=11 SCAR=48.8
Pod undocumented
105 0 my $data = $self->data();
106  
107 0 my %gl = map { $_ => defineName($_) } keys %{$data->{'wx'}};
108  
109 0 foreach my $n (0 .. 255) {
110 0 delete $gl{$data->{'e2n'}->[$n]};
111 }
112  
113 0 ▶ if (defined $data->{'comps'} and not $self->{'-nocomps'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data->{"comps"} and not $self->{"-nocomps"}) 0 0 0
Condition0%0/3
defined $data->{"comps"} and not $self->{"-nocomps"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $data->{"comps"} and not $self->{"-nocomps"}
defined $data->{"comps"} not $self->{"-nocomps"}
Truth table0%0/3
A and not(B)
A= defined $data->{"comps"}B= not $self->{"-nocomps"}
ABresult
0X0
100
111
114 0 foreach my $n (keys %{$data->{'comps'}}) {
115 0 delete $gl{$n};
116 }
117 }
118  
119 0 my @nm = sort { $gl{$a} <=> $gl{$b} } keys %gl;
120  
121 0 my @fonts;
122 0 my $count = 0;
123 0 ▶ while (my @glyphs = splice(@nm, 0, 223)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@glyphs) = splice(@nm, 0, 223)) 0 0 0
124 0 my $obj = $self->SUPER::new($self->{' apipdf'}, $self->name() . 'am' . $count);
125 0 $obj->{' data'} = { %$data };
126 0 $obj->data->{'firstchar'} = 32;
127 0 $obj->data->{'lastchar'} = 32 + scalar(@glyphs);
128 0 push @fonts, $obj;
129 0 foreach my $key (qw(Subtype BaseFont FontDescriptor)) {
130 0 ▶ $obj->{$key} = $self->{$key} if defined $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{$key} 0 0 0
131 }
132 0 $obj->data->{'char'} = [];
133 0 $obj->data->{'uni'} = [];
134 0 foreach my $n (0 .. 31) {
135 0 $obj->data->{'char'}->[$n] = '.notdef';
136 0 $obj->data->{'uni'}->[$n] = 0;
137 }
138 0 $obj->data->{'char'}->[32] = 'space';
139 0 $obj->data->{'uni'}->[32] = 32;
140 0 foreach my $n (33 .. $obj->data->{'lastchar'}) {
141 0 $obj->data->{'char'}->[$n] = $glyphs[$n - 33];
142 0 $obj->data->{'uni'}->[$n] = $gl{$glyphs[$n - 33]};
143 }
144 0 foreach my $n (($obj->data->{'lastchar'} + 1) .. 255) {
145 0 $obj->data->{'char'}->[$n] = '.notdef';
146 0 $obj->data->{'uni'}->[$n] = 0;
147 }
148 0 $obj->encodeByData(undef);
149  
150 0 $count++;
151 }
152  
153 0 return @fonts;
154 }
155  
156 sub remap {
157 0 ▶ my ($self, $enc) = @_;
Subroutine remap: not called CC=3 SCAR=24.8
Pod undocumented
158  
159 0 my $obj = $self->SUPER::new($self->{' apipdf'}, $self->name() . 'rm' . pdfkey());
160 0 $obj->{' data'} = { %{$self->data()} };
161 0 foreach my $key (qw(Subtype BaseFont FontDescriptor)) {
162 0 ▶ $obj->{$key} = $self->{$key} if defined $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{$key} 0 0 0
163 }
164  
165 0 $obj->encodeByData($enc);
166  
167 0 return $obj;
168 }
169  
170 9 1;
« API2/Resource/XObject/Image/TIFF/File.pm ↑ Summary API2/NamedDestination.pm »