| 1 | package PDF::API2::Resource::XObject::Form::BarCode::int2of5; | ||||||||||
| 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 | # Interleaved 2 of 5 Barcodes | ||||||||||
| 11 | |||||||||||
| 12 | # Pairs of digits are encoded; the first digit is represented by five | ||||||||||
| 13 | # bars, and the second digit is represented by five spaces interleaved | ||||||||||
| 14 | # with the bars. | ||||||||||
| 15 | |||||||||||
| 16 | sub new { | ||||||||||
| 17 | 1 | ▶ | my ($class, $pdf, %options) = @_; | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 18 | 1 | my $self = $class->SUPER::new($pdf,%options); | |||||||||
| 19 | |||||||||||
| 20 | 1 | my @bars = $self->encode($options{'-code'}); | |||||||||
| 21 | |||||||||||
| 22 | 1 | $self->drawbar([@bars], $options{'caption'}); | |||||||||
| 23 | |||||||||||
| 24 | 1 | return $self; | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 2 | my @bar25interleaved = qw(11221 21112 12112 22111 11212 21211 12211 11122 21121 12121); | |||||||||
| 28 | |||||||||||
| 29 | sub encode { | ||||||||||
| 30 | 2 | ▶ | my ($self, $string) = @_; | ||||||||
|
Subroutine
encode: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||
| 31 | |||||||||||
| 32 | # Remove any character that isn't a digit | ||||||||||
| 33 | 2 | $string =~ s/[^0-9]//g; | |||||||||
| 34 | |||||||||||
| 35 | # Prepend a 0 if there is an odd number of digits | ||||||||||
| 36 | 2 | ▶ | $string = '0' . $string if length($string) % 2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | |||||||||||
| 38 | # Start Code | ||||||||||
| 39 | 2 | my @bars = ('aaaa'); | |||||||||
| 40 | |||||||||||
| 41 | # Encode pairs of digits | ||||||||||
| 42 | 2 | my ($c1, $c2, $s1, $s2, $pair); | |||||||||
| 43 | 2 | ▶ | while (length($string)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 6 | ($c1, $c2, $string) = split //, $string, 3; | |||||||||
| 45 | |||||||||||
| 46 | 6 | $s1 = $bar25interleaved[$c1]; | |||||||||
| 47 | 6 | $s2 = $bar25interleaved[$c2]; | |||||||||
| 48 | 6 | $pair = ''; | |||||||||
| 49 | 6 | foreach my $i (0 .. 4) { | |||||||||
| 50 | 30 | $pair .= substr($s1, $i, 1); | |||||||||
| 51 | 30 | $pair .= substr($s2, $i, 1); | |||||||||
| 52 | } | ||||||||||
| 53 | 6 | push @bars, [$pair, ($c1 . $c2)]; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | # Stop Code | ||||||||||
| 57 | 2 | push @bars, 'baaa'; | |||||||||
| 58 | |||||||||||
| 59 | 2 | return @bars; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 2 | 1; | |||||||||