File Coverage

blib/lib/PDF/API3/Compat/API2/Basic/PDF/Page.pm
Criterion Covered Total %
statement 15 43 34.8
branch 0 10 0.0
condition n/a
subroutine 5 8 62.5
pod 3 3 100.0
total 23 64 35.9


line stmt bran cond sub pod time code
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             #=======================================================================
12             #
13             # THIS IS A REUSED PERL MODULE, FOR PROPER LICENCING TERMS SEE BELOW:
14             #
15             #
16             # Copyright Martin Hosken
17             #
18             # No warranty or expression of effectiveness, least of all regarding
19             # anyone's safety, is implied in this software or documentation.
20             #
21             # This specific module is licensed under the Perl Artistic License.
22             #
23             #
24             # $Id: Page.pm,v 2.0 2005/11/16 02:16:00 areibens Exp $
25             #
26             #=======================================================================
27             package PDF::API3::Compat::API2::Basic::PDF::Page;
28            
29 1     1   6 use strict;
  1         1  
  1         39  
30 1     1   5 use vars qw(@ISA);
  1         2  
  1         48  
31             @ISA = qw(PDF::API3::Compat::API2::Basic::PDF::Pages);
32 1     1   5 no warnings qw[ deprecated recursion uninitialized ];
  1         1  
  1         46  
33 1     1   695 use PDF::API3::Compat::API2::Basic::PDF::Pages;
  1         3  
  1         32  
34            
35 1     1   7 use PDF::API3::Compat::API2::Basic::PDF::Utils;
  1         1  
  1         418  
36            
37             =head1 NAME
38            
39             PDF::API3::Compat::API2::Basic::PDF::Page - Represents a PDF page, inherits from L
40            
41             =head1 DESCRIPTION
42            
43             Represents a page of output in PDF. It also keeps track of the content stream,
44             any resources (such as fonts) being switched, etc.
45            
46             Page inherits from Pages due to a number of shared methods. They are really
47             structurally quite different.
48            
49             =head1 INSTANCE VARIABLES
50            
51             A page has various working variables:
52            
53             =item curstrm
54            
55             The currently open stream
56            
57             =head1 METHODS
58            
59             =head2 PDF::API3::Compat::API2::Basic::PDF::Page->new($pdf, $parent, $index)
60            
61             Creates a new page based on a pages object (perhaps the root object).
62            
63             The page is also added to the parent at this point, so pages are ordered in
64             a PDF document in the order in which they are created rather than in the order
65             they are closed.
66            
67             Only the essential elements in the page dictionary are created here, all others
68             are either optional or can be inherited.
69            
70             The optional index value indicates the index in the parent list that this page
71             should be inserted (so that new pages need not be appended)
72            
73             =cut
74            
75             sub new
76             {
77 0     0 1   my ($class, $pdf, $parent, $index) = @_;
78 0           my ($self) = {};
79            
80 0 0         $class = ref $class if ref $class;
81 0           $self = $class->SUPER::new($pdf, $parent);
82 0           $self->{'Type'} = PDFName('Page');
83 0           delete $self->{'Count'};
84 0           delete $self->{'Kids'};
85 0           $parent->add_page($self, $index);
86 0           $self;
87             }
88            
89            
90             =head2 $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             {
102 0     0 1   my ($self, $str) = @_;
103 0           my ($strm) = $self->{' curstrm'};
104            
105 0 0         if (!defined $strm)
106             {
107 0           $strm = PDF::API3::Compat::API2::Basic::PDF::Dict->new;
108 0           foreach (@{$self->{' outto'}})
  0            
109 0           { $_->new_obj($strm); }
110 0 0         $self->{'Contents'} = PDFArray() unless defined $self->{'Contents'};
111 0 0         unless (ref $self->{'Contents'} eq "PDF::API3::Compat::API2::Basic::PDF::Array")
112 0           { $self->{'Contents'} = PDFArray($self->{'Contents'}); }
113 0           $self->{'Contents'}->add_elements($strm);
114 0           $self->{' curstrm'} = $strm;
115             }
116            
117 0           $strm->{' stream'} .= $str;
118 0           $self;
119             }
120            
121            
122             =head2 $p->ship_out($pdf)
123            
124             Ships the page out to the given output file context
125            
126             =cut
127            
128             sub ship_out
129             {
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'}->elementsof); }
135 0           $self;
136             }
137            
138