API3/Compat/API2/Resource/Font.pm

filter: Statementstmt 17.2% 27 / 157 Branchbran 0.0% 0 / 48 Conditioncond 0.0% 0 / 25 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 75.0% 9 / 12 Podpod 33.3% 1 / 3 totaltotal 14.2% 37 / 260 CC 45 SCAR 65.3
CC
45
Cov
12%
encodeByData
1122.0
automap
132.0
remap
12.0
CRAP 687.9
« API3/Compat/API2/Resource/XObject/Image/PNG.pm ↑ Summary API3/Compat/API2/Resource/XObject/Image/TIFF.pm »
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 # Copyright 1999-2005 Alfred Reibenschuh <areibens@cpan.org>.
12 #
13 #=======================================================================
14 #
15 # This library is free software; you can redistribute it and/or
16 # modify it under the terms of the GNU Lesser General Public
17 # License as published by the Free Software Foundation; either
18 # version 2 of the License, or (at your option) any later version.
19 #
20 # This library is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 # Lesser General Public License for more details.
24 #
25 # You should have received a copy of the GNU Lesser General Public
26 # License along with this library; if not, write to the
27 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 # Boston, MA 02111-1307, USA.
29 #
30 # $Id: Font.pm,v 2.2 2008/11/04 23:54:51 areibens Exp $
31 #
32 #=======================================================================
33 package PDF::API3::Compat::API2::Resource::Font;
34
35 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
36
37 1 ▶ use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 ▶ use Encode qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
39
40 1 ▶ use PDF::API3::Compat::API2::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 ▶ use PDF::API3::Compat::API2::Basic::PDF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 1 ▶ use PDF::API3::Compat::API2::Resource::BaseFont;
Subroutine BEGIN: called CC=1 SCAR=0.0
43
44 1 ▶ use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
45
46 1 ▶ use vars qw(@ISA $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
47
48 1 @ISA = qw( PDF::API3::Compat::API2::Resource::BaseFont );
49
50 1 ( $VERSION ) = sprintf '%i.%03i', split(/\./,('$Revision: 2.2 $' =~ /Revision: (\S+)\s/)[0]); # $Date: 2008/11/04 23:54:51 $
51
52 }
53 1 ▶no warnings qw[ deprecated recursion uninitialized ];
Subroutine BEGIN: called CC=1 SCAR=0.0
54
55 =item $font->encodeByData $encoding
56
57 Encodes the font in the specified byte-encoding.
58
59 =cut
60
61 0 ▶sub encodeByData {
Subroutine encodeByData: not called CC=33 SCAR=70.2
Pod documented
62 0 my ($self,$encoding)=@_;
63 0 my $data=$self->data;
64
65 0 my ($firstChar,$lastChar);
66
67 0 ▶ if($self->issymbol || $encoding eq 'asis') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->issymbol or $encoding eq "asis") 0 0 0
Condition0%0/3
$self->issymbol or $encoding eq "asis"
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->issymbol or $encoding eq "asis"
$self->issymbol $encoding eq "asis"
Truth table0%0/3
A or B
A= $self->issymbolB= $encoding eq "asis"
ABresult
1X1
011
000
68 0 $encoding=undef;
69 }
70
71 0 ▶ if(defined $encoding && $encoding=~m|^uni(\d+)$|o)
Branch: 3 branches
BranchTrueFalseTotal
if (defined $encoding and $encoding =~ /^uni(\d+)$/o) { } 0 0 0
elsif (defined $encoding) { } 0 0 0
elsif (defined $data->{'uni'}) { } 0 0 0
Condition0%0/3
defined $encoding and $encoding =~ /^uni(\d+)$/o
!ll&&!rl&&r
000
MC/DC0%0/2
defined $encoding and $encoding =~ /^uni(\d+)$/o
defined $encoding $encoding =~ /^uni(\d+)$/o
Truth table0%0/3
A and B
A= defined $encodingB= $encoding =~ /^uni(\d+)$/o
ABresult
0X0
100
111
72 {
73 0 my $blk=$1;
74 0 $data->{e2u}=[ map { $blk*256+$_ } (0..255) ];
75 0 ▶ $data->{e2n}=[ map { nameByUni($_) || '.notdef' } @{$data->{e2u}} ];
Condition0%0/2
nameByUni($_) || '.notdef'
l!l
00
MC/DC0%0/1
nameByUni($_) || '.notdef'
nameByUni($_)
Truth table0%0/2
A
A= nameByUni($_)
Aresult
11
00
76 0 $data->{firstchar} = 0;
77 }
78 elsif(defined $encoding)
79 {
80 0 $data->{e2u}=[ unpack('U*',decode($encoding,pack('C*',(0..255)))) ];
81 0 ▶ $data->{e2n}=[ map { nameByUni($_) || '.notdef' } @{$data->{e2u}} ];
Condition0%0/2
nameByUni($_) || '.notdef'
l!l
00
MC/DC0%0/1
nameByUni($_) || '.notdef'
nameByUni($_)
Truth table0%0/2
A
A= nameByUni($_)
Aresult
11
00
82 }
83 elsif(defined $data->{uni})
84 {
85 0 $data->{e2u}=[ @{$data->{uni}} ];
86 0 ▶ $data->{e2n}=[ map { $_ || '.notdef' } @{$data->{char}} ];
Condition0%0/2
$_ || '.notdef'
l!l
00
MC/DC0%0/1
$_ || '.notdef'
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
87 }
88 else
89 {
90 0 $data->{e2u}=[ map { uniByName($_) } @{$data->{char}} ];
91 0 ▶ $data->{e2n}=[ map { $_ || '.notdef' } @{$data->{char}} ];
Condition0%0/2
$_ || '.notdef'
l!l
00
MC/DC0%0/1
$_ || '.notdef'
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
92 }
93
94 0 $data->{u2c}={};
95 0 $data->{u2e}={};
96 0 $data->{u2n}={};
97 0 $data->{n2c}={};
98 0 $data->{n2e}={};
99 0 $data->{n2u}={};
100
101 0 foreach my $n (0..255) {
102 0 my $xchar=undef;
103 0 my $xuni=undef;
104 0 ▶ if(defined $data->{char}->[$n]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data->{'char'}[$n]) { } 0 0 0
105 0 $xchar=$data->{char}->[$n];
106 } else {
107 0 $xchar='.notdef';
108 }
109 0 ▶ $data->{n2c}->{$xchar}=$n unless(defined $data->{n2c}->{$xchar});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data->{"n2c"}{$xchar} 0 0 0
110
111 0 ▶ if(defined $data->{e2n}->[$n]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data->{'e2n'}[$n]) { } 0 0 0
112 0 $xchar=$data->{e2n}->[$n];
113 } else {
114 0 $xchar='.notdef';
115 }
116 0 ▶ $data->{n2e}->{$xchar}=$n unless(defined $data->{n2e}->{$xchar});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data->{"n2e"}{$xchar} 0 0 0
117
118 0 ▶ $data->{n2u}->{$xchar}=$data->{e2u}->[$n] unless(defined $data->{n2u}->{$xchar});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data->{"n2u"}{$xchar} 0 0 0
119
120 0 ▶ if(defined $data->{char}->[$n]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data->{'char'}[$n]) { } 0 0 0
121 0 $xchar=$data->{char}->[$n];
122 } else {
123 0 $xchar='.notdef';
124 }
125 0 ▶ if(defined $data->{uni}->[$n]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data->{'uni'}[$n]) { } 0 0 0
126 0 $xuni=$data->{uni}->[$n];
127 } else {
128 0 $xuni=0;
129 }
130 0 ▶ $data->{n2u}->{$xchar}=$xuni unless(defined $data->{n2u}->{$xchar});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data->{"n2u"}{$xchar} 0 0 0
131
132 0 ▶ $data->{u2c}->{$xuni}||=$n unless(defined $data->{u2c}->{$xuni});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data->{"u2c"}{$xuni} 0 0 0
Condition0%0/3
$data->{"u2c"}{$xuni} ||= $n
l!l&&r!l&&!r
000
MC/DC0%0/2
$data->{"u2c"}{$xuni} ||= $n
$data->{"u2c"}{$xuni} $n
Truth table0%0/3
A ||= B
A= $data->{"u2c"}{$xuni}B= $n
ABresult
1X1
011
000
133
134 0 ▶ if(defined $data->{e2u}->[$n]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data->{'e2u'}[$n]) { } 0 0 0
135 0 $xuni=$data->{e2u}->[$n];
136 } else {
137 0 $xuni=0;
138 }
139 0 ▶ $data->{u2e}->{$xuni}||=$n unless(defined $data->{u2e}->{$xuni});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data->{"u2e"}{$xuni} 0 0 0
Condition0%0/3
$data->{"u2e"}{$xuni} ||= $n
l!l&&r!l&&!r
000
MC/DC0%0/2
$data->{"u2e"}{$xuni} ||= $n
$data->{"u2e"}{$xuni} $n
Truth table0%0/3
A ||= B
A= $data->{"u2e"}{$xuni}B= $n
ABresult
1X1
011
000
140
141 0 ▶ if(defined $data->{e2n}->[$n]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data->{'e2n'}[$n]) { } 0 0 0
142 0 $xchar=$data->{e2n}->[$n];
143 } else {
144 0 $xchar='.notdef';
145 }
146 0 ▶ $data->{u2n}->{$xuni}=$xchar unless(defined $data->{u2n}->{$xuni});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data->{"u2n"}{$xuni} 0 0 0
147
148 0 ▶ if(defined $data->{char}->[$n]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data->{'char'}[$n]) { } 0 0 0
149 0 $xchar=$data->{char}->[$n];
150 } else {
151 0 $xchar='.notdef';
152 }
153 0 ▶ if(defined $data->{uni}->[$n]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data->{'uni'}[$n]) { } 0 0 0
154 0 $xuni=$data->{uni}->[$n];
155 } else {
156 0 $xuni=0;
157 }
158 0 ▶ $data->{u2n}->{$xuni}=$xchar unless(defined $data->{u2n}->{$xuni});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data->{"u2n"}{$xuni} 0 0 0
159 }
160
161 0 my $en = PDFDict();
162 0 $self->{Encoding}=$en;
163
164 0 $en->{Type}=PDFName('Encoding');
165 0 $en->{BaseEncoding}=PDFName('WinAnsiEncoding');
166
167 0 $en->{Differences}=PDFArray(PDFNum(0));
168 0 foreach my $n (0..255) {
169 0 ▶ $en->{Differences}->add_elements( PDFName($self->glyphByEnc($n) || '.notdef') );
Condition0%0/2
$self->glyphByEnc($n) || '.notdef'
l!l
00
MC/DC0%0/1
$self->glyphByEnc($n) || '.notdef'
$self->glyphByEnc($n)
Truth table0%0/2
A
A= $self->glyphByEnc($n)
Aresult
11
00
170 }
171
172 0 $self->{'FirstChar'} = PDFNum($data->{firstchar});
173 0 $self->{'LastChar'} = PDFNum($data->{lastchar});
174
175 0 $self->{Widths}=PDFArray();
176 0 foreach my $n ($data->{firstchar}..$data->{lastchar}) {
177 0 $self->{Widths}->add_elements( PDFNum($self->wxByEnc($n)) );
178 }
179
180 #use Data::Dumper;
181 # print Dumper($data);
182
183 0 return($self);
184 }
185
186 0 ▶sub automap {
Subroutine automap: not called CC=11 SCAR=48.8
Pod undocumented
187 0 my ($self)=@_;
188 0 my $data=$self->data;
189
190 0 my %gl=map { $_=>defineName($_) } keys %{$data->{wx}};
191
192 0 foreach my $n (0..255) {
193 0 delete $gl{$data->{e2n}->[$n]};
194 }
195
196 0 ▶ if(defined $data->{comps} && !$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
197 {
198 0 foreach my $n (keys %{$data->{comps}})
199 {
200 0 delete $gl{$n};
201 }
202 }
203
204 0 my @nm=sort { $gl{$a} <=> $gl{$b} } keys %gl;
205
206 0 my @fnts=();
207 0 my $count=0;
208 0 ▶ while(@glyphs=splice(@nm,0,223))
Branch: 1 branch
BranchTrueFalseTotal
if (@glyphs = splice(@nm, 0, 223)) 0 0 0
209 {
210 0 my $obj=$self->SUPER::new($self->{' apipdf'},$self->name.'am'.$count);
211 0 $obj->{' data'}={ %{$data} };
212 0 $obj->data->{firstchar}=32;
213 0 $obj->data->{lastchar}=32+scalar(@glyphs);
214 0 push @fnts,$obj;
215 0 foreach my $key (qw( Subtype BaseFont FontDescriptor ))
216 {
217 0 ▶ $obj->{$key}=$self->{$key} if(defined $self->{$key});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{$key} 0 0 0
218 }
219 0 $obj->data->{char}=[];
220 0 $obj->data->{uni}=[];
221 0 foreach my $n (0..31)
222 {
223 0 $obj->data->{char}->[$n]='.notdef';
224 0 $obj->data->{uni}->[$n]=0;
225 }
226 0 $obj->data->{char}->[32]='space';
227 0 $obj->data->{uni}->[32]=32;
228 0 foreach my $n (33..$obj->data->{lastchar})
229 {
230 0 $obj->data->{char}->[$n]=$glyphs[$n-33];
231 0 $obj->data->{uni}->[$n]=$gl{$glyphs[$n-33]};
232 }
233 0 foreach my $n (($obj->data->{lastchar}+1)..255)
234 {
235 0 $obj->data->{char}->[$n]='.notdef';
236 0 $obj->data->{uni}->[$n]=0;
237 }
238 0 $obj->encodeByData(undef);
239
240 0 $count++;
241 }
242
243 0 return(@fnts);
244 }
245
246 0 ▶sub remap {
Subroutine remap: not called CC=3 SCAR=24.8
Pod undocumented
247 0 my ($self,$enc)=@_;
248
249 0 my $obj=$self->SUPER::new($self->{' apipdf'},$self->name.'rm'.pdfkey());
250 0 $obj->{' data'}={ %{$self->data} };
251 0 foreach my $key (qw( Subtype BaseFont FontDescriptor )) {
252 0 ▶ $obj->{$key}=$self->{$key} if(defined $self->{$key});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{$key} 0 0 0
253 }
254
255 0 $obj->encodeByData($enc);
256
257 0 return($obj);
258 }
259
260 1 1;
261
262 __END__
« API3/Compat/API2/Resource/XObject/Image/PNG.pm ↑ Summary API3/Compat/API2/Resource/XObject/Image/TIFF.pm »