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