line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PDF::Builder::Resource::XObject::Form::BarCode::code3of9; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1102
|
use base 'PDF::Builder::Resource::XObject::Form::BarCode'; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
252
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
14
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
56
|
|
6
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1377
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '3.023'; # VERSION |
9
|
|
|
|
|
|
|
our $LAST_UPDATE = '3.017'; # manually update whenever code is changed |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
PDF::Builder::Resource::XObject::Form::BarCode::code3of9 - specific information for 3-of-9 bar codes. Inherits from L |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
2
|
|
|
2
|
1
|
25
|
my ($class, $pdf, %options) = @_; |
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
|
|
24
|
my $self = $class->SUPER::new($pdf, %options); |
21
|
|
|
|
|
|
|
my @bars = encode_3of9($options{'-code'}, |
22
|
|
|
|
|
|
|
$options{'-chk'}? 1: 0, |
23
|
2
|
50
|
|
|
|
16
|
$options{'-ext'}? 1: 0); |
|
|
50
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
2
|
|
|
|
|
22
|
$self->drawbar([@bars], $options{'caption'}); |
26
|
|
|
|
|
|
|
|
27
|
2
|
|
|
|
|
35
|
return $self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# allowed alphabet and bar widths |
31
|
|
|
|
|
|
|
my $code3of9 = q(0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%*); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my @bar3of9 = qw( |
34
|
|
|
|
|
|
|
1112212111 2112111121 1122111121 2122111111 |
35
|
|
|
|
|
|
|
1112211121 2112211111 1122211111 1112112121 |
36
|
|
|
|
|
|
|
2112112111 1122112111 2111121121 1121121121 |
37
|
|
|
|
|
|
|
2121121111 1111221121 2111221111 1121221111 |
38
|
|
|
|
|
|
|
1111122121 2111122111 1121122111 1111222111 |
39
|
|
|
|
|
|
|
2111111221 1121111221 2121111211 1111211221 |
40
|
|
|
|
|
|
|
2111211211 1121211211 1111112221 2111112211 |
41
|
|
|
|
|
|
|
1121112211 1111212211 2211111121 1221111121 |
42
|
|
|
|
|
|
|
2221111111 1211211121 2211211111 1221211111 |
43
|
|
|
|
|
|
|
1211112121 2211112111 1221112111 1212121111 |
44
|
|
|
|
|
|
|
1212111211 1211121211 1112121211 abaababaa1 |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my @extended_map = ( |
48
|
|
|
|
|
|
|
'%U', '$A', '$B', '$C', '$D', '$E', '$F', '$G', '$H', '$I', |
49
|
|
|
|
|
|
|
'$J', '$K', '$L', '$M', '$N', '$O', '$P', '$Q', '$R', '$S', |
50
|
|
|
|
|
|
|
'$T', '$U', '$V', '$W', '$X', '$Y', '$Z', '%A', '%B', '%C', |
51
|
|
|
|
|
|
|
'%D', '$E', ' ', '/A', '/B', '/C', '/D', '/E', '/F', '/G', |
52
|
|
|
|
|
|
|
'/H', '/I', '/J', '/K', '/L', '-', '.', '/O', '0', '1', |
53
|
|
|
|
|
|
|
'2', '3', '4', '5', '6', '7', '8', '9', '/Z', '%F', |
54
|
|
|
|
|
|
|
'%G', '%H', '%I', '%J', '%V', 'A', 'B', 'C', 'D', 'E', |
55
|
|
|
|
|
|
|
'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', |
56
|
|
|
|
|
|
|
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', |
57
|
|
|
|
|
|
|
'Z', '%K', '%L', '%M', '%N', '%O', '%W', '+A', '+B', '+C', |
58
|
|
|
|
|
|
|
'+D', '+E', '+F', '+G', '+H', '+I', '+J', '+K', '+L', '+M', |
59
|
|
|
|
|
|
|
'+N', '+O', '+P', '+Q', '+R', '+S', '+T', '+U', '+V', '+W', |
60
|
|
|
|
|
|
|
'+X', '+Y', '+Z', '%P', '%Q', '%R', '%S', '%T' |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub encode_3of9_char { |
64
|
36
|
|
|
36
|
0
|
48
|
my $character = shift; |
65
|
|
|
|
|
|
|
|
66
|
36
|
|
|
|
|
83
|
return $bar3of9[index($code3of9, $character)]; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub encode_3of9_string { |
70
|
6
|
|
|
6
|
0
|
15
|
my ($string, $is_mod43) = @_; |
71
|
|
|
|
|
|
|
|
72
|
6
|
|
|
|
|
9
|
my $bar; |
73
|
6
|
|
|
|
|
11
|
my $checksum = 0; |
74
|
6
|
|
|
|
|
41
|
foreach my $char (split //, $string) { |
75
|
24
|
|
|
|
|
38
|
$bar .= encode_3of9_char($char); |
76
|
24
|
|
|
|
|
50
|
$checksum += index($code3of9, $char); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
6
|
100
|
|
|
|
18
|
if ($is_mod43) { |
80
|
2
|
|
|
|
|
5
|
$checksum %= 43; |
81
|
2
|
|
|
|
|
6
|
$bar .= $bar3of9[$checksum]; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
6
|
|
|
|
|
17
|
return $bar; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Note: encode_3of9_string_w_chk now encode_3of9_string(*, 1) |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub encode_3of9 { |
90
|
6
|
|
|
6
|
0
|
2170
|
my ($string, $is_mod43, $is_extended) = @_; |
91
|
|
|
|
|
|
|
|
92
|
6
|
|
|
|
|
10
|
my $display; |
93
|
6
|
100
|
|
|
|
16
|
unless ($is_extended) { |
94
|
4
|
|
|
|
|
11
|
$string = uc($string); |
95
|
4
|
|
|
|
|
21
|
$string =~ s/[^0-9A-Z\-\.\ \$\/\+\%]+//g; |
96
|
4
|
|
|
|
|
8
|
$display = $string; |
97
|
|
|
|
|
|
|
} else { |
98
|
|
|
|
|
|
|
# Extended Code39 supports all 7-bit ASCII characters |
99
|
2
|
|
|
|
|
7
|
$string =~ s/[^\x00-\x7f]//g; |
100
|
2
|
|
|
|
|
5
|
$display = $string; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# Encode, but don't display, non-printable characters |
103
|
2
|
|
|
|
|
5
|
$display =~ s/[[:cntrl:]]//g; |
104
|
|
|
|
|
|
|
|
105
|
2
|
|
|
|
|
8
|
$string = join('', map { $extended_map[ord($_)] } split(//, $string)); |
|
8
|
|
|
|
|
28
|
|
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
6
|
|
|
|
|
11
|
my @bars; |
109
|
6
|
|
|
|
|
15
|
push @bars, encode_3of9_char('*'); |
110
|
6
|
|
|
|
|
29
|
push @bars, [ encode_3of9_string($string, $is_mod43), $display ]; |
111
|
6
|
|
|
|
|
15
|
push @bars, encode_3of9_char('*'); |
112
|
|
|
|
|
|
|
|
113
|
6
|
|
|
|
|
20
|
return @bars; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# Note: encode_3of9_w_chk now encode_3of9(*, 1, 0) |
117
|
|
|
|
|
|
|
# Note: encode_3of9_ext now encode_3of9(*, 0, 1) |
118
|
|
|
|
|
|
|
# Note: encode_3of9_ext_w_chk now encode_3of9(*, 1, 1) |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |