line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PDF::API2::Resource::XObject::Form::BarCode::ean13; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
965
|
use base 'PDF::API2::Resource::XObject::Form::BarCode'; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
231
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
14
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
41
|
|
6
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1071
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '2.044'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
1
|
|
|
1
|
1
|
4
|
my ($class, $pdf, %options) = @_; |
12
|
1
|
|
|
|
|
9
|
my $self = $class->SUPER::new($pdf, %options); |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
|
|
4
|
my @bars = $self->encode($options{'-code'}); |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
8
|
$self->drawbar([@bars], $options{'caption'}); |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
|
|
9
|
return $self; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my @ean_code_odd = qw(3211 2221 2122 1411 1132 1231 1114 1312 1213 3112); |
22
|
|
|
|
|
|
|
my @ean_code_even = qw(1123 1222 2212 1141 2311 1321 4111 2131 3121 2113); |
23
|
|
|
|
|
|
|
my @parity = qw(OOOOOO OOEOEE OOEEOE OOEEEO OEOOEE OEEOOE OEEEOO OEOEOE OEOEEO OEEOEO); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub encode { |
26
|
11
|
|
|
11
|
0
|
5597
|
my ($self, $string) = @_; |
27
|
11
|
|
|
|
|
53
|
my @digits = split //, $string; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# The first digit determines the even/odd pattern of the next six |
30
|
|
|
|
|
|
|
# digits, and is printed to the left of the barcode |
31
|
11
|
|
|
|
|
30
|
my $first = shift @digits; |
32
|
11
|
|
|
|
|
33
|
my @bars = (['07', $first]); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Start Guard |
35
|
11
|
|
|
|
|
22
|
push @bars, 'a1a'; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Digits 2-7 |
38
|
11
|
|
|
|
|
27
|
foreach my $i (0 .. 5) { |
39
|
66
|
|
|
|
|
102
|
my $digit = shift @digits; |
40
|
66
|
100
|
|
|
|
143
|
if (substr($parity[$first], $i, 1) eq 'O') { |
41
|
39
|
|
|
|
|
95
|
push @bars, [$ean_code_odd[$digit], $digit]; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
else { |
44
|
27
|
|
|
|
|
61
|
push @bars, [$ean_code_even[$digit], $digit]; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Center Guard |
49
|
11
|
|
|
|
|
25
|
push @bars, '1a1a1'; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Digits 8-13 |
52
|
11
|
|
|
|
|
22
|
for (0..5) { |
53
|
66
|
|
|
|
|
100
|
my $digit = shift @digits; |
54
|
66
|
|
|
|
|
131
|
push @bars, [$ean_code_odd[$digit], $digit]; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Right Guard |
58
|
11
|
|
|
|
|
18
|
push @bars, 'a1a'; |
59
|
|
|
|
|
|
|
|
60
|
11
|
|
|
|
|
42
|
return @bars; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub calculate_check_digit { |
64
|
0
|
|
|
0
|
0
|
|
my ($self, $string) = @_; |
65
|
0
|
|
|
|
|
|
my @digits = split //, $string; |
66
|
0
|
|
|
|
|
|
my $weight = 1; |
67
|
0
|
|
|
|
|
|
my $checksum = 0; |
68
|
0
|
|
|
|
|
|
foreach my $i (0..11) { |
69
|
0
|
|
|
|
|
|
$checksum += $digits[$i] * $weight; |
70
|
0
|
0
|
|
|
|
|
$weight = $weight == 1 ? 3 : 1; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
$checksum = $checksum % 10; |
74
|
0
|
0
|
|
|
|
|
return 0 unless $checksum; |
75
|
0
|
|
|
|
|
|
return 10 - $checksum; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |