API2/Basic/PDF/Pages.pm

filter: Statementstmt 64.2% 122 / 190 Branchbran 48.9% 47 / 96 Conditioncond 17.0% 7 / 41 MC/DCmcdc 8.0% 2 / 25 Subroutinesub 70.8% 17 / 24 Podpod 62.5% 10 / 16 totaltotal 52.3% 205 / 392 CC 69 SCAR 35.4
CC
69
Cov
54%
add_font
156.0
bbox
72.0
add_page_recurse
18.1
CRAP 34.4
« API2/Resource/CIDFont/CJKFont.pm ↑ Summary API2/Resource/XObject/Image/TIFF.pm »
1 # Code in the PDF::API2::Basic::PDF namespace was originally copied from the
2 # Text::PDF distribution.
3 #
4 # Copyright Martin Hosken <Martin_Hosken@sil.org>
5 #
6 # Martin Hosken's code may be used under the terms of the MIT license.
7 # Subsequent versions of the code have the same license as PDF::API2.
8  
9 package PDF::API2::Basic::PDF::Pages;
10  
11 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 40 ▶use base 'PDF::API2::Basic::PDF::Dict';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 40 our $VERSION = '2.049'; # VERSION
17  
18 40 ▶use PDF::API2::Basic::PDF::Array;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 40 ▶use PDF::API2::Basic::PDF::Dict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 40 ▶use PDF::API2::Basic::PDF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 40 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 40 our %inst = map {$_ => 1} qw(Parent Type);
25  
26 =head1 NAME
27  
28 PDF::API2::Basic::PDF::Pages - Low-level page tree object
29  
30 =head1 DESCRIPTION
31  
32 A Pages object is the parent to other pages objects or to page objects
33 themselves.
34  
35 =head1 METHODS
36  
37 =head2 PDF::API2::Basic::PDF::Pages->new($pdf, $parent)
38  
39 This creates a new Pages object in a PDF. Notice that $parent here is
40 not the file context for the object but the parent pages object for
41 this pages. If we are using this class to create a root node, then
42 $parent should point to the file context, which is identified by not
43 having a Type of Pages. $pdf is the file object (or a reference to an
44 array of file objects) in which to create the new Pages object.
45  
46 =cut
47  
48 306 ▶sub new {
Subroutine new: called CC=9 SCAR=23.7
Pod documented
49 306 my ($class, $pdf, $parent) = @_;
50 306 ▶ $pdf //= $class->get_top->{' parent'} if ref($class);
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 306 306
Condition0%0/3
$pdf //= $class->get_top->{" parent"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$pdf //= $class->get_top->{" parent"}
$pdf $class->get_top->{" parent"}
Truth table0%0/3
A //= B
A= $pdfB= $class->get_top->{" parent"}
ABresult
1X1
011
000
51  
52 # Prior to 2.034, $pdf could be an array of PDFs
53 306 ▶ if (ref($pdf) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $pdf eq "ARRAY") 0 306 306
54 0 ▶ die 'Only one PDF is supported as of version 2.034' if scalar(@$pdf) > 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$pdf > 1 0 0 0
55 0 ($pdf) = @$pdf;
56 }
57  
58 306 ▶ $class = ref($class) if ref($class);
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 306 306
59 306 my $self = $class->SUPER::new($pdf, $parent);
60  
61 306 $self->{'Type'} = PDFName('Pages');
62 306 ▶ $self->{'Parent'} = $parent if defined $parent;
Branch: 1 branch
BranchTrueFalseTotal
if defined $parent 142 164 306
63 306 $self->{'Count'} = PDFNum(0);
64 306 $self->{'Kids'} = PDF::API2::Basic::PDF::Array->new();
65  
66 306 $pdf->new_obj($self);
67 306 ▶ unless (defined $self->{'Parent'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"Parent"}) 164 142 306
68 164 $pdf->{'Root'}->{'Pages'} = $self;
69 164 $pdf->out_obj($pdf->{'Root'});
70  
71 164 $self->{' parent'} = $pdf;
72 164 weaken $self->{' parent'};
73 }
74  
75 306 ▶ weaken $self->{'Parent'} if defined $parent;
Branch: 1 branch
BranchTrueFalseTotal
if defined $parent 142 164 306
76  
77 306 return $self;
78 }
79  
80 426 ▶sub _pdf {
Subroutine _pdf: called CC=1 SCAR=0.0
81 426 my $self = shift();
82 426 return $self->get_top->{' parent'};
83 }
84  
85 =head2 $p->find_page($page_number)
86  
87 Returns the given page, using the page count values in the pages tree. Pages
88 start at 0.
89  
90 =cut
91  
92 133 ▶sub find_page {
Subroutine find_page: called CC=1 SCAR=0.0
Pod documented
93 133 my ($self, $page_number) = @_;
94 133 my $top = $self->get_top();
95  
96 133 $top->find_page_recurse(\$page_number);
97 }
98  
99  
100 133 ▶sub find_page_recurse {
Subroutine find_page_recurse: called CC=6 SCAR=22.9
Pod undocumented
101 133 my ($self, $page_number_ref) = @_;
102  
103 133 ▶ if ($self->{'Count'}->realise->val() <= $$page_number_ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"Count"}->realise->val <= $$page_number_ref) 0 133 133
104 0 $$page_number_ref -= $self->{'Count'}->val();
105 0 return;
106 }
107  
108 133 my $result;
109 133 foreach my $kid ($self->{'Kids'}->realise->elements()) {
110 3 ▶ if ($kid->{'Type'}->realise->val() eq 'Page') {
Branch: 2 branches
BranchTrueFalseTotal
if ($kid->{'Type'}->realise->val eq 'Page') { } 3 0 3
elsif ($result = $kid->realise->find_page_recurse($page_number_ref)) { } 0 0 0
111 3 ▶ return $kid if $$page_number_ref == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $$page_number_ref == 0 3 0 3
112 0 $$page_number_ref--;
113 }
114 elsif ($result = $kid->realise->find_page_recurse($page_number_ref)) {
115 0 return $result;
116 }
117 }
118  
119 130 return;
120 }
121  
122 =head2 $p->add_page($page, $page_number)
123  
124 Inserts the page before the given $page_number. $page_number can be negative to
125 count from the END of the document. -1 is after the last page. Likewise
126 $page_number can be greater than the number of pages currently in the document,
127 to append.
128  
129 =cut
130  
131 142 ▶sub add_page {
Subroutine add_page: called CC=14 SCAR=27.3
Pod documented
132 142 my ($self, $page, $page_number) = @_;
133 142 my $top = $self->get_top();
134  
135 142 ▶ $page_number = -1 unless defined $page_number and $page_number < $top->{'Count'}->val();
Branch: 1 branch
BranchTrueFalseTotal
unless defined $page_number and $page_number < $top->{"Count"}->val 140 2 142
Condition66%2/3
defined $page_number and $page_number < $top->{"Count"}->val
!ll&&!rl&&r
14002
MC/DC50%1/2
defined $page_number and $page_number < $top->{"Count"}->val
defined $page_number $page_number < $top->{"Count"}->val
Truth table66%2/3
A and B
A= defined $page_numberB= $page_number < $top->{"Count"}->val
ABresult
0X0
100
111
136  
137 142 my $previous_page;
138 142 ▶ if ($page_number == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($page_number == -1) { } 140 2 142
139 140 $previous_page = $top->{' last_page'};
140 140 ▶ unless (defined $previous_page) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $previous_page) 133 7 140
141 133 $previous_page = $top->find_page($top->{'Count'}->val() - 1);
142 }
143 140 $top->{' last_page'} = $page;
144 }
145 else {
146 2 ▶ $page_number = $top->{'Count'}->val() + $page_number + 1 if $page_number < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $page_number < 0 0 2 2
147 2 ▶ $page_number = 0 if $page_number < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $page_number < 0 0 2 2
148 2 ▶ if ($top->{'Count'}->val() == scalar($top->{'Kids'}->realise->elements())) {
Branch: 1 branch
BranchTrueFalseTotal
if ($top->{'Count'}->val == scalar $top->{'Kids'}->realise->elements) { } 2 0 2
149 2 $previous_page = ($top->{'Kids'}->elements())[$page_number];
150 }
151 else {
152 0 $previous_page = $top->find_page($page_number);
153 }
154 }
155  
156 142 my $parent;
157 142 ▶ if (defined $previous_page->{'Parent'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $previous_page->{'Parent'}) { } 12 130 142
158 12 $parent = $previous_page->{'Parent'}->realise();
159 }
160 else {
161 130 $parent = $self;
162 }
163  
164 142 my $parent_kid_count = scalar $parent->{'Kids'}->realise->elements();
165  
166 142 my $page_index;
167 142 ▶ if ($page_number == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($page_number == -1) { } 140 2 142
168 140 $page_index = -1;
169 }
170 else {
171 2 ▶ for ($page_index = 0; $page_index < $parent_kid_count; $page_index++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($page_index < $parent_kid_count) 2 0 2
172 2 ▶ last if $parent->{'Kids'}{' val'}[$page_index] eq $previous_page;
Branch: 1 branch
BranchTrueFalseTotal
if $parent->{"Kids"}{" val"}[$page_index] eq $previous_page 2 0 2
173 }
174 2 ▶ $page_index = -1 if $page_index == $parent_kid_count;
Branch: 1 branch
BranchTrueFalseTotal
if $page_index == $parent_kid_count 0 2 2
175 }
176  
177 142 $parent->add_page_recurse($page->realise(), $page_index);
178 142 ▶ for ($parent = $page->{'Parent'}; defined $parent->{'Parent'}; $parent = $parent->{'Parent'}->realise()) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parent->{"Parent"}) 0 142 142
179 0 $parent->set_modified();
180 0 $parent->{'Count'}->realise->{'val'}++;
181 }
182 142 $parent->set_modified();
183 142 $parent->{'Count'}->realise->{'val'}++;
184  
185 142 return $page;
186 }
187  
188 142 ▶sub add_page_recurse {
Subroutine add_page_recurse: called CC=8 SCAR=29.0
Pod undocumented
189 142 my ($self, $page, $page_index) = @_;
190  
191 142 my $parent = $self;
192 142 my $max_kids_per_parent = 8; # Why?
193 142 ▶ if (scalar $parent->{'Kids'}->elements() >= $max_kids_per_parent and $parent->{'Parent'} and $page_index == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar $parent->{'Kids'}->elements >= $max_kids_per_parent and $parent->{'Parent'} and $page_index == -1) { } 0 142 142
Condition33%2/6
scalar $parent->{"Kids"}->elements >= $max_kids_per_parent and $parent->{"Parent"} and $page_index == -1
!ll&&!rl&&r
14200
scalar $parent->{"Kids"}->elements >= $max_kids_per_parent and $parent->{"Parent"}
!ll&&!rl&&r
14200
MC/DC0%0/3
scalar $parent->{"Kids"}->elements >= $max_kids_per_parent and $parent->{"Parent"} and $page_index == -1
scalar $parent->{"Kids"}->elements >= $max_kids_per_parent $parent->{"Parent"} $page_index == -1
Truth table25%1/4
A and B and C
A= scalar $parent->{"Kids"}->elements >= $max_kids_per_parentB= $parent->{"Parent"}C= $page_index == -1
ABCresult
0XX0
10X0
1100
1111
194 0 my $grandparent = $parent->{'Parent'}->realise();
195 0 $parent = $parent->new($parent->_pdf(), $grandparent);
196  
197 0 my $grandparent_kid_count = scalar $grandparent->{'Kids'}->realise->elements();
198 0 my $new_parent_index;
199 0 ▶ for ($new_parent_index = 0; $new_parent_index < $grandparent_kid_count; $new_parent_index++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_parent_index < $grandparent_kid_count) 0 0 0
200 0 ▶ last if $grandparent->{'Kids'}{' val'}[$new_parent_index] eq $self;
Branch: 1 branch
BranchTrueFalseTotal
if $grandparent->{"Kids"}{" val"}[$new_parent_index] eq $self 0 0 0
201 }
202 0 $new_parent_index++;
203 0 ▶ $new_parent_index = -1 if $new_parent_index > $grandparent_kid_count;
Branch: 1 branch
BranchTrueFalseTotal
if $new_parent_index > $grandparent_kid_count 0 0 0
204 0 $grandparent->add_page_recurse($parent, $new_parent_index);
205 }
206 else {
207 142 $parent->set_modified();
208 }
209  
210 142 ▶ if ($page_index < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($page_index < 0) { } 140 2 142
211 140 push @{$parent->{'Kids'}->realise->{' val'}}, $page;
212 }
213 else {
214 2 splice @{$parent->{'Kids'}{' val'}}, $page_index, 0, $page;
215 }
216 142 $page->{'Parent'} = $parent;
217 142 weaken $page->{'Parent'};
218 }
219  
220 284 ▶sub set_modified {
Subroutine set_modified: called CC=1 SCAR=0.0
Pod undocumented
221 284 my $self = shift();
222 284 $self->_pdf->out_obj($self);
223 }
224  
225 # Previously documented but not implemented
226 0 ▶sub rebuild_tree { return; }
Subroutine rebuild_tree: not called CC=1 SCAR=6.9
Pod undocumented
227  
228 =head2 @objects = $p->get_pages()
229  
230 Returns a list of page objects in the document in page order
231  
232 =cut
233  
234 0 ▶sub get_pages {
Subroutine get_pages: not called CC=1 SCAR=6.9
Pod documented
235 0 my $self = shift();
236 0 return $self->get_top->get_pages_recurse();
237 }
238  
239 # Renamed for clarity
240 0 ▶sub get_kids { return get_pages_recurse(@_) }
Subroutine get_kids: not called CC=1 SCAR=6.9
Pod undocumented
241  
242 0 ▶sub get_pages_recurse {
Subroutine get_pages_recurse: not called CC=3 SCAR=24.8
Pod undocumented
243 0 my $self = shift();
244 0 my @pages;
245  
246 0 foreach my $kid ($self->{'Kids'}->elements()) {
247 0 $kid->realise();
248 0 ▶ if ($kid->{'Type'}->val() eq 'Pages') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kid->{'Type'}->val eq 'Pages') { } 0 0 0
249 0 push @pages, $kid->get_pages_recurse();
250 }
251 else {
252 0 push @pages, $kid;
253 }
254 }
255  
256 0 return @pages;
257 }
258  
259 =head2 $p->find_prop($key)
260  
261 Searches up through the inheritance tree to find a property.
262  
263 =cut
264  
265 576 ▶sub find_prop {
Subroutine find_prop: called CC=5 SCAR=16.8
Pod documented
266 576 my ($self, $prop) = @_;
267  
268 576 ▶ if (defined $self->{$prop}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{$prop}) { } 225 351 576
elsif (defined $self->{'Parent'}) { } 167 184 351
269 225 ▶ if (ref($self->{$prop}) and $self->{$prop}->isa('PDF::API2::Basic::PDF::Objind')) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{$prop} and $self->{$prop}->isa('PDF::API2::Basic::PDF::Objind')) { } 225 0 225
Condition33%1/3
ref $self->{$prop} and $self->{$prop}->isa("PDF::API2::Basic::PDF::Objind")
!ll&&!rl&&r
00225
MC/DC0%0/2
ref $self->{$prop} and $self->{$prop}->isa("PDF::API2::Basic::PDF::Objind")
ref $self->{$prop} $self->{$prop}->isa("PDF::API2::Basic::PDF::Objind")
Truth table33%1/3
A and B
A= ref $self->{$prop}B= $self->{$prop}->isa("PDF::API2::Basic::PDF::Objind")
ABresult
0X0
100
111
270 225 return $self->{$prop}->realise();
271 }
272 else {
273 0 return $self->{$prop};
274 }
275 }
276 elsif (defined $self->{'Parent'}) {
277 167 return $self->{'Parent'}->find_prop($prop);
278 }
279  
280 184 return;
281 }
282  
283  
284 =head2 $p->add_font($pdf, $font)
285  
286 Creates or edits the resource dictionary at this level in the hierarchy. If
287 the font is already supported even through the hierarchy, then it is not added.
288  
289 =cut
290  
291 0 ▶sub add_font {
Subroutine add_font: not called CC=12 SCAR=50.5
Pod documented
292 # Maintainer's note: arguments are in a different order than what is shown in the POD
293 0 my ($self, $font, $pdf) = @_;
294 0 my $name = $font->{'Name'}->val();
295 0 my $dict = $self->find_prop('Resources');
296  
297 0 ▶ return $self if $dict and defined $dict->{'Font'} and defined $dict->{'Font'}{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $dict and defined $dict->{"Font"} and defined $dict->{"Font"}{$name} 0 0 0
Condition0%0/6
$dict and defined $dict->{"Font"} and defined $dict->{"Font"}{$name}
!ll&&!rl&&r
000
$dict and defined $dict->{"Font"}
!ll&&!rl&&r
000
MC/DC0%0/3
$dict and defined $dict->{"Font"} and defined $dict->{"Font"}{$name}
$dict defined $dict->{"Font"} defined $dict->{"Font"}{$name}
Truth table0%0/4
A and B and C
A= $dictB= defined $dict->{"Font"}C= defined $dict->{"Font"}{$name}
ABCresult
0XX0
10X0
1100
1111
298  
299 0 ▶ unless (defined $self->{'Resources'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'Resources'}) { } 0 0 0
300 0 ▶ $dict = $dict ? $dict->copy($pdf) : PDFDict();
Branch: 1 branch
BranchTrueFalseTotal
$dict ? : 0 0 0
301 0 $self->{'Resources'} = $dict;
302 }
303 else {
304 0 $dict = $self->{'Resources'};
305 }
306 0 ▶ $dict->{'Font'} //= PDFDict();
Condition0%0/3
$dict->{"Font"} //= PDFDict()
l!l&&r!l&&!r
000
MC/DC0%0/2
$dict->{"Font"} //= PDFDict()
$dict->{"Font"} PDFDict()
Truth table0%0/3
A //= B
A= $dict->{"Font"}B= PDFDict()
ABresult
1X1
011
000
307  
308 0 my $resource = $dict->{'Font'}->val();
309 0 ▶ $resource->{$name} //= $font;
Condition0%0/3
$resource->{$name} //= $font
l!l&&r!l&&!r
000
MC/DC0%0/2
$resource->{$name} //= $font
$resource->{$name} $font
Truth table0%0/3
A //= B
A= $resource->{$name}B= $font
ABresult
1X1
011
000
310 0 ▶ if (ref($dict) ne 'HASH' and $dict->is_obj($pdf)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $dict ne "HASH" and $dict->is_obj($pdf)) 0 0 0
Condition0%0/3
ref $dict ne "HASH" and $dict->is_obj($pdf)
!ll&&!rl&&r
000
MC/DC0%0/2
ref $dict ne "HASH" and $dict->is_obj($pdf)
ref $dict ne "HASH" $dict->is_obj($pdf)
Truth table0%0/3
A and B
A= ref $dict ne "HASH"B= $dict->is_obj($pdf)
ABresult
0X0
100
111
311 0 $pdf->out_obj($dict);
312 }
313 0 ▶ if (ref($resource) ne 'HASH' and $resource->is_obj($pdf)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $resource ne "HASH" and $resource->is_obj($pdf)) 0 0 0
Condition0%0/3
ref $resource ne "HASH" and $resource->is_obj($pdf)
!ll&&!rl&&r
000
MC/DC0%0/2
ref $resource ne "HASH" and $resource->is_obj($pdf)
ref $resource ne "HASH" $resource->is_obj($pdf)
Truth table0%0/3
A and B
A= ref $resource ne "HASH"B= $resource->is_obj($pdf)
ABresult
0X0
100
111
314 0 $pdf->out_obj($resource);
315 }
316  
317 0 return $self;
318 }
319  
320  
321 =head2 $p->bbox($xmin, $ymin, $xmax, $ymax, [$param])
322  
323 Specifies the bounding box for this and all child pages. If the values are
324 identical to those inherited then no change is made. $param specifies the attribute
325 name so that other 'bounding box'es can be set with this method.
326  
327 =cut
328  
329 0 ▶sub bbox {
Subroutine bbox: not called CC=8 SCAR=42.8
Pod documented
330 0 my ($self, @bbox) = @_;
331 0 ▶ my $key = $bbox[4] || 'MediaBox';
Condition0%0/2
$bbox[4] || 'MediaBox'
l!l
00
MC/DC0%0/1
$bbox[4] || 'MediaBox'
$bbox[4]
Truth table0%0/2
A
A= $bbox[4]
Aresult
11
00
332 0 my $inherited = $self->find_prop($key);
333  
334 0 ▶ if ($inherited) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inherited) 0 0 0
335 0 my $is_changed;
336 0 my $i = 0;
337 0 foreach my $element ($inherited->elements()) {
338 0 ▶ $is_changed = 1 unless $element->val() == $bbox[$i++];
Branch: 1 branch
BranchTrueFalseTotal
unless $element->val == $bbox[$i++] 0 0 0
339 }
340 0 ▶ return $self if $i == 4 and not $is_changed;
Branch: 1 branch
BranchTrueFalseTotal
if $i == 4 and not $is_changed 0 0 0
Condition0%0/3
$i == 4 and not $is_changed
!ll&&!rl&&r
000
MC/DC0%0/2
$i == 4 and not $is_changed
$i == 4 not $is_changed
Truth table0%0/3
A and not(B)
A= $i == 4B= not $is_changed
ABresult
0X0
100
111
341 }
342  
343 0 my $array = PDF::API2::Basic::PDF::Array->new();
344 0 foreach my $element (@bbox[0..3]) {
345 0 $array->add_elements(PDFNum($element));
346 }
347 0 $self->{$key} = $array;
348  
349 0 return $self;
350 }
351  
352 =head2 $p->proc_set(@entries)
353  
354 Ensures that the current resource contains all the entries in the proc_sets
355 listed. If necessary it creates a local resource dictionary to achieve this.
356  
357 =cut
358  
359 306 ▶sub proc_set {
Subroutine proc_set: called CC=10 SCAR=23.5
Pod documented
360 306 my ($self, @entries) = @_;
361  
362 306 my $dict = $self->find_prop('Resources');
363 306 ▶ if ($dict and defined $dict->{'ProcSet'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dict and defined $dict->{"ProcSet"}) 142 164 306
Condition66%2/3
$dict and defined $dict->{"ProcSet"}
!ll&&!rl&&r
1640142
MC/DC50%1/2
$dict and defined $dict->{"ProcSet"}
$dict defined $dict->{"ProcSet"}
Truth table66%2/3
A and B
A= $dictB= defined $dict->{"ProcSet"}
ABresult
0X0
100
111
364 142 my @missing = @entries;
365 142 foreach my $element ($dict->{'ProcSet'}->elements()) {
366 710 @missing = grep { $_ ne $element } @missing;
367 }
368 142 ▶ return $self if scalar @missing == 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @missing == 0 0 142 142
369 142 ▶ @entries = @missing if defined $self->{'Resources'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"Resources"} 0 142 142
370 }
371  
372 306 ▶ unless (defined $self->{'Resources'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"Resources"}) 306 0 306
373 306 ▶ $self->{'Resources'} = $dict ? $dict->copy($self->_pdf()) : PDFDict();
Branch: 1 branch
BranchTrueFalseTotal
$dict ? : 142 164 306
374 }
375  
376 306 ▶ $self->{'Resources'}{'ProcSet'} = PDFArray() unless defined $self->{'ProcSet'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"ProcSet"} 306 0 306
377  
378 306 foreach my $e (@entries) {
379 1530 $self->{'Resources'}{'ProcSet'}->add_elements(PDFName($e));
380 }
381  
382 306 return $self;
383 }
384  
385 0 ▶sub empty {
Subroutine empty: not called CC=2 SCAR=17.9
Pod documented
386 0 my $self = shift();
387 0 my $parent = $self->{'Parent'};
388  
389 0 $self->SUPER::empty();
390 0 ▶ if (defined $parent) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parent) 0 0 0
391 0 $self->{'Parent'} = $parent;
392 0 weaken $self->{'Parent'};
393 }
394  
395 0 return $self;
396 }
397  
398 =head2 $p->get_top
399  
400 Returns the top of the pages tree
401  
402 =cut
403  
404 701 ▶sub get_top {
Subroutine get_top: called CC=2 SCAR=6.9
Pod documented
405 701 my $self = shift();
406  
407 701 my $top = $self;
408 701 ▶ $top = $top->{'Parent'} while defined $top->{'Parent'};
Branch: 1 branch
BranchTrueFalseTotal
defined $top->{"Parent"} and do { $top = $top->{"Parent"} } 142 701 843
409  
410 701 return $top->realise();
411 }
412  
413 40 1;
« API2/Resource/CIDFont/CJKFont.pm ↑ Summary API2/Resource/XObject/Image/TIFF.pm »