| 1 | package PDF::Builder::Resource::XObject::Form::BarCode::ean13; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use base 'PDF::Builder::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 = '3.028'; # VERSION | |||||||||||||||||||||||||||
| 9 | 2 | our $LAST_UPDATE = '3.027'; # manually update whenever code is changed | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head1 NAME | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | PDF::Builder::Resource::XObject::Form::BarCode::ean13 - Specific information for EAN-13 bar codes | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | Inherits from L<PDF::Builder::Resource::XObject::Form::BarCode> | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 METHODS | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =head2 new | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | PDF::Builder::Resource::XObject::Form::BarCode::ean13->new() | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =over | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | Create an EAN-13 bar code object. Note that it is invoked from the Builder.pm | ||||||||||||||||||||||||||||
| 26 | level method! | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =back | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =cut | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | 1 | my ($class, $pdf, %options) = @_; | |||||||||||||||||||||||||||
| 34 | # copy dashed option names to preferred undashed names | ||||||||||||||||||||||||||||
| 35 | 1 | ▶ | if (defined $options{'-code'} && !defined $options{'code'}) { $options{'code'} = delete($options{'-code'}); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $options{"-code"} and not defined $options{"code"}
MC/DC0%0/2
defined $options{"-code"} and not defined $options{"code"}
defined $options{"-code"}
not defined $options{"code"}
Truth table33%1/3
A and not(B)
A= defined $options{"-code"}B= not defined $options{"code"}
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 1 | my $self = $class->SUPER::new($pdf, %options); | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 1 | my @bars = $self->encode($options{'code'}); | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 1 | $self->drawbar([@bars], $options{'caption'}); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 1 | return $self; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 2 | my @ean_code_odd = qw(3211 2221 2122 1411 1132 1231 1114 1312 1213 3112); | |||||||||||||||||||||||||||
| 47 | 2 | my @ean_code_even = qw(1123 1222 2212 1141 2311 1321 4111 2131 3121 2113); | |||||||||||||||||||||||||||
| 48 | 2 | my @parity = qw(OOOOOO OOEOEE OOEEOE OOEEEO OEOOEE OEEOOE OEEEOO OEOEOE OEOEEO OEEOEO); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 11 | ▶ | sub encode { | ||||||||||||||||||||||||||
|
Subroutine
encode: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 51 | 11 | my ($self, $string) = @_; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 11 | my @digits = split(//, $string); | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | # The first digit determines the even/odd pattern of the next six | ||||||||||||||||||||||||||||
| 56 | # digits, and is printed to the left of the barcode | ||||||||||||||||||||||||||||
| 57 | 11 | my $first = shift(@digits); | |||||||||||||||||||||||||||
| 58 | 11 | my @bars = (['07', $first]); | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # Start Guard | ||||||||||||||||||||||||||||
| 61 | 11 | push @bars, 'a1a'; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | # Digits 2-7 | ||||||||||||||||||||||||||||
| 64 | 11 | foreach my $i (0 .. 5) { | |||||||||||||||||||||||||||
| 65 | 66 | my $digit = shift(@digits); | |||||||||||||||||||||||||||
| 66 | 66 | ▶ | if (substr($parity[$first], $i, 1) eq 'O') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 39 | push @bars, [$ean_code_odd[$digit], $digit]; | |||||||||||||||||||||||||||
| 68 | } else { | ||||||||||||||||||||||||||||
| 69 | 27 | push @bars, [$ean_code_even[$digit], $digit]; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # Center Guard | ||||||||||||||||||||||||||||
| 74 | 11 | push @bars, '1a1a1'; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | # Digits 8-13 | ||||||||||||||||||||||||||||
| 77 | 11 | for (0..5) { | |||||||||||||||||||||||||||
| 78 | 66 | my $digit = shift @digits; | |||||||||||||||||||||||||||
| 79 | 66 | push @bars, [$ean_code_odd[$digit], $digit]; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | # Right Guard | ||||||||||||||||||||||||||||
| 83 | 11 | push @bars, 'a1a'; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 11 | return @bars; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub calculate_check_digit { | ||||||||||||||||||||||||||
|
Subroutine
calculate_check_digit: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 89 | 0 | my ($self, $string) = @_; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | my @digits = split(//, $string); | |||||||||||||||||||||||||||
| 92 | 0 | my $weight = 1; | |||||||||||||||||||||||||||
| 93 | 0 | my $checksum = 0; | |||||||||||||||||||||||||||
| 94 | 0 | foreach my $i (0..11) { | |||||||||||||||||||||||||||
| 95 | 0 | $checksum += $digits[$i] * $weight; | |||||||||||||||||||||||||||
| 96 | 0 | ▶ | $weight = $weight == 1? 3: 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | $checksum = $checksum % 10; | |||||||||||||||||||||||||||
| 100 | 0 | ▶ | return 0 unless $checksum; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 0 | return 10 - $checksum; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 2 | 1; | |||||||||||||||||||||||||||