line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PDF::API2::Resource::XObject::Form::BarCode::ean13; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1096
|
use base 'PDF::API2::Resource::XObject::Form::BarCode'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
232
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
20
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
44
|
|
6
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
1112
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '2.043'; # 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
|
|
|
|
|
11
|
$self->drawbar([@bars], $options{'caption'}); |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
|
|
10
|
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
|
5679
|
my ($self, $string) = @_; |
27
|
11
|
|
|
|
|
51
|
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
|
|
|
|
|
23
|
my $first = shift @digits; |
32
|
11
|
|
|
|
|
31
|
my @bars = (['07', $first]); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Start Guard |
35
|
11
|
|
|
|
|
22
|
push @bars, 'a1a'; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Digits 2-7 |
38
|
11
|
|
|
|
|
26
|
foreach my $i (0 .. 5) { |
39
|
66
|
|
|
|
|
105
|
my $digit = shift @digits; |
40
|
66
|
100
|
|
|
|
145
|
if (substr($parity[$first], $i, 1) eq 'O') { |
41
|
39
|
|
|
|
|
120
|
push @bars, [$ean_code_odd[$digit], $digit]; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
else { |
44
|
27
|
|
|
|
|
72
|
push @bars, [$ean_code_even[$digit], $digit]; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Center Guard |
49
|
11
|
|
|
|
|
46
|
push @bars, '1a1a1'; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Digits 8-13 |
52
|
11
|
|
|
|
|
24
|
for (0..5) { |
53
|
66
|
|
|
|
|
98
|
my $digit = shift @digits; |
54
|
66
|
|
|
|
|
138
|
push @bars, [$ean_code_odd[$digit], $digit]; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Right Guard |
58
|
11
|
|
|
|
|
22
|
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; |