API3/Compat/API2/Annotation.pm

filter: Statementstmt 18.0% 27 / 150 Branchbran 0.0% 0 / 64 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 39.1% 9 / 23 Podpod 92.8% 13 / 14 totaltotal 18.7% 49 / 261 CC 36 SCAR 42.5
CC
36
Cov
12%
dest
240.0
link
20.0
url
20.0
CRAP 70.1
« API3/Compat/API2/Basic/TTF/GDEF.pm ↑ Summary API3/Compat/API2/Basic/TTF/OldCmap.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: Annotation.pm,v 2.1 2007/10/02 19:59:37 areibens Exp $
31 #
32 #=======================================================================
33 package PDF::API3::Compat::API2::Annotation;
34
35 BEGIN
36 1 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
37
38 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶ use vars qw(@ISA $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
40
41 1 ▶ use PDF::API3::Compat::API2::Basic::PDF::Dict;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 1 ▶ use PDF::API3::Compat::API2::Basic::PDF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 1 ▶ use PDF::API3::Compat::API2::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
44
45 1 @ISA = qw(PDF::API3::Compat::API2::Basic::PDF::Dict);
46
47 1 ( $VERSION ) = sprintf '%i.%03i', split(/\./,('$Revision: 2.1 $' =~ /Revision: (\S+)\s/)[0]); # $Date: 2007/10/02 19:59:37 $
48
49 1 ▶ use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 1 ▶ use Encode qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
51 }
52
53 1 ▶no warnings qw[ deprecated recursion uninitialized ];
Subroutine BEGIN: called CC=1 SCAR=0.0
54
55 =head1 $ant = PDF::API3::Compat::API2::Annotation->new
56
57 Returns a annotation object (called from $page->annotation).
58
59 =cut
60
61 sub new
62 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
63 0 my ($class,%opts)=@_;
64 0 my $self=$class->SUPER::new;
65 0 $self->{Type}=PDFName('Annot');
66 0 $self->{Border}=PDFArray(PDFNum(0),PDFNum(0),PDFNum(0));
67 0 return($self);
68 }
69
70 sub outobjdeep
71 0 ▶{
Subroutine outobjdeep: not called CC=2 SCAR=17.9
Pod documented
72 0 my ($self, @opts) = @_;
73 0 foreach my $k (qw[ api apipdf apipage ])
74 {
75 0 $self->{" $k"}=undef;
76 0 delete($self->{" $k"});
77 }
78 0 $self->SUPER::outobjdeep(@opts);
79 }
80
81 =item $ant->link $page, %opts
82
83 Defines the annotation as launch-page with page $page and
84 options %opts (-rect, -border or 'dest-options').
85
86 =cut
87
88 sub link
89 0 ▶{
Subroutine link: not called CC=4 SCAR=30.0
Pod documented
90 0 my ($self,$page,%opts)=@_;
91 0 $self->{Subtype}=PDFName('Link');
92 0 ▶ if(ref $page)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $page) 0 0 0
93 {
94 0 $self->{A}=PDFDict();
95 0 $self->{A}->{S}=PDFName('GoTo');
96 }
97 0 $self->dest($page,%opts);
98 0 ▶ $self->rect(@{$opts{-rect}}) if(defined $opts{-rect});
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"-rect"} 0 0 0
99 0 ▶ $self->border(@{$opts{-border}}) if(defined $opts{-border});
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"-border"} 0 0 0
100 0 return($self);
101 }
102
103 =item $ant->url $url, %opts
104
105 Defines the annotation as launch-url with url $url and
106 options %opts (-rect and/or -border).
107
108 =cut
109
110 sub url
111 0 ▶{
Subroutine url: not called CC=4 SCAR=30.0
Pod documented
112 0 my ($self,$url,%opts)=@_;
113 0 $self->{Subtype}=PDFName('Link');
114 0 $self->{A}=PDFDict();
115 0 $self->{A}->{S}=PDFName('URI');
116 0 ▶ if(is_utf8($url))
Branch: 1 branch
BranchTrueFalseTotal
if (&is_utf8($url)) 0 0 0
117 {
118 # URI must be 7-bit ascii
119 0 utf8::downgrade($url);
120 }
121 0 $self->{A}->{URI}=PDFStr($url);
122 # this will come again -- since the utf8 urls are coming !
123 # -- fredo
124 #if(is_utf8($url) || utf8::valid($url)) {
125 # $self->{A}->{URI}=PDFUtf($url);
126 #} else {
127 # $self->{A}->{URI}=PDFStr($url);
128 #}
129 0 ▶ $self->rect(@{$opts{-rect}}) if(defined $opts{-rect});
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"-rect"} 0 0 0
130 0 ▶ $self->border(@{$opts{-border}}) if(defined $opts{-border});
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"-border"} 0 0 0
131 0 return($self);
132 }
133
134 =item $ant->file $file, %opts
135
136 Defines the annotation as launch-file with filepath $file and
137 options %opts (-rect and/or -border).
138
139 =cut
140
141 sub file
142 0 ▶{
Subroutine file: not called CC=4 SCAR=30.0
Pod documented
143 0 my ($self,$url,%opts)=@_;
144 0 $self->{Subtype}=PDFName('Link');
145 0 $self->{A}=PDFDict();
146 0 $self->{A}->{S}=PDFName('Launch');
147 0 ▶ if(is_utf8($url))
Branch: 1 branch
BranchTrueFalseTotal
if (&is_utf8($url)) 0 0 0
148 {
149 # URI must be 7-bit ascii
150 0 utf8::downgrade($url);
151 }
152 0 $self->{A}->{F}=PDFStr($url);
153 # this will come again -- since the utf8 urls are coming !
154 # -- fredo
155 #if(is_utf8($url) || utf8::valid($url)) {
156 # $self->{A}->{F}=PDFUtf($url);
157 #} else {
158 # $self->{A}->{F}=PDFStr($url);
159 #}
160 0 ▶ $self->rect(@{$opts{-rect}}) if(defined $opts{-rect});
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"-rect"} 0 0 0
161 0 ▶ $self->border(@{$opts{-border}}) if(defined $opts{-border});
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"-border"} 0 0 0
162 0 return($self);
163 }
164
165 =item $ant->pdfile $pdfile, $pagenum, %opts
166
167 Defines the annotation as pdf-file with filepath $pdfile, $pagenum
168 and options %opts (same as dest).
169
170 =cut
171
172 sub pdfile
173 0 ▶{
Subroutine pdfile: not called CC=4 SCAR=30.0
Pod documented
174 0 my ($self,$url,$pnum,%opts)=@_;
175 0 $self->{Subtype}=PDFName('Link');
176 0 $self->{A}=PDFDict();
177 0 $self->{A}->{S}=PDFName('GoToR');
178 0 ▶ if(is_utf8($url))
Branch: 1 branch
BranchTrueFalseTotal
if (&is_utf8($url)) 0 0 0
179 {
180 # URI must be 7-bit ascii
181 0 utf8::downgrade($url);
182 }
183 0 $self->{A}->{F}=PDFStr($url);
184 # this will come again -- since the utf8 urls are coming !
185 # -- fredo
186 #if(is_utf8($url) || utf8::valid($url)) {
187 # $self->{A}->{F}=PDFUtf($url);
188 #} else {
189 # $self->{A}->{F}=PDFStr($url);
190 #}
191
192 0 $self->dest(PDFNum($pnum),%opts);
193
194 0 ▶ $self->rect(@{$opts{-rect}}) if(defined $opts{-rect});
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"-rect"} 0 0 0
195 0 ▶ $self->border(@{$opts{-border}}) if(defined $opts{-border});
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"-border"} 0 0 0
196
197 0 return($self);
198 }
199
200 =item $ant->text $text, %opts
201
202 Defines the annotation as textnote with content $text and
203 options %opts (-rect and/or -open).
204
205 =cut
206
207 sub text
208 0 ▶{
Subroutine text: not called CC=3 SCAR=24.8
Pod documented
209 0 my ($self,$text,%opts)=@_;
210 0 $self->{Subtype}=PDFName('Text');
211 0 $self->content($text);
212 0 ▶ $self->rect(@{$opts{-rect}}) if(defined $opts{-rect});
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"-rect"} 0 0 0
213 0 ▶ $self->open($opts{-open}) if(defined $opts{-open});
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"-open"} 0 0 0
214 0 return($self);
215 }
216
217 =item $ant->movie $file, $contentype, %opts
218
219 Defines the annotation as a movie from $file with $contentype and
220 options %opts (-rect).
221
222 =cut
223
224 sub movie
225 0 ▶{
Subroutine movie: not called CC=2 SCAR=17.9
Pod documented
226 0 my ($self,$file,$contentype,%opts)=@_;
227 0 $self->{Subtype}=PDFName('Movie');
228 0 $self->{A}=PDFBool(1);
229 0 $self->{Movie}=PDFDict();
230 0 $self->{Movie}->{F}=PDFDict();
231 0 $self->{' apipdf'}->new_obj($self->{Movie}->{F});
232 0 my $f=$self->{Movie}->{F};
233 0 $f->{Type}=PDFName('EmbeddedFile');
234 0 $f->{Subtype}=PDFName($contentype);
235 0 $f->{' streamfile'}=$file;
236 0 ▶ $self->rect(@{$opts{-rect}}) if(defined $opts{-rect});
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"-rect"} 0 0 0
237 0 return($self);
238 }
239
240 =item $ant->rect $llx, $lly, $urx, $ury
241
242 Sets the rectangle of the annotation.
243
244 =cut
245
246 sub rect
247 0 ▶{
Subroutine rect: not called CC=2 SCAR=17.9
Pod documented
248 0 my ($self,@r)=@_;
249 0 ▶ die "insufficient parameters to annotation->rect( ) " unless(scalar @r == 4);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @r == 4 0 0 0
250 0 $self->{Rect}=PDFArray( map { PDFNum($_) } $r[0],$r[1],$r[2],$r[3], );
251 0 return($self);
252 }
253
254 =item $ant->border @b
255
256 Sets the border-styles of the annotation, if applicable.
257
258 =cut
259
260 sub border
261 0 ▶{
Subroutine border: not called CC=2 SCAR=17.9
Pod documented
262 0 my ($self,@r)=@_;
263 0 ▶ die "insufficient parameters to annotation->border( ) " unless(scalar @r == 3);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @r == 3 0 0 0
264 0 $self->{Border}=PDFArray( map { PDFNum($_) } $r[0],$r[1],$r[2] );
265 0 return($self);
266 }
267
268 =item $ant->content @lines
269
270 Sets the text-content of the annotation, if applicable.
271
272 =cut
273
274 sub content
275 0 ▶{
Subroutine content: not called CC=3 SCAR=24.8
Pod documented
276 0 my ($self,@t)=@_;
277 0 my $t=join("\n",@t);
278 0 ▶ if(is_utf8($t) || utf8::valid($t))
Branch: 1 branch
BranchTrueFalseTotal
if (&is_utf8($t) or utf8::valid($t)) { } 0 0 0
Condition0%0/3
&is_utf8($t) or utf8::valid($t)
l!l&&r!l&&!r
000
MC/DC0%0/2
&is_utf8($t) or utf8::valid($t)
&is_utf8($t) utf8::valid($t)
Truth table0%0/3
A or B
A= &is_utf8($t)B= utf8::valid($t)
ABresult
1X1
011
000
279 {
280 0 $self->{Contents}=PDFUtf($t);
281 }
282 else
283 {
284 0 $self->{Contents}=PDFStr($t);
285 }
286 0 return($self);
287 }
288
289 sub name
290 0 ▶{
Subroutine name: not called CC=1 SCAR=6.9
Pod undocumented
291 0 my ($self,$n)=@_;
292 0 $self->{Name}=PDFName($n);
293 0 return($self);
294 }
295
296 =item $ant->open $bool
297
298 Display the annotation either open or closed, if applicable.
299
300 =cut
301
302 sub open
303 0 ▶{
Subroutine open: not called CC=2 SCAR=17.9
Pod documented
304 0 my ($self,$n)=@_;
305 0 ▶ $self->{Open}=PDFBool( $n ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$n ? : 0 0 0
306 0 return($self);
307 }
308
309 =item $ant->dest( $page, -fit => 1 )
310
311 Display the page designated by page, with its contents magnified just enough to
312 fit the entire page within the window both horizontally and vertically. If the
313 required horizontal and vertical magnification factors are different, use the
314 smaller of the two, centering the page within the window in the other dimension.
315
316 =item $ant->dest( $page, -fith => $top )
317
318 Display the page designated by page, with the vertical coordinate top positioned
319 at the top edge of the window and the contents of the page magnified just enough
320 to fit the entire width of the page within the window.
321
322 =item $ant->dest( $page, -fitv => $left )
323
324 Display the page designated by page, with the horizontal coordinate left positioned
325 at the left edge of the window and the contents of the page magnified just enough
326 to fit the entire height of the page within the window.
327
328 =item $ant->dest( $page, -fitr => [ $left, $bottom, $right, $top ] )
329
330 Display the page designated by page, with its contents magnified just enough to
331 fit the rectangle specified by the coordinates left, bottom, right, and top
332 entirely within the window both horizontally and vertically. If the required
333 horizontal and vertical magnification factors are different, use the smaller of
334 the two, centering the rectangle within the window in the other dimension.
335
336 =item $ant->dest( $page, -fitb => 1 )
337
338 (PDF 1.1) Display the page designated by page, with its contents magnified just
339 enough to fit its bounding box entirely within the window both horizontally and
340 vertically. If the required horizontal and vertical magnification factors are
341 different, use the smaller of the two, centering the bounding box within the
342 window in the other dimension.
343
344 =item $ant->dest( $page, -fitbh => $top )
345
346 (PDF 1.1) Display the page designated by page, with the vertical coordinate top
347 positioned at the top edge of the window and the contents of the page magnified
348 just enough to fit the entire width of its bounding box within the window.
349
350 =item $ant->dest( $page, -fitbv => $left )
351
352 (PDF 1.1) Display the page designated by page, with the horizontal coordinate
353 left positioned at the left edge of the window and the contents of the page
354 magnified just enough to fit the entire height of its bounding box within the
355 window.
356
357 =item $ant->dest( $page, -xyz => [ $left, $top, $zoom ] )
358
359 Display the page designated by page, with the coordinates (left, top) positioned
360 at the top-left corner of the window and the contents of the page magnified by
361 the factor zoom. A zero (0) value for any of the parameters left, top, or zoom
362 specifies that the current value of that parameter is to be retained unchanged.
363
364 =item $ant->dest( $name )
365
366 (PDF 1.2) Connect the Annotation to a "Named Destination" defined elswere.
367
368 =cut
369
370 sub dest
371 0 ▶{
Subroutine dest: not called CC=15 SCAR=54.8
Pod documented
372 0 my ($self,$page,%opts)=@_;
373
374 0 ▶ if(ref $page)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $page) { } 0 0 0
375 {
376 0 ▶ $opts{-xyz}=[undef,undef,undef] if(scalar(keys %opts)<1);
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %opts < 1 0 0 0
377
378 0 ▶ $self->{A}||=PDFDict();
Condition0%0/3
$self->{"A"} ||= PDFDict()
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"A"} ||= PDFDict()
$self->{"A"} PDFDict()
Truth table0%0/3
A ||= B
A= $self->{"A"}B= PDFDict()
ABresult
1X1
011
000
379
380 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
381 {
382 0 $self->{A}->{D}=PDFArray($page,PDFName('Fit'));
383 }
384 elsif(defined $opts{-fith})
385 {
386 0 $self->{A}->{D}=PDFArray($page,PDFName('FitH'),PDFNum($opts{-fith}));
387 }
388 elsif(defined $opts{-fitb})
389 {
390 0 $self->{A}->{D}=PDFArray($page,PDFName('FitB'));
391 }
392 elsif(defined $opts{-fitbh})
393 {
394 0 $self->{A}->{D}=PDFArray($page,PDFName('FitBH'),PDFNum($opts{-fitbh}));
395 }
396 elsif(defined $opts{-fitv})
397 {
398 0 $self->{A}->{D}=PDFArray($page,PDFName('FitV'),PDFNum($opts{-fitv}));
399 }
400 elsif(defined $opts{-fitbv})
401 {
402 0 $self->{A}->{D}=PDFArray($page,PDFName('FitBV'),PDFNum($opts{-fitbv}));
403 }
404 elsif(defined $opts{-fitr})
405 {
406 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
407 0 $self->{A}->{D}=PDFArray($page,PDFName('FitR'),map {PDFNum($_)} @{$opts{-fitr}});
408 }
409 elsif(defined $opts{-xyz})
410 {
411 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
412 0 ▶ $self->{A}->{D}=PDFArray($page,PDFName('XYZ'),map {defined $_ ? PDFNum($_) : PDFNull()} @{$opts{-xyz}});
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
413 }
414 }
415 else
416 {
417 0 $self->{Dest}=PDFStr($page);
418 }
419
420 0 return($self);
421 }
422
423 1 1;
424
425 __END__
« API3/Compat/API2/Basic/TTF/GDEF.pm ↑ Summary API3/Compat/API2/Basic/TTF/OldCmap.pm »