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 <Martin_Hosken@sil.org>
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 40     40   331 use base 'PDF::Builder::Basic::PDF::Pages';
  40         104  
  40         30211  
19              
20 40     40   328 use strict;
  40         89  
  40         1049  
21 40     40   196 use warnings;
  40         95  
  40         3272  
22              
23             our $VERSION = '3.028'; # VERSION
24             our $LAST_UPDATE = '3.027'; # manually update whenever code is changed
25              
26 40     40   252 use PDF::Builder::Basic::PDF::Dict;
  40         92  
  40         919  
27 40     40   195 use PDF::Builder::Basic::PDF::Utils;
  40         91  
  40         13993  
28              
29             =head1 NAME
30              
31             PDF::Builder::Basic::PDF::Page - Represents a PDF page
32              
33             Inherits from L<PDF::Builder::Basic::PDF::Pages>
34              
35             =head1 DESCRIPTION
36              
37             Represents a page of output in PDF. It also keeps track of the content stream,
38             any resources (such as fonts) being switched, etc.
39              
40             Page inherits from Pages due to a number of shared methods. They are really
41             structurally quite different.
42              
43             =head1 INSTANCE VARIABLES
44              
45             A page has various working variables:
46              
47             =over
48              
49             =item ' curstrm'
50              
51             The currently open stream
52              
53             =back
54              
55             =head1 METHODS
56              
57             =head2 new
58              
59             PDF::Builder::Basic::PDF::Page->new($pdf, $parent, $index)
60              
61             =over
62              
63             Creates a new page based on a pages object (perhaps the root object).
64              
65             The page is also added to the parent at this point, so pages are ordered in
66             a PDF document in the order in which they are created rather than in the order
67             they are closed.
68              
69             Only the essential elements in the page dictionary are created here, all others
70             are either optional or can be inherited.
71              
72             The optional index value indicates the index in the parent list that this page
73             should be inserted (so that new pages need not be appended)
74              
75             =back
76              
77             =cut
78              
79             sub new {
80 0     0 1   my ($class, $pdf, $parent, $index) = @_;
81 0           my $self = {};
82              
83 0 0         $class = ref($class) if ref($class);
84 0           $self = $class->SUPER::new($pdf, $parent);
85 0           $self->{'Type'} = PDFName('Page');
86 0           delete $self->{'Count'};
87 0           delete $self->{'Kids'};
88 0           $parent->add_page($self, $index);
89            
90 0           return $self;
91             }
92              
93             # the add() method was deleted from PDF::API2 2.034, but it looks like it
94             # still may be used in Builder.pm! apparently calls Content.pm's add().
95              
96             #=head2 add
97             #
98             # $p->add($str)
99             #
100             #=over
101             #
102             #Adds the string to the currently active stream for this page. If no stream
103             #exists, then one is created and added to the list of streams for this page.
104             #
105             #The slightly cryptic name is an aim to keep it short given the number of times
106             #people are likely to have to type it.
107             #
108             #=back
109             #
110             #=cut
111             #
112             #sub add {
113             # my ($self, $string) = @_;
114             #
115             # my $dict = $self->{' curstrm'};
116             #
117             # unless (defined $dict) {
118             # $dict = PDF::Builder::Basic::PDF::Dict->new();
119             # foreach my $pdf (@{$self->{' destination_pdfs'}}) {
120             # $pdf->new_obj($dict);
121             # }
122             # $self->{'Contents'} = PDFArray() unless defined $self->{'Contents'};
123             # unless (ref($self->{'Contents'}) eq 'PDF::Builder::Basic::PDF::Array') {
124             # $self->{'Contents'} = PDFArray($self->{'Contents'});
125             # }
126             # $self->{'Contents'}->add_elements($dict);
127             # $self->{' curstrm'} = $dict;
128             # }
129             #
130             # $dict->{' stream'} .= $string;
131             #
132             # return $self;
133             #}
134              
135             =head2 ship_out
136              
137             $p->ship_out($pdf)
138              
139             =over
140              
141             Ships the page out to the given output file context
142              
143             =back
144              
145             =cut
146              
147             sub ship_out {
148 0     0 1   my ($self, $pdf) = @_;
149              
150 0           $pdf->ship_out($self);
151 0 0         if (defined $self->{'Contents'}) {
152 0           $pdf->ship_out($self->{'Contents'}->elements());
153             }
154              
155 0           return $self;
156             }
157              
158             1;