| 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::Pages; | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 40 | ▶ | use base 'PDF::Builder::Basic::PDF::Dict'; | ||||||||||||||||||||||||||||||||||||||||
|
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::Array; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 40 | ▶ | use PDF::Builder::Basic::PDF::Dict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 40 | ▶ | use PDF::Builder::Basic::PDF::Utils; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 40 | ▶ | use Scalar::Util qw(weaken); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 40 | our %inst = map {$_ => 1} qw(Parent Type); | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | PDF::Builder::Basic::PDF::Pages - PDF pages hierarchical element | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | Inherits from L<PDF::Builder::Basic::PDF::Dict> | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | A Pages object is the parent to other pages objects or to page objects | ||||||||||||||||||||||||||||||||||||||||||
| 43 | themselves. | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | PDF::Builder::Basic::PDF::Pages->new($pdf, $parent) | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | This creates a new Pages object in a PDF. Notice that the C<$parent> here is | ||||||||||||||||||||||||||||||||||||||||||
| 54 | not the file context for the object, but the parent pages object for these | ||||||||||||||||||||||||||||||||||||||||||
| 55 | pages. If we are using this class to create a root node, C<$parent> should | ||||||||||||||||||||||||||||||||||||||||||
| 56 | point to the file context, which is identified by I<not> having a Type of | ||||||||||||||||||||||||||||||||||||||||||
| 57 | I<Pages>. C<$pdf> is the file object (or a reference to an array of I<one> | ||||||||||||||||||||||||||||||||||||||||||
| 58 | file object [3.016 and later, or multiple file objects earlier]) in which to | ||||||||||||||||||||||||||||||||||||||||||
| 59 | create the new Pages object. | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 426 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=9 SCAR=23.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 426 | my ($class, $pdf, $parent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 426 | ▶ | $pdf //= $class->get_top()->{' parent'} if ref($class); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$pdf //= $class->get_top->{" parent"}
MC/DC0%0/2
$pdf //= $class->get_top->{" parent"}
$pdf
$class->get_top->{" parent"}
Truth table0%0/3
A //= B
A= $pdfB= $class->get_top->{" parent"}
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | # before PDF::API2 2.034/PDF::Builder 3.016, $pdf could be an array of PDFs | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 426 | ▶ | if (ref($pdf) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | die 'Pages: Only one PDF is supported as of version 3.016' if scalar(@$pdf) > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ($pdf) = @$pdf; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 426 | ▶ | $class = ref($class) if ref($class); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 426 | my $self = $class->SUPER::new($pdf, $parent); | |||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 426 | $self->{'Type'} = PDFName('Pages'); | |||||||||||||||||||||||||||||||||||||||||
| 79 | 426 | ▶ | $self->{'Parent'} = $parent if defined $parent; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 426 | $self->{'Count'} = PDFNum(0); | |||||||||||||||||||||||||||||||||||||||||
| 81 | 426 | $self->{'Kids'} = PDF::Builder::Basic::PDF::Array->new(); | |||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 426 | $pdf->new_obj($self); | |||||||||||||||||||||||||||||||||||||||||
| 84 | 426 | ▶ | unless (defined $self->{'Parent'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 234 | $pdf->{'Root'}->{'Pages'} = $self; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 234 | $pdf->out_obj($pdf->{'Root'}); | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 234 | $self->{' parent'} = $pdf; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 234 | weaken $self->{' parent'}; | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 426 | ▶ | weaken $self->{'Parent'} if defined $parent; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 426 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | #sub init { | ||||||||||||||||||||||||||||||||||||||||||
| 97 | # my ($self, $pdf) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 98 | # $self->{' destination_pdfs'} = [$pdf]; | ||||||||||||||||||||||||||||||||||||||||||
| 99 | # weaken $self->{' destination_pdfs'}->[0] if defined $pdf; | ||||||||||||||||||||||||||||||||||||||||||
| 100 | # | ||||||||||||||||||||||||||||||||||||||||||
| 101 | # return $self; | ||||||||||||||||||||||||||||||||||||||||||
| 102 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | #=head2 out_obj | ||||||||||||||||||||||||||||||||||||||||||
| 105 | # | ||||||||||||||||||||||||||||||||||||||||||
| 106 | # $p->out_obj($is_new) | ||||||||||||||||||||||||||||||||||||||||||
| 107 | # | ||||||||||||||||||||||||||||||||||||||||||
| 108 | #=over | ||||||||||||||||||||||||||||||||||||||||||
| 109 | # | ||||||||||||||||||||||||||||||||||||||||||
| 110 | #Tells all the files that this thing is destined for that they should output this | ||||||||||||||||||||||||||||||||||||||||||
| 111 | #object, come time to output. If this object has no parent, then it must be the | ||||||||||||||||||||||||||||||||||||||||||
| 112 | #root. So set as the root for the files in question and tell it to be output too. | ||||||||||||||||||||||||||||||||||||||||||
| 113 | #If C<$is_new> is set, then call C<new_obj> rather than C<out_obj> to create as | ||||||||||||||||||||||||||||||||||||||||||
| 114 | #a new object in the file. | ||||||||||||||||||||||||||||||||||||||||||
| 115 | # | ||||||||||||||||||||||||||||||||||||||||||
| 116 | #=back | ||||||||||||||||||||||||||||||||||||||||||
| 117 | # | ||||||||||||||||||||||||||||||||||||||||||
| 118 | #=cut | ||||||||||||||||||||||||||||||||||||||||||
| 119 | # | ||||||||||||||||||||||||||||||||||||||||||
| 120 | #sub out_obj { | ||||||||||||||||||||||||||||||||||||||||||
| 121 | # my ($self, $is_new) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 122 | # | ||||||||||||||||||||||||||||||||||||||||||
| 123 | # foreach my $pdf (@{$self->{' destination_pdfs'}}) { | ||||||||||||||||||||||||||||||||||||||||||
| 124 | # if ($is_new) { | ||||||||||||||||||||||||||||||||||||||||||
| 125 | # $pdf->new_obj($self); | ||||||||||||||||||||||||||||||||||||||||||
| 126 | # } else { | ||||||||||||||||||||||||||||||||||||||||||
| 127 | # $pdf->out_obj($self); | ||||||||||||||||||||||||||||||||||||||||||
| 128 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | # | ||||||||||||||||||||||||||||||||||||||||||
| 130 | # unless (defined $self->{'Parent'}) { | ||||||||||||||||||||||||||||||||||||||||||
| 131 | # $pdf->{'Root'}{'Pages'} = $self; | ||||||||||||||||||||||||||||||||||||||||||
| 132 | # $pdf->out_obj($pdf->{'Root'}); | ||||||||||||||||||||||||||||||||||||||||||
| 133 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | # | ||||||||||||||||||||||||||||||||||||||||||
| 136 | # return $self; | ||||||||||||||||||||||||||||||||||||||||||
| 137 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 576 | ▶ | sub _pdf { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pdf: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 576 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 576 | return $self->get_top()->{' parent'}; | |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | =head2 find_page | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | $p->find_page($page_number) | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | Returns the given page, using the page count values in the pages tree. Pages | ||||||||||||||||||||||||||||||||||||||||||
| 151 | start at 0. | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 192 | ▶ | sub find_page { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_page: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 192 | my ($self, $page_number) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 192 | my $top = $self->get_top(); | |||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 192 | return $top->find_page_recursively(\$page_number); | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 192 | ▶ | sub find_page_recursively { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_page_recursively: called CC=6 SCAR=22.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 192 | my ($self, $page_number_ref) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 192 | ▶ | if ($self->{'Count'}->realise()->val() <= $$page_number_ref) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | $$page_number_ref -= $self->{'Count'}->val(); | |||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 192 | my $result; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 192 | foreach my $kid ($self->{'Kids'}->realise()->elements()) { | |||||||||||||||||||||||||||||||||||||||||
| 174 | 12 | ▶ | if ($kid->{'Type'}->realise()->val() eq 'Page') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 12 | ▶ | return $kid if $$page_number_ref == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | $$page_number_ref--; | |||||||||||||||||||||||||||||||||||||||||
| 177 | } elsif ($result = $kid->realise()->find_page_recursively($page_number_ref)) { | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 180 | return; | |||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | =head2 add_page | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | $p->add_page($page, $page_number) | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | Inserts the page before the given C<$page_number>. C<$page_number> can be | ||||||||||||||||||||||||||||||||||||||||||
| 192 | negative to count backwards from the END of the document. -1 is after the last | ||||||||||||||||||||||||||||||||||||||||||
| 193 | page. Likewise C<$page_number> can be greater than the number of pages | ||||||||||||||||||||||||||||||||||||||||||
| 194 | currently in the document, to append. | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | This method only guarantees to provide a reasonable pages tree if pages are | ||||||||||||||||||||||||||||||||||||||||||
| 197 | appended or prepended to the document. Pages inserted in the middle of the | ||||||||||||||||||||||||||||||||||||||||||
| 198 | document may simply be inserted in the appropriate leaf in the pages tree | ||||||||||||||||||||||||||||||||||||||||||
| 199 | without adding any new branches or leaves, leaving it unbalanced (slower | ||||||||||||||||||||||||||||||||||||||||||
| 200 | performance, but still usable). | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | # -- removed from end of second para: | ||||||||||||||||||||||||||||||||||||||||||
| 207 | #To tidy up such a mess, it is best | ||||||||||||||||||||||||||||||||||||||||||
| 208 | #to call C<$p->rebuild_tree()> to rebuild the pages tree into something | ||||||||||||||||||||||||||||||||||||||||||
| 209 | #efficient. B<Note that C<rebuild_tree> is currently a no-op!> | ||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | 192 | ▶ | sub add_page { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_page: called CC=11 SCAR=24.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 192 | my ($self, $page, $page_number) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 213 | 192 | my $top = $self->get_top(); | |||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 192 | ▶ | $page_number = -1 unless defined $page_number and $page_number <= $top->{'Count'}->val(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $page_number and $page_number <= $top->{"Count"}->val
MC/DC50%1/2
defined $page_number and $page_number <= $top->{"Count"}->val
defined $page_number
$page_number <= $top->{"Count"}->val
Truth table66%2/3
A and B
A= defined $page_numberB= $page_number <= $top->{"Count"}->val
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 192 | my $previous_page; | |||||||||||||||||||||||||||||||||||||||||
| 218 | 192 | ▶ | if ($page_number == -1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 190 | $previous_page = $top->find_page($top->{'Count'}->val() - 1); | |||||||||||||||||||||||||||||||||||||||||
| 220 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 2 | ▶ | $page_number = $top->{'Count'}->val() + $page_number + 1 if $page_number < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 2 | $previous_page = $top->find_page($page_number); | |||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 192 | my $parent; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 192 | ▶ | if (defined $previous_page->{'Parent'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 12 | $parent = $previous_page->{'Parent'}->realise(); | |||||||||||||||||||||||||||||||||||||||||
| 228 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 229 | 180 | $parent = $self; | |||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 192 | my $parent_kid_count = scalar $parent->{'Kids'}->realise()->elements(); | |||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 192 | my $page_index; | |||||||||||||||||||||||||||||||||||||||||
| 235 | 192 | ▶ | if ($page_number == -1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 190 | $page_index = -1; | |||||||||||||||||||||||||||||||||||||||||
| 237 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 2 | ▶ | for ($page_index = 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | $page_index < $parent_kid_count; | ||||||||||||||||||||||||||||||||||||||||||
| 240 | $page_index++) { | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 2 | ▶ | last if $parent->{'Kids'}{' val'}[$page_index] eq $previous_page; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 2 | ▶ | $page_index = -1 if $page_index == $parent_kid_count; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 192 | $parent->add_page_recursively($page->realise(), $page_index); | |||||||||||||||||||||||||||||||||||||||||
| 247 | 192 | ▶ | for ($parent = $page->{'Parent'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | defined $parent->{'Parent'}; | ||||||||||||||||||||||||||||||||||||||||||
| 249 | $parent = $parent->{'Parent'}->realise()) { | ||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | $parent->set_modified(); | |||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | $parent->{'Count'}->realise()->{'val'}++; | |||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 192 | $parent->set_modified(); | |||||||||||||||||||||||||||||||||||||||||
| 254 | 192 | $parent->{'Count'}->realise()->{'val'}++; | |||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 192 | return $page; | |||||||||||||||||||||||||||||||||||||||||
| 257 | } # end of add_page() | ||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | 192 | ▶ | sub add_page_recursively { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_page_recursively: called CC=8 SCAR=28.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | 192 | my ($self, $page, $page_index) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 192 | my $parent = $self; | |||||||||||||||||||||||||||||||||||||||||
| 263 | 192 | my $max_kids_per_parent = 8; # Why 8? effort to somewhat balance tree? | |||||||||||||||||||||||||||||||||||||||||
| 264 | 192 | ▶ | if (scalar $parent->{'Kids'}->elements() >= $max_kids_per_parent and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
scalar $parent->{"Kids"}->elements >= $max_kids_per_parent and $parent->{"Parent"} and $page_index < 0
scalar $parent->{"Kids"}->elements >= $max_kids_per_parent and $parent->{"Parent"}
MC/DC0%0/3
scalar $parent->{"Kids"}->elements >= $max_kids_per_parent and $parent->{"Parent"} and $page_index < 0
scalar $parent->{"Kids"}->elements >= $max_kids_per_parent
$parent->{"Parent"}
$page_index < 0
Truth table25%1/4
A and B and C
A= scalar $parent->{"Kids"}->elements >= $max_kids_per_parentB= $parent->{"Parent"}C= $page_index < 0
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | $parent->{'Parent'} and | ||||||||||||||||||||||||||||||||||||||||||
| 266 | $page_index < 0) { | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | my $grandparent = $parent->{'Parent'}->realise(); | |||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | $parent = $parent->new($parent->_pdf(), $grandparent); | |||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | my $grandparent_kid_count = scalar $grandparent->{'Kids'}->realise()->elements(); | |||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | my $new_parent_index; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | for ($new_parent_index = 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | $new_parent_index < $grandparent_kid_count; | ||||||||||||||||||||||||||||||||||||||||||
| 274 | $new_parent_index++) { | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | last if $grandparent->{'Kids'}{' val'}[$new_parent_index] eq $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | $new_parent_index++; | |||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | $new_parent_index = -1 if $new_parent_index > $grandparent_kid_count; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | $grandparent->add_page_recursively($parent, $new_parent_index); | |||||||||||||||||||||||||||||||||||||||||
| 280 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 192 | $parent->set_modified(); | |||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 192 | ▶ | if ($page_index < 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 190 | push @{$parent->{'Kids'}->realise()->{' val'}}, $page; | |||||||||||||||||||||||||||||||||||||||||
| 286 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 287 | 2 | splice @{$parent->{'Kids'}{' val'}}, $page_index, 0, $page; | |||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | 192 | $page->{'Parent'} = $parent; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 192 | weaken $page->{'Parent'}; | |||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | 192 | return; | |||||||||||||||||||||||||||||||||||||||||
| 293 | } # end of add_page_recursively() | ||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 384 | ▶ | sub set_modified { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_modified: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | 384 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 297 | 384 | $self->_pdf()->out_obj($self); | |||||||||||||||||||||||||||||||||||||||||
| 298 | 384 | return; | |||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | #=head2 rebuild_tree | ||||||||||||||||||||||||||||||||||||||||||
| 302 | # | ||||||||||||||||||||||||||||||||||||||||||
| 303 | # $root_pages = $p->rebuild_tree([@pglist]) | ||||||||||||||||||||||||||||||||||||||||||
| 304 | # | ||||||||||||||||||||||||||||||||||||||||||
| 305 | #=over | ||||||||||||||||||||||||||||||||||||||||||
| 306 | # | ||||||||||||||||||||||||||||||||||||||||||
| 307 | #B<WARNING: Not yet implemented. Do not attempt to use!> | ||||||||||||||||||||||||||||||||||||||||||
| 308 | # | ||||||||||||||||||||||||||||||||||||||||||
| 309 | #Rebuilds the pages tree to make a nice balanced tree that conforms to Adobe | ||||||||||||||||||||||||||||||||||||||||||
| 310 | #recommendations. If passed a C<@pglist> then the tree is built for that list of | ||||||||||||||||||||||||||||||||||||||||||
| 311 | #pages. No check is made of whether the C<@pglist> contains pages. | ||||||||||||||||||||||||||||||||||||||||||
| 312 | # | ||||||||||||||||||||||||||||||||||||||||||
| 313 | #Returns the top of the tree for insertion in the root object. | ||||||||||||||||||||||||||||||||||||||||||
| 314 | # | ||||||||||||||||||||||||||||||||||||||||||
| 315 | #=back | ||||||||||||||||||||||||||||||||||||||||||
| 316 | # | ||||||||||||||||||||||||||||||||||||||||||
| 317 | #=cut | ||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | # TBD where's the code? | ||||||||||||||||||||||||||||||||||||||||||
| 320 | #sub rebuild_tree { | ||||||||||||||||||||||||||||||||||||||||||
| 321 | # my ($self, @pglist) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 322 | # return; | ||||||||||||||||||||||||||||||||||||||||||
| 323 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | =head2 get_pages | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | @objects = $p->get_pages() | ||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | Returns a list of page objects in the document, in page order. | ||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | sub get_pages { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_pages: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | return $self->get_top()->get_pages_recursively(); | |||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | # Renamed for clarity. should this be deprecated? | ||||||||||||||||||||||||||||||||||||||||||
| 344 | # appears not to have been used, and was undocumented. | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | sub get_kids { return get_pages_recursively(@_); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_kids: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | sub get_pages_recursively { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_pages_recursively: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | my @pages; | |||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | foreach my $kid ($self->{'Kids'}->elements()) { | |||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | $kid->realise(); | |||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | ▶ | if ($kid->{'Type'}->val() eq 'Pages') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | push @pages, $kid->get_pages_recursively(); | |||||||||||||||||||||||||||||||||||||||||
| 355 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | push @pages, $kid; | |||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | return @pages; | |||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | =head2 find_prop | ||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | $p->find_prop($key) | ||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | Searches up through the inheritance tree to find a property (key). | ||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | 694 | ▶ | sub find_prop { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_prop: called CC=5 SCAR=16.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | 694 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | 694 | ▶ | if (defined $self->{$key}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | 242 | ▶ | if (ref($self->{$key}) and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $self->{$key} and $self->{$key}->isa("PDF::Builder::Basic::PDF::Objind")
MC/DC0%0/2
ref $self->{$key} and $self->{$key}->isa("PDF::Builder::Basic::PDF::Objind")
ref $self->{$key}
$self->{$key}->isa("PDF::Builder::Basic::PDF::Objind")
Truth table33%1/3
A and B
A= ref $self->{$key}B= $self->{$key}->isa("PDF::Builder::Basic::PDF::Objind")
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | $self->{$key}->isa('PDF::Builder::Basic::PDF::Objind')) { | ||||||||||||||||||||||||||||||||||||||||||
| 381 | 242 | return $self->{$key}->realise(); | |||||||||||||||||||||||||||||||||||||||||
| 382 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | return $self->{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | # Per Klaus Ethgen (RT 131147), this is an alternative patch for the | ||||||||||||||||||||||||||||||||||||||||||
| 386 | # problem of Null objects bubbling up. If Vadim Repin's patch in ./File.pm | ||||||||||||||||||||||||||||||||||||||||||
| 387 | # turns out to have too wide of scope, we might use this one instead. | ||||||||||||||||||||||||||||||||||||||||||
| 388 | # comment out 1, uncomment 2, and reverse change made in ./File.pm. | ||||||||||||||||||||||||||||||||||||||||||
| 389 | } elsif (defined $self->{'Parent'}) { | ||||||||||||||||||||||||||||||||||||||||||
| 390 | #} elsif (defined $self->{'Parent'} and | ||||||||||||||||||||||||||||||||||||||||||
| 391 | # ref($self->('Parent'}) ne 'PDF::Builder::Basic::PDF::Null') { | ||||||||||||||||||||||||||||||||||||||||||
| 392 | 208 | return $self->{'Parent'}->find_prop($key); | |||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | 244 | return; | |||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | =head2 add_font | ||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | $p->add_font($pdf, $font) | ||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | Creates or edits the resource dictionary at this level in the hierarchy. If | ||||||||||||||||||||||||||||||||||||||||||
| 405 | the font is already supported, even through the hierarchy, then it is not added. | ||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | B<CAUTION:> if this method was used in older releases, the code may have | ||||||||||||||||||||||||||||||||||||||||||
| 408 | swapped the order of C<$pdf> and C<$font>, requiring ad hoc swapping of | ||||||||||||||||||||||||||||||||||||||||||
| 409 | parameters in user code, contrary to the POD definition above. Now the code | ||||||||||||||||||||||||||||||||||||||||||
| 410 | matches the documentation. | ||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | ▶ | sub add_font { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_font: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | my ($self, $pdf, $font) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | my $name = $font->{'Name'}->val(); | |||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | my $dict = $self->find_prop('Resources'); | |||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | return $self if ($dict and | ||||||||||||||||||||||||||||||||||||||||||
| 423 | defined $dict->{'Font'} and | ||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | ▶ | defined $dict->{'Font'}{$name}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$dict and defined $dict->{"Font"} and defined $dict->{"Font"}{$name}
$dict and defined $dict->{"Font"}
MC/DC0%0/3
$dict and defined $dict->{"Font"} and defined $dict->{"Font"}{$name}
$dict
defined $dict->{"Font"}
defined $dict->{"Font"}{$name}
Truth table0%0/4
A and B and C
A= $dictB= defined $dict->{"Font"}C= defined $dict->{"Font"}{$name}
| |||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | ▶ | unless (defined $self->{'Resources'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | ▶ | $dict = $dict ? $dict->copy($pdf) : PDFDict(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | $self->{'Resources'} = $dict; | |||||||||||||||||||||||||||||||||||||||||
| 428 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | $dict = $self->{'Resources'}; | |||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | ▶ | $dict->{'Font'} //= PDFDict(); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$dict->{"Font"} //= PDFDict()
MC/DC0%0/2
$dict->{"Font"} //= PDFDict()
$dict->{"Font"}
PDFDict()
Truth table0%0/3
A //= B
A= $dict->{"Font"}B= PDFDict()
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | my $resource = $dict->{'Font'}->val(); | |||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | $resource->{$name} //= $font; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$resource->{$name} //= $font
MC/DC0%0/2
$resource->{$name} //= $font
$resource->{$name}
$font
Truth table0%0/3
A //= B
A= $resource->{$name}B= $font
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | ▶ | if (ref($dict) ne 'HASH' and $dict->is_obj($pdf)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $dict ne "HASH" and $dict->is_obj($pdf)
MC/DC0%0/2
ref $dict ne "HASH" and $dict->is_obj($pdf)
ref $dict ne "HASH"
$dict->is_obj($pdf)
Truth table0%0/3
A and B
A= ref $dict ne "HASH"B= $dict->is_obj($pdf)
| |||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | $pdf->out_obj($dict); | |||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | ▶ | if (ref($resource) ne 'HASH' and $resource->is_obj($pdf)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $resource ne "HASH" and $resource->is_obj($pdf)
MC/DC0%0/2
ref $resource ne "HASH" and $resource->is_obj($pdf)
ref $resource ne "HASH"
$resource->is_obj($pdf)
Truth table0%0/3
A and B
A= ref $resource ne "HASH"B= $resource->is_obj($pdf)
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | $pdf->out_obj($resource); | |||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 443 | } # end of add_font() | ||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||
| 445 | =head2 bbox | ||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | $p->bbox($xmin,$ymin, $xmax,$ymax, $param) | ||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | $p->bbox($xmin,$ymin, $xmax,$ymax) | ||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||
| 451 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | Specifies the bounding box for this and all child pages. If the values are | ||||||||||||||||||||||||||||||||||||||||||
| 454 | identical to those inherited, no change is made. C<$param> specifies the | ||||||||||||||||||||||||||||||||||||||||||
| 455 | attribute name so that other 'bounding box'es can be set with this method. | ||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||
| 459 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | ▶ | sub bbox { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bbox: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | my ($self, @bbox) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | ▶ | my $key = $bbox[4] || 'MediaBox'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$bbox[4] || 'MediaBox'
MC/DC0%0/1
$bbox[4] || 'MediaBox'
$bbox[4]
Truth table0%0/2
A
A= $bbox[4]
| |||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | my $inherited = $self->find_prop($key); | |||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | ▶ | if ($inherited) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | my $is_changed = 0; | |||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | foreach my $element ($inherited->elements()) { | |||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | ▶ | $is_changed = 1 unless $element->val() == $bbox[$i++]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | ▶ | return $self if $i == 4 and not $is_changed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$i == 4 and not $is_changed
MC/DC0%0/2
$i == 4 and not $is_changed
$i == 4
not $is_changed
Truth table0%0/3
A and not(B)
A= $i == 4B= not $is_changed
| |||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | my $array = PDF::Builder::Basic::PDF::Array->new(); | |||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | foreach my $element (@bbox[0 .. 3]) { | |||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | $array->add_elements(PDFNum($element)); | |||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | $self->{$key} = $array; | |||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | =head2 proc_set | ||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||
| 486 | $p->proc_set(@entries) | ||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||
| 490 | Ensures that the current resource contains all the entries in the proc_sets | ||||||||||||||||||||||||||||||||||||||||||
| 491 | listed. If necessary, it creates a local resource dictionary to achieve this. | ||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||
| 493 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||
| 495 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||
| 497 | 426 | ▶ | sub proc_set { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
proc_set: called CC=10 SCAR=23.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 498 | 426 | my ($self, @entries) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | 426 | my $dict = $self->find_prop('Resources'); | |||||||||||||||||||||||||||||||||||||||||
| 501 | 426 | ▶ | if ($dict and defined $dict->{'ProcSet'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$dict and defined $dict->{"ProcSet"}
MC/DC50%1/2
$dict and defined $dict->{"ProcSet"}
$dict
defined $dict->{"ProcSet"}
Truth table66%2/3
A and B
A= $dictB= defined $dict->{"ProcSet"}
| |||||||||||||||||||||||||||||||||||||||||||
| 502 | 192 | my @missing = @entries; | |||||||||||||||||||||||||||||||||||||||||
| 503 | 192 | foreach my $element ($dict->{'ProcSet'}->elements()) { | |||||||||||||||||||||||||||||||||||||||||
| 504 | 960 | @missing = grep { $_ ne $element } @missing; | |||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||
| 506 | 192 | ▶ | return $self if scalar @missing == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 507 | 192 | ▶ | @entries = @missing if defined $self->{'Resources'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||
| 510 | 426 | ▶ | unless (defined $self->{'Resources'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 511 | 426 | ▶ | $self->{'Resources'} = $dict ? $dict->copy($self->_pdf()) : PDFDict(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||
| 514 | 426 | ▶ | $self->{'Resources'}{'ProcSet'} = PDFArray() unless defined $self->{'ProcSet'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||
| 516 | 426 | foreach my $element (@entries) { | |||||||||||||||||||||||||||||||||||||||||
| 517 | 2130 | $self->{'Resources'}{'ProcSet'}->add_elements(PDFName($element)); | |||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||
| 520 | 426 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 521 | } # end of proc_set() | ||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | ▶ | sub empty { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
empty: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | my $parent = $self->{'Parent'}; | |||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | $self->SUPER::empty(); | |||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | ▶ | if (defined $parent) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | $self->{'Parent'} = $parent; | |||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | weaken $self->{'Parent'}; | |||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | =head2 get_top | ||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||
| 538 | $p->get_top() | ||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||
| 540 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||
| 542 | Returns the top of the pages tree. | ||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||
| 544 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||
| 546 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||
| 548 | 960 | ▶ | sub get_top { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_top: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 549 | 960 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | 960 | my $top = $self; | |||||||||||||||||||||||||||||||||||||||||
| 552 | 960 | ▶ | $top = $top->{'Parent'} while defined $top->{'Parent'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||
| 554 | 960 | return $top->realise(); | |||||||||||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||
| 557 | 40 | 1; | |||||||||||||||||||||||||||||||||||||||||