API3/Compat/API2/NamedDestination.pm

filter: Statementstmt 30.3% 24 / 79 Branchbran 0.0% 0 / 38 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 53.3% 8 / 15 Podpod 100% 7 / 7 totaltotal 28.0% 39 / 139 CC 20 SCAR 44.9
CC
20
Cov
21%
dest
210.0
new
12.0
new_api
6.0
CRAP 89.2
« API3/Compat/API2/Resource/CIDFont.pm ↑ Summary API3/Compat/API2/Resource/Font/CoreFont.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 FILE IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
21 # AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
23 # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 # SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR CONTRIBUTORS
25 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 # ARISING IN ANY WAY OUT OF THE USE OF THIS FILE, EVEN IF
32 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #
34 # SEE THE GNU LESSER GENERAL PUBLIC LICENSE FOR MORE DETAILS.
35 #
36 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU LESSER GENERAL PUBLIC
37 # LICENSE ALONG WITH THIS LIBRARY; IF NOT, WRITE TO THE
38 # FREE SOFTWARE FOUNDATION, INC., 59 TEMPLE PLACE - SUITE 330,
39 # BOSTON, MA 02111-1307, USA.
40 #
41 # $Id: NamedDestination.pm,v 2.0 2005/11/16 02:16:00 areibens Exp $
42 #
43 #=======================================================================
44 package PDF::API3::Compat::API2::NamedDestination;
45
46 =head1 NAME
47
48 PDF::API3::Compat::API2::NamedDestination
49
50 =head1 SYNOPSIS
51
52 =head1 METHODS
53
54 =over 4
55
56 =cut
57
58 BEGIN
59 1 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
60 1 ▶ use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
61 1 ▶ use Encode qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
62
63 1 ▶ use vars qw( @ISA $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
64
65 1 ▶ use PDF::API3::Compat::API2::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 1 ▶ use PDF::API3::Compat::API2::Basic::PDF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 1 ▶ use PDF::API3::Compat::API2::Basic::PDF::Dict;
Subroutine BEGIN: called CC=1 SCAR=0.0
68
69 1 @ISA=qw(PDF::API3::Compat::API2::Basic::PDF::Dict);
70
71 1 ( $VERSION ) = sprintf '%i.%03i', split(/\./,('$Revision: 2.0 $' =~ /Revision: (\S+)\s/)[0]); # $Date: 2005/11/16 02:16:00 $
72 }
73
74 1 ▶no warnings qw[ recursion uninitialized ];
Subroutine BEGIN: called CC=1 SCAR=0.0
75
76 =item $dest = PDF::API3::Compat::API2::NamedDestination->new $pdf
77
78 =cut
79
80 sub new
81 0 ▶{
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
82 0 my ($class,$pdf) = @_;
83 0 my ($self);
84
85 0 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
86 0 $self = $class->SUPER::new($pdf);
87
88 0 ▶ $pdf->new_obj($self) unless($self->is_obj($pdf));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_obj($pdf) 0 0 0
89
90 0 return($self);
91 }
92
93 =item $dest = PDF::API3::Compat::API2::NamedDestination->new_api $api
94
95 Returns a destination object. This method is different from 'new' that
96 it needs an PDF::API3::Compat::API2-object rather than a PDF::API3::Compat::API2::PDF::File-object.
97
98 =cut
99
100 0 ▶sub new_api {
Subroutine new_api: not called CC=2 SCAR=17.9
Pod documented
101 0 my ($class,$api,@opts)=@_;
102
103 0 my $obj=$class->new($api->{pdf},@opts);
104
105 0 ▶ $api->{pdf}->new_obj($obj) unless($obj->is_obj($api->{pdf}));
Branch: 1 branch
BranchTrueFalseTotal
unless $obj->is_obj($api->{"pdf"}) 0 0 0
106
107 0 $api->{pdf}->out_obj($api->{pages});
108
109 0 return($obj);
110 }
111
112 =item $dest->link $page, %opts
113
114 Defines the destination as launch-page with page $page and
115 options %opts (-rect, -border or 'dest-options').
116
117 =cut
118
119 sub link
120 0 ▶{
Subroutine link: not called CC=1 SCAR=6.9
Pod documented
121 0 my ($self,$page,%opts)=@_;
122
123 0 $self->{S}=PDFName('GoTo');
124 0 $self->dest($page,%opts);
125
126 0 return($self);
127 }
128
129 =item $dest->url $url, %opts
130
131 Defines the destination as launch-url with url $url and
132 options %opts (-rect and/or -border).
133
134 =cut
135
136 sub url
137 0 ▶{
Subroutine url: not called CC=2 SCAR=17.9
Pod documented
138 0 my ($self,$url,%opts)=@_;
139
140 0 $self->{S}=PDFName('URI');
141 0 ▶ if(is_utf8($url))
Branch: 1 branch
BranchTrueFalseTotal
if (&is_utf8($url)) 0 0 0
142 {
143 # URI must be 7-bit ascii
144 0 utf8::downgrade($url);
145 }
146 0 $self->{URI}=PDFStr($url);
147
148 # this will come again -- since the utf8 urls are coming !
149 # -- fredo
150 #if(is_utf8($url) || utf8::valid($url)) {
151 # $self->{URI}=PDFUtf($url);
152 #} else {
153 # $self->{URI}=PDFStr($url);
154 #}
155 0 return($self);
156 }
157
158 =item $dest->file $file, %opts
159
160 Defines the destination as launch-file with filepath $file and
161 options %opts (-rect and/or -border).
162
163 =cut
164
165 sub file
166 0 ▶{
Subroutine file: not called CC=2 SCAR=17.9
Pod documented
167 0 my ($self,$url,%opts)=@_;
168
169 0 $self->{S}=PDFName('Launch');
170 0 ▶ if(is_utf8($url))
Branch: 1 branch
BranchTrueFalseTotal
if (&is_utf8($url)) 0 0 0
171 {
172 # URI must be 7-bit ascii
173 0 utf8::downgrade($url);
174 }
175 0 $self->{F}=PDFStr($url);
176
177 # this will come again -- since the utf8 urls are coming !
178 # -- fredo
179 #if(is_utf8($url) || utf8::valid($url)) {
180 # $self->{F}=PDFUtf($url);
181 #} else {
182 # $self->{F}=PDFStr($url);
183 #}
184 0 return($self);
185 }
186
187 =item $dest->pdfile $pdfile, $pagenum, %opts
188
189 Defines the destination as pdf-file with filepath $pdfile, $pagenum
190 and options %opts (same as dest).
191
192 =cut
193
194 sub pdfile
195 0 ▶{
Subroutine pdfile: not called CC=2 SCAR=17.9
Pod documented
196 0 my ($self,$url,$pnum,%opts)=@_;
197
198 0 $self->{S}=PDFName('GoToR');
199 0 ▶ if(is_utf8($url))
Branch: 1 branch
BranchTrueFalseTotal
if (&is_utf8($url)) 0 0 0
200 {
201 # URI must be 7-bit ascii
202 0 utf8::downgrade($url);
203 }
204 0 $self->{F}=PDFStr($url);
205
206 # this will come again -- since the utf8 urls are coming !
207 # -- fredo
208 #if(is_utf8($url) || utf8::valid($url)) {
209 # $self->{F}=PDFUtf($url);
210 #} else {
211 # $self->{F}=PDFStr($url);
212 #}
213
214 0 $self->dest(PDFNum($pnum),%opts);
215
216 0 return($self);
217 }
218
219 =item $dest->dest( $page, -fit => 1 )
220
221 Display the page designated by page, with its contents magnified just enough to
222 fit the entire page within the window both horizontally and vertically. If the
223 required horizontal and vertical magnification factors are different, use the
224 smaller of the two, centering the page within the window in the other dimension.
225
226 =item $dest->dest( $page, -fith => $top )
227
228 Display the page designated by page, with the vertical coordinate top positioned
229 at the top edge of the window and the contents of the page magnified just enough
230 to fit the entire width of the page within the window.
231
232 =item $dest->dest( $page, -fitv => $left )
233
234 Display the page designated by page, with the horizontal coordinate left positioned
235 at the left edge of the window and the contents of the page magnified just enough
236 to fit the entire height of the page within the window.
237
238 =item $dest->dest( $page, -fitr => [ $left, $bottom, $right, $top ] )
239
240 Display the page designated by page, with its contents magnified just enough to
241 fit the rectangle specified by the coordinates left, bottom, right, and top
242 entirely within the window both horizontally and vertically. If the required
243 horizontal and vertical magnification factors are different, use the smaller of
244 the two, centering the rectangle within the window in the other dimension.
245
246 =item $dest->dest( $page, -fitb => 1 )
247
248 (PDF 1.1) Display the page designated by page, with its contents magnified just
249 enough to fit its bounding box entirely within the window both horizontally and
250 vertically. If the required horizontal and vertical magnification factors are
251 different, use the smaller of the two, centering the bounding box within the
252 window in the other dimension.
253
254 =item $dest->dest( $page, -fitbh => $top )
255
256 (PDF 1.1) Display the page designated by page, with the vertical coordinate top
257 positioned at the top edge of the window and the contents of the page magnified
258 just enough to fit the entire width of its bounding box within the window.
259
260 =item $dest->dest( $page, -fitbv => $left )
261
262 (PDF 1.1) Display the page designated by page, with the horizontal coordinate
263 left positioned at the left edge of the window and the contents of the page
264 magnified just enough to fit the entire height of its bounding box within the
265 window.
266
267 =item $dest->dest( $page, -xyz => [ $left, $top, $zoom ] )
268
269 Display the page designated by page, with the coordinates (left, top) positioned
270 at the top-left corner of the window and the contents of the page magnified by
271 the factor zoom. A zero (0) value for any of the parameters left, top, or zoom
272 specifies that the current value of that parameter is to be retained unchanged.
273
274 =cut
275
276 sub dest
277 0 ▶{
Subroutine dest: not called CC=14 SCAR=53.5
Pod documented
278 0 my ($self,$page,%opts)=@_;
279
280 0 ▶ if(ref $page)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $page) 0 0 0
281 {
282 0 ▶ $opts{-xyz}=[undef,undef,undef] if(scalar(keys %opts)<1);
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %opts < 1 0 0 0
283
284 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
285 {
286 0 $self->{D}=PDFArray($page,PDFName('Fit'));
287 }
288 elsif(defined $opts{-fith})
289 {
290 0 $self->{D}=PDFArray($page,PDFName('FitH'),PDFNum($opts{-fith}));
291 }
292 elsif(defined $opts{-fitb})
293 {
294 0 $self->{D}=PDFArray($page,PDFName('FitB'));
295 }
296 elsif(defined $opts{-fitbh})
297 {
298 0 $self->{D}=PDFArray($page,PDFName('FitBH'),PDFNum($opts{-fitbh}));
299 }
300 elsif(defined $opts{-fitv})
301 {
302 0 $self->{D}=PDFArray($page,PDFName('FitV'),PDFNum($opts{-fitv}));
303 }
304 elsif(defined $opts{-fitbv})
305 {
306 0 $self->{D}=PDFArray($page,PDFName('FitBV'),PDFNum($opts{-fitbv}));
307 }
308 elsif(defined $opts{-fitr})
309 {
310 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
311 0 $self->{D}=PDFArray($page,PDFName('FitR'),map {PDFNum($_)} @{$opts{-fitr}});
312 }
313 elsif(defined $opts{-xyz})
314 {
315 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
316 0 ▶ $self->{D}=PDFArray($page,PDFName('XYZ'),map {defined $_ ? PDFNum($_) : PDFNull()} @{$opts{-xyz}});
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
317 }
318 }
319
320 0 return($self);
321 }
322
323 1 1;
324
325 __END__
« API3/Compat/API2/Resource/CIDFont.pm ↑ Summary API3/Compat/API2/Resource/Font/CoreFont.pm »