File Coverage

blib/lib/PDF/Imposition/Schema2x4x1.pm
Criterion Covered Total %
statement 30 33 90.9
branch 8 8 100.0
condition n/a
subroutine 5 7 71.4
pod 2 2 100.0
total 45 50 90.0


line stmt bran cond sub pod time code
1             package PDF::Imposition::Schema2x4x1;
2 2     2   1465 use strict;
  2         5  
  2         70  
3 2     2   13 use warnings;
  2         5  
  2         57  
4 2     2   11 use Moo;
  2         4  
  2         16  
5             with 'PDF::Imposition::Schema';
6              
7             =head1 NAME
8              
9             PDF::Imposition::Schema2x4x1 - fixed size 8 pages on 1 sheet signature schema, with double folding.
10              
11             =head1 SYNOPSIS
12              
13             use PDF::Imposition::Schema2x4x1;
14             my $imposer = PDF::Imposition::Schema2x4x1->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 8 pages, printed recto-verso on 1 sheet.
25              
26             Typical usage: print A5 on A3, or A6 on A4, then fold twice and cut
27             the top edge.
28              
29             Visualization (the prefix C means logical page disposed
30             upside-down -- rotated 180 degrees):
31              
32              
33             +------+------+ +------+------+
34             | | | | | |
35             | r5 | r4 | | r3 | r6 |
36             | | | | | |
37             +------+------+ +------+------+
38             | | | | | |
39             | 8 | 1 | | 2 | 7 |
40             | | | | | |
41             +------+------+ +------+------+
42              
43              
44             To complete the block of 8 logical pages, blank pages are inserted if
45             needed.
46              
47             =cut
48              
49             sub _do_impose {
50 1     1   4 my $self = shift;
51             # set the mediabox doubling them
52 1         21 $self->out_pdf_obj->mediabox(
53             $self->orig_width * 2,
54             $self->orig_height * 2,
55             );
56             # here we work with fixed signatures of 8, with the module
57 1         213 my $total = $self->total_pages;
58 1         37 my @pages = (1..$total);
59              
60             # loop over the pages and compose the 4 physical pages
61 1         6 while (@pages) {
62 3         852 my ($p1, $p2, $p3, $p4,
63             $p5, $p6, $p7, $p8) = splice @pages, 0, 8;
64             # initialize
65 3         20 $self->_compose_quadruple($p8, $p1, $p4, $p5);
66 3         848 $self->_compose_quadruple($p2, $p7, $p6, $p3);
67             }
68             }
69              
70             sub _compose_quadruple {
71 6     6   20 my ($self, @seq) = @_;
72 6         12 my $chunk;
73 6         149 my $page = $self->out_pdf_obj->page;
74 6         5295 my $gfx = $page->gfx;
75              
76 6         1261 $chunk = $self->get_imported_page($seq[0]);
77 6 100       274311 $gfx->formimage($chunk, 0, 0) if $chunk;
78              
79 6         2107 $chunk = $self->get_imported_page($seq[1]);
80 6 100       22674 $gfx->formimage($chunk, $self->orig_width, 0) if $chunk;
81              
82             # translate
83 6         2151 $gfx->transform (
84             -translate => [$self->orig_width * 2,
85             $self->orig_height * 2],
86             -rotate => 180,
87             );
88              
89 6         5237 $chunk = $self->get_imported_page($seq[2]);
90 6 100       21343 $gfx->formimage($chunk, 0, 0) if $chunk;
91            
92 6         1582 $chunk = $self->get_imported_page($seq[3]);
93 6 100       21605 $gfx->formimage($chunk, $self->orig_width, 0) if $chunk;
94             }
95              
96             =head1 INTERNALS
97              
98             =head2 pages_per_sheet
99              
100             Returns 8
101              
102             =head2 cropmarks_options
103              
104             Set inner to false and force signature to 8.
105              
106             =cut
107              
108              
109             sub cropmarks_options {
110 0     0 1   my %options = (
111             top => 1,
112             bottom => 1,
113             inner => 0,
114             outer => 1,
115             twoside => 1,
116             signature => 8,
117             );
118 0           return %options;
119             }
120              
121 0     0 1   sub pages_per_sheet { 8 };
122              
123             1;
124              
125             =head1 SEE ALSO
126              
127             L
128              
129             =head1 LICENSE
130              
131             This program is free software; you can redistribute it and/or modify
132             it under the terms of either: the GNU General Public License as
133             published by the Free Software Foundation; or the Artistic License.
134              
135             =head1 AUTHOR
136              
137             Daniel Drennan ElAwar
138              
139             =cut
140              
141