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 39     39   313 use base 'PDF::Builder::Basic::PDF::Pages';
  39         94  
  39         20429  
19              
20 39     39   314 use strict;
  39         75  
  39         781  
21 39     39   194 use warnings;
  39         79  
  39         1875  
22              
23             our $VERSION = '3.025'; # VERSION
24             our $LAST_UPDATE = '3.022'; # manually update whenever code is changed
25              
26 39     39   228 use PDF::Builder::Basic::PDF::Dict;
  39         89  
  39         683  
27 39     39   189 use PDF::Builder::Basic::PDF::Utils;
  39         71  
  39         10156  
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             =over
56              
57             =item PDF::Builder::Basic::PDF::Page->new($pdf, $parent, $index)
58              
59             Creates a new page based on a pages object (perhaps the root object).
60              
61             The page is also added to the parent at this point, so pages are ordered in
62             a PDF document in the order in which they are created rather than in the order
63             they are closed.
64              
65             Only the essential elements in the page dictionary are created here, all others
66             are either optional or can be inherited.
67              
68             The optional index value indicates the index in the parent list that this page
69             should be inserted (so that new pages need not be appended)
70              
71             =cut
72              
73             sub new {
74 0     0 1   my ($class, $pdf, $parent, $index) = @_;
75 0           my $self = {};
76              
77 0 0         $class = ref($class) if ref($class);
78 0           $self = $class->SUPER::new($pdf, $parent);
79 0           $self->{'Type'} = PDFName('Page');
80 0           delete $self->{'Count'};
81 0           delete $self->{'Kids'};
82 0           $parent->add_page($self, $index);
83            
84 0           return $self;
85             }
86              
87             # the add() method was deleted from PDF::API2 2.034, but it looks like it
88             # still may be used in Builder.pm! apparently calls Content.pm's add().
89              
90             #=item $p->add($str)
91             #
92             #Adds the string to the currently active stream for this page. If no stream
93             #exists, then one is created and added to the list of streams for this page.
94             #
95             #The slightly cryptic name is an aim to keep it short given the number of times
96             #people are likely to have to type it.
97             #
98             #=cut
99             #
100             #sub add {
101             # my ($self, $string) = @_;
102             #
103             # my $dict = $self->{' curstrm'};
104             #
105             # unless (defined $dict) {
106             # $dict = PDF::Builder::Basic::PDF::Dict->new();
107             # foreach my $pdf (@{$self->{' destination_pdfs'}}) {
108             # $pdf->new_obj($dict);
109             # }
110             # $self->{'Contents'} = PDFArray() unless defined $self->{'Contents'};
111             # unless (ref($self->{'Contents'}) eq 'PDF::Builder::Basic::PDF::Array') {
112             # $self->{'Contents'} = PDFArray($self->{'Contents'});
113             # }
114             # $self->{'Contents'}->add_elements($dict);
115             # $self->{' curstrm'} = $dict;
116             # }
117             #
118             # $dict->{' stream'} .= $string;
119             #
120             # return $self;
121             #}
122              
123             =item $p->ship_out($pdf)
124              
125             Ships the page out to the given output file context
126              
127             =cut
128              
129             sub ship_out {
130 0     0 1   my ($self, $pdf) = @_;
131              
132 0           $pdf->ship_out($self);
133 0 0         if (defined $self->{'Contents'}) {
134 0           $pdf->ship_out($self->{'Contents'}->elements());
135             }
136              
137 0           return $self;
138             }
139              
140             =back
141              
142             =cut
143              
144             1;