API2/Basic/PDF/Pages.pm

filter: Statementstmt 63.5% 117 / 184 Branchbran 47.7% 43 / 90 Conditioncond 17.0% 7 / 41 MC/DCmcdc 8.0% 2 / 25 Subroutinesub 70.8% 17 / 24 Podpod 62.5% 10 / 16 totaltotal 51.5% 196 / 380 SCAR 62.5
CC
66
Cov
53%
add_font
156.0
bbox
72.0
add_page_recurse
18.1
CRAP 517.8
« API2/Resource/BaseFont.pm ↑ Summary API2/Resource/XObject/Image/PNG.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 39 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 39 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 39 ▶use base 'PDF::API2::Basic::PDF::Dict';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 39 our $VERSION = '2.044'; # VERSION
17  
18 39 ▶use PDF::API2::Basic::PDF::Array;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 39 ▶use PDF::API2::Basic::PDF::Dict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 39 ▶use PDF::API2::Basic::PDF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 39 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 39 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 sub new {
49 306 ▶ my ($class, $pdf, $parent) = @_;
Subroutine new: called CC=9 SCAR=23.7
Pod documented
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 sub _pdf {
81 426 ▶ my $self = shift();
Subroutine _pdf: called CC=1 SCAR=0.0
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 sub find_page {
93 142 ▶ my ($self, $page_number) = @_;
Subroutine find_page: called CC=1 SCAR=0.0
Pod documented
94 142 my $top = $self->get_top();
95  
96 142 $top->find_page_recurse(\$page_number);
97 }
98  
99  
100 sub find_page_recurse {
101 142 ▶ my ($self, $page_number_ref) = @_;
Subroutine find_page_recurse: called CC=6 SCAR=22.9
Pod undocumented
102  
103 142 ▶ if ($self->{'Count'}->realise->val() <= $$page_number_ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"Count"}->realise->val <= $$page_number_ref) 0 142 142
104 0 $$page_number_ref -= $self->{'Count'}->val();
105 0 return;
106 }
107  
108 142 my $result;
109 142 foreach my $kid ($self->{'Kids'}->realise->elements()) {
110 12 ▶ if ($kid->{'Type'}->realise->val() eq 'Page') {
Branch: 2 branches
BranchTrueFalseTotal
if ($kid->{'Type'}->realise->val eq 'Page') { } 12 0 12
elsif ($result = $kid->realise->find_page_recurse($page_number_ref)) { } 0 0 0
111 12 ▶ return $kid if $$page_number_ref == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $$page_number_ref == 0 12 0 12
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 sub add_page {
132 142 ▶ my ($self, $page, $page_number) = @_;
Subroutine add_page: called CC=11 SCAR=24.5
Pod documented
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->find_page($top->{'Count'}->val() - 1);
140 }
141 else {
142 2 ▶ $page_number = $top->{'Count'}->val() + $page_number + 1 if $page_number < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $page_number < 0 0 2 2
143 2 $previous_page = $top->find_page($page_number);
144 }
145  
146 142 my $parent;
147 142 ▶ if (defined $previous_page->{'Parent'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $previous_page->{'Parent'}) { } 12 130 142
148 12 $parent = $previous_page->{'Parent'}->realise();
149 }
150 else {
151 130 $parent = $self;
152 }
153  
154 142 my $parent_kid_count = scalar $parent->{'Kids'}->realise->elements();
155  
156 142 my $page_index;
157 142 ▶ if ($page_number == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($page_number == -1) { } 140 2 142
158 140 $page_index = -1;
159 }
160 else {
161 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
162 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
163 }
164 2 ▶ $page_index = -1 if $page_index == $parent_kid_count;
Branch: 1 branch
BranchTrueFalseTotal
if $page_index == $parent_kid_count 0 2 2
165 }
166  
167 142 $parent->add_page_recurse($page->realise(), $page_index);
168 142 ▶ for ($parent = $page->{'Parent'}; defined $parent->{'Parent'}; $parent = $parent->{'Parent'}->realise()) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parent->{"Parent"}) 0 142 142
169 0 $parent->set_modified();
170 0 $parent->{'Count'}->realise->{'val'}++;
171 }
172 142 $parent->set_modified();
173 142 $parent->{'Count'}->realise->{'val'}++;
174  
175 142 return $page;
176 }
177  
178 sub add_page_recurse {
179 142 ▶ my ($self, $page, $page_index) = @_;
Subroutine add_page_recurse: called CC=8 SCAR=29.0
Pod undocumented
180  
181 142 my $parent = $self;
182 142 my $max_kids_per_parent = 8; # Why?
183 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
184 0 my $grandparent = $parent->{'Parent'}->realise();
185 0 $parent = $parent->new($parent->_pdf(), $grandparent);
186  
187 0 my $grandparent_kid_count = scalar $grandparent->{'Kids'}->realise->elements();
188 0 my $new_parent_index;
189 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
190 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
191 }
192 0 $new_parent_index++;
193 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
194 0 $grandparent->add_page_recurse($parent, $new_parent_index);
195 }
196 else {
197 142 $parent->set_modified();
198 }
199  
200 142 ▶ if ($page_index < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($page_index < 0) { } 140 2 142
201 140 push @{$parent->{'Kids'}->realise->{' val'}}, $page;
202 }
203 else {
204 2 splice @{$parent->{'Kids'}{' val'}}, $page_index, 0, $page;
205 }
206 142 $page->{'Parent'} = $parent;
207 142 weaken $page->{'Parent'};
208 }
209  
210 sub set_modified {
211 284 ▶ my $self = shift();
Subroutine set_modified: called CC=1 SCAR=0.0
Pod undocumented
212 284 $self->_pdf->out_obj($self);
213 }
214  
215 # Previously documented but not implemented
216 0 ▶sub rebuild_tree { return; }
Subroutine rebuild_tree: not called CC=1 SCAR=6.9
Pod undocumented
217  
218 =head2 @objects = $p->get_pages()
219  
220 Returns a list of page objects in the document in page order
221  
222 =cut
223  
224 sub get_pages {
225 0 ▶ my $self = shift();
Subroutine get_pages: not called CC=1 SCAR=6.9
Pod documented
226 0 return $self->get_top->get_pages_recurse();
227 }
228  
229 # Renamed for clarity
230 0 ▶sub get_kids { return get_pages_recurse(@_) }
Subroutine get_kids: not called CC=1 SCAR=6.9
Pod undocumented
231  
232 sub get_pages_recurse {
233 0 ▶ my $self = shift();
Subroutine get_pages_recurse: not called CC=3 SCAR=24.8
Pod undocumented
234 0 my @pages;
235  
236 0 foreach my $kid ($self->{'Kids'}->elements()) {
237 0 $kid->realise();
238 0 ▶ if ($kid->{'Type'}->val() eq 'Pages') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kid->{'Type'}->val eq 'Pages') { } 0 0 0
239 0 push @pages, $kid->get_pages_recurse();
240 }
241 else {
242 0 push @pages, $kid;
243 }
244 }
245  
246 0 return @pages;
247 }
248  
249 =head2 $p->find_prop($key)
250  
251 Searches up through the inheritance tree to find a property.
252  
253 =cut
254  
255 sub find_prop {
256 576 ▶ my ($self, $prop) = @_;
Subroutine find_prop: called CC=5 SCAR=16.8
Pod documented
257  
258 576 ▶ if (defined $self->{$prop}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{$prop}) { } 225 351 576
elsif (defined $self->{'Parent'}) { } 167 184 351
259 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
260 225 return $self->{$prop}->realise();
261 }
262 else {
263 0 return $self->{$prop};
264 }
265 }
266 elsif (defined $self->{'Parent'}) {
267 167 return $self->{'Parent'}->find_prop($prop);
268 }
269  
270 184 return;
271 }
272  
273  
274 =head2 $p->add_font($pdf, $font)
275  
276 Creates or edits the resource dictionary at this level in the hierarchy. If
277 the font is already supported even through the hierarchy, then it is not added.
278  
279 =cut
280  
281 sub add_font {
282 # Maintainer's note: arguments are in a different order than what is shown in the POD
283 0 ▶ my ($self, $font, $pdf) = @_;
Subroutine add_font: not called CC=12 SCAR=50.5
Pod documented
284 0 my $name = $font->{'Name'}->val();
285 0 my $dict = $self->find_prop('Resources');
286  
287 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
288  
289 0 ▶ unless (defined $self->{'Resources'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'Resources'}) { } 0 0 0
290 0 ▶ $dict = $dict ? $dict->copy($pdf) : PDFDict();
Branch: 1 branch
BranchTrueFalseTotal
$dict ? : 0 0 0
291 0 $self->{'Resources'} = $dict;
292 }
293 else {
294 0 $dict = $self->{'Resources'};
295 }
296 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
297  
298 0 my $resource = $dict->{'Font'}->val();
299 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
300 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
301 0 $pdf->out_obj($dict);
302 }
303 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
304 0 $pdf->out_obj($resource);
305 }
306  
307 0 return $self;
308 }
309  
310  
311 =head2 $p->bbox($xmin, $ymin, $xmax, $ymax, [$param])
312  
313 Specifies the bounding box for this and all child pages. If the values are
314 identical to those inherited then no change is made. $param specifies the attribute
315 name so that other 'bounding box'es can be set with this method.
316  
317 =cut
318  
319 sub bbox {
320 0 ▶ my ($self, @bbox) = @_;
Subroutine bbox: not called CC=8 SCAR=42.8
Pod documented
321 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
322 0 my $inherited = $self->find_prop($key);
323  
324 0 ▶ if ($inherited) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inherited) 0 0 0
325 0 my $is_changed;
326 0 my $i = 0;
327 0 foreach my $element ($inherited->elements()) {
328 0 ▶ $is_changed = 1 unless $element->val() == $bbox[$i++];
Branch: 1 branch
BranchTrueFalseTotal
unless $element->val == $bbox[$i++] 0 0 0
329 }
330 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
331 }
332  
333 0 my $array = PDF::API2::Basic::PDF::Array->new();
334 0 foreach my $element (@bbox[0..3]) {
335 0 $array->add_elements(PDFNum($element));
336 }
337 0 $self->{$key} = $array;
338  
339 0 return $self;
340 }
341  
342 =head2 $p->proc_set(@entries)
343  
344 Ensures that the current resource contains all the entries in the proc_sets
345 listed. If necessary it creates a local resource dictionary to achieve this.
346  
347 =cut
348  
349 sub proc_set {
350 306 ▶ my ($self, @entries) = @_;
Subroutine proc_set: called CC=10 SCAR=23.5
Pod documented
351  
352 306 my $dict = $self->find_prop('Resources');
353 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
354 142 my @missing = @entries;
355 142 foreach my $element ($dict->{'ProcSet'}->elements()) {
356 710 @missing = grep { $_ ne $element } @missing;
357 }
358 142 ▶ return $self if scalar @missing == 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @missing == 0 0 142 142
359 142 ▶ @entries = @missing if defined $self->{'Resources'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"Resources"} 0 142 142
360 }
361  
362 306 ▶ unless (defined $self->{'Resources'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"Resources"}) 306 0 306
363 306 ▶ $self->{'Resources'} = $dict ? $dict->copy($self->_pdf()) : PDFDict();
Branch: 1 branch
BranchTrueFalseTotal
$dict ? : 142 164 306
364 }
365  
366 306 ▶ $self->{'Resources'}{'ProcSet'} = PDFArray() unless defined $self->{'ProcSet'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"ProcSet"} 306 0 306
367  
368 306 foreach my $e (@entries) {
369 1530 $self->{'Resources'}{'ProcSet'}->add_elements(PDFName($e));
370 }
371  
372 306 return $self;
373 }
374  
375 sub empty {
376 0 ▶ my $self = shift();
Subroutine empty: not called CC=2 SCAR=17.9
Pod documented
377 0 my $parent = $self->{'Parent'};
378  
379 0 $self->SUPER::empty();
380 0 ▶ if (defined $parent) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parent) 0 0 0
381 0 $self->{'Parent'} = $parent;
382 0 weaken $self->{'Parent'};
383 }
384  
385 0 return $self;
386 }
387  
388 =head2 $p->get_top
389  
390 Returns the top of the pages tree
391  
392 =cut
393  
394 sub get_top {
395 710 ▶ my $self = shift();
Subroutine get_top: called CC=2 SCAR=6.9
Pod documented
396  
397 710 my $top = $self;
398 710 ▶ $top = $top->{'Parent'} while defined $top->{'Parent'};
Branch: 1 branch
BranchTrueFalseTotal
defined $top->{"Parent"} and do { $top = $top->{"Parent"} } 142 710 852
399  
400 710 return $top->realise();
401 }
402  
403 39 1;
« API2/Resource/BaseFont.pm ↑ Summary API2/Resource/XObject/Image/PNG.pm »