Builder/Outline.pm

filter: Statementstmt 76.2% 173 / 227 Branchbran 68.7% 77 / 112 Conditioncond 41.1% 14 / 34 MC/DCmcdc 13.6% 3 / 22 Subroutinesub 74.2% 26 / 35 Podpod 96.1% 25 / 26 totaltotal 69.7% 318 / 456 CC 70 SCAR 41.6
CC
70
Cov
71%
_fit
221.4
count
8.0
pdf
6.0
CRAP 64.3
« Builder/Resource/XObject/Image/GD.pm ↑ Summary Builder/Basic/PDF/Literal.pm »
1 package PDF::Builder::Outline;
2  
3 2 ▶use base 'PDF::Builder::Basic::PDF::Dict';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = '3.028'; # VERSION
9 2 our $LAST_UPDATE = '3.028'; # manually update whenever code is changed
10  
11 2 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use PDF::Builder::Basic::PDF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 =head1 NAME
16  
17 PDF::Builder::Outline - Manage PDF outlines (a.k.a. I<bookmarks>)
18  
19 Inherits from L<PDF::Builder::Basic::PDF::Dict>
20  
21 =head1 SYNOPSIS
22  
23 # Get/create the top-level outline tree
24 my $outlines = $pdf->outline();
25  
26 # Add an entry
27 my $item = $outlines->outline();
28 $item->title('First Page');
29 $item->dest($pdf->open_page(1), fit-def);
30  
31 =head1 METHODS
32  
33 =head2 new
34  
35 $outline = PDF::Builder::Outline->new($api, $parent)
36  
37 $outline = PDF::Builder::Outline->new($api)
38  
39 =over
40  
41 Returns a new outline object (called from $outlines->outline()).
42  
43 By default, if C<$parent> is omitted, the new bookmark is
44 placed at the end of any existing list of bookmarks. Otherwise, it becomes
45 the child of the C<$parent> bookmark.
46  
47 =back
48  
49 =cut
50  
51 17 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
52 17 my ($class, $api, $parent) = @_;
53 17 my $self = $class->SUPER::new();
54  
55 17 ▶ $self->{'Parent'} = $parent if defined $parent;
Branch: 1 branch
BranchTrueFalseTotal
if defined $parent 14 3 17
56 17 $self->{' api'} = $api;
57 17 weaken $self->{' api'};
58 17 ▶ weaken $self->{'Parent'} if defined $parent;
Branch: 1 branch
BranchTrueFalseTotal
if defined $parent 14 3 17
59  
60 17 return $self;
61 }
62  
63 =head2 Examine the Outline Tree
64  
65 =head3 has_children
66  
67 $boolean = $outline->has_children()
68  
69 =over
70  
71 Return true if the current outline item has children (child items).
72  
73 =back
74  
75 =cut
76  
77 67 ▶sub has_children {
Subroutine has_children: called CC=3 SCAR=11.0
Pod documented
78 67 my $self = shift();
79  
80 # Opened by PDF::Builder
81 67 ▶ return 1 if exists $self->{'First'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"First"} 13 54 67
82  
83 # Created by PDF::Builder
84 54 ▶ return @{$self->{' children'}} > 0 if exists $self->{' children'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{" children"} 18 36 54
85  
86 36 return;
87 }
88  
89 =head3 count
90  
91 $integer = $outline->count()
92  
93 =over
94  
95 Return the number of descendants that are visible when the current outline item
96 is open (expanded).
97  
98 =back
99  
100 =cut
101  
102 26 ▶sub count {
Subroutine count: called CC=8 SCAR=20.8
Pod documented
103 26 my $self = shift();
104  
105 # Set count to the number of descendant items that will be visible when the
106 # current item is open.
107 26 my $count = 0;
108 26 ▶ if ($self->has_children()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_children) 20 6 26
109 20 ▶ $self->_load_children() unless exists $self->{' children'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{" children"} 2 18 20
110 20 $count += @{$self->{' children'}};
111 20 foreach my $child (@{$self->{' children'}}) {
112 39 ▶ next unless $child->has_children();
Branch: 1 branch
BranchTrueFalseTotal
unless $child->has_children 29 10 39
113 10 ▶ next unless $child->is_open();
Branch: 1 branch
BranchTrueFalseTotal
unless $child->is_open 4 6 10
114 6 $count += $child->count();
115 }
116 }
117  
118 26 ▶ if ($count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count) 20 6 26
119 20 ▶ $self->{'Count'} = PDFNum($self->is_open() ? $count : -$count);
Branch: 1 branch
BranchTrueFalseTotal
$self->is_open ? : 17 3 20
120 }
121  
122 26 return $count;
123 }
124  
125 #sub count { # older version
126 # my $self = shift();
127 #
128 # my $count = scalar @{$self->{' children'} || []};
129 # $count += $_->count() for @{$self->{' children'}};
130 # $self->{'Count'} = PDFNum($self->{' closed'}? -$count: $count) if $count > 0;
131 # return $count;
132 #}
133  
134 2 ▶sub _load_children {
Subroutine _load_children: called CC=3 SCAR=11.0
135 2 my $self = shift();
136 2 my $item = $self->{'First'};
137 2 ▶ return unless $item;
Branch: 1 branch
BranchTrueFalseTotal
unless $item 0 2 2
138 2 $item->realise();
139 2 bless $item, __PACKAGE__;
140  
141 2 push @{$self->{' children'}}, $item;
142 2 ▶ while ($item->next()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item->next) 2 2 4
143 2 $item = $item->next();
144 2 $item->realise();
145 2 bless $item, __PACKAGE__;
146 2 push @{$self->{' children'}}, $item;
147 }
148 2 return $self;
149 }
150  
151 =head3 first
152  
153 $child = $outline->first()
154  
155 =over
156  
157 Return the first child of the current outline level, if one exists.
158  
159 =back
160  
161 =cut
162  
163 19 ▶sub first {
Subroutine first: called CC=3 SCAR=11.0
Pod documented
164 19 my $self = shift();
165 19 ▶ if (defined $self->{' children'} and defined $self->{' children'}->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{" children"} and defined $self->{" children"}[0]) 14 5 19
Condition66%2/3
defined $self->{" children"} and defined $self->{" children"}[0]
!ll&&!rl&&r
5014
MC/DC50%1/2
defined $self->{" children"} and defined $self->{" children"}[0]
defined $self->{" children"} defined $self->{" children"}[0]
Truth table66%2/3
A and B
A= defined $self->{" children"}B= defined $self->{" children"}[0]
ABresult
0X0
100
111
166 14 $self->{'First'} = $self->{' children'}->[0];
167 }
168 #weaken $self->{'First'}; # not in API2
169 19 return $self->{'First'};
170 }
171  
172 =head3 last
173  
174 $child = $outline->last()
175  
176 =over
177  
178 Return the last child of the current outline level, if one exists.
179  
180 =back
181  
182 =cut
183  
184 11 ▶sub last {
Subroutine last: called CC=3 SCAR=11.0
Pod documented
185 11 my $self = shift();
186 11 ▶ if (defined $self->{' children'} and defined $self->{' children'}->[-1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{" children"} and defined $self->{" children"}[-1]) 6 5 11
Condition66%2/3
defined $self->{" children"} and defined $self->{" children"}[-1]
!ll&&!rl&&r
506
MC/DC50%1/2
defined $self->{" children"} and defined $self->{" children"}[-1]
defined $self->{" children"} defined $self->{" children"}[-1]
Truth table66%2/3
A and B
A= defined $self->{" children"}B= defined $self->{" children"}[-1]
ABresult
0X0
100
111
187 6 $self->{'Last'} = $self->{' children'}->[-1];
188 }
189 #weaken $self->{'Last'}; # not in API2
190 11 return $self->{'Last'};
191 }
192  
193 =head3 parent
194  
195 $parent = $outline->parent()
196  
197 =over
198  
199 Return the parent of the current item, if not at the top level of the outline
200 tree.
201  
202 =back
203  
204 =cut
205  
206 11 ▶sub parent {
Subroutine parent: called CC=2 SCAR=7.1
Pod documented
207 11 my $self = shift();
208 11 ▶ $self->{'Parent'} = shift() if defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 0 11 11
209 #weaken $self->{'Parent'}; # not in API2
210 11 return $self->{'Parent'};
211 }
212  
213 =head3 prev
214  
215 $sibling = $outline->prev() # Get
216  
217 $sibling = $outline->prev(outline_obj) # Set
218  
219 =over
220  
221 Return the previous item of the current level of the outline tree
222 (C<undef> if already at the first item).
223  
224 =back
225  
226 =cut
227  
228 25 ▶sub prev {
Subroutine prev: called CC=2 SCAR=6.9
Pod documented
229 25 my $self = shift();
230 25 ▶ $self->{'Prev'} = shift() if defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 10 15 25
231 #weaken $self->{'Prev'}; # not in API2
232 25 return $self->{'Prev'};
233 }
234  
235 =head3 next
236  
237 $sibling = $outline->next() # Get
238  
239 $sibling = $outline->next(outline_obj) # Set
240  
241 =over
242  
243 Return the next item of the current level of the outline tree
244 (C<undef> if already at the last item).
245  
246 =back
247  
248 =cut
249  
250 67 ▶sub next {
Subroutine next: called CC=2 SCAR=6.9
Pod documented
251 67 my $self = shift();
252 67 ▶ $self->{'Next'} = shift() if defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 10 57 67
253 #weaken $self->{'Next'}; # not in API2
254 67 return $self->{'Next'};
255 }
256  
257 =head2 Modify the Outline Tree
258  
259 =head3 outline
260  
261 $child_outline = $parent_outline->outline()
262  
263 =over
264  
265 Returns a new sub-outline (nested outline) added at the end of the
266 C<$parent_outline>'s children. If there are no existing children, create
267 the first one.
268  
269 =back
270  
271 =cut
272  
273 10 ▶sub outline {
Subroutine outline: called CC=5 SCAR=16.1
Pod documented
274 10 my $self = shift();
275  
276 10 my $child = PDF::Builder::Outline->new($self->{' api'}, $self);
277 10 ▶ $self->{' children'} //= [];
Condition100%2/2
$self->{" children"} //= []
l!l
46
MC/DC100%1/1
$self->{" children"} //= []
$self->{" children"}
Truth table100%2/2
A
A= $self->{" children"}
Aresult
11
00
278 # it's not clear whether self->{children} will change by prev() call,
279 # so leave as done in PDF::API2
280 10 ▶ $child->prev($self->{' children'}->[-1]) if @{ $self->{' children'} };
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{" children"};} 4 6 10
281 10 ▶ $self->{' children'}->[-1]->next($child) if @{ $self->{' children'} };
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{" children"};} 4 6 10
282 10 push @{$self->{' children'}}, $child;
283 $self->{' api'}->{'pdf'}->new_obj($child)
284 10 ▶ unless $child->is_obj($self->{' api'}->{'pdf'});
Branch: 1 branch
BranchTrueFalseTotal
unless $child->is_obj($self->{" api"}{"pdf"}) 10 0 10
285  
286 10 return $child;
287 }
288  
289 =head3 insert_after
290  
291 $sibling = $outline->insert_after()
292  
293 =over
294  
295 Add an outline item immediately following the C<$outline> item.
296  
297 =back
298  
299 =cut
300  
301 2 ▶sub insert_after {
Subroutine insert_after: called CC=3 SCAR=11.0
Pod documented
302 2 my $self = shift();
303  
304 2 my $sibling = PDF::Builder::Outline->new($self->{' api'}, $self->parent());
305 2 $sibling->next($self->next());
306 2 ▶ $self->next->prev($sibling) if $self->next();
Branch: 1 branch
BranchTrueFalseTotal
if $self->next 1 1 2
307 2 $self->next($sibling);
308 2 $sibling->prev($self);
309 2 ▶ unless ($sibling->is_obj($self->{' api'}->{'pdf'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sibling->is_obj($self->{" api"}{"pdf"})) 2 0 2
310 2 $self->{' api'}->{'pdf'}->new_obj($sibling);
311 }
312 2 $self->parent->_reset_children();
313 2 return $sibling;
314 }
315  
316 =head3 insert_before
317  
318 $sibling = $outline->insert_before()
319  
320 =over
321  
322 Add an outline item immediately preceding the C<$outline> item.
323  
324 =back
325  
326 =cut
327  
328 2 ▶sub insert_before {
Subroutine insert_before: called CC=3 SCAR=11.0
Pod documented
329 2 my $self = shift();
330  
331 2 my $sibling = PDF::Builder::Outline->new($self->{' api'}, $self->parent());
332 2 $sibling->prev($self->prev());
333 2 ▶ $self->prev->next($sibling) if $self->prev();
Branch: 1 branch
BranchTrueFalseTotal
if $self->prev 1 1 2
334 2 $self->prev($sibling);
335 2 $sibling->next($self);
336 2 ▶ unless ($sibling->is_obj($self->{' api'}->{'pdf'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sibling->is_obj($self->{" api"}{"pdf"})) 2 0 2
337 2 $self->{' api'}->{'pdf'}->new_obj($sibling);
338 }
339 2 $self->parent->_reset_children();
340 2 return $sibling;
341 }
342  
343 4 ▶sub _reset_children {
Subroutine _reset_children: called CC=3 SCAR=11.0
344 4 my $self = shift();
345 4 my $item = $self->first();
346 4 $self->{' children'} = [];
347 4 ▶ return unless $item;
Branch: 1 branch
BranchTrueFalseTotal
unless $item 0 4 4
348  
349 4 push @{$self->{' children'}}, $item;
350 4 ▶ while ($item->next()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item->next) 16 4 20
351 16 $item = $item->next();
352 16 push @{$self->{' children'}}, $item;
353 }
354 4 return $self;
355 }
356  
357 =head3 delete
358  
359 $outline->delete()
360  
361 =over
362  
363 Remove the current outline item from the outline tree. If the item has any
364 children, they will effectively be deleted as well, since they will no longer
365 be linked.
366  
367 =back
368  
369 =cut
370  
371 1 ▶sub delete {
Subroutine delete: called CC=4 SCAR=14.1
Pod documented
372 1 my $self = shift();
373  
374 1 my $prev = $self->prev();
375 1 my $next = $self->next();
376 1 ▶ $prev->next($next) if defined $prev;
Branch: 1 branch
BranchTrueFalseTotal
if defined $prev 0 1 1
377 1 ▶ $next->prev($prev) if defined $next;
Branch: 1 branch
BranchTrueFalseTotal
if defined $next 0 1 1
378  
379 1 my $siblings = $self->parent->{' children'};
380 1 @$siblings = grep { $_ ne $self } @$siblings;
381 1 ▶ delete $self->parent->{' children'} unless $self->parent->has_children();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->parent->has_children 1 0 1
382  
383 1 return;
384 }
385  
386 =head3 is_open
387  
388 $boolean = $outline->is_open() # Get
389  
390 $outline = $outline->is_open($boolean) # Set
391  
392 =over
393  
394 Get/set whether the outline is expanded (open) or collapsed (closed).
395 C<$boolean> is 0/false to close (collapse) the outline (hide its children), or
396 1/true to open (expand) it (make its children visible).
397  
398 =back
399  
400 =cut
401  
402 33 ▶sub is_open {
Subroutine is_open: called CC=5 SCAR=16.1
Pod documented
403 33 my $self = shift();
404  
405 # Get
406 33 ▶ unless (@_) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 32 1 33
407 # Created by PDF::Builder
408 32 ▶ return $self->{' closed'} ? 0 : 1 if exists $self->{' closed'};
Branch: 2 branches
BranchTrueFalseTotal
if exists $self->{" closed"} 6 26 32
$self->{' closed'} ? : 6 0 6
409  
410 # Opened by PDF::Builder
411 26 ▶ return $self->{'Count'}->val() > 0 if exists $self->{'Count'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"Count"} 19 7 26
412  
413 # Default
414 7 return 1;
415 }
416  
417 # Set
418 1 my $is_open = shift();
419 1 $self->{' closed'} = (not $is_open);
420  
421 1 return $self;
422 }
423  
424 =head3 open
425  
426 $outline->open()
427  
428 =over
429  
430 Set the status of the outline to open (i.e., expanded).
431  
432 This is an B<alternate> method to using is_open(true).
433  
434 =back
435  
436 =cut
437  
438 # TBD consider implementing as is_open(1)
439 # deprecated in API2
440 0 ▶sub open {
Subroutine open: not called CC=1 SCAR=6.9
Pod documented
441 0 my $self = shift();
442 0 delete $self->{' closed'};
443 0 return $self;
444 }
445  
446 =head3 closed
447  
448 $outline->closed()
449  
450 =over
451  
452 Set the status of the outline to closed (i.e., collapsed).
453  
454 This is an B<alternate> method to using is_open(false).
455  
456 =back
457  
458 =cut
459  
460 # TBD consider implementing as is_open(0)
461 # deprecated in API2
462 0 ▶sub closed {
Subroutine closed: not called CC=1 SCAR=6.9
Pod documented
463 0 my $self = shift();
464 0 $self->{' closed'} = 1;
465 0 return $self;
466 }
467  
468 =head2 Set Outline Attributes
469  
470 =head3 title
471  
472 $title = $outline->title() # Get
473  
474 $outline = $outline->title($text) # Set
475  
476 =over
477  
478 Get/set the title of the outline item.
479  
480 =back
481  
482 =cut
483  
484 4 ▶sub title {
Subroutine title: called CC=3 SCAR=11.0
Pod documented
485 4 my $self = shift();
486  
487 # Get
488 4 ▶ unless (@_) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 1 3 4
489 1 ▶ return unless $self->{'Title'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"Title"} 0 1 1
490 1 return $self->{'Title'}->val();
491 }
492  
493 # Set
494 3 my $text = shift();
495 3 $self->{'Title'} = PDFString($text, 'o');
496 3 return $self;
497 }
498  
499 =head3 dest
500  
501 $outline->dest($page_object, %position)
502  
503 $outline->dest($page_object)
504  
505 =over
506  
507 Sets the destination page and optional position of the outline.
508  
509 %position can be any of those listed in L<PDF::Builder::Docs/Page Fit Options>.
510  
511 "xyz" is the B<default> fit setting, with position (left and top) and zoom
512 the same as the calling page's.
513  
514 $outline->dest($name, %position)
515  
516 $outline->dest($name)
517  
518 Connect the Outline to a "Named Destination" defined elsewhere,
519 and optional positioning as described above.
520  
521 Note that PDF::Builder's C<dest()> is B<not> the same (i.e., an alias)
522 as PDF::API2's C<destination()>. The argument lists are quite different.
523  
524 =back
525  
526 =cut
527  
528 2 ▶sub dest {
Subroutine dest: called CC=2 SCAR=7.2
Pod documented
529 2 my ($self, $page, %position) = @_;
530 2 delete $self->{'A'};
531  
532 2 ▶ if (ref($page)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $page) { } 2 0 2
533 2 $self = $self->_fit($page, %position);
534 } else {
535 0 $self->{'Dest'} = PDFString($page, 'n');
536 }
537  
538 2 return $self;
539 }
540  
541 # process destination, including position setting, with default of xyz undef*3
542
543 2 ▶sub _fit {
Subroutine _fit: called CC=29 SCAR=54.0
544 2 my ($self, $destination, %position) = @_;
545 # copy dashed names over to preferred non-dashed names
546 0 ▶ if (defined $position{'-fit'} && !defined $position{'fit'}) { $position{'fit'} = delete($position{'-fit'}); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $position{"-fit"} and not defined $position{"fit"}) 0 2 2
Condition33%1/3
defined $position{"-fit"} and not defined $position{"fit"}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $position{"-fit"} and not defined $position{"fit"}
defined $position{"-fit"} not defined $position{"fit"}
Truth table33%1/3
A and not(B)
A= defined $position{"-fit"}B= not defined $position{"fit"}
ABresult
0X0
100
111
547 0 ▶ if (defined $position{'-fith'} && !defined $position{'fith'}) { $position{'fith'} = delete($position{'-fith'}); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $position{"-fith"} and not defined $position{"fith"}) 0 2 2
Condition33%1/3
defined $position{"-fith"} and not defined $position{"fith"}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $position{"-fith"} and not defined $position{"fith"}
defined $position{"-fith"} not defined $position{"fith"}
Truth table33%1/3
A and not(B)
A= defined $position{"-fith"}B= not defined $position{"fith"}
ABresult
0X0
100
111
548 0 ▶ if (defined $position{'-fitb'} && !defined $position{'fitb'}) { $position{'fitb'} = delete($position{'-fitb'}); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $position{"-fitb"} and not defined $position{"fitb"}) 0 2 2
Condition33%1/3
defined $position{"-fitb"} and not defined $position{"fitb"}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $position{"-fitb"} and not defined $position{"fitb"}
defined $position{"-fitb"} not defined $position{"fitb"}
Truth table33%1/3
A and not(B)
A= defined $position{"-fitb"}B= not defined $position{"fitb"}
ABresult
0X0
100
111
549 0 ▶ if (defined $position{'-fitbh'} && !defined $position{'fitbh'}) { $position{'fitbh'} = delete($position{'-fitbh'}); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $position{"-fitbh"} and not defined $position{"fitbh"}) 0 2 2
Condition33%1/3
defined $position{"-fitbh"} and not defined $position{"fitbh"}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $position{"-fitbh"} and not defined $position{"fitbh"}
defined $position{"-fitbh"} not defined $position{"fitbh"}
Truth table33%1/3
A and not(B)
A= defined $position{"-fitbh"}B= not defined $position{"fitbh"}
ABresult
0X0
100
111
550 0 ▶ if (defined $position{'-fitv'} && !defined $position{'fitv'}) { $position{'fitv'} = delete($position{'-fitv'}); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $position{"-fitv"} and not defined $position{"fitv"}) 0 2 2
Condition33%1/3
defined $position{"-fitv"} and not defined $position{"fitv"}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $position{"-fitv"} and not defined $position{"fitv"}
defined $position{"-fitv"} not defined $position{"fitv"}
Truth table33%1/3
A and not(B)
A= defined $position{"-fitv"}B= not defined $position{"fitv"}
ABresult
0X0
100
111
551 0 ▶ if (defined $position{'-fitbv'} && !defined $position{'fitbv'}) { $position{'fitbv'} = delete($position{'-fitbv'}); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $position{"-fitbv"} and not defined $position{"fitbv"}) 0 2 2
Condition33%1/3
defined $position{"-fitbv"} and not defined $position{"fitbv"}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $position{"-fitbv"} and not defined $position{"fitbv"}
defined $position{"-fitbv"} not defined $position{"fitbv"}
Truth table33%1/3
A and not(B)
A= defined $position{"-fitbv"}B= not defined $position{"fitbv"}
ABresult
0X0
100
111
552 0 ▶ if (defined $position{'-fitr'} && !defined $position{'fitr'}) { $position{'fitr'} = delete($position{'-fitr'}); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $position{"-fitr"} and not defined $position{"fitr"}) 0 2 2
Condition33%1/3
defined $position{"-fitr"} and not defined $position{"fitr"}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $position{"-fitr"} and not defined $position{"fitr"}
defined $position{"-fitr"} not defined $position{"fitr"}
Truth table33%1/3
A and not(B)
A= defined $position{"-fitr"}B= not defined $position{"fitr"}
ABresult
0X0
100
111
553 0 ▶ if (defined $position{'-xyz'} && !defined $position{'xyz'}) { $position{'xyz'} = delete($position{'-xyz'}); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $position{"-xyz"} and not defined $position{"xyz"}) 0 2 2
Condition33%1/3
defined $position{"-xyz"} and not defined $position{"xyz"}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $position{"-xyz"} and not defined $position{"xyz"}
defined $position{"-xyz"} not defined $position{"xyz"}
Truth table33%1/3
A and not(B)
A= defined $position{"-xyz"}B= not defined $position{"xyz"}
ABresult
0X0
100
111
554  
555 2 ▶ if (defined $position{'fit'}) {
Branch: 8 branches
BranchTrueFalseTotal
if (defined $position{'fit'}) { } 0 2 2
elsif (defined $position{'fith'}) { } 0 2 2
elsif (defined $position{'fitb'}) { } 0 2 2
elsif (defined $position{'fitbh'}) { } 0 2 2
elsif (defined $position{'fitv'}) { } 0 2 2
elsif (defined $position{'fitbv'}) { } 0 2 2
elsif (defined $position{'fitr'}) { } 0 2 2
elsif (defined $position{'xyz'}) { } 0 2 2
556 0 $self->{'Dest'} = PDFArray($destination, PDFName('Fit'));
557 } elsif (defined $position{'fith'}) {
558 0 $self->{'Dest'} = PDFArray($destination, PDFName('FitH'), PDFNum($position{'fith'}));
559 } elsif (defined $position{'fitb'}) {
560 0 $self->{'Dest'} = PDFArray($destination, PDFName('FitB'));
561 } elsif (defined $position{'fitbh'}) {
562 0 $self->{'Dest'} = PDFArray($destination, PDFName('FitBH'), PDFNum($position{'fitbh'}));
563 } elsif (defined $position{'fitv'}) {
564 0 $self->{'Dest'} = PDFArray($destination, PDFName('FitV'), PDFNum($position{'fitv'}));
565 } elsif (defined $position{'fitbv'}) {
566 0 $self->{'Dest'} = PDFArray($destination, PDFName('FitBV'), PDFNum($position{'fitbv'}));
567 } elsif (defined $position{'fitr'}) {
568 0 ▶ croak "Insufficient parameters to fitr => []) " unless scalar @{$position{'fitr'}} == 4;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$position{"fitr"};} == 4 0 0 0
569 0 $self->{'Dest'} = PDFArray($destination, PDFName('FitR'), map {PDFNum($_)} @{$position{'fitr'}});
570 } elsif (defined $position{'xyz'}) {
571 0 ▶ croak "Insufficient parameters to xyz => []) " unless scalar @{$position{'xyz'}} == 3;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$position{"xyz"};} == 3 0 0 0
572 0 ▶ $self->{'Dest'} = PDFArray($destination, PDFName('XYZ'), map {defined $_? PDFNum($_): PDFNull()} @{$position{'xyz'}});
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
573 } else {
574 # no "fit" option found. use default.
575 2 $position{'xyz'} = [undef,undef,undef];
576 2 ▶ $self->{'Dest'} = PDFArray($destination, PDFName('XYZ'), map {defined $_? PDFNum($_): PDFNull()} @{$position{'xyz'}});
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 6 6
577 }
578  
579 2 return $self;
580 }
581  
582 =head2 Destination targets
583  
584 =head3 uri, url
585  
586 $outline->uri($url)
587  
588 =over
589  
590 Defines the outline as launch-url with url C<$url>, typically a web page.
591  
592 B<Alternate name:> C<url>
593  
594 Either C<uri> or C<url> may be used; C<uri> is for compatibility with PDF::API2.
595  
596 =back
597  
598 =cut
599  
600 0 ▶sub url { return uri(@_); } # alternate name
Subroutine url: not called CC=1 SCAR=6.9
Pod documented
601  
602 0 ▶sub uri {
Subroutine uri: not called CC=1 SCAR=6.9
Pod documented
603 0 my ($self, $url, %opts) = @_;
604 # no current opts
605  
606 0 delete $self->{'Dest'};
607 0 $self->{'A'} = PDFDict();
608 0 $self->{'A'}->{'S'} = PDFName('URI');
609 0 $self->{'A'}->{'URI'} = PDFString($url, 'u');
610  
611 0 return $self;
612 }
613  
614 =head3 launch, file
615  
616 $outline->launch($file)
617  
618 =over
619  
620 Defines the outline as launch-file with filepath C<$file>. This is typically
621 a local application or file.
622  
623 B<Alternate name:> C<file>
624  
625 Either C<launch> or C<file> may be used; C<launch> is for compatibility with PDF::API2.
626  
627 =back
628  
629 =cut
630  
631 0 ▶sub file { return launch(@_); } # alternate name
Subroutine file: not called CC=1 SCAR=6.9
Pod documented
632  
633 0 ▶sub launch {
Subroutine launch: not called CC=1 SCAR=6.9
Pod documented
634 0 my ($self, $file, %opts) = @_;
635 # no current opts
636  
637 0 delete $self->{'Dest'};
638 0 $self->{'A'} = PDFDict();
639 0 $self->{'A'}->{'S'} = PDFName('Launch');
640 0 $self->{'A'}->{'F'} = PDFString($file, 'f');
641  
642 0 return $self;
643 }
644  
645 =head3 pdf, pdf_file, pdfile
646  
647 $outline->pdf($pdffile, $page_number, %position, %args)
648  
649 $outline->pdf($pdffile, $page_number)
650  
651 =over
652  
653 Defines the destination of the outline as a PDF-file with filepath
654 C<$pdffile>, on page C<$pagenum> (default 0), and position C<%position>
655 (same as dest()).
656  
657 B<Alternate names:> C<pdf_file> and C<pdfile>
658  
659 Either C<pdf> or C<pdf_file> (or the older C<pdfile>) may be used; C<pdf> is
660 for compatibility with PDF::API2.
661  
662 =back
663  
664 =cut
665  
666 0 ▶sub pdf_file { return pdf(@_); } # alternative method
Subroutine pdf_file: not called CC=1 SCAR=6.9
Pod documented
667 0 ▶sub pdfile { return pdf(@_); } # alternative method (older)
Subroutine pdfile: not called CC=1 SCAR=6.9
Pod documented
668  
669 0 ▶sub pdf {
Subroutine pdf: not called CC=2 SCAR=17.9
Pod documented
670 0 my ($self, $file, $page_number, %position) = @_;
671  
672 0 delete $self->{'Dest'};
673 0 $self->{'A'} = PDFDict();
674 0 $self->{'A'}->{'S'} = PDFName('GoToR');
675 0 $self->{'A'}->{'F'} = PDFString($file, 'f');
676 0 ▶ $self->{'A'}->{'D'} = $self->_fit(PDFNum($page_number // 0), %position);
Condition0%0/2
$page_number // 0
l!l
00
MC/DC0%0/1
$page_number // 0
$page_number
Truth table0%0/2
A
A= $page_number
Aresult
11
00
677
678 0 return $self;
679 }
680  
681 # internal routine
682 9 ▶sub fix_outline {
Subroutine fix_outline: called CC=1 SCAR=0.0
Pod undocumented
683 9 my ($self) = @_;
684  
685 9 $self->first();
686 9 $self->last();
687 9 $self->count();
688 9 return;
689 }
690  
691 #sub out_obj {
692 # my ($self, @param) = @_;
693 #
694 # $self->fix_outline();
695 # return $self->SUPER::out_obj(@param);
696 #}
697  
698 9 ▶sub outobjdeep {
Subroutine outobjdeep: called CC=1 SCAR=0.0
Pod documented
699 # my ($self, @param) = @_;
700 #
701 # $self->fix_outline();
702 # foreach my $k (qw/ api apipdf apipage /) {
703 # $self->{" $k"} = undef;
704 # delete($self->{" $k"});
705 # }
706 # my @ret = $self->SUPER::outobjdeep(@param);
707 # foreach my $k (qw/ First Parent Next Last Prev /) {
708 # $self->{$k} = undef;
709 # delete($self->{$k});
710 # }
711 # return @ret;
712 9 my $self = shift();
713 9 $self->fix_outline();
714 9 return $self->SUPER::outobjdeep(@_);
715 }
716  
717 2 1;
« Builder/Resource/XObject/Image/GD.pm ↑ Summary Builder/Basic/PDF/Literal.pm »