lib/PDF/Imposition/Schema4up.pm

filter: Statementstmt 97.7% 43 / 44 Branchbran 72.7% 16 / 22 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 84.1% 69 / 82 CC 14 SCAR 24.7
CC
14
Cov
86%
_do_impose
14.9
BEGIN
1.0
BEGIN
1.0
CRAP 11.8
↑ Summary lib/PDF/Imposition/Schema2up.pm »
1 package PDF::Imposition::Schema4up;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 extends 'PDF::Imposition::Schema2up';
7  
8 =head1 NAME
9  
10 PDF::Imposition::Schema4up - Imposition schema 4up (booklet)
11  
12 =head1 SYNOPSIS
13  
14 See L<PDF::Imposition>.
15  
16 =head1 SCHEMA EXPLANATION
17  
18 This schema is basically the same (with the same options and features)
19 of L<PDF::Imposition::Schema2up>. But while with the C<2up> schema you
20 get 2 logical pages on each physical page, with the C<4up> you get 4
21 pages on each side of the sheet. Hence, the signature must be a
22 multiple of 8.
23  
24 To actually use this schema, paper cutting is needed. First print
25 recto-verso, then cut horizontally and put the lower stack on the
26 upper one and proceed as you would with the C<2up>.
27  
28 It's basically a shortcut to save paper if you impose, e.g. A6 on A4.
29  
30  
31 RECTO VERSO
32 +-----+-----+ +-----+-----+
33 | | | | | |
34 | 8 | 1 | | 2 | 7 |
35 | | | | | |
36 8<----+---->8 8<----+---->8
37 | | | | | |
38 | 6 | 3 | | 4 | 5 |
39 | | | | | |
40 +-----+-----+ +-----+-----+
41  
42 =head2 INTERNALS
43  
44 =head3 pages_per_sheet
45  
46 Always return 8.
47  
48  
49 =cut
50  
51 26 ▶sub pages_per_sheet { 8 };
Subroutine pages_per_sheet: called CC=1 SCAR=0.0
Pod documented
52  
53 6 ▶sub _do_impose {
Subroutine _do_impose: called CC=14 SCAR=27.0
54 6 my $self = shift;
55 # each physical page, 4 logical pages, recto-verso = 8
56 6 ▶ die if $self->pages_per_sheet != 8;
Branch: 1 branch
BranchTrueFalseTotal
if $self->pages_per_sheet != 8 0 6 6
57 6 ▶ if ($self->computed_signature % 8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->computed_signature % 8) 0 6 6
58 0 die "Signature must be a multiple of 8!\n";
59 }
60  
61 $self->out_pdf_obj->mediabox(
62 6 $self->orig_width * 2,
63 $self->orig_height * 2,
64 );
65 # get the 2up sequence
66 6 my @seq = @{ $self->page_sequence_for_booklet };
67  
68 6 ▶ die "Number of pages is off : " . scalar(@seq) . " should be a multiple of 2!"
Branch: 1 branch
BranchTrueFalseTotal
if @seq % 2 0 6 6
69 if @seq % 2;
70 6 my $half = @seq / 2;
71  
72 6 my @upper = splice @seq, 0, $half;
73 6 my @lower = splice @seq;
74  
75 6 ▶ die "Odd arrays!" if @upper != @lower;
Branch: 1 branch
BranchTrueFalseTotal
if @upper != @lower 0 6 6
76 6 my @final_seq;
77 6 ▶ while (@upper && @lower) {
Branch: 1 branch
BranchTrueFalseTotal
if (@upper and @lower) 26 6 32
Condition66%2/3
@upper and @lower
!ll&&!rl&&r
6026
MC/DC50%1/2
@upper and @lower
@upper @lower
Truth table66%2/3
A and B
A= @upperB= @lower
ABresult
0X0
100
111
78 26 push @final_seq, [ @{ shift(@upper) }, @{ shift(@lower) } ];
79 }
80 6 ▶ die "Odd arrays!" if @upper || @lower;
Branch: 1 branch
BranchTrueFalseTotal
if @upper or @lower 0 6 6
Condition33%1/3
@upper or @lower
l!l&&r!l&&!r
006
MC/DC0%0/2
@upper or @lower
@upper @lower
Truth table33%1/3
A or B
A= @upperB= @lower
ABresult
1X1
011
000
81 6 ▶ while (@final_seq) {
Branch: 1 branch
BranchTrueFalseTotal
if (@final_seq) 26 6 32
82 26 my ($page, $gfx, $chunk);
83 26 $page = $self->out_pdf_obj->page;
84 26 $gfx = $page->gfx;
85 26 my ($one, $two, $three, $four) = @{ shift(@final_seq) };
86 26 $chunk = $self->get_imported_page($three);
87 26 ▶ $gfx->formimage($chunk, 0, 0) if $chunk;
Branch: 1 branch
BranchTrueFalseTotal
if $chunk 22 4 26
88  
89 26 $chunk = $self->get_imported_page($four);
90 26 ▶ $gfx->formimage($chunk, $self->orig_width, 0) if $chunk;
Branch: 1 branch
BranchTrueFalseTotal
if $chunk 22 4 26
91  
92 26 $chunk = $self->get_imported_page($two);
93 26 ▶ $gfx->formimage($chunk,
Branch: 1 branch
BranchTrueFalseTotal
if $chunk 24 2 26
94 $self->orig_width,
95 $self->orig_height) if $chunk;
96  
97 26 $chunk = $self->get_imported_page($one);
98 26 ▶ $gfx->formimage($chunk,
Branch: 1 branch
BranchTrueFalseTotal
if $chunk 26 0 26
99 0,
100 $self->orig_height) if $chunk;
101 }
102 }
103  
104  
105 3 1;
↑ Summary lib/PDF/Imposition/Schema2up.pm »