/usr/share/perl5/PDF/API2/Outline.pm is in libpdf-api2-perl 2.020-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | package PDF::API2::Outline;
our $VERSION = '2.020'; # VERSION
use base 'PDF::API2::Basic::PDF::Dict';
use PDF::API2::Basic::PDF::Utils;
use PDF::API2::Util;
no warnings qw[ deprecated recursion uninitialized ];
=head1 NAME
PDF::API2::Outline - outline management
=head1 METHODS
=over
=item $otl = PDF::API2::Outline->new $api,$parent,$prev
Returns a new outline object (called from $otls->outline).
=cut
sub new {
my ($class,$api,$parent,$prev)=@_;
my $self = $class->SUPER::new;
$self->{' apipdf'}=$api->{pdf};
$self->{' api'}=$api;
$self->{Parent}=$parent if(defined $parent);
$self->{Prev}=$prev if(defined $prev);
return($self);
}
sub parent {
my $self=shift @_;
if(defined $_[0]) {
$self->{Parent}=shift @_;
}
return $self->{Parent};
}
sub prev {
my $self=shift @_;
if(defined $_[0]) {
$self->{Prev}=shift @_;
}
return $self->{Prev};
}
sub next {
my $self=shift @_;
if(defined $_[0]) {
$self->{Next}=shift @_;
}
return $self->{Next};
}
sub first {
my $self=shift @_;
$self->{First}=$self->{' childs'}->[0] if(defined $self->{' childs'} && defined $self->{' childs'}->[0]);
return $self->{First} ;
}
sub last {
my $self=shift @_;
$self->{Last}=$self->{' childs'}->[-1] if(defined $self->{' childs'} && defined $self->{' childs'}->[-1]);
return $self->{Last};
}
sub count {
my $self=shift @_;
my $cnt=scalar @{$self->{' childs'}||[]};
map { $cnt+=$_->count();} @{$self->{' childs'}};
$self->{Count}=PDFNum($self->{' closed'} ? -$cnt : $cnt) if($cnt>0);
return $cnt;
}
sub fix_outline {
my ($self)=@_;
$self->first;
$self->last;
$self->count;
}
=item $otl->title $text
Set the title of the outline.
=cut
sub title {
my ($self,$txt)=@_;
$self->{Title}=PDFStr($txt);
return($self);
}
=item $otl->closed
Set the status of the outline to closed.
=cut
sub closed {
my $self=shift @_;
$self->{' closed'}=1;
return $self;
}
=item $otl->open
Set the status of the outline to open.
=cut
sub open {
my $self=shift @_;
delete $self->{' closed'};
return $self;
}
=item $sotl=$otl->outline
Returns a new sub-outline.
=cut
sub outline {
my $self=shift @_;
my $obj=PDF::API2::Outline->new($self->{' api'},$self);
$obj->prev($self->{' childs'}->[-1]) if(defined $self->{' childs'});
$self->{' childs'}->[-1]->next($obj) if(defined $self->{' childs'});
push(@{$self->{' childs'}},$obj);
$self->{' api'}->{pdf}->new_obj($obj) if(!$obj->is_obj($self->{' api'}->{pdf}));
return $obj;
}
=item $otl->dest $pageobj [, %opts]
Sets the destination page of the outline.
=item $otl->dest( $page, -fit => 1 )
Display the page designated by page, with its contents magnified just enough to
fit the entire page within the window both horizontally and vertically. If the
required horizontal and vertical magnification factors are different, use the
smaller of the two, centering the page within the window in the other dimension.
=item $otl->dest( $page, -fith => $top )
Display the page designated by page, with the vertical coordinate top positioned
at the top edge of the window and the contents of the page magnified just enough
to fit the entire width of the page within the window.
=item $otl->dest( $page, -fitv => $left )
Display the page designated by page, with the horizontal coordinate left positioned
at the left edge of the window and the contents of the page magnified just enough
to fit the entire height of the page within the window.
=item $otl->dest( $page, -fitr => [ $left, $bottom, $right, $top ] )
Display the page designated by page, with its contents magnified just enough to
fit the rectangle specified by the coordinates left, bottom, right, and top
entirely within the window both horizontally and vertically. If the required
horizontal and vertical magnification factors are different, use the smaller of
the two, centering the rectangle within the window in the other dimension.
=item $otl->dest( $page, -fitb => 1 )
Display the page designated by page, with its contents magnified just
enough to fit its bounding box entirely within the window both horizontally and
vertically. If the required horizontal and vertical magnification factors are
different, use the smaller of the two, centering the bounding box within the
window in the other dimension.
=item $otl->dest( $page, -fitbh => $top )
Display the page designated by page, with the vertical coordinate top
positioned at the top edge of the window and the contents of the page magnified
just enough to fit the entire width of its bounding box within the window.
=item $otl->dest( $page, -fitbv => $left )
Display the page designated by page, with the horizontal coordinate
left positioned at the left edge of the window and the contents of the page
magnified just enough to fit the entire height of its bounding box within the
window.
=item $otl->dest( $page, -xyz => [ $left, $top, $zoom ] )
Display the page designated by page, with the coordinates (left, top) positioned
at the top-left corner of the window and the contents of the page magnified by
the factor zoom. A zero (0) value for any of the parameters left, top, or zoom
specifies that the current value of that parameter is to be retained unchanged.
=item $otl->dest( $name )
(PDF 1.2) Connect the Outline to a "Named Destination" defined elswere.
=cut
sub dest
{
my ($self,$page,%opts)=@_;
if(ref $page)
{
$opts{-xyz}=[undef,undef,undef] if(scalar(keys %opts)<1);
if(defined $opts{-fit})
{
$self->{Dest}=PDFArray($page,PDFName('Fit'));
}
elsif(defined $opts{-fith})
{
$self->{Dest}=PDFArray($page,PDFName('FitH'),PDFNum($opts{-fith}));
}
elsif(defined $opts{-fitb})
{
$self->{Dest}=PDFArray($page,PDFName('FitB'));
}
elsif(defined $opts{-fitbh})
{
$self->{Dest}=PDFArray($page,PDFName('FitBH'),PDFNum($opts{-fitbh}));
}
elsif(defined $opts{-fitv})
{
$self->{Dest}=PDFArray($page,PDFName('FitV'),PDFNum($opts{-fitv}));
}
elsif(defined $opts{-fitbv})
{
$self->{Dest}=PDFArray($page,PDFName('FitBV'),PDFNum($opts{-fitbv}));
}
elsif(defined $opts{-fitr})
{
die "insufficient parameters to ->dest( page, -fitr => [] ) " unless(scalar @{$opts{-fitr}} == 4);
$self->{Dest}=PDFArray($page,PDFName('FitR'),map {PDFNum($_)} @{$opts{-fitr}});
}
elsif(defined $opts{-xyz})
{
die "insufficient parameters to ->dest( page, -xyz => [] ) " unless(scalar @{$opts{-xyz}} == 3);
$self->{Dest}=PDFArray($page,PDFName('XYZ'),map {defined $_ ? PDFNum($_) : PDFNull()} @{$opts{-xyz}});
}
}
else
{
$self->{Dest}=PDFStr($page);
}
return($self);
}
=item $otl->url $url, %opts
Defines the outline as launch-url with url $url.
=cut
sub url {
my ($self,$url,%opts)=@_;
delete $self->{Dest};
$self->{A}=PDFDict();
$self->{A}->{S}=PDFName('URI');
$self->{A}->{URI}=PDFStr($url);
return($self);
}
=item $otl->file $file, %opts
Defines the outline as launch-file with filepath $file.
=cut
sub file {
my ($self,$file,%opts)=@_;
delete $self->{Dest};
$self->{A}=PDFDict();
$self->{A}->{S}=PDFName('Launch');
$self->{A}->{F}=PDFStr($file);
return($self);
}
=item $otl->pdfile $pdfile, $pagenum, %opts
Defines the destination of the outline as pdf-file with filepath $pdfile, $pagenum
and options %opts (same as dest).
=cut
sub pdfile {
my ($self,$file,$pnum,%opts)=@_;
delete $self->{Dest};
$self->{A}=PDFDict();
$self->{A}->{S}=PDFName('GoToR');
$self->{A}->{F}=PDFStr($file);
if(defined $opts{-fit}) {
$self->{A}->{D}=PDFArray(PDFNum($pnum),PDFName('Fit'));
} elsif(defined $opts{-fith}) {
$self->{A}->{D}=PDFArray(PDFNum($pnum),PDFName('FitH'),PDFNum($opts{-fith}));
} elsif(defined $opts{-fitb}) {
$self->{A}->{D}=PDFArray(PDFNum($pnum),PDFName('FitB'));
} elsif(defined $opts{-fitbh}) {
$self->{A}->{D}=PDFArray(PDFNum($pnum),PDFName('FitBH'),PDFNum($opts{-fitbh}));
} elsif(defined $opts{-fitv}) {
$self->{A}->{D}=PDFArray(PDFNum($pnum),PDFName('FitV'),PDFNum($opts{-fitv}));
} elsif(defined $opts{-fitbv}) {
$self->{A}->{D}=PDFArray(PDFNum($pnum),PDFName('FitBV'),PDFNum($opts{-fitbv}));
} elsif(defined $opts{-fitr}) {
die "insufficient parameters to ->dest( page, -fitr => [] ) " unless(scalar @{$opts{-fitr}} == 4);
$self->{A}->{D}=PDFArray(PDFNum($pnum),PDFName('FitR'),map {PDFNum($_)} @{$opts{-fitr}});
} elsif(defined $opts{-xyz}) {
die "insufficient parameters to dest( page, -xyz => [] ) " unless(scalar @{$opts{-fitr}} == 3);
$self->{A}->{D}=PDFArray(PDFNum($pnum),PDFName('XYZ'),map {PDFNum($_)} @{$opts{-xyz}});
}
return($self);
}
sub out_obj {
my ($self,@param)=@_;
$self->fix_outline;
return $self->SUPER::out_obj(@param);
}
sub outobjdeep {
my ($self,@param)=@_;
$self->fix_outline;
foreach my $k (qw/ api apipdf apipage /) {
$self->{" $k"}=undef;
delete($self->{" $k"});
}
my @ret=$self->SUPER::outobjdeep(@param);
foreach my $k (qw/ First Parent Next Last Prev /) {
$self->{$k}=undef;
delete($self->{$k});
}
return @ret;
}
1;
__END__
=back
=head1 AUTHOR
alfred reibenschuh
=cut
|