API2/Resource/CIDFont/TrueType/FontFile.pm

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