File Coverage

blib/lib/PDF/Imposition/Schema2x4x2.pm
Criterion Covered Total %
statement 35 35 100.0
branch 8 8 100.0
condition n/a
subroutine 7 7 100.0
pod 2 2 100.0
total 52 52 100.0


line stmt bran cond sub pod time code
1             package PDF::Imposition::Schema2x4x2;
2 3     3   2261 use strict;
  3         9  
  3         112  
3 3     3   23 use warnings;
  3         8  
  3         105  
4 3     3   21 use Moo;
  3         8  
  3         28  
5             with 'PDF::Imposition::Schema';
6              
7             =head1 NAME
8              
9             PDF::Imposition::Schema2x4x2 - fixed size 16 pages on 2 sheets signature schema, with double folding.
10              
11             =head1 SYNOPSIS
12              
13             use PDF::Imposition::Schema2x4x2;
14             my $imposer = PDF::Imposition::Schema2x4x2->new(
15             file => "test.pdf",
16             output => "out.pdf",
17             );
18             $imposer->impose;
19              
20             The output pdf will be left in C<< $imposer->output >>
21              
22             =head1 SCHEMA EXPLANATION
23              
24             Fixed signature size of 16 pages, printed recto-verso on 2 sheets.
25              
26             Typical usage: print A5 on A3, or A6 on A4, then fold twice and cut
27             the edges.
28              
29             Visualization (the prefix C means logical page disposed
30             upside-down -- rotated 180 degrees):
31              
32              
33             +------+------+ +------+------+
34             | | | | | |
35             | r9 | r8 | | r7 | r10 |
36             | | | | | |
37             +------+------+ +------+------+
38             | | | | | |
39             | 16 | 1 | | 2 | 15 |
40             | | | | | |
41             +------+------+ +------+------+
42              
43             +------+------+ +------+------+
44             | | | | | |
45             | r11 | r6 | | r5 | r12 |
46             | | | | | |
47             +------+------+ +------+------+
48             | | | | | |
49             | 14 | 3 | | 4 | 13 |
50             | | | | | |
51             +------+------+ +------+------+
52              
53              
54             To complete the block of 16 logical pages, blank pages are inserted if
55             needed.
56              
57             =cut
58              
59             sub _do_impose {
60 2     2   5 my $self = shift;
61             # set the mediabox doubling them
62 2         34 $self->out_pdf_obj->mediabox(
63             $self->orig_width * 2,
64             $self->orig_height * 2,
65             );
66             # here we work with fixed signatures of 16, with the module
67 2         321 my $total = $self->total_pages;
68 2         57 my @pages = (1..$total);
69              
70             # loop over the pages and compose the 4 physical pages
71 2         8 while (@pages) {
72 4         727 my ($p1, $p2, $p3, $p4,
73             $p5, $p6, $p7, $p8,
74             $p9, $p10, $p11, $p12,
75             $p13, $p14, $p15, $p16) = splice @pages, 0, 16;
76             # initialize
77 4         19 $self->_compose_quadruple($p16, $p1, $p8, $p9);
78 4         1653 $self->_compose_quadruple($p2, $p15, $p10, $p7);
79 4         1917 $self->_compose_quadruple($p14, $p3, $p6, $p11);
80 4         1953 $self->_compose_quadruple($p4, $p13, $p12, $p5);
81             }
82             }
83              
84             sub _compose_quadruple {
85 36     36   126 my ($self, @seq) = @_;
86 36         84 my $chunk;
87 36         855 my $page = $self->out_pdf_obj->page;
88 36         20063 my $gfx = $page->gfx;
89              
90 36         7189 $chunk = $self->get_imported_page($seq[0]);
91 36 100       1856334 $gfx->formimage($chunk, 0, 0) if $chunk;
92              
93 36         12752 $chunk = $self->get_imported_page($seq[1]);
94 36 100       237734 $gfx->formimage($chunk, $self->orig_width, 0) if $chunk;
95              
96             # translate
97 36         13167 $gfx->transform (
98             -translate => [$self->orig_width * 2,
99             $self->orig_height * 2],
100             -rotate => 180,
101             );
102              
103 36         28974 $chunk = $self->get_imported_page($seq[2]);
104 36 100       231140 $gfx->formimage($chunk, 0, 0) if $chunk;
105            
106 36         11842 $chunk = $self->get_imported_page($seq[3]);
107 36 100       237045 $gfx->formimage($chunk, $self->orig_width, 0) if $chunk;
108             }
109              
110             =head1 INTERNALS
111              
112             =head2 pages_per_sheet
113              
114             Returns 8
115              
116             =head2 cropmarks_options
117              
118             Set inner to false and force signature to 16.
119              
120             =cut
121              
122              
123             sub cropmarks_options {
124 2     2 1 18 my %options = (
125             top => 1,
126             bottom => 1,
127             inner => 0,
128             outer => 1,
129             twoside => 1,
130             signature => 16,
131             );
132 2         29 return %options;
133             }
134              
135 2     2 1 6 sub pages_per_sheet { 8 };
136              
137             1;
138              
139             =head1 SEE ALSO
140              
141             L
142              
143             =cut
144              
145