API3/Compat/API2/Resource/CIDFont/TrueType/FontFile.pm

filter: Statementstmt 8.7% 34 / 389 Branchbran 0.0% 0 / 192 Conditioncond 0.0% 0 / 59 MC/DCmcdc 0.0% 0 / 34 Subroutinesub 42.3% 11 / 26 Podpod 14.2% 2 / 14 totaltotal 6.5% 47 / 714 CC 137 SCAR 74.5
CC
137
Cov
5%
readcffdict
3422.0
new
1806.0
readcffstructs
156.0
CRAP 1716.7
↑ Summary API3/Compat/API2/Resource/Font/neTrueType.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: FontFile.pm,v 2.6 2008/01/04 08:08:39 areibens Exp $
31 #
32 #=======================================================================
33 package PDF::API3::Compat::API2::Resource::CIDFont::TrueType::FontFile;
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 1 ▶ use PDF::API3::Compat::API2::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
40
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::Basic::PDF::Dict;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 1 ▶ use PDF::API3::Compat::API2::Basic::TTF::Font;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 1 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 1 ▶ use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
46
47 1 ▶ use vars qw( @ISA $VERSION $cmap );
Subroutine BEGIN: called CC=1 SCAR=0.0
48
49 1 @ISA = qw( PDF::API3::Compat::API2::Basic::PDF::Dict );
50
51 1 ( $VERSION ) = sprintf '%i.%03i', split(/\./,('$Revision: 2.6 $' =~ /Revision: (\S+)\s/)[0]); # $Date: 2008/01/04 08:08:39 $
52 1 $cmap={};
53 }
54 1 ▶no warnings qw[ recursion uninitialized ];
Subroutine BEGIN: called CC=1 SCAR=0.0
55
56
57 0 ▶sub _look_for_cmap ($) {
Subroutine _look_for_cmap: not called CC=3 SCAR=24.8
58 0 my $fname=lc(shift);
59 0 $fname=~s/[^a-z0-9]+//gi;
60 0 ▶ return({%{$cmap->{$fname}}}) if(defined $cmap->{$fname});
Branch: 1 branch
BranchTrueFalseTotal
if defined $cmap->{$fname} 0 0 0
61 0 eval "require PDF::API3::Compat::API2::Resource::CIDFont::CMap::$fname; ";
62 0 ▶ unless($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
63 0 return({%{$cmap->{$fname}}});
64 } else {
65 0 die "requested cmap '$fname' not installed ";
66 }
67 }
68
69 sub readcffindex
70 0 ▶{
Subroutine readcffindex: not called CC=3 SCAR=24.8
Pod undocumented
71 0 my ($fh,$off,$buf)=@_;
72 0 my @idx=();
73 0 my $index=[];
74 0 seek($fh,$off,0);
75 0 read($fh,$buf,3);
76 0 my ($count,$offsize)=unpack('nC',$buf);
77 0 foreach (0..$count)
78 {
79 0 read($fh,$buf,$offsize);
80 0 $buf=substr("\x00\x00\x00$buf",-4,4);
81 0 my $id=unpack('N',$buf);
82 0 push @idx,$id;
83 }
84 0 my $dataoff=tell($fh)-1;
85
86 0 foreach my $i (0..$count-1)
87 {
88 0 push @{$index},{ 'OFF' => $dataoff+$idx[$i], 'LEN' => $idx[$i+1]-$idx[$i] };
89 }
90 0 return($index);
91 }
92
93 sub readcffdict
94 0 ▶{
Subroutine readcffdict: not called CC=58 SCAR=81.4
Pod undocumented
95 0 my ($fh,$off,$len,$foff,$buf)=@_;
96 0 my @idx=();
97 0 my $dict={};
98 0 seek($fh,$off,0);
99 0 my @st=();
100 0 ▶ while(tell($fh)<($off+$len))
Branch: 1 branch
BranchTrueFalseTotal
if (tell $fh < $off + $len) 0 0 0
101 {
102 0 read($fh,$buf,1);
103 0 my $b0=unpack('C',$buf);
104 0 my $v='';
105
106 0 ▶ if($b0==12) # two byte commands
Branch: 9 branches
BranchTrueFalseTotal
if ($b0 == 12) { } 0 0 0
elsif ($b0 < 28) { } 0 0 0
elsif ($b0 == 28) { } 0 0 0
elsif ($b0 == 29) { } 0 0 0
elsif ($b0 == 30) { } 0 0 0
elsif ($b0 == 31) { } 0 0 0
elsif ($b0 < 247) { } 0 0 0
elsif ($b0 < 251) { } 0 0 0
elsif ($b0 < 255) { } 0 0 0
107 {
108 0 read($fh,$buf,1);
109 0 my $b1=unpack('C',$buf);
110 0 ▶ if($b1==0)
Branch: 25 branches
BranchTrueFalseTotal
if ($b1 == 0) { } 0 0 0
elsif ($b1 == 1) { } 0 0 0
elsif ($b1 == 2) { } 0 0 0
elsif ($b1 == 3) { } 0 0 0
elsif ($b1 == 4) { } 0 0 0
elsif ($b1 == 5) { } 0 0 0
elsif ($b1 == 6) { } 0 0 0
elsif ($b1 == 7) { } 0 0 0
elsif ($b1 == 8) { } 0 0 0
elsif ($b1 == 20) { } 0 0 0
elsif ($b1 == 21) { } 0 0 0
elsif ($b1 == 22) { } 0 0 0
elsif ($b1 == 23) { } 0 0 0
elsif ($b1 == 24) { } 0 0 0
elsif ($b1 == 25) { } 0 0 0
elsif ($b1 == 30) { } 0 0 0
elsif ($b1 == 31) { } 0 0 0
elsif ($b1 == 32) { } 0 0 0
elsif ($b1 == 33) { } 0 0 0
elsif ($b1 == 34) { } 0 0 0
elsif ($b1 == 35) { } 0 0 0
elsif ($b1 == 36) { } 0 0 0
elsif ($b1 == 37) { } 0 0 0
elsif ($b1 == 38) { } 0 0 0
elsif ($b1 == 39) { } 0 0 0
111 {
112 0 $dict->{Copyright}={ 'SID' => splice(@st,-1) };
113 }
114 elsif($b1==1)
115 {
116 0 $dict->{isFixedPitch}=splice(@st,-1);
117 }
118 elsif($b1==2)
119 {
120 0 $dict->{ItalicAngle}=splice(@st,-1);
121 }
122 elsif($b1==3)
123 {
124 0 $dict->{UnderlinePosition}=splice(@st,-1);
125 }
126 elsif($b1==4)
127 {
128 0 $dict->{UnderlineThickness}=splice(@st,-1);
129 }
130 elsif($b1==5)
131 {
132 0 $dict->{PaintType}=splice(@st,-1);
133 }
134 elsif($b1==6)
135 {
136 0 $dict->{CharstringType}=splice(@st,-1);
137 }
138 elsif($b1==7)
139 {
140 0 $dict->{FontMatrix}=[ splice(@st,-4) ];
141 }
142 elsif($b1==8)
143 {
144 0 $dict->{StrokeWidth}=splice(@st,-1);
145 }
146 elsif($b1==20)
147 {
148 0 $dict->{SyntheticBase}=splice(@st,-1);
149 }
150 elsif($b1==21)
151 {
152 0 $dict->{PostScript}={ 'SID' => splice(@st,-1) };
153 }
154 elsif($b1==22)
155 {
156 0 $dict->{BaseFontName}={ 'SID' => splice(@st,-1) };
157 }
158 elsif($b1==23)
159 {
160 0 $dict->{BaseFontBlend}=[ splice(@st,0) ];
161 }
162 elsif($b1==24)
163 {
164 0 $dict->{MultipleMaster}=[ splice(@st,0) ];
165 }
166 elsif($b1==25)
167 {
168 0 $dict->{BlendAxisTypes}=[ splice(@st,0) ];
169 }
170 elsif($b1==30)
171 {
172 0 $dict->{ROS}=[ splice(@st,-3) ];
173 }
174 elsif($b1==31)
175 {
176 0 $dict->{CIDFontVersion}=splice(@st,-1);
177 }
178 elsif($b1==32)
179 {
180 0 $dict->{CIDFontRevision}=splice(@st,-1);
181 }
182 elsif($b1==33)
183 {
184 0 $dict->{CIDFontType}=splice(@st,-1);
185 }
186 elsif($b1==34)
187 {
188 0 $dict->{CIDCount}=splice(@st,-1);
189 }
190 elsif($b1==35)
191 {
192 0 $dict->{UIDBase}=splice(@st,-1);
193 }
194 elsif($b1==36)
195 {
196 0 $dict->{FDArray}={ 'OFF' => $foff+splice(@st,-1) };
197 }
198 elsif($b1==37)
199 {
200 0 $dict->{FDSelect}={ 'OFF' => $foff+splice(@st,-1) };
201 }
202 elsif($b1==38)
203 {
204 0 $dict->{FontName}={ 'SID' => splice(@st,-1) };
205 }
206 elsif($b1==39)
207 {
208 0 $dict->{Chameleon}=splice(@st,-1);
209 }
210 0 next;
211 }
212 elsif($b0<28) # commands
213 {
214 0 ▶ if($b0==0)
Branch: 12 branches
BranchTrueFalseTotal
if ($b0 == 0) { } 0 0 0
elsif ($b0 == 1) { } 0 0 0
elsif ($b0 == 2) { } 0 0 0
elsif ($b0 == 3) { } 0 0 0
elsif ($b0 == 4) { } 0 0 0
elsif ($b0 == 5) { } 0 0 0
elsif ($b0 == 13) { } 0 0 0
elsif ($b0 == 14) { } 0 0 0
elsif ($b0 == 15) { } 0 0 0
elsif ($b0 == 16) { } 0 0 0
elsif ($b0 == 17) { } 0 0 0
elsif ($b0 == 18) { } 0 0 0
215 {
216 0 $dict->{Version}={ 'SID' => splice(@st,-1) };
217 }
218 elsif($b0==1)
219 {
220 0 $dict->{Notice}={ 'SID' => splice(@st,-1) };
221 }
222 elsif($b0==2)
223 {
224 0 $dict->{FullName}={ 'SID' => splice(@st,-1) };
225 }
226 elsif($b0==3)
227 {
228 0 $dict->{FamilyName}={ 'SID' => splice(@st,-1) };
229 }
230 elsif($b0==4)
231 {
232 0 $dict->{Weight}={ 'SID' => splice(@st,-1) };
233 }
234 elsif($b0==5)
235 {
236 0 $dict->{FontBBX}=[ splice(@st,-4) ];
237 }
238 elsif($b0==13)
239 {
240 0 $dict->{UniqueID}=splice(@st,-1);
241 }
242 elsif($b0==14)
243 {
244 0 $dict->{XUID}=[splice(@st,0)];
245 }
246 elsif($b0==15)
247 {
248 0 $dict->{CharSet}={ 'OFF' => $foff+splice(@st,-1) };
249 }
250 elsif($b0==16)
251 {
252 0 $dict->{Encoding}={ 'OFF' => $foff+splice(@st,-1) };
253 }
254 elsif($b0==17)
255 {
256 0 $dict->{CharStrings}={ 'OFF' => $foff+splice(@st,-1) };
257 }
258 elsif($b0==18)
259 {
260 0 $dict->{Private}={ 'LEN' => splice(@st,-1), 'OFF' => $foff+splice(@st,-1) };
261 }
262 0 next;
263 }
264 elsif($b0==28) # int16
265 {
266 0 read($fh,$buf,2);
267 0 $v=unpack('n',$buf);
268 0 ▶ $v=-(0x10000-$v) if($v>0x7fff);
Branch: 1 branch
BranchTrueFalseTotal
if $v > 32767 0 0 0
269 }
270 elsif($b0==29) # int32
271 {
272 0 read($fh,$buf,4);
273 0 $v=unpack('N',$buf);
274 0 ▶ $v=-$v+0xffffffff+1 if($v>0x7fffffff);
Branch: 1 branch
BranchTrueFalseTotal
if $v > 2147483647 0 0 0
275 }
276 elsif($b0==30) # float
277 {
278 0 $e=1;
279 0 ▶ while($e)
Branch: 1 branch
BranchTrueFalseTotal
if ($e) 0 0 0
280 {
281 0 read($fh,$buf,1);
282 0 $v0=unpack('C',$buf);
283 0 foreach my $m ($v0>>8,$v0&0xf)
284 {
285 0 ▶ if($m<10)
Branch: 6 branches
BranchTrueFalseTotal
if ($m < 10) { } 0 0 0
elsif ($m == 10) { } 0 0 0
elsif ($m == 11) { } 0 0 0
elsif ($m == 12) { } 0 0 0
elsif ($m == 14) { } 0 0 0
elsif ($m == 15) { } 0 0 0
286 {
287 0 $v.=$m;
288 }
289 elsif($m==10)
290 {
291 0 $v.='.';
292 }
293 elsif($m==11)
294 {
295 0 $v.='E+';
296 }
297 elsif($m==12)
298 {
299 0 $v.='E-';
300 }
301 elsif($m==14)
302 {
303 0 $v.='-';
304 }
305 elsif($m==15)
306 {
307 0 $e=0;
308 0 last;
309 }
310 }
311 }
312 }
313 elsif($b0==31) # command
314 {
315 0 $v="c=$b0";
316 0 next;
317 }
318 elsif($b0<247) # 1 byte signed
319 {
320 0 $v=$b0-139;
321 }
322 elsif($b0<251) # 2 byte plus
323 {
324 0 read($fh,$buf,1);
325 0 $v=unpack('C',$buf);
326 0 $v=($b0-247)*256+($v+108);
327 }
328 elsif($b0<255) # 2 byte minus
329 {
330 0 read($fh,$buf,1);
331 0 $v=unpack('C',$buf);
332 0 $v=-($b0-251)*256-$v-108;
333 }
334 0 push @st,$v;
335 }
336
337 0 return($dict);
338 }
339
340 sub read_kern_table
341 0 ▶{
Subroutine read_kern_table: not called CC=10 SCAR=47.0
Pod undocumented
342 0 my $font=shift @_;
343 0 my $upem=shift @_;
344 0 my $self=shift @_;
345 0 my $fh=$font->{' INFILE'};
346 0 my $data=undef;
347
348 0 ▶ return(undef) unless($font->{kern});
Branch: 1 branch
BranchTrueFalseTotal
unless $font->{"kern"} 0 0 0
349
350 0 my $buf = undef;
351
352 0 seek($fh,$font->{kern}->{' OFFSET'}+2,0);
353 0 read($fh,$buf, 2);
354 0 my $num=unpack('n',$buf);
355 0 foreach my $n (1..$num)
356 {
357 0 read($fh, $buf, 6);
358 0 my ($ver, $len, $cov) = unpack('n3', $buf);
359 0 $len-=6;
360 0 my $fmt=$cov>>8;
361 0 ▶ if($fmt==0)
Branch: 2 branches
BranchTrueFalseTotal
if ($fmt == 0) { } 0 0 0
elsif ($fmt == 2) { } 0 0 0
362 {
363 0 ▶ $data||={};
Condition0%0/2
$data ||= {}
l!l
00
MC/DC0%0/1
$data ||= {}
$data
Truth table0%0/2
A
A= $data
Aresult
11
00
364 0 read($fh, $buf, 8);
365 0 my $nc = unpack('n', $buf);
366 0 foreach (1..$nc)
367 {
368 0 read($fh, $buf, 6);
369 0 my ($idx1,$idx2,$val)=unpack('nnn',$buf);
370 0 ▶ $val-=65536 if($val>32767);
Branch: 1 branch
BranchTrueFalseTotal
if $val > 32767 0 0 0
371 0 ▶ $val= $val < 0 ? -floor($val*1000/$upem) : -ceil($val*1000/$upem);
Branch: 1 branch
BranchTrueFalseTotal
$val < 0 ? : 0 0 0
372 0 ▶ if($val != 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($val != 0) 0 0 0
373 {
374 0 $data->{"$idx1:$idx2"}=$val;
375 0 $data->{$self->data->{g2n}->[$idx1].':'.$self->data->{g2n}->[$idx2]}=$val;
376 }
377 }
378 }
379 elsif($fmt==2)
380 {
381 0 read($fh, $buf, $len);
382 }
383 else
384 {
385 0 read($fh, $buf, $len);
386 }
387 }
388 ##print Dumper($data);
389 0 return($data);
390 }
391
392 sub readcffstructs
393 0 ▶{
Subroutine readcffstructs: not called CC=12 SCAR=50.5
Pod undocumented
394 0 my $font=shift @_;
395 0 my $fh=$font->{' INFILE'};
396 0 my $data={};
397 # read CFF table
398 0 seek($fh,$font->{'CFF '}->{' OFFSET'},0);
399 0 read($fh,$buf, 4);
400 0 my ($cffmajor,$cffminor,$cffheadsize,$cffglobaloffsize)=unpack('C4',$buf);
401
402 0 $data->{name}=readcffindex($fh,$font->{'CFF '}->{' OFFSET'}+$cffheadsize);
403 0 foreach my $dict (@{$data->{name}})
404 {
405 0 seek($fh,$dict->{OFF},0);
406 0 read($fh,$dict->{VAL},$dict->{LEN});
407 }
408
409 0 $data->{topdict}=readcffindex($fh,$data->{name}->[-1]->{OFF}+$data->{name}->[-1]->{LEN});
410 0 foreach my $dict (@{$data->{topdict}})
411 {
412 0 $dict->{VAL}=readcffdict($fh,$dict->{OFF},$dict->{LEN},$font->{'CFF '}->{' OFFSET'});
413 }
414
415 0 $data->{string}=readcffindex($fh,$data->{topdict}->[-1]->{OFF}+$data->{topdict}->[-1]->{LEN});
416 0 foreach my $dict (@{$data->{string}})
417 {
418 0 seek($fh,$dict->{OFF},0);
419 0 read($fh,$dict->{VAL},$dict->{LEN});
420 }
421 0 push @{$data->{string}},{ 'VAL' => '001.000' };
422 0 push @{$data->{string}},{ 'VAL' => '001.001' };
423 0 push @{$data->{string}},{ 'VAL' => '001.002' };
424 0 push @{$data->{string}},{ 'VAL' => '001.003' };
425 0 push @{$data->{string}},{ 'VAL' => 'Black' };
426 0 push @{$data->{string}},{ 'VAL' => 'Bold' };
427 0 push @{$data->{string}},{ 'VAL' => 'Book' };
428 0 push @{$data->{string}},{ 'VAL' => 'Light' };
429 0 push @{$data->{string}},{ 'VAL' => 'Medium' };
430 0 push @{$data->{string}},{ 'VAL' => 'Regular' };
431 0 push @{$data->{string}},{ 'VAL' => 'Roman' };
432 0 push @{$data->{string}},{ 'VAL' => 'Semibold' };
433
434 0 foreach my $dict (@{$data->{topdict}})
435 {
436 0 foreach my $k (keys %{$dict->{VAL}})
437 {
438 0 my $dt=$dict->{VAL}->{$k};
439 0 ▶ if($k eq 'ROS')
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "ROS") 0 0 0
440 {
441 0 $dict->{VAL}->{$k}->[0]=$data->{string}->[$dict->{VAL}->{$k}->[0]-391]->{VAL};
442 0 $dict->{VAL}->{$k}->[1]=$data->{string}->[$dict->{VAL}->{$k}->[1]-391]->{VAL};
443 0 next;
444 }
445 0 ▶ next unless(ref($dt) eq 'HASH' && defined $dt->{SID});
Branch: 1 branch
BranchTrueFalseTotal
unless ref $dt eq "HASH" and defined $dt->{"SID"} 0 0 0
Condition0%0/3
ref $dt eq "HASH" and defined $dt->{"SID"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $dt eq "HASH" and defined $dt->{"SID"}
ref $dt eq "HASH" defined $dt->{"SID"}
Truth table0%0/3
A and B
A= ref $dt eq "HASH"B= defined $dt->{"SID"}
ABresult
0X0
100
111
446 0 ▶ if($dt->{SID}>=379)
Branch: 1 branch
BranchTrueFalseTotal
if ($dt->{"SID"} >= 379) 0 0 0
447 {
448 0 $dict->{VAL}->{$k}=$data->{string}->[$dt->{SID}-391]->{VAL};
449 }
450 }
451 }
452 0 my $dict={};
453 0 foreach my $k (qw[ CIDCount CIDFontVersion FamilyName FontBBX FullName ROS Weight XUID ])
454 {
455 0 ▶ $dict->{$k}=$data->{topdict}->[0]->{VAL}->{$k} if(defined $data->{topdict}->[0]->{VAL}->{$k});
Branch: 1 branch
BranchTrueFalseTotal
if defined $data->{"topdict"}[0]{"VAL"}{$k} 0 0 0
456 }
457 0 return($dict);
458 }
459
460 0 ▶sub new {
Subroutine new: not called CC=42 SCAR=75.0
Pod documented
461 0 my ($class,$pdf,$file,%opts)=@_;
462 0 my $data={};
463
464 0 ▶ die "cannot find font '$file' ..." unless(-f $file);
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 0 0 0
465 0 my $font=PDF::API3::Compat::API2::Basic::TTF::Font->open($file);
466 0 $data->{obj}=$font;
467
468 0 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
469 0 $self=$class->SUPER::new();
470
471 0 $self->{Filter}=PDFArray(PDFName('FlateDecode'));
472 0 $self->{' font'}=$font;
473 0 $self->{' data'}=$data;
474
475 0 ▶ $data->{noembed} = $opts{-noembed}==1 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$opts{'-noembed'} == 1 ? : 0 0 0
476 0 ▶ $data->{iscff} = (defined $font->{'CFF '}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $font->{'CFF '} ? : 0 0 0
477
478 0 ▶ $self->{Subtype}=PDFName('Type1C') if($data->{iscff});
Branch: 1 branch
BranchTrueFalseTotal
if $data->{"iscff"} 0 0 0
479
480 0 $data->{fontfamily}=$font->{'name'}->read->find_name(1);
481 0 $data->{fontname}=$font->{'name'}->read->find_name(4);
482
483 0 $font->{'OS/2'}->read;
484 0 my @stretch=qw[
485 Normal
486 UltraCondensed
487 ExtraCondensed
488 Condensed
489 SemiCondensed
490 Normal
491 SemiExpanded
492 Expanded
493 ExtraExpanded
494 UltraExpanded
495 ];
496 0 ▶ $data->{fontstretch}=$stretch[$font->{'OS/2'}->{usWidthClass}] || 'Normal';
Condition0%0/2
$stretch[$font->{'OS/2'}{'usWidthClass'}] || 'Normal'
l!l
00
MC/DC0%0/1
$stretch[$font->{'OS/2'}{'usWidthClass'}] || 'Normal'
$stretch[$font->{'OS/2'}{'usWidthClass'}]
Truth table0%0/2
A
A= $stretch[$font->{'OS/2'}{'usWidthClass'}]
Aresult
11
00
497
498 0 $data->{fontweight}=$font->{'OS/2'}->{usWeightClass};
499
500 0 $data->{panose}=pack('n',$font->{'OS/2'}->{sFamilyClass});
501
502 0 foreach my $p (qw[bFamilyType bSerifStyle bWeight bProportion bContrast bStrokeVariation bArmStyle bLetterform bMidline bXheight])
503 {
504 0 $data->{panose}.=pack('C',$font->{'OS/2'}->{$p});
505 }
506
507 0 $data->{apiname}=$data->{fontname};
508 0 $data->{apiname}=~s/[^A-Za-z0-9]+/ /og;
509 0 $data->{apiname}=join('',map { $_=~s/[^A-Za-z0-9]+//og; $_=ucfirst(lc(substr($_,0,2))); $_; } split(/\s+/,$data->{apiname}));
510 0 $data->{fontname}=~s/[\x00-\x1f\s]//og;
511
512 0 $data->{altname}=$font->{'name'}->find_name(1);
513 0 $data->{altname}=~s/[\x00-\x1f\s]//og;
514
515 0 $data->{subname}=$font->{'name'}->find_name(2);
516 0 $data->{subname}=~s/[\x00-\x1f\s]//og;
517
518 0 ▶ $font->{cmap}->read->find_ms($opts{-isocmap}||0);
Condition0%0/2
$opts{'-isocmap'} || 0
l!l
00
MC/DC0%0/1
$opts{'-isocmap'} || 0
$opts{'-isocmap'}
Truth table0%0/2
A
A= $opts{'-isocmap'}
Aresult
11
00
519 0 ▶ if(defined $font->{cmap}->find_ms)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $font->{'cmap'}->find_ms) { } 0 0 0
520 {
521 0 ▶ $data->{issymbol} = ($font->{cmap}->find_ms->{'Platform'} == 3 && $font->{cmap}->read->find_ms->{'Encoding'} == 0) || 0;
Condition0%0/5
$font->{'cmap'}->find_ms->{'Platform'} == 3 && $font->{'cmap'}->read->find_ms->{'Encoding'} == 0 || 0
l!l
00
$font->{"cmap"}->find_ms->{"Platform"} == 3 and $font->{"cmap"}->read->find_ms->{"Encoding"} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$font->{'cmap'}->find_ms->{'Platform'} == 3 && $font->{'cmap'}->read->find_ms->{'Encoding'} == 0 || 0
$font->{"cmap"}->find_ms->{"Platform"} == 3 $font->{"cmap"}->read->find_ms->{"Encoding"} == 0
Truth table0%0/3
A and B
A= $font->{"cmap"}->find_ms->{"Platform"} == 3B= $font->{"cmap"}->read->find_ms->{"Encoding"} == 0
ABresult
111
0X0
100
522 }
523 else
524 {
525 0 $data->{issymbol} = 0;
526 }
527
528 0 $data->{upem}=$font->{'head'}->read->{'unitsPerEm'};
529
530 $data->{fontbbox}=[
531 int($font->{'head'}->{'xMin'} * 1000 / $data->{upem}),
532 int($font->{'head'}->{'yMin'} * 1000 / $data->{upem}),
533 int($font->{'head'}->{'xMax'} * 1000 / $data->{upem}),
534 int($font->{'head'}->{'yMax'} * 1000 / $data->{upem})
535 0 ];
536
537 0 $data->{stemv}=0;
538 0 $data->{stemh}=0;
539
540 0 ▶ $data->{missingwidth}=int($font->{'hhea'}->read->{'advanceWidthMax'} * 1000 / $data->{upem}) || 1000;
Condition0%0/2
int $font->{'hhea'}->read->{'advanceWidthMax'} * 1000 / $data->{'upem'} || 1000
l!l
00
MC/DC0%0/1
int $font->{'hhea'}->read->{'advanceWidthMax'} * 1000 / $data->{'upem'} || 1000
int $font->{'hhea'}->read->{'advanceWidthMax'} * 1000 / $data->{'upem'}
Truth table0%0/2
A
A= int $font->{'hhea'}->read->{'advanceWidthMax'} * 1000 / $data->{'upem'}
Aresult
11
00
541 0 $data->{maxwidth}=int($font->{'hhea'}->{'advanceWidthMax'} * 1000 / $data->{upem});
542 0 $data->{ascender}=int($font->{'hhea'}->read->{'Ascender'} * 1000 / $data->{upem});
543 0 $data->{descender}=int($font->{'hhea'}{'Descender'} * 1000 / $data->{upem});
544
545 0 $data->{flags} = 0;
546 0 ▶ $data->{flags} |= 1 if ($font->{'OS/2'}->read->{'bProportion'} == 9);
Branch: 1 branch
BranchTrueFalseTotal
if $font->{"OS/2"}->read->{"bProportion"} == 9 0 0 0
547 0 ▶ $data->{flags} |= 2 unless ($font->{'OS/2'}{'bSerifStyle'} > 10 && $font->{'OS/2'}{'bSerifStyle'} < 14);
Branch: 1 branch
BranchTrueFalseTotal
unless $font->{"OS/2"}{"bSerifStyle"} > 10 and $font->{"OS/2"}{"bSerifStyle"} < 14 0 0 0
Condition0%0/3
$font->{"OS/2"}{"bSerifStyle"} > 10 and $font->{"OS/2"}{"bSerifStyle"} < 14
!ll&&!rl&&r
000
MC/DC0%0/2
$font->{"OS/2"}{"bSerifStyle"} > 10 and $font->{"OS/2"}{"bSerifStyle"} < 14
$font->{"OS/2"}{"bSerifStyle"} > 10 $font->{"OS/2"}{"bSerifStyle"} < 14
Truth table0%0/3
A and B
A= $font->{"OS/2"}{"bSerifStyle"} > 10B= $font->{"OS/2"}{"bSerifStyle"} < 14
ABresult
0X0
100
111
548 0 ▶ $data->{flags} |= 8 if ($font->{'OS/2'}{'bFamilyType'} == 2);
Branch: 1 branch
BranchTrueFalseTotal
if $font->{"OS/2"}{"bFamilyType"} == 2 0 0 0
549 0 $data->{flags} |= 32; # if ($font->{'OS/2'}{'bFamilyType'} > 3);
550 0 ▶ $data->{flags} |= 64 if ($font->{'OS/2'}{'bLetterform'} > 8);;
Branch: 1 branch
BranchTrueFalseTotal
if $font->{"OS/2"}{"bLetterform"} > 8 0 0 0
551
552 0 ▶ $data->{capheight}=$font->{'OS/2'}->{CapHeight} || int($data->{fontbbox}->[3]*0.8);
Condition0%0/3
$font->{'OS/2'}{'CapHeight'} || int $data->{'fontbbox'}[3] * 0.8
l!l&&r!l&&!r
000
MC/DC0%0/2
$font->{'OS/2'}{'CapHeight'} || int $data->{'fontbbox'}[3] * 0.8
$font->{'OS/2'}{'CapHeight'} int $data->{'fontbbox'}[3] * 0.8
Truth table0%0/3
A || B
A= $font->{'OS/2'}{'CapHeight'}B= int $data->{'fontbbox'}[3] * 0.8
ABresult
1X1
011
000
553 0 ▶ $data->{xheight}=$font->{'OS/2'}->{xHeight} || int($data->{fontbbox}->[3]*0.4);
Condition0%0/3
$font->{'OS/2'}{'xHeight'} || int $data->{'fontbbox'}[3] * 0.4
l!l&&r!l&&!r
000
MC/DC0%0/2
$font->{'OS/2'}{'xHeight'} || int $data->{'fontbbox'}[3] * 0.4
$font->{'OS/2'}{'xHeight'} int $data->{'fontbbox'}[3] * 0.4
Truth table0%0/3
A || B
A= $font->{'OS/2'}{'xHeight'}B= int $data->{'fontbbox'}[3] * 0.4
ABresult
1X1
011
000
554
555 0 ▶ if($data->{issymbol})
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{'issymbol'}) { } 0 0 0
556 {
557 0 $data->{e2u}=[0xf000 .. 0xf0ff];
558 }
559 else
560 {
561 0 $data->{e2u}=[ unpack('U*',decode('cp1252', pack('C*',0..255))) ];
562 }
563
564 0 ▶ if(($font->{'post'}->read->{FormatType} == 3) && defined($font->{cmap}->read->find_ms))
Branch: 1 branch
BranchTrueFalseTotal
if ($font->{'post'}->read->{'FormatType'} == 3 and defined $font->{'cmap'}->read->find_ms) { } 0 0 0
Condition0%0/3
$font->{"post"}->read->{"FormatType"} == 3 and defined $font->{"cmap"}->read->find_ms
!ll&&!rl&&r
000
MC/DC0%0/2
$font->{"post"}->read->{"FormatType"} == 3 and defined $font->{"cmap"}->read->find_ms
$font->{"post"}->read->{"FormatType"} == 3 defined $font->{"cmap"}->read->find_ms
Truth table0%0/3
A and B
A= $font->{"post"}->read->{"FormatType"} == 3B= defined $font->{"cmap"}->read->find_ms
ABresult
0X0
100
111
565 {
566 0 $data->{g2n} = [];
567 0 foreach my $u (sort {$a<=>$b} keys %{$font->{cmap}->read->find_ms->{val}})
568 {
569 0 my $n=nameByUni($u);
570 0 $data->{g2n}->[$font->{cmap}->read->find_ms->{val}->{$u}]=$n;
571 }
572 }
573 else
574 {
575 0 ▶ $data->{g2n} = [ map { $_ || '.notdef' } @{$font->{'post'}->read->{'VAL'}} ];
Condition0%0/2
$_ || '.notdef'
l!l
00
MC/DC0%0/1
$_ || '.notdef'
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
576 }
577
578 0 $data->{italicangle}=$font->{'post'}->{italicAngle};
579 0 $data->{isfixedpitch}=$font->{'post'}->{isFixedPitch};
580 0 $data->{underlineposition}=$font->{'post'}->{underlinePosition};
581 0 $data->{underlinethickness}=$font->{'post'}->{underlineThickness};
582
583 0 ▶ if($self->iscff)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->iscff) 0 0 0
584 {
585 0 $data->{cff}=readcffstructs($font);
586 }
587
588 0 ▶ if(defined $data->{cff}->{ROS})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data->{'cff'}{'ROS'}) { } 0 0 0
589 {
590 0 my %cffcmap=(
591 'Adobe:Japan1'=>'japanese',
592 'Adobe:Korea1'=>'korean',
593 'Adobe:CNS1'=>'traditional',
594 'Adobe:GB1'=>'simplified',
595 );
596 0 my $ccmap=_look_for_cmap($cffcmap{"$data->{cff}->{ROS}->[0]:$data->{cff}->{ROS}->[1]"});
597 0 $data->{u2g}=$ccmap->{u2g};
598 0 $data->{g2u}=$ccmap->{g2u};
599 }
600 else
601 {
602 0 $data->{u2g} = {};
603
604 0 my $gmap=$font->{cmap}->read->find_ms->{val};
605 0 foreach my $u (sort {$a<=>$b} keys %{$gmap})
606 {
607 0 ▶ my $uni=$u||0;
Condition0%0/2
$u || 0
l!l
00
MC/DC0%0/1
$u || 0
$u
Truth table0%0/2
A
A= $u
Aresult
11
00
608 0 $data->{u2g}->{$uni}=$gmap->{$uni};
609 }
610 0 ▶ $data->{g2u}=[ map { $_ || 0 } $font->{'cmap'}->read->reverse ];
Condition0%0/2
$_ || 0
l!l
00
MC/DC0%0/1
$_ || 0
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
611 }
612
613 0 ▶ if($data->{issymbol})
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"issymbol"}) 0 0 0
614 {
615 0 ▶ map { $data->{u2g}->{$_} ||= $font->{'cmap'}->read->ms_lookup($_) } (0xf000 .. 0xf0ff);
Condition0%0/3
$data->{"u2g"}{$_} ||= $font->{"cmap"}->read->ms_lookup($_)
l!l&&r!l&&!r
000
MC/DC0%0/2
$data->{"u2g"}{$_} ||= $font->{"cmap"}->read->ms_lookup($_)
$data->{"u2g"}{$_} $font->{"cmap"}->read->ms_lookup($_)
Truth table0%0/3
A ||= B
A= $data->{"u2g"}{$_}B= $font->{"cmap"}->read->ms_lookup($_)
ABresult
1X1
011
000
616 0 ▶ map { $data->{u2g}->{$_ & 0xff} ||= $font->{'cmap'}->read->ms_lookup($_) } (0xf000 .. 0xf0ff);
Condition0%0/3
$data->{"u2g"}{$_ & 255} ||= $font->{"cmap"}->read->ms_lookup($_)
l!l&&r!l&&!r
000
MC/DC0%0/2
$data->{"u2g"}{$_ & 255} ||= $font->{"cmap"}->read->ms_lookup($_)
$data->{"u2g"}{$_ & 255} $font->{"cmap"}->read->ms_lookup($_)
Truth table0%0/3
A ||= B
A= $data->{"u2g"}{$_ & 255}B= $font->{"cmap"}->read->ms_lookup($_)
ABresult
1X1
011
000
617 }
618
619 0 ▶ $data->{e2n}=[ map { $data->{g2n}->[$data->{u2g}->{$_} || 0] || '.notdef' } @{$data->{e2u}} ];
Condition0%0/4
$data->{'g2n'}[$data->{'u2g'}{$_} or 0] || '.notdef'
l!l
00
$data->{'u2g'}{$_} || 0
l!l
00
MC/DC0%0/1
$data->{'g2n'}[$data->{'u2g'}{$_} or 0] || '.notdef'
$data->{'g2n'}[$data->{'u2g'}{$_} or 0]
MC/DC0%0/1
$data->{'u2g'}{$_} || 0
$data->{'u2g'}{$_}
Truth table0%0/2
A
A= $data->{'g2n'}[$data->{'u2g'}{$_} or 0]
Aresult
11
00
Truth table0%0/2
A
A= $data->{'u2g'}{$_}
Aresult
11
00
620
621 0 ▶ $data->{e2g}=[ map { $data->{u2g}->{$_ || 0} || 0 } @{$data->{e2u}} ];
Condition0%0/4
$data->{'u2g'}{$_ or 0} || 0
l!l
00
$_ || 0
l!l
00
MC/DC0%0/1
$data->{'u2g'}{$_ or 0} || 0
$data->{'u2g'}{$_ or 0}
MC/DC0%0/1
$_ || 0
$_
Truth table0%0/2
A
A= $data->{'u2g'}{$_ or 0}
Aresult
11
00
Truth table0%0/2
A
A= $_
Aresult
11
00
622 0 $data->{u2e}={};
623 0 foreach my $n (reverse 0..255)
624 {
625 0 ▶ $data->{u2e}->{$data->{e2u}->[$n]}=$n unless(defined $data->{u2e}->{$data->{e2u}->[$n]});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data->{"u2e"}{$data->{"e2u"}[$n]} 0 0 0
626 }
627
628 0 $data->{u2n}={ map { $data->{g2u}->[$_] => $data->{g2n}->[$_] } (0 .. (scalar @{$data->{g2u}} -1)) };
629
630 0 $data->{wx}=[];
631 0 foreach my $w (0..(scalar @{$data->{g2u}}-1))
632 {
633 $data->{wx}->[$w]=int($font->{'hmtx'}->read->{'advance'}[$w]*1000/$data->{upem})
634 0 ▶ || $data->{missingwidth};
Condition0%0/3
int $font->{'hmtx'}->read->{'advance'}[$w] * 1000 / $data->{'upem'} || $data->{'missingwidth'}
l!l&&r!l&&!r
000
MC/DC0%0/2
int $font->{'hmtx'}->read->{'advance'}[$w] * 1000 / $data->{'upem'} || $data->{'missingwidth'}
int $font->{'hmtx'}->read->{'advance'}[$w] * 1000 / $data->{'upem'} $data->{'missingwidth'}
Truth table0%0/3
A || B
A= int $font->{'hmtx'}->read->{'advance'}[$w] * 1000 / $data->{'upem'}B= $data->{'missingwidth'}
ABresult
1X1
011
000
635 }
636
637 0 $data->{kern}=read_kern_table($font,$data->{upem},$self);
638 0 ▶ delete $data->{kern} unless(defined $data->{kern});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data->{"kern"} 0 0 0
639
640 0 $data->{fontname}=~s/\s+//og;
641 0 $data->{fontfamily}=~s/\s+//og;
642 0 $data->{apiname}=~s/\s+//og;
643 0 $data->{altname}=~s/\s+//og;
644 0 $data->{subname}=~s/\s+//og;
645
646 0 $self->subsetByCId(0);
647
648 0 return($self,$data);
649 }
650
651 0 ▶sub font { return( $_[0]->{' font'} ); }
Subroutine font: not called CC=1 SCAR=6.9
Pod undocumented
652 0 ▶sub data { return( $_[0]->{' data'} ); }
Subroutine data: not called CC=1 SCAR=6.9
Pod undocumented
653 0 ▶sub iscff { return( $_[0]->data->{iscff} ); }
Subroutine iscff: not called CC=1 SCAR=6.9
Pod undocumented
654
655 0 ▶sub haveKernPairs { return( $_[0]->data->{kern} ? 1 : 0 ); }
Subroutine haveKernPairs: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->data->{'kern'} ? : 0 0 0
656
657 sub kernPairCid
658 0 ▶{
Subroutine kernPairCid: not called CC=4 SCAR=30.0
Pod undocumented
659 0 my ($self, $i1, $i2) = @_;
660 0 ▶ return(0) if($i1==0 || $i2==0);
Branch: 1 branch
BranchTrueFalseTotal
if $i1 == 0 or $i2 == 0 0 0 0
Condition0%0/3
$i1 == 0 or $i2 == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$i1 == 0 or $i2 == 0
$i1 == 0 $i2 == 0
Truth table0%0/3
A or B
A= $i1 == 0B= $i2 == 0
ABresult
1X1
011
000
661 0 ▶ return($self->data->{kern}->{"$i1:$i2"} || 0);
Condition0%0/2
$self->data->{'kern'}{"${i1}:$i2"} || 0
l!l
00
MC/DC0%0/1
$self->data->{'kern'}{"${i1}:$i2"} || 0
$self->data->{'kern'}{"${i1}:$i2"}
Truth table0%0/2
A
A= $self->data->{'kern'}{"${i1}:$i2"}
Aresult
11
00
662 }
663
664 sub subsetByCId
665 0 ▶{
Subroutine subsetByCId: not called CC=3 SCAR=24.8
Pod undocumented
666 0 my $self = shift @_;
667 0 my $g = shift @_;
668 0 $self->data->{subset}=1;
669 0 vec($self->data->{subvec},$g,1)=1;
670 0 ▶ return if($self->iscff);
Branch: 1 branch
BranchTrueFalseTotal
if $self->iscff 0 0 0
671 0 ▶ if(defined $self->font->{loca}->read->{glyphs}->[$g]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->font->{"loca"}->read->{"glyphs"}[$g]) 0 0 0
672 0 $self->font->{loca}->read->{glyphs}->[$g]->read;
673 0 map { vec($self->data->{subvec},$_,1)=1; } $self->font->{loca}->{glyphs}->[$g]->get_refs;
674 }
675 }
676
677 0 ▶sub subvec {
Subroutine subvec: not called CC=2 SCAR=17.9
Pod undocumented
678 0 my $self = shift @_;
679 0 ▶ return(1) if($self->iscff);
Branch: 1 branch
BranchTrueFalseTotal
if $self->iscff 0 0 0
680 0 my $g = shift @_;
681 0 return(vec($self->data->{subvec},$g,1));
682 }
683
684 0 ▶sub glyphNum { return ( $_[0]->font->{'maxp'}->read->{'numGlyphs'} ); }
Subroutine glyphNum: not called CC=1 SCAR=6.9
Pod undocumented
685
686 0 ▶sub outobjdeep {
Subroutine outobjdeep: not called CC=8 SCAR=42.8
Pod documented
687 0 my ($self, $fh, $pdf, %opts) = @_;
688
689 0 ▶ return $self->SUPER::outobjdeep($fh, $pdf) if defined $opts{'passthru'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"passthru"} 0 0 0
690
691 0 my $f = $self->font;
692
693 0 ▶ if($self->iscff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->iscff) { } 0 0 0
694 0 $f->{'CFF '}->read_dat;
695 0 $self->{' stream'} = $f->{'CFF '}->{' dat'};
696 } else {
697 0 ▶ if ($self->data->{subset} && !$self->data->{nosubset}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->data->{"subset"} and not $self->data->{"nosubset"}) 0 0 0
Condition0%0/3
$self->data->{"subset"} and not $self->data->{"nosubset"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->data->{"subset"} and not $self->data->{"nosubset"}
$self->data->{"subset"} not $self->data->{"nosubset"}
Truth table0%0/3
A and not(B)
A= $self->data->{"subset"}B= not $self->data->{"nosubset"}
ABresult
0X0
100
111
698 0 $f->{'glyf'}->read;
699 0 ▶ for (my $i = 0; $i < $self->glyphNum; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->glyphNum) 0 0 0
700 0 ▶ next if($self->subvec($i));
Branch: 1 branch
BranchTrueFalseTotal
if $self->subvec($i) 0 0 0
701 0 $f->{'loca'}{'glyphs'}->[$i] = undef;
702 # print STDERR "$i,";
703 }
704 }
705
706 0 ▶ if($self->data->{noembed} != 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->data->{"noembed"} != 1) 0 0 0
707 {
708 0 $self->{' stream'} = "";
709 0 my $ffh;
710 0 CORE::open($ffh, '+>', \$self->{' stream'});
711 0 binmode($ffh,':raw');
712 0 $f->out($ffh, 'cmap', 'cvt ', 'fpgm', 'glyf', 'head', 'hhea', 'hmtx', 'loca', 'maxp', 'prep');
713 0 $self->{'Length1'}=PDFNum(length($self->{' stream'}));
714 0 CORE::close($ffh);
715 }
716 }
717
718 0 $self->SUPER::outobjdeep($fh, $pdf, %opts);
719 }
720
721
722 1 1;
723
724 __END__
↑ Summary API3/Compat/API2/Resource/Font/neTrueType.pm »