Builder/Basic/PDF/Page.pm

filter: Statementstmt 56.2% 18 / 32 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 5 / 7 Podpod 100% 2 / 2 totaltotal 55.5% 25 / 45 CC 3 SCAR 11.7
CC
3
Cov
50%
new
6.0
ship_out
6.0
BEGIN
1.0
CRAP 3.2
« Builder/Basic/PDF/Name.pm ↑ Summary Builder/Basic/PDF/Array.pm »
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 ▶use base 'PDF::Builder::Basic::PDF::Pages';
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 40 our $VERSION = '3.028'; # VERSION
24 40 our $LAST_UPDATE = '3.027'; # manually update whenever code is changed
25  
26 40 ▶use PDF::Builder::Basic::PDF::Dict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 40 ▶use PDF::Builder::Basic::PDF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
80 0 my ($class, $pdf, $parent, $index) = @_;
81 0 my $self = {};
82  
83 0 ▶ $class = ref($class) if ref($class);
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
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 0 ▶sub ship_out {
Subroutine ship_out: not called CC=2 SCAR=17.9
Pod documented
148 0 my ($self, $pdf) = @_;
149  
150 0 $pdf->ship_out($self);
151 0 ▶ if (defined $self->{'Contents'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"Contents"}) 0 0 0
152 0 $pdf->ship_out($self->{'Contents'}->elements());
153 }
154  
155 0 return $self;
156 }
157  
158 40 1;
« Builder/Basic/PDF/Name.pm ↑ Summary Builder/Basic/PDF/Array.pm »