line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Bingo::Print; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: Print.pm 1835 2007-03-17 17:36:20Z jonasbn $ |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
455282
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
7
|
1
|
|
|
1
|
|
1003
|
use integer; |
|
1
|
|
|
|
|
22
|
|
|
1
|
|
|
|
|
5
|
|
8
|
1
|
|
|
1
|
|
33
|
use Carp qw(croak); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
157
|
|
9
|
1
|
|
|
1
|
|
3354
|
use PDFLib; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use vars qw($VERSION); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use Games::Bingo::Card; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$VERSION = '0.04'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
|
|
|
|
|
|
my ( $class, %opts ) = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $self = bless { |
20
|
|
|
|
|
|
|
text => $opts{text} ? $opts{text} : 'by jonasbn ', |
21
|
|
|
|
|
|
|
heading => $opts{heading} ? $opts{heading} : 'Games::Bingo', |
22
|
|
|
|
|
|
|
papersize => $opts{papersize} ? $opts{papersize} : 'a4', |
23
|
|
|
|
|
|
|
}, $class || ref $class; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
eval { |
26
|
|
|
|
|
|
|
$self->{pdf} = PDFLib->new( |
27
|
|
|
|
|
|
|
filename => $opts{filename} ? $opts{filename} : 'bingo.pdf', |
28
|
|
|
|
|
|
|
papersize => $self->{papersize}, |
29
|
|
|
|
|
|
|
creator => 'Games::Bingo::Print', |
30
|
|
|
|
|
|
|
author => 'Jonas B. Nielsen', |
31
|
|
|
|
|
|
|
title => 'Bingo!', |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
$self->{pdf}->start_page; |
34
|
|
|
|
|
|
|
}; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
if ($@) { |
37
|
|
|
|
|
|
|
croak 'Unable to construct object - '.$@; |
38
|
|
|
|
|
|
|
} else { |
39
|
|
|
|
|
|
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub print_pages { |
44
|
|
|
|
|
|
|
my ( $self, $pages, $cards ) = @_; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
eval { |
47
|
|
|
|
|
|
|
foreach my $i ( 1 .. $pages ) |
48
|
|
|
|
|
|
|
{ |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
if ($cards) { |
51
|
|
|
|
|
|
|
if ( $cards > 3 ) { |
52
|
|
|
|
|
|
|
$cards = 3; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} else { |
55
|
|
|
|
|
|
|
$cards = 3; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$self->{pdf}->set_font( |
59
|
|
|
|
|
|
|
face => 'Helvetica', |
60
|
|
|
|
|
|
|
size => 40, |
61
|
|
|
|
|
|
|
bold => 1 |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
$self->{pdf}->print_boxed( |
64
|
|
|
|
|
|
|
$self->{heading}, |
65
|
|
|
|
|
|
|
mode => 'center', |
66
|
|
|
|
|
|
|
'x' => 0, |
67
|
|
|
|
|
|
|
'y' => 740, |
68
|
|
|
|
|
|
|
'w' => 595, |
69
|
|
|
|
|
|
|
'h' => 50 |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
$self->{pdf}->set_font( |
72
|
|
|
|
|
|
|
face => 'Helvetica', |
73
|
|
|
|
|
|
|
size => 12, |
74
|
|
|
|
|
|
|
bold => 1 |
75
|
|
|
|
|
|
|
); |
76
|
|
|
|
|
|
|
$self->{pdf}->print_boxed( |
77
|
|
|
|
|
|
|
$self->{text}, |
78
|
|
|
|
|
|
|
'mode' => 'center', |
79
|
|
|
|
|
|
|
'x' => 0, |
80
|
|
|
|
|
|
|
'y' => 685, |
81
|
|
|
|
|
|
|
'w' => 595, |
82
|
|
|
|
|
|
|
'h' => 50 |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my $y_start_cordinate = 685; |
86
|
|
|
|
|
|
|
my $x_start_cordinate = 30; |
87
|
|
|
|
|
|
|
my $size = 60; |
88
|
|
|
|
|
|
|
my $yec; |
89
|
|
|
|
|
|
|
my $ysc; |
90
|
|
|
|
|
|
|
my $cardsize = $size * 3; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
for ( my $card = 1; $card <= $cards; $card++ ) { |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
$ysc = $y_start_cordinate - $cardsize; |
95
|
|
|
|
|
|
|
$yec = $ysc + $cardsize; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
$self->_print_card( |
98
|
|
|
|
|
|
|
size => $size, |
99
|
|
|
|
|
|
|
x_start_cordinate => $x_start_cordinate, |
100
|
|
|
|
|
|
|
y_start_cordinate => $ysc, |
101
|
|
|
|
|
|
|
y_end_cordinate => $yec, |
102
|
|
|
|
|
|
|
); |
103
|
|
|
|
|
|
|
$y_start_cordinate = $ysc - 50; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
$self->{pdf}->stroke; |
107
|
|
|
|
|
|
|
$self->{pdf}->finish; |
108
|
|
|
|
|
|
|
}; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
if ($@) { |
111
|
|
|
|
|
|
|
carp ('Unable to generate page - '.$@); |
112
|
|
|
|
|
|
|
return 0; |
113
|
|
|
|
|
|
|
} else { |
114
|
|
|
|
|
|
|
return 1; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub _print_card { |
119
|
|
|
|
|
|
|
my $self = shift; |
120
|
|
|
|
|
|
|
my %args = @_; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
my $p = Games::Bingo::Card->new(); |
123
|
|
|
|
|
|
|
$p = $p->populate(); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
my $ysc = $args{'y_start_cordinate'}; |
126
|
|
|
|
|
|
|
my $yec = $args{'y_end_cordinate'}; |
127
|
|
|
|
|
|
|
my $xsc = $args{'x_start_cordinate'}; |
128
|
|
|
|
|
|
|
my $size = $args{'size'}; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
my $y = 3; |
131
|
|
|
|
|
|
|
for ( my $ry = $ysc; $ry < $yec; $ry += $size ) { |
132
|
|
|
|
|
|
|
my @numbers; |
133
|
|
|
|
|
|
|
for ( my $x = 0; $x <= 9; $x++ ) { |
134
|
|
|
|
|
|
|
push( @numbers, $p->[ $x - 1 ]->[ $y - 1 ] ); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
$self->_print_row( |
137
|
|
|
|
|
|
|
size => $size, |
138
|
|
|
|
|
|
|
x_start_cordinate => $xsc, |
139
|
|
|
|
|
|
|
y_start_cordinate => $ry, |
140
|
|
|
|
|
|
|
x_end_cordinate => 540, |
141
|
|
|
|
|
|
|
numbers => \@numbers, |
142
|
|
|
|
|
|
|
); |
143
|
|
|
|
|
|
|
$y--; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
return 1; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub _print_row { |
149
|
|
|
|
|
|
|
my $self = shift; |
150
|
|
|
|
|
|
|
my %args = @_; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
my $ysc = $args{'y_start_cordinate'}; |
153
|
|
|
|
|
|
|
my $xsc = $args{'x_start_cordinate'}; |
154
|
|
|
|
|
|
|
my $xec = $args{'x_end_cordinate'}; |
155
|
|
|
|
|
|
|
my $size = $args{'size'}; |
156
|
|
|
|
|
|
|
my $numbers = $args{'numbers'}; |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
my $x; |
159
|
|
|
|
|
|
|
for ( my $rx = $xsc; $rx <= $xec; $rx += $size ) { |
160
|
|
|
|
|
|
|
++$x; |
161
|
|
|
|
|
|
|
my $label = $numbers->[$x] ? $numbers->[$x] : ''; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
$self->{pdf}->rect( |
164
|
|
|
|
|
|
|
'x' => $rx, |
165
|
|
|
|
|
|
|
'y' => $ysc, |
166
|
|
|
|
|
|
|
'w' => $size, |
167
|
|
|
|
|
|
|
'h' => $size |
168
|
|
|
|
|
|
|
); |
169
|
|
|
|
|
|
|
$self->{pdf}->stroke; |
170
|
|
|
|
|
|
|
$self->{pdf}->set_font( |
171
|
|
|
|
|
|
|
face => 'Helvetica', |
172
|
|
|
|
|
|
|
size => 40, |
173
|
|
|
|
|
|
|
bold => 1 |
174
|
|
|
|
|
|
|
); |
175
|
|
|
|
|
|
|
$self->{pdf}->print_at( |
176
|
|
|
|
|
|
|
$label, |
177
|
|
|
|
|
|
|
'mode' => 'right', |
178
|
|
|
|
|
|
|
'w' => $size, |
179
|
|
|
|
|
|
|
'h' => $size, |
180
|
|
|
|
|
|
|
'x' => $rx + 8, |
181
|
|
|
|
|
|
|
'y' => $ysc + 13 |
182
|
|
|
|
|
|
|
); |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
return 1; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
1; |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
__END__ |