API3/Compat/API2/Basic/PDF/Page.pm

filter: Statementstmt 36.3% 16 / 44 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 62.5% 5 / 8 Podpod 100% 3 / 3 totaltotal 36.9% 24 / 65 CC 7 SCAR 25.5
CC
7
Cov
30%
add
30.0
new
6.0
ship_out
6.0
CRAP 12.8
« API3/Compat/API2/Resource/XObject/Form/BarCode/code3of9.pm ↑ Summary API3/Compat/API2/Basic/TTF/Mort/Contextual.pm »
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 <Martin_Hosken@sil.org>
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 @ISA = qw(PDF::API3::Compat::API2::Basic::PDF::Pages);
32 1 ▶no warnings qw[ deprecated recursion uninitialized ];
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶use PDF::API3::Compat::API2::Basic::PDF::Pages;
Subroutine BEGIN: called CC=1 SCAR=0.0
34
35 1 ▶use PDF::API3::Compat::API2::Basic::PDF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
36
37 =head1 NAME
38
39 PDF::API3::Compat::API2::Basic::PDF::Page - Represents a PDF page, inherits from L<PDF::API3::Compat::API2::Basic::PDF::Pages>
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 0 ▶{
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
77 0 my ($class, $pdf, $parent, $index) = @_;
78 0 my ($self) = {};
79
80 0 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
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 0 ▶{
Subroutine add: not called CC=5 SCAR=34.0
Pod documented
102 0 my ($self, $str) = @_;
103 0 my ($strm) = $self->{' curstrm'};
104
105 0 ▶ if (!defined $strm)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $strm) 0 0 0
106 {
107 0 $strm = PDF::API3::Compat::API2::Basic::PDF::Dict->new;
108 0 foreach (@{$self->{' outto'}})
109 0 { $_->new_obj($strm); }
110 0 ▶ $self->{'Contents'} = PDFArray() unless defined $self->{'Contents'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"Contents"} 0 0 0
111 0 ▶ unless (ref $self->{'Contents'} eq "PDF::API3::Compat::API2::Basic::PDF::Array")
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self->{"Contents"} eq "PDF::API3::Compat::API2::Basic::PDF::Array") 0 0 0
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 0 ▶{
Subroutine ship_out: not called CC=2 SCAR=17.9
Pod documented
130 0 my ($self, $pdf) = @_;
131
132 0 $pdf->ship_out($self);
133 0 ▶ if (defined $self->{'Contents'})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"Contents"}) 0 0 0
134 0 { $pdf->ship_out($self->{'Contents'}->elementsof); }
135 0 $self;
136 }
137
138
« API3/Compat/API2/Resource/XObject/Form/BarCode/code3of9.pm ↑ Summary API3/Compat/API2/Basic/TTF/Mort/Contextual.pm »