line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package GD::Barcode::Code93; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
17652
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
4
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
2
|
BEGIN { eval{require 'GD.pm';}; }; |
|
1
|
|
|
|
|
477
|
|
7
|
1
|
|
|
1
|
|
803
|
use GD::Barcode; |
|
1
|
|
|
|
|
708
|
|
|
1
|
|
|
|
|
59
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Exporter; |
10
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION @ISA $error_string); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
972
|
|
11
|
|
|
|
|
|
|
@ISA = qw(GD::Barcode Exporter); |
12
|
|
|
|
|
|
|
$VERSION='1.4'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $code93bar = { |
15
|
|
|
|
|
|
|
0 =>'100010100', |
16
|
|
|
|
|
|
|
1 =>'101001000', |
17
|
|
|
|
|
|
|
2 =>'101000100', |
18
|
|
|
|
|
|
|
3 =>'101000010', |
19
|
|
|
|
|
|
|
4 =>'100101000', |
20
|
|
|
|
|
|
|
5 =>'100100100', |
21
|
|
|
|
|
|
|
6 =>'100100010', |
22
|
|
|
|
|
|
|
7 =>'101010000', |
23
|
|
|
|
|
|
|
8 =>'100010010', |
24
|
|
|
|
|
|
|
9 =>'100001010', |
25
|
|
|
|
|
|
|
A =>'110101000', |
26
|
|
|
|
|
|
|
B =>'110100100', |
27
|
|
|
|
|
|
|
C =>'110100010', |
28
|
|
|
|
|
|
|
D =>'110010100', |
29
|
|
|
|
|
|
|
E =>'110010010', |
30
|
|
|
|
|
|
|
F =>'110001010', |
31
|
|
|
|
|
|
|
G =>'101101000', |
32
|
|
|
|
|
|
|
H =>'101100100', |
33
|
|
|
|
|
|
|
I =>'101100010', |
34
|
|
|
|
|
|
|
J =>'100110100', |
35
|
|
|
|
|
|
|
K =>'100011010', |
36
|
|
|
|
|
|
|
L =>'101011000', |
37
|
|
|
|
|
|
|
M =>'101001100', |
38
|
|
|
|
|
|
|
N =>'101000110', |
39
|
|
|
|
|
|
|
O =>'100101100', |
40
|
|
|
|
|
|
|
P =>'100010110', |
41
|
|
|
|
|
|
|
Q =>'110110100', |
42
|
|
|
|
|
|
|
R =>'110110010', |
43
|
|
|
|
|
|
|
S =>'110101100', |
44
|
|
|
|
|
|
|
T =>'110100110', |
45
|
|
|
|
|
|
|
U =>'110010110', |
46
|
|
|
|
|
|
|
V =>'110011010', |
47
|
|
|
|
|
|
|
W =>'101101100', |
48
|
|
|
|
|
|
|
X =>'101100110', |
49
|
|
|
|
|
|
|
Y =>'100110110', |
50
|
|
|
|
|
|
|
Z =>'100111010', |
51
|
|
|
|
|
|
|
' ' =>'111010010', |
52
|
|
|
|
|
|
|
'$' =>'111001010', |
53
|
|
|
|
|
|
|
'%' =>'110101110', |
54
|
|
|
|
|
|
|
'($)'=>'100100110', |
55
|
|
|
|
|
|
|
'(%)'=>'111011010', |
56
|
|
|
|
|
|
|
'(+)'=>'100110010', |
57
|
|
|
|
|
|
|
'(/)'=>'111010110', |
58
|
|
|
|
|
|
|
'+' =>'101110110', |
59
|
|
|
|
|
|
|
'-' =>'100101110', |
60
|
|
|
|
|
|
|
'.' =>'111010100', |
61
|
|
|
|
|
|
|
'/' =>'101101110', |
62
|
|
|
|
|
|
|
'*' =>'101011110', ##Start/Stop |
63
|
|
|
|
|
|
|
}; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my %code93values = ( |
66
|
|
|
|
|
|
|
'0' =>'0', |
67
|
|
|
|
|
|
|
'1' =>'1', |
68
|
|
|
|
|
|
|
'2' =>'2', |
69
|
|
|
|
|
|
|
'3' =>'3', |
70
|
|
|
|
|
|
|
'4' =>'4', |
71
|
|
|
|
|
|
|
'5' =>'5', |
72
|
|
|
|
|
|
|
'6' =>'6', |
73
|
|
|
|
|
|
|
'7' =>'7', |
74
|
|
|
|
|
|
|
'8' =>'8', |
75
|
|
|
|
|
|
|
'9' =>'9', |
76
|
|
|
|
|
|
|
'A' =>'10', |
77
|
|
|
|
|
|
|
'B' =>'11', |
78
|
|
|
|
|
|
|
'C' =>'12', |
79
|
|
|
|
|
|
|
'D' =>'13', |
80
|
|
|
|
|
|
|
'E' =>'14', |
81
|
|
|
|
|
|
|
'F' =>'15', |
82
|
|
|
|
|
|
|
'G' =>'16', |
83
|
|
|
|
|
|
|
'H' =>'17', |
84
|
|
|
|
|
|
|
'I' =>'18', |
85
|
|
|
|
|
|
|
'J' =>'19', |
86
|
|
|
|
|
|
|
'K' =>'20', |
87
|
|
|
|
|
|
|
'L' =>'21', |
88
|
|
|
|
|
|
|
'M' =>'22', |
89
|
|
|
|
|
|
|
'N' =>'23', |
90
|
|
|
|
|
|
|
'O' =>'24', |
91
|
|
|
|
|
|
|
'P' =>'25', |
92
|
|
|
|
|
|
|
'Q' =>'26', |
93
|
|
|
|
|
|
|
'R' =>'27', |
94
|
|
|
|
|
|
|
'S' =>'28', |
95
|
|
|
|
|
|
|
'T' =>'29', |
96
|
|
|
|
|
|
|
'U' =>'30', |
97
|
|
|
|
|
|
|
'V' =>'31', |
98
|
|
|
|
|
|
|
'W' =>'32', |
99
|
|
|
|
|
|
|
'X' =>'33', |
100
|
|
|
|
|
|
|
'Y' =>'34', |
101
|
|
|
|
|
|
|
'Z' =>'35', |
102
|
|
|
|
|
|
|
'-' =>'36', |
103
|
|
|
|
|
|
|
'.' =>'37', |
104
|
|
|
|
|
|
|
' ' =>'38', |
105
|
|
|
|
|
|
|
'$' =>'39', |
106
|
|
|
|
|
|
|
'/' =>'40', |
107
|
|
|
|
|
|
|
'+' =>'41', |
108
|
|
|
|
|
|
|
'%' =>'42', |
109
|
|
|
|
|
|
|
'($)' =>'43', |
110
|
|
|
|
|
|
|
'(%)' =>'44', |
111
|
|
|
|
|
|
|
'(/)' =>'45', |
112
|
|
|
|
|
|
|
'(+)' =>'46', |
113
|
|
|
|
|
|
|
'*' => '', |
114
|
|
|
|
|
|
|
); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
117
|
|
|
|
|
|
|
# new (for GD::Barcode::Code93) |
118
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
119
|
|
|
|
|
|
|
sub new { |
120
|
1
|
|
|
1
|
1
|
14
|
my ( $class, $txt ) = @_; |
121
|
|
|
|
|
|
|
|
122
|
1
|
|
|
|
|
3
|
my $error_string = ''; |
123
|
1
|
|
|
|
|
3
|
my $self = {}; |
124
|
1
|
|
|
|
|
4
|
bless $self, $class; |
125
|
|
|
|
|
|
|
|
126
|
1
|
50
|
|
|
|
7
|
return undef if $error_string = $self->init($txt); |
127
|
1
|
|
|
|
|
4
|
return $self; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
131
|
|
|
|
|
|
|
# init (for GD::Barcode::Code93) |
132
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
133
|
|
|
|
|
|
|
sub init { |
134
|
1
|
|
|
1
|
0
|
1
|
my ($self, $txt) = @_; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# Validate string: |
137
|
1
|
50
|
|
|
|
5
|
return 'Invalid Characters' if $txt =~ /[^0-9A-Za-z\-*+\$%\/. ]/; |
138
|
1
|
|
|
|
|
11
|
$self->{text} = uc($txt); |
139
|
1
|
|
|
|
|
5
|
return; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
143
|
|
|
|
|
|
|
# barcode (for GD::Barcode::Code93) |
144
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
145
|
|
|
|
|
|
|
sub barcode { |
146
|
2
|
|
|
2
|
1
|
3
|
my $self = shift; |
147
|
|
|
|
|
|
|
|
148
|
2
|
|
|
|
|
6
|
my @sum_text = ('*', $self->calculateSums, '*'); |
149
|
|
|
|
|
|
|
|
150
|
2
|
|
|
|
|
4
|
my $return_string = ''; |
151
|
2
|
|
|
|
|
291
|
map { $return_string .= $code93bar->{$_} } @sum_text; |
|
14
|
|
|
|
|
30
|
|
152
|
2
|
|
|
|
|
10
|
return $return_string . "1"; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
156
|
|
|
|
|
|
|
# plot (for GD::Barcode::Code93) |
157
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
158
|
|
|
|
|
|
|
sub plot(@) { |
159
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
160
|
1
|
|
|
|
|
3
|
my %params = @_; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
## Normalize the hash keys: |
163
|
1
|
|
|
|
|
4
|
%params = map { lc($_) => $params{$_} } keys %params; |
|
0
|
|
|
|
|
0
|
|
164
|
|
|
|
|
|
|
|
165
|
1
|
|
|
|
|
3
|
my $text = $self->{text}; |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
#Barcode Pattern |
168
|
1
|
|
|
|
|
3
|
my $pattern = $self->barcode(); |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
#Create Image |
171
|
1
|
50
|
|
|
|
6
|
my $height = $params{height} ? $params{height} : 50; |
172
|
|
|
|
|
|
|
|
173
|
1
|
|
|
|
|
10
|
my $gd; |
174
|
1
|
50
|
|
|
|
4
|
if ( $params{notext} ) { |
175
|
0
|
|
|
|
|
0
|
( $gd, undef ) = GD::Barcode::plot($pattern, length($pattern), $height, 0, 0); |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
else { |
178
|
1
|
|
|
|
|
157
|
my ( $font_width, $font_height ) = ( GD::Font->Small->width, GD::Font->Small->height ); |
179
|
0
|
|
|
|
|
0
|
my $width = length($pattern); |
180
|
|
|
|
|
|
|
|
181
|
0
|
|
|
|
|
0
|
my $color; |
182
|
|
|
|
|
|
|
#Bar Image |
183
|
0
|
|
|
|
|
0
|
( $gd, $color ) = GD::Barcode::plot |
184
|
|
|
|
|
|
|
( |
185
|
|
|
|
|
|
|
$pattern |
186
|
|
|
|
|
|
|
, $width |
187
|
|
|
|
|
|
|
, $height |
188
|
|
|
|
|
|
|
, $font_height |
189
|
|
|
|
|
|
|
, 0 |
190
|
|
|
|
|
|
|
); |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
#String |
193
|
0
|
|
|
|
|
0
|
my $string_width = ( length($pattern) - $font_width * length($text) ) / 2; |
194
|
0
|
|
|
|
|
0
|
my $string_height = $height - $font_height; |
195
|
0
|
|
|
|
|
0
|
$gd->string( GD::Font->Small, $string_width, $string_height, $text, $color ); |
196
|
|
|
|
|
|
|
} |
197
|
0
|
|
|
|
|
0
|
return $gd; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
201
|
|
|
|
|
|
|
# calculateSums (for GD::Barcode::Code93) |
202
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
203
|
|
|
|
|
|
|
sub calculateSums { |
204
|
3
|
|
|
3
|
0
|
611
|
my $self = shift; |
205
|
3
|
|
|
|
|
15
|
my @array = split(//, scalar reverse $self->{text}); |
206
|
|
|
|
|
|
|
|
207
|
3
|
|
|
|
|
113
|
my %invCode93Values = reverse %code93values; |
208
|
3
|
|
|
|
|
12
|
my $weighted_sum; |
209
|
|
|
|
|
|
|
|
210
|
3
|
|
|
|
|
7
|
foreach my $counter ( qw/4 3/ ) { |
211
|
6
|
|
|
|
|
19
|
for (my $i = 0, my $x = 1; $i <= $#array; $i++, $x++) { |
212
|
21
|
|
|
|
|
27
|
my $letter = $array[$i]; |
213
|
|
|
|
|
|
|
|
214
|
21
|
50
|
|
|
|
40
|
if ($x > ($counter * 5)) { $x = 1 } |
|
0
|
|
|
|
|
0
|
|
215
|
21
|
|
|
|
|
56
|
$weighted_sum += ($code93values{$letter} * $x); |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
6
|
|
|
|
|
14
|
my $check = $invCode93Values{($weighted_sum % 47)}; |
219
|
6
|
|
|
|
|
10
|
unshift @array, $check; |
220
|
6
|
|
|
|
|
13
|
$weighted_sum = (); |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
3
|
|
|
|
|
37
|
return reverse @array; |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
1; |
226
|
|
|
|
|
|
|
__END__ |