File Coverage

blib/lib/PDF/Imposition/Schema1x4x2cutfoldbind.pm
Criterion Covered Total %
statement 46 46 100.0
branch 11 12 91.6
condition n/a
subroutine 10 10 100.0
pod 3 3 100.0
total 70 71 98.5


line stmt bran cond sub pod time code
1             package PDF::Imposition::Schema1x4x2cutfoldbind;
2              
3 3     3   2391 use strict;
  3         9  
  3         110  
4 3     3   21 use warnings;
  3         6  
  3         131  
5              
6 3     3   21 use Types::Standard qw/Bool/;
  3         8  
  3         36  
7 3     3   2176 use namespace::clean;
  3         7  
  3         32  
8              
9 3     3   815 use Moo;
  3         14  
  3         27  
10             with 'PDF::Imposition::Schema';
11              
12             =head1 NAME
13              
14             PDF::Imposition::Schema1x4x2cutfoldbind - 1x4x2cutfoldbind imposition schema
15              
16             =head1 SYNOPSIS
17              
18             use PDF::Imposition::Schema1x4x2cutfoldbind;
19             my $imposer = PDF::Imposition::Schema1x4x2cutfoldbind
20             ->new(
21             file => "test.pdf",
22             output => "out.pdf",
23             );
24             $imposer->impose;
25              
26             =head1 SCHEMA EXPLANATION
27              
28             +-----+-----+ +-----+-----+
29             | | | | | |
30             | 4 | 1 | | 2 | 3 |
31             | | | | | |
32             +-----+-----+ +-----+-----+
33             | | | | | |
34             | 8 | 5 | | 6 | 7 |
35             | | | | | |
36             +-----+-----+ +-----+-----+
37              
38             The schema uses fixes signatures of 8 logical pages, layed out on a
39             single sheet, printed recto-verso.
40              
41             To get a booklet out of this schema, you first have to B the
42             sheets along the x-axys in the middle, then B each half along
43             the y-axys, stack them, repeat for each sheet, and finally glue or
44             B the spine. (Hence the name of the module).
45              
46             Does it sound weird? Well, kind of. Looks like a lot of manual work.
47             But if it works for you, it works for me as well.
48              
49             =head1 METHODS
50              
51             =head2 cover
52              
53             This schema supports the cover option.
54              
55             =cut
56              
57             has cover => (is => 'rw', isa => Bool);
58              
59 2     2 1 55 sub pages_per_sheet { 8 }
60              
61 4     4 1 18 sub signature { 8 }
62              
63             =head1 INTERNALS
64              
65             =head2 signature
66              
67             Returns 8.
68              
69             =head2 pages_per_sheet
70              
71             Returns 8.
72              
73             =head2 cropmarks_options
74              
75             Set inner to false and force the signature to 4 for cropmarks purposes.
76              
77             =cut
78              
79             sub cropmarks_options {
80 2     2 1 25 my %options = (
81             top => 1,
82             bottom => 1,
83             inner => 0,
84             outer => 1,
85             twoside => 1,
86             # for the purpose of the cropping, the signature is 4
87             signature => 4,
88             );
89 2         37 return %options;
90             }
91              
92             sub _do_impose {
93 8     8   23 my $self = shift;
94             # set the mediabox doubling them
95 8         161 $self->out_pdf_obj->mediabox(
96             $self->orig_width * 2,
97             $self->orig_height * 2,
98             );
99 8         1834 my $total = $self->total_pages;
100 8         296 my @pages = (1..$total);
101 8 100       174 if ($self->cover) {
102 5 100       70 if (my $modulo = $total % 4) {
103 3         9 my $blanks = 4 - $modulo;
104 3         9 my $last = pop @pages;
105 3         15 for (1 .. $blanks) {
106 4         25 push @pages, undef;
107             }
108 3         10 push @pages, $last;
109             }
110             }
111 8         65 while (@pages) {
112 14         2660 my ($p1, $p2, $p3, $p4, $p5, $p6, $p7, $p8) = splice @pages, 0, 8;
113 14         85 $self->_compose_quadruple($p8, $p5, $p1, $p4);
114 14         5786 $self->_compose_quadruple($p6, $p7, $p3, $p2);
115             }
116             }
117              
118             sub _compose_quadruple {
119 28     28   111 my ($self, @seq) = @_;
120 28         70 my $chunk;
121 28         726 my $page = $self->out_pdf_obj->page;
122 28         24607 my $gfx = $page->gfx;
123 28         6040 $chunk = $self->get_imported_page($seq[0]);
124 28 100       2342841 $gfx->formimage($chunk, 0, 0) if $chunk;
125 28         7819 $chunk = $self->get_imported_page($seq[1]);
126 28 100       117427 $gfx->formimage($chunk, $self->orig_width, 0) if $chunk;
127 28         6658 $chunk = $self->get_imported_page($seq[2]);
128 28 100       409818 $gfx->formimage($chunk, $self->orig_width, $self->orig_height) if $chunk;
129 28         11424 $chunk = $self->get_imported_page($seq[3]);
130 28 50       201650 $gfx->formimage($chunk, 0, $self->orig_height) if $chunk;
131             }
132              
133             1;
134              
135              
136              
137              
138