line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package GD::Barcode::EAN8; |
2
|
1
|
|
|
1
|
|
235779
|
use strict; |
|
1
|
|
|
|
|
18
|
|
|
1
|
|
|
|
|
30
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
390
|
use GD::Barcode; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
48
|
|
6
|
1
|
|
|
1
|
|
6
|
use parent qw(Exporter); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
7
|
1
|
|
|
1
|
|
47
|
use vars qw($VERSION @ISA $errStr); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
767
|
|
8
|
|
|
|
|
|
|
@ISA = qw(GD::Barcode Exporter); |
9
|
|
|
|
|
|
|
our $VERSION = '2.00'; |
10
|
|
|
|
|
|
|
my $leftOddBar = { |
11
|
|
|
|
|
|
|
'0' => '0001101', |
12
|
|
|
|
|
|
|
'1' => '0011001', |
13
|
|
|
|
|
|
|
'2' => '0010011', |
14
|
|
|
|
|
|
|
'3' => '0111101', |
15
|
|
|
|
|
|
|
'4' => '0100011', |
16
|
|
|
|
|
|
|
'5' => '0110001', |
17
|
|
|
|
|
|
|
'6' => '0101111', |
18
|
|
|
|
|
|
|
'7' => '0111011', |
19
|
|
|
|
|
|
|
'8' => '0110111', |
20
|
|
|
|
|
|
|
'9' => '0001011' |
21
|
|
|
|
|
|
|
}; |
22
|
|
|
|
|
|
|
my $rightBar = { |
23
|
|
|
|
|
|
|
'0' => '1110010', |
24
|
|
|
|
|
|
|
'1' => '1100110', |
25
|
|
|
|
|
|
|
'2' => '1101100', |
26
|
|
|
|
|
|
|
'3' => '1000010', |
27
|
|
|
|
|
|
|
'4' => '1011100', |
28
|
|
|
|
|
|
|
'5' => '1001110', |
29
|
|
|
|
|
|
|
'6' => '1010000', |
30
|
|
|
|
|
|
|
'7' => '1000100', |
31
|
|
|
|
|
|
|
'8' => '1001000', |
32
|
|
|
|
|
|
|
'9' => '1110100' |
33
|
|
|
|
|
|
|
}; |
34
|
|
|
|
|
|
|
my $guardBar = 'G0G'; |
35
|
|
|
|
|
|
|
my $centerBar = '0G0G0'; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub new { |
38
|
1
|
|
|
1
|
1
|
100
|
my ( $sClass, $sTxt ) = @_; |
39
|
1
|
|
|
|
|
3
|
$errStr = ''; |
40
|
1
|
|
|
|
|
3
|
my $oThis = {}; |
41
|
1
|
|
|
|
|
3
|
bless $oThis, $sClass; |
42
|
1
|
50
|
|
|
|
6
|
return if ( $errStr = $oThis->init($sTxt) ); |
43
|
1
|
|
|
|
|
4
|
return $oThis; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub init { |
47
|
1
|
|
|
1
|
0
|
3
|
my ( $oThis, $sTxt ) = @_; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#Check |
50
|
1
|
50
|
|
|
|
5
|
return 'Invalid Characters' if ( $sTxt =~ /[^0-9]/ ); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
#CalcCd |
53
|
1
|
50
|
|
|
|
5
|
if ( length($sTxt) == 7 ) { |
|
|
0
|
|
|
|
|
|
54
|
1
|
|
|
|
|
4
|
$sTxt .= calcEAN8CD($sTxt); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
elsif ( length($sTxt) == 8 ) { |
57
|
|
|
|
|
|
|
; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
else { |
60
|
0
|
|
|
|
|
0
|
return 'Invalid Length'; |
61
|
|
|
|
|
|
|
} |
62
|
1
|
|
|
|
|
10
|
$oThis->{text} = $sTxt; |
63
|
1
|
|
|
|
|
4
|
return ''; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub calcEAN8CD { |
67
|
1
|
|
|
1
|
0
|
5
|
my ($sTxt) = @_; |
68
|
1
|
|
|
|
|
3
|
my ( $i, $iSum ); |
69
|
|
|
|
|
|
|
|
70
|
1
|
|
|
|
|
3
|
my @aWeight = ( 3, 1, 3, 1, 3, 1, 3 ); |
71
|
1
|
|
|
|
|
2
|
$iSum = 0; |
72
|
1
|
|
|
|
|
6
|
for ( $i = 0 ; $i < 7 ; $i++ ) { |
73
|
7
|
|
|
|
|
18
|
$iSum += substr( $sTxt, $i, 1 ) * $aWeight[$i]; |
74
|
|
|
|
|
|
|
} |
75
|
1
|
|
|
|
|
5
|
$iSum %= 10; |
76
|
1
|
50
|
|
|
|
5
|
$iSum = ( $iSum == 0 ) ? 0 : ( 10 - $iSum ); |
77
|
1
|
|
|
|
|
5
|
return "$iSum"; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub barcode { |
81
|
1
|
|
|
1
|
1
|
17
|
my ($oThis) = @_; |
82
|
1
|
|
|
|
|
4
|
my ( $i, $sRes ); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
#(1) Init |
85
|
1
|
|
|
|
|
4
|
my $sTxt = $oThis->{text}; |
86
|
1
|
|
|
|
|
6
|
$sRes = $guardBar; #GUARD |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
#(2) Left 4 |
89
|
1
|
|
|
|
|
6
|
for ( $i = 0 ; $i < 4 ; $i++ ) { |
90
|
4
|
|
|
|
|
14
|
$sRes .= GD::Barcode::barPtn( substr( $sTxt, $i, 1 ), $leftOddBar ); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
#(3) Center |
94
|
1
|
|
|
|
|
3
|
$sRes .= $centerBar; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
#(4) Right 4 bytes |
97
|
1
|
|
|
|
|
4
|
for ( $i = 4 ; $i < 8 ; $i++ ) { |
98
|
4
|
|
|
|
|
11
|
$sRes .= GD::Barcode::barPtn( substr( $sTxt, $i, 1 ), $rightBar ); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
#(5)GUARD |
102
|
1
|
|
|
|
|
3
|
$sRes .= $guardBar; |
103
|
1
|
|
|
|
|
6
|
return $sRes; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub plot { |
107
|
0
|
|
|
0
|
1
|
|
my ( $oThis, %hParam ) = @_; |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
my $sPtn = $oThis->barcode(); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
#Create Image |
112
|
0
|
|
|
|
|
|
require GD; |
113
|
0
|
0
|
|
|
|
|
my $iHeight = ( $hParam{Height} ) ? $hParam{Height} : 50; |
114
|
0
|
|
|
|
|
|
my ( $oGd, $cBlack ); |
115
|
0
|
0
|
|
|
|
|
if ( $hParam{NoText} ) { |
116
|
0
|
|
|
|
|
|
( $oGd, $cBlack ) = |
117
|
|
|
|
|
|
|
GD::Barcode::plot( $sPtn, length($sPtn), $iHeight, 0, 0 ); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
else { |
120
|
0
|
|
|
|
|
|
my ( $fW, $fH ) = ( GD::Font->Small->width, GD::Font->Small->height ); |
121
|
0
|
|
|
|
|
|
my $iWidth = length($sPtn); |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
( $oGd, $cBlack ) = |
124
|
|
|
|
|
|
|
GD::Barcode::plot( $sPtn, $iWidth, $iHeight, $fH, 0 ); |
125
|
|
|
|
|
|
|
$oGd->string( |
126
|
|
|
|
|
|
|
GD::Font->Small, $fW + 1, |
127
|
|
|
|
|
|
|
$iHeight - $fH, |
128
|
0
|
|
|
|
|
|
substr( $oThis->{text}, 0, 4 ), $cBlack |
129
|
|
|
|
|
|
|
); |
130
|
|
|
|
|
|
|
$oGd->string( |
131
|
|
|
|
|
|
|
GD::Font->Small, $fW + 33, |
132
|
|
|
|
|
|
|
$iHeight - $fH, |
133
|
0
|
|
|
|
|
|
substr( $oThis->{text}, 4, 4 ), $cBlack |
134
|
|
|
|
|
|
|
); |
135
|
|
|
|
|
|
|
} |
136
|
0
|
|
|
|
|
|
return $oGd; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
1; |
139
|
|
|
|
|
|
|
__END__ |