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   1893 use strict;
  3         6  
  3         90  
3 3     3   9 use warnings;
  3         4  
  3         73  
4 3     3   9 use Moo;
  3         4  
  3         22  
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   5 my $self = shift;
65             # set the mediabox doubling them
66 2         43 $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         332 my $total = $self->total_pages;
72 2         51 my @pages = (1..$total);
73              
74             # loop over the pages and compose the 4 physical pages
75 2         8 while (@pages) {
76 3         447 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         19 $self->_compose_eight($p4, $p13, $p16, $p1,
81             $p8, $p9, $p12, $p5);
82 3         942 $self->_compose_eight($p2, $p15, $p14, $p3,
83             $p6, $p11, $p10, $p7);
84             }
85            
86             }
87              
88             sub _compose_eight {
89 6     6   15 my ($self, @seq) = @_;
90 6         11 my $chunk;
91 6         142 my $page = $self->out_pdf_obj->page;
92 6         2070 my $gfx = $page->gfx;
93              
94 6         748 $chunk = $self->get_imported_page($seq[0]);
95 6 50       589656 $gfx->formimage($chunk, 0, 0) if $chunk;
96              
97 6         1807 $chunk = $self->get_imported_page($seq[1]);
98 6 50       38130 $gfx->formimage($chunk, $self->orig_width, 0) if $chunk;
99              
100 6         2005 $chunk = $self->get_imported_page($seq[2]);
101 6 50       30626 $gfx->formimage($chunk, $self->orig_width * 2, 0) if $chunk;
102              
103 6         1636 $chunk = $self->get_imported_page($seq[3]);
104 6 50       36813 $gfx->formimage($chunk, $self->orig_width * 3, 0) if $chunk;
105              
106             # translate
107 6         1693 $gfx->transform (
108             -translate => [$self->orig_width * 4,
109             $self->orig_height * 2],
110             -rotate => 180,
111             );
112              
113 6         2838 $chunk = $self->get_imported_page($seq[4]);
114 6 50       41681 $gfx->formimage($chunk, 0, 0) if $chunk;
115            
116 6         1631 $chunk = $self->get_imported_page($seq[5]);
117 6 50       44529 $gfx->formimage($chunk, $self->orig_width, 0) if $chunk;
118              
119 6         1795 $chunk = $self->get_imported_page($seq[6]);
120 6 50       49042 $gfx->formimage($chunk, $self->orig_width * 2, 0) if $chunk;
121              
122 6         1707 $chunk = $self->get_imported_page($seq[7]);
123 6 50       45166 $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 3 sub pages_per_sheet { 16 }
143              
144             sub cropmarks_options {
145 1     1 1 8 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         13 return %options;
155             }
156              
157              
158              
159              
160             1;
161              
162             =head1 SEE ALSO
163              
164             L
165              
166             =cut
167              
168