File Coverage

blib/lib/PDF/Imposition/Schema1x8x2.pm
Criterion Covered Total %
statement 41 41 100.0
branch 8 16 50.0
condition n/a
subroutine 7 7 100.0
pod 2 2 100.0
total 58 66 87.8


line stmt bran cond sub pod time code
1             package PDF::Imposition::Schema1x8x2;
2 3     3   2449 use strict;
  3         10  
  3         122  
3 3     3   22 use warnings;
  3         8  
  3         103  
4 3     3   22 use Moo;
  3         8  
  3         30  
5             with 'PDF::Imposition::Schema';
6              
7             =head1 NAME
8              
9             PDF::Imposition::Schema1x8x2 - fixed 16 pages signatures on a single sheet, with triple folding.
10              
11             =head1 SYNOPSIS
12              
13             use PDF::Imposition::Schema1x8x2;
14             my $imposer = PDF::Imposition::Schema1x8x2->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 a single sheet.
25              
26             Typical usage: print A6 on A3, then fold trice, first along the y
27             axys, then the x axys and finally the y axys again. You need to trim
28             the top and right margins before binding.
29              
30             Not suitable for home-printing because the spine is unstable unless
31             done by a machine.
32              
33             Visualization (the prefix C means logical page disposed
34             upside-down -- rotated 180 degrees):
35              
36              
37             +------+------+------+------+
38             | | | | |
39             | r5 | r12 | r9 | r8 |
40             | | | | |
41             +------+------+------+------+
42             | | | | |
43             | 4 | 13 | 16 | 1 |
44             | | | | |
45             +------+------+------+------+
46              
47             +------+------+------+------+
48             | | | | |
49             | r7 | r10 | r11 | r6 |
50             | | | | |
51             +------+------+------+------+
52             | | | | |
53             | 2 | 15 | 14 | 3 |
54             | | | | |
55             +------+------+------+------+
56              
57              
58             To complete the block of 16 logical pages, blank pages are inserted if
59             needed.
60              
61             =cut
62              
63             sub _do_impose {
64 2     2   8 my $self = shift;
65             # set the mediabox doubling them
66 2         46 $self->out_pdf_obj->mediabox(
67             $self->orig_width * 4,
68             $self->orig_height * 2,
69             );
70             # here we work with fixed signatures of 16, with the module
71 2         531 my $total = $self->total_pages;
72 2         92 my @pages = (1..$total);
73              
74             # loop over the pages and compose the 4 physical pages
75 2         13 while (@pages) {
76 3         368 my ($p1, $p2, $p3, $p4,
77             $p5, $p6, $p7, $p8,
78             $p9, $p10, $p11, $p12,
79             $p13, $p14, $p15, $p16) = splice @pages, 0, 16;
80 3         24 $self->_compose_eight($p4, $p13, $p16, $p1,
81             $p8, $p9, $p12, $p5);
82 3         1604 $self->_compose_eight($p2, $p15, $p14, $p3,
83             $p6, $p11, $p10, $p7);
84             }
85            
86             }
87              
88             sub _compose_eight {
89 6     6   28 my ($self, @seq) = @_;
90 6         16 my $chunk;
91 6         173 my $page = $self->out_pdf_obj->page;
92 6         4183 my $gfx = $page->gfx;
93              
94 6         1578 $chunk = $self->get_imported_page($seq[0]);
95 6 50       857791 $gfx->formimage($chunk, 0, 0) if $chunk;
96              
97 6         2865 $chunk = $self->get_imported_page($seq[1]);
98 6 50       51747 $gfx->formimage($chunk, $self->orig_width, 0) if $chunk;
99              
100 6         2646 $chunk = $self->get_imported_page($seq[2]);
101 6 50       44622 $gfx->formimage($chunk, $self->orig_width * 2, 0) if $chunk;
102              
103 6         2694 $chunk = $self->get_imported_page($seq[3]);
104 6 50       46231 $gfx->formimage($chunk, $self->orig_width * 3, 0) if $chunk;
105              
106             # translate
107 6         2368 $gfx->transform (
108             -translate => [$self->orig_width * 4,
109             $self->orig_height * 2],
110             -rotate => 180,
111             );
112              
113 6         5288 $chunk = $self->get_imported_page($seq[4]);
114 6 50       54546 $gfx->formimage($chunk, 0, 0) if $chunk;
115            
116 6         2274 $chunk = $self->get_imported_page($seq[5]);
117 6 50       54554 $gfx->formimage($chunk, $self->orig_width, 0) if $chunk;
118              
119 6         2370 $chunk = $self->get_imported_page($seq[6]);
120 6 50       54094 $gfx->formimage($chunk, $self->orig_width * 2, 0) if $chunk;
121              
122 6         2401 $chunk = $self->get_imported_page($seq[7]);
123 6 50       53919 $gfx->formimage($chunk, $self->orig_width * 3, 0) if $chunk;
124              
125              
126              
127             }
128              
129             =head1 INTERNALS
130              
131             =head2 pages_per_sheet
132              
133             Returns 16
134              
135             =head2 cropmarks_options
136              
137             Set inner to false and force signature to 16.
138              
139             =cut
140              
141              
142 1     1 1 4 sub pages_per_sheet { 16 }
143              
144             sub cropmarks_options {
145 1     1 1 12 my %options = (
146             top => 1,
147             bottom => 1,
148             inner => 0,
149             outer => 1,
150             # no shifting need
151             twoside => 1,
152             signature => 16,
153             );
154 1         22 return %options;
155             }
156              
157              
158              
159              
160             1;
161              
162             =head1 SEE ALSO
163              
164             L
165              
166             =cut
167              
168