File Coverage

blib/lib/PDF/Builder/Basic/PDF/Page.pm
Criterion Covered Total %
statement 15 29 51.7
branch 0 4 0.0
condition n/a
subroutine 5 7 71.4
pod 2 2 100.0
total 22 42 52.3


line stmt bran cond sub pod time code
1             #=======================================================================
2             #
3             # THIS IS A REUSED PERL MODULE, FOR PROPER LICENCING TERMS SEE BELOW:
4             #
5             # Copyright Martin Hosken
6             #
7             # No warranty or expression of effectiveness, least of all regarding
8             # anyone's safety, is implied in this software or documentation.
9             #
10             # This specific module is licensed under the Perl Artistic License.
11             # Effective 28 January 2021, the original author and copyright holder,
12             # Martin Hosken, has given permission to use and redistribute this module
13             # under the MIT license.
14             #
15             #=======================================================================
16             package PDF::Builder::Basic::PDF::Page;
17              
18 35     35   273 use base 'PDF::Builder::Basic::PDF::Pages';
  35         82  
  35         19343  
19              
20 35     35   297 use strict;
  35         75  
  35         775  
21 35     35   195 use warnings;
  35         72  
  35         1737  
22              
23             our $VERSION = '3.023'; # VERSION
24             our $LAST_UPDATE = '3.022'; # manually update whenever code is changed
25              
26 35     35   207 use PDF::Builder::Basic::PDF::Dict;
  35         70  
  35         660  
27 35     35   178 use PDF::Builder::Basic::PDF::Utils;
  35         71  
  35         8764  
28              
29             =head1 NAME
30              
31             PDF::Builder::Basic::PDF::Page - Represents a PDF page, inherits from L
32              
33             =head1 DESCRIPTION
34              
35             Represents a page of output in PDF. It also keeps track of the content stream,
36             any resources (such as fonts) being switched, etc.
37              
38             Page inherits from Pages due to a number of shared methods. They are really
39             structurally quite different.
40              
41             =head1 INSTANCE VARIABLES
42              
43             A page has various working variables:
44              
45             =over
46              
47             =item ' curstrm'
48              
49             The currently open stream
50              
51             =back
52              
53             =head1 METHODS
54              
55             =head2 PDF::Builder::Basic::PDF::Page->new($pdf, $parent, $index)
56              
57             Creates a new page based on a pages object (perhaps the root object).
58              
59             The page is also added to the parent at this point, so pages are ordered in
60             a PDF document in the order in which they are created rather than in the order
61             they are closed.
62              
63             Only the essential elements in the page dictionary are created here, all others
64             are either optional or can be inherited.
65              
66             The optional index value indicates the index in the parent list that this page
67             should be inserted (so that new pages need not be appended)
68              
69             =cut
70              
71             sub new {
72 0     0 1   my ($class, $pdf, $parent, $index) = @_;
73 0           my $self = {};
74              
75 0 0         $class = ref($class) if ref($class);
76 0           $self = $class->SUPER::new($pdf, $parent);
77 0           $self->{'Type'} = PDFName('Page');
78 0           delete $self->{'Count'};
79 0           delete $self->{'Kids'};
80 0           $parent->add_page($self, $index);
81            
82 0           return $self;
83             }
84              
85             # the add() method was deleted from PDF::API2 2.034, but it looks like it
86             # still may be used in Builder.pm! apparently calls Content.pm's add().
87              
88             #=head2 $p->add($str)
89             #
90             #Adds the string to the currently active stream for this page. If no stream
91             #exists, then one is created and added to the list of streams for this page.
92             #
93             #The slightly cryptic name is an aim to keep it short given the number of times
94             #people are likely to have to type it.
95             #
96             #=cut
97             #
98             #sub add {
99             # my ($self, $string) = @_;
100             #
101             # my $dict = $self->{' curstrm'};
102             #
103             # unless (defined $dict) {
104             # $dict = PDF::Builder::Basic::PDF::Dict->new();
105             # foreach my $pdf (@{$self->{' destination_pdfs'}}) {
106             # $pdf->new_obj($dict);
107             # }
108             # $self->{'Contents'} = PDFArray() unless defined $self->{'Contents'};
109             # unless (ref($self->{'Contents'}) eq 'PDF::Builder::Basic::PDF::Array') {
110             # $self->{'Contents'} = PDFArray($self->{'Contents'});
111             # }
112             # $self->{'Contents'}->add_elements($dict);
113             # $self->{' curstrm'} = $dict;
114             # }
115             #
116             # $dict->{' stream'} .= $string;
117             #
118             # return $self;
119             #}
120              
121             =head2 $p->ship_out($pdf)
122              
123             Ships the page out to the given output file context
124              
125             =cut
126              
127             sub ship_out {
128 0     0 1   my ($self, $pdf) = @_;
129              
130 0           $pdf->ship_out($self);
131 0 0         if (defined $self->{'Contents'}) {
132 0           $pdf->ship_out($self->{'Contents'}->elements());
133             }
134              
135 0           return $self;
136             }
137              
138             1;