API3/Compat/API2/Outline.pm

filter: Statementstmt 14.4% 21 / 145 Branchbran 0.0% 0 / 70 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 28.0% 7 / 25 Podpod 61.1% 11 / 18 totaltotal 14.3% 39 / 271 CC 41 SCAR 42.9
CC
41
Cov
9%
dest
210.0
pdfile
132.0
count
20.0
CRAP 73.1
« API3/Compat/API2/Resource/XObject/Form/BarCode/code128.pm ↑ Summary API3/Compat/API2/Basic/PDF/Pages.pm »
1 #=======================================================================
2 # ____ ____ _____ _ ____ ___ ____
3 # | _ \| _ \| ___| _ _ / \ | _ \_ _| |___ \
4 # | |_) | | | | |_ (_) (_) / _ \ | |_) | | __) |
5 # | __/| |_| | _| _ _ / ___ \| __/| | / __/
6 # |_| |____/|_| (_) (_) /_/ \_\_| |___| |_____|
7 #
8 # A Perl Module Chain to faciliate the Creation and Modification
9 # of High-Quality "Portable Document Format (PDF)" Files.
10 #
11 # Copyright 1999-2005 Alfred Reibenschuh <areibens@cpan.org>.
12 #
13 #=======================================================================
14 #
15 # This library is free software; you can redistribute it and/or
16 # modify it under the terms of the GNU Lesser General Public
17 # License as published by the Free Software Foundation; either
18 # version 2 of the License, or (at your option) any later version.
19 #
20 # This library is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 # Lesser General Public License for more details.
24 #
25 # You should have received a copy of the GNU Lesser General Public
26 # License along with this library; if not, write to the
27 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 # Boston, MA 02111-1307, USA.
29 #
30 # $Id: Outline.pm,v 2.0 2005/11/16 02:16:00 areibens Exp $
31 #
32 #=======================================================================
33
34 package PDF::API3::Compat::API2::Outline;
35
36 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 ▶ use vars qw( @ISA $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶ use PDF::API3::Compat::API2::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 1 ▶ use PDF::API3::Compat::API2::Basic::PDF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 ▶ use PDF::API3::Compat::API2::Basic::PDF::Dict;
Subroutine BEGIN: called CC=1 SCAR=0.0
42
43 1 @ISA = qw(PDF::API3::Compat::API2::Basic::PDF::Dict);
44
45 1 ( $VERSION ) = sprintf '%i.%03i', split(/\./,('$Revision: 2.0 $' =~ /Revision: (\S+)\s/)[0]); # $Date: 2005/11/16 02:16:00 $
46
47 }
48
49 1 ▶no warnings qw[ deprecated recursion uninitialized ];
Subroutine BEGIN: called CC=1 SCAR=0.0
50
51 =head1 $otl = PDF::API3::Compat::API2::Outline->new $api,$parent,$prev
52
53 Returns a new outline object (called from $otls->outline).
54
55 =cut
56
57 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
58 0 my ($class,$api,$parent,$prev)=@_;
59 0 my $self = $class->SUPER::new;
60 0 $self->{' apipdf'}=$api->{pdf};
61 0 $self->{' api'}=$api;
62 0 ▶ $self->{Parent}=$parent if(defined $parent);
Branch: 1 branch
BranchTrueFalseTotal
if defined $parent 0 0 0
63 0 ▶ $self->{Prev}=$prev if(defined $prev);
Branch: 1 branch
BranchTrueFalseTotal
if defined $prev 0 0 0
64 0 return($self);
65 }
66
67 0 ▶sub parent {
Subroutine parent: not called CC=2 SCAR=17.9
Pod documented
68 0 my $self=shift @_;
69 0 ▶ if(defined $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]) 0 0 0
70 0 $self->{Parent}=shift @_;
71 }
72 0 return $self->{Parent};
73 }
74
75 0 ▶sub prev {
Subroutine prev: not called CC=2 SCAR=17.9
Pod undocumented
76 0 my $self=shift @_;
77 0 ▶ if(defined $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]) 0 0 0
78 0 $self->{Prev}=shift @_;
79 }
80 0 return $self->{Prev};
81 }
82
83 0 ▶sub next {
Subroutine next: not called CC=2 SCAR=17.9
Pod undocumented
84 0 my $self=shift @_;
85 0 ▶ if(defined $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]) 0 0 0
86 0 $self->{Next}=shift @_;
87 }
88 0 return $self->{Next};
89 }
90
91 0 ▶sub first {
Subroutine first: not called CC=3 SCAR=24.8
Pod undocumented
92 0 my $self=shift @_;
93 0 ▶ $self->{First}=$self->{' childs'}->[0] if(defined $self->{' childs'} && defined $self->{' childs'}->[0]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{" childs"} and defined $self->{" childs"}[0] 0 0 0
Condition0%0/3
defined $self->{" childs"} and defined $self->{" childs"}[0]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{" childs"} and defined $self->{" childs"}[0]
defined $self->{" childs"} defined $self->{" childs"}[0]
Truth table0%0/3
A and B
A= defined $self->{" childs"}B= defined $self->{" childs"}[0]
ABresult
0X0
100
111
94 0 return $self->{First} ;
95 }
96
97 0 ▶sub last {
Subroutine last: not called CC=3 SCAR=24.8
Pod undocumented
98 0 my $self=shift @_;
99 0 ▶ $self->{Last}=$self->{' childs'}->[-1] if(defined $self->{' childs'} && defined $self->{' childs'}->[-1]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{" childs"} and defined $self->{" childs"}[-1] 0 0 0
Condition0%0/3
defined $self->{" childs"} and defined $self->{" childs"}[-1]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{" childs"} and defined $self->{" childs"}[-1]
defined $self->{" childs"} defined $self->{" childs"}[-1]
Truth table0%0/3
A and B
A= defined $self->{" childs"}B= defined $self->{" childs"}[-1]
ABresult
0X0
100
111
100 0 return $self->{Last};
101 }
102
103 0 ▶sub count {
Subroutine count: not called CC=4 SCAR=30.0
Pod undocumented
104 0 my $self=shift @_;
105 0 ▶ my $cnt=scalar @{$self->{' childs'}||[]};
Condition0%0/2
$self->{' childs'} || []
l!l
00
MC/DC0%0/1
$self->{' childs'} || []
$self->{' childs'}
Truth table0%0/2
A
A= $self->{' childs'}
Aresult
11
00
106 0 map { $cnt+=$_->count();} @{$self->{' childs'}};
107 0 ▶ $self->{Count}=PDFNum($self->{' closed'} ? -$cnt : $cnt) if($cnt>0);
Branch: 2 branches
BranchTrueFalseTotal
if $cnt > 0 0 0 0
$self->{' closed'} ? : 0 0 0
108 0 return $cnt;
109 }
110
111 0 ▶sub fix_outline {
Subroutine fix_outline: not called CC=1 SCAR=6.9
Pod undocumented
112 0 my ($self)=@_;
113 0 $self->first;
114 0 $self->last;
115 0 $self->count;
116 }
117
118 =item $otl->title $text
119
120 Set the title of the outline.
121
122 =cut
123
124 0 ▶sub title {
Subroutine title: not called CC=1 SCAR=6.9
Pod documented
125 0 my ($self,$txt)=@_;
126 0 $self->{Title}=PDFStr($txt);
127 0 return($self);
128 }
129
130 =item $otl->closed
131
132 Set the status of the outline to closed.
133
134 =cut
135
136 0 ▶sub closed {
Subroutine closed: not called CC=1 SCAR=6.9
Pod documented
137 0 my $self=shift @_;
138 0 $self->{' closed'}=1;
139 0 return $self;
140 }
141
142 =item $otl->open
143
144 Set the status of the outline to open.
145
146 =cut
147
148 0 ▶sub open {
Subroutine open: not called CC=1 SCAR=6.9
Pod documented
149 0 my $self=shift @_;
150 0 delete $self->{' closed'};
151 0 return $self;
152 }
153
154 =item $sotl=$otl->outline
155
156 Returns a new sub-outline.
157
158 =cut
159
160 0 ▶sub outline {
Subroutine outline: not called CC=4 SCAR=30.0
Pod documented
161 0 my $self=shift @_;
162 0 my $obj=PDF::API3::Compat::API2::Outline->new($self->{' api'},$self);
163 0 ▶ $obj->prev($self->{' childs'}->[-1]) if(defined $self->{' childs'});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{" childs"} 0 0 0
164 0 ▶ $self->{' childs'}->[-1]->next($obj) if(defined $self->{' childs'});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{" childs"} 0 0 0
165 0 push(@{$self->{' childs'}},$obj);
166 0 ▶ $self->{' api'}->{pdf}->new_obj($obj) if(!$obj->is_obj($self->{' api'}->{pdf}));
Branch: 1 branch
BranchTrueFalseTotal
unless $obj->is_obj($self->{" api"}{"pdf"}) 0 0 0
167 0 return $obj;
168 }
169
170 =item $otl->dest $pageobj [, %opts]
171
172 Sets the destination page of the outline.
173
174 =item $otl->dest( $page, -fit => 1 )
175
176 Display the page designated by page, with its contents magnified just enough to
177 fit the entire page within the window both horizontally and vertically. If the
178 required horizontal and vertical magnification factors are different, use the
179 smaller of the two, centering the page within the window in the other dimension.
180
181 =item $otl->dest( $page, -fith => $top )
182
183 Display the page designated by page, with the vertical coordinate top positioned
184 at the top edge of the window and the contents of the page magnified just enough
185 to fit the entire width of the page within the window.
186
187 =item $otl->dest( $page, -fitv => $left )
188
189 Display the page designated by page, with the horizontal coordinate left positioned
190 at the left edge of the window and the contents of the page magnified just enough
191 to fit the entire height of the page within the window.
192
193 =item $otl->dest( $page, -fitr => [ $left, $bottom, $right, $top ] )
194
195 Display the page designated by page, with its contents magnified just enough to
196 fit the rectangle specified by the coordinates left, bottom, right, and top
197 entirely within the window both horizontally and vertically. If the required
198 horizontal and vertical magnification factors are different, use the smaller of
199 the two, centering the rectangle within the window in the other dimension.
200
201 =item $otl->dest( $page, -fitb => 1 )
202
203 Display the page designated by page, with its contents magnified just
204 enough to fit its bounding box entirely within the window both horizontally and
205 vertically. If the required horizontal and vertical magnification factors are
206 different, use the smaller of the two, centering the bounding box within the
207 window in the other dimension.
208
209 =item $otl->dest( $page, -fitbh => $top )
210
211 Display the page designated by page, with the vertical coordinate top
212 positioned at the top edge of the window and the contents of the page magnified
213 just enough to fit the entire width of its bounding box within the window.
214
215 =item $otl->dest( $page, -fitbv => $left )
216
217 Display the page designated by page, with the horizontal coordinate
218 left positioned at the left edge of the window and the contents of the page
219 magnified just enough to fit the entire height of its bounding box within the
220 window.
221
222 =item $otl->dest( $page, -xyz => [ $left, $top, $zoom ] )
223
224 Display the page designated by page, with the coordinates (left, top) positioned
225 at the top-left corner of the window and the contents of the page magnified by
226 the factor zoom. A zero (0) value for any of the parameters left, top, or zoom
227 specifies that the current value of that parameter is to be retained unchanged.
228
229 =item $otl->dest( $name )
230
231 (PDF 1.2) Connect the Outline to a "Named Destination" defined elswere.
232
233 =cut
234
235 sub dest
236 0 ▶{
Subroutine dest: not called CC=14 SCAR=53.5
Pod documented
237 0 my ($self,$page,%opts)=@_;
238
239 0 ▶ if(ref $page)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $page) { } 0 0 0
240 {
241 0 ▶ $opts{-xyz}=[undef,undef,undef] if(scalar(keys %opts)<1);
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %opts < 1 0 0 0
242
243 0 ▶ if(defined $opts{-fit})
Branch: 8 branches
BranchTrueFalseTotal
if (defined $opts{'-fit'}) { } 0 0 0
elsif (defined $opts{'-fith'}) { } 0 0 0
elsif (defined $opts{'-fitb'}) { } 0 0 0
elsif (defined $opts{'-fitbh'}) { } 0 0 0
elsif (defined $opts{'-fitv'}) { } 0 0 0
elsif (defined $opts{'-fitbv'}) { } 0 0 0
elsif (defined $opts{'-fitr'}) { } 0 0 0
elsif (defined $opts{'-xyz'}) { } 0 0 0
244 {
245 0 $self->{Dest}=PDFArray($page,PDFName('Fit'));
246 }
247 elsif(defined $opts{-fith})
248 {
249 0 $self->{Dest}=PDFArray($page,PDFName('FitH'),PDFNum($opts{-fith}));
250 }
251 elsif(defined $opts{-fitb})
252 {
253 0 $self->{Dest}=PDFArray($page,PDFName('FitB'));
254 }
255 elsif(defined $opts{-fitbh})
256 {
257 0 $self->{Dest}=PDFArray($page,PDFName('FitBH'),PDFNum($opts{-fitbh}));
258 }
259 elsif(defined $opts{-fitv})
260 {
261 0 $self->{Dest}=PDFArray($page,PDFName('FitV'),PDFNum($opts{-fitv}));
262 }
263 elsif(defined $opts{-fitbv})
264 {
265 0 $self->{Dest}=PDFArray($page,PDFName('FitBV'),PDFNum($opts{-fitbv}));
266 }
267 elsif(defined $opts{-fitr})
268 {
269 0 ▶ die "insufficient parameters to ->dest( page, -fitr => [] ) " unless(scalar @{$opts{-fitr}} == 4);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$opts{"-fitr"};} == 4 0 0 0
270 0 $self->{Dest}=PDFArray($page,PDFName('FitR'),map {PDFNum($_)} @{$opts{-fitr}});
271 }
272 elsif(defined $opts{-xyz})
273 {
274 0 ▶ die "insufficient parameters to ->dest( page, -xyz => [] ) " unless(scalar @{$opts{-xyz}} == 3);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$opts{"-xyz"};} == 3 0 0 0
275 0 ▶ $self->{Dest}=PDFArray($page,PDFName('XYZ'),map {defined $_ ? PDFNum($_) : PDFNull()} @{$opts{-xyz}});
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
276 }
277 }
278 else
279 {
280 0 $self->{Dest}=PDFStr($page);
281 }
282 0 return($self);
283 }
284
285 =item $otl->url $url, %opts
286
287 Defines the outline as launch-url with url $url.
288
289 =cut
290
291 0 ▶sub url {
Subroutine url: not called CC=1 SCAR=6.9
Pod documented
292 0 my ($self,$url,%opts)=@_;
293 0 delete $self->{Dest};
294 0 $self->{A}=PDFDict();
295 0 $self->{A}->{S}=PDFName('URI');
296 0 $self->{A}->{URI}=PDFStr($url);
297 0 return($self);
298 }
299
300 =item $otl->file $file, %opts
301
302 Defines the outline as launch-file with filepath $file.
303
304 =cut
305
306 0 ▶sub file {
Subroutine file: not called CC=1 SCAR=6.9
Pod documented
307 0 my ($self,$file,%opts)=@_;
308 0 delete $self->{Dest};
309 0 $self->{A}=PDFDict();
310 0 $self->{A}->{S}=PDFName('Launch');
311 0 $self->{A}->{F}=PDFStr($file);
312 0 return($self);
313 }
314
315 =item $otl->pdfile $pdfile, $pagenum, %opts
316
317 Defines the destination of the outline as pdf-file with filepath $pdfile, $pagenum
318 and options %opts (same as dest).
319
320 =cut
321
322 0 ▶sub pdfile {
Subroutine pdfile: not called CC=11 SCAR=48.8
Pod documented
323 0 my ($self,$file,$pnum,%opts)=@_;
324 0 delete $self->{Dest};
325 0 $self->{A}=PDFDict();
326 0 $self->{A}->{S}=PDFName('GoToR');
327 0 $self->{A}->{F}=PDFStr($file);
328 0 ▶ if(defined $opts{-fit}) {
Branch: 8 branches
BranchTrueFalseTotal
if (defined $opts{'-fit'}) { } 0 0 0
elsif (defined $opts{'-fith'}) { } 0 0 0
elsif (defined $opts{'-fitb'}) { } 0 0 0
elsif (defined $opts{'-fitbh'}) { } 0 0 0
elsif (defined $opts{'-fitv'}) { } 0 0 0
elsif (defined $opts{'-fitbv'}) { } 0 0 0
elsif (defined $opts{'-fitr'}) { } 0 0 0
elsif (defined $opts{'-xyz'}) { } 0 0 0
329 0 $self->{A}->{D}=PDFArray(PDFNum($pnum),PDFName('Fit'));
330 } elsif(defined $opts{-fith}) {
331 0 $self->{A}->{D}=PDFArray(PDFNum($pnum),PDFName('FitH'),PDFNum($opts{-fith}));
332 } elsif(defined $opts{-fitb}) {
333 0 $self->{A}->{D}=PDFArray(PDFNum($pnum),PDFName('FitB'));
334 } elsif(defined $opts{-fitbh}) {
335 0 $self->{A}->{D}=PDFArray(PDFNum($pnum),PDFName('FitBH'),PDFNum($opts{-fitbh}));
336 } elsif(defined $opts{-fitv}) {
337 0 $self->{A}->{D}=PDFArray(PDFNum($pnum),PDFName('FitV'),PDFNum($opts{-fitv}));
338 } elsif(defined $opts{-fitbv}) {
339 0 $self->{A}->{D}=PDFArray(PDFNum($pnum),PDFName('FitBV'),PDFNum($opts{-fitbv}));
340 } elsif(defined $opts{-fitr}) {
341 0 ▶ die "insufficient parameters to ->dest( page, -fitr => [] ) " unless(scalar @{$opts{-fitr}} == 4);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$opts{"-fitr"};} == 4 0 0 0
342 0 $self->{A}->{D}=PDFArray(PDFNum($pnum),PDFName('FitR'),map {PDFNum($_)} @{$opts{-fitr}});
343 } elsif(defined $opts{-xyz}) {
344 0 ▶ die "insufficient parameters to dest( page, -xyz => [] ) " unless(scalar @{$opts{-fitr}} == 3);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$opts{"-fitr"};} == 3 0 0 0
345 0 $self->{A}->{D}=PDFArray(PDFNum($pnum),PDFName('XYZ'),map {PDFNum($_)} @{$opts{-xyz}});
346 }
347 0 return($self);
348 }
349
350 0 ▶sub out_obj {
Subroutine out_obj: not called CC=1 SCAR=6.9
Pod undocumented
351 0 my ($self,@param)=@_;
352 0 $self->fix_outline;
353 0 return $self->SUPER::out_obj(@param);
354 }
355
356 0 ▶sub outobjdeep {
Subroutine outobjdeep: not called CC=3 SCAR=24.8
Pod documented
357 0 my ($self,@param)=@_;
358 0 $self->fix_outline;
359 0 foreach my $k (qw/ api apipdf apipage /) {
360 0 $self->{" $k"}=undef;
361 0 delete($self->{" $k"});
362 }
363 0 my @ret=$self->SUPER::outobjdeep(@param);
364 0 foreach my $k (qw/ First Parent Next Last Prev /) {
365 0 $self->{$k}=undef;
366 0 delete($self->{$k});
367 }
368 0 return @ret;
369 }
370
371 1 1;
372
373 __END__
« API3/Compat/API2/Resource/XObject/Form/BarCode/code128.pm ↑ Summary API3/Compat/API2/Basic/PDF/Pages.pm »