File: codabar.pm

package info (click to toggle)
libpdf-api2-perl 2.019-1%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 20,264 kB
  • sloc: perl: 42,313; sh: 23; makefile: 9
file content (40 lines) | stat: -rw-r--r-- 828 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package PDF::API2::Resource::XObject::Form::BarCode::codabar;

our $VERSION = '2.019';

use base 'PDF::API2::Resource::XObject::Form::BarCode';

no warnings qw[ deprecated recursion uninitialized ];

sub new {
    my ($class,$pdf,%opts) = @_;
    my $self;

    $class = ref $class if ref $class;

    $self=$class->SUPER::new($pdf,%opts);

    my @bar = $self->encode($opts{-code});

    $self->drawbar([@bar]);

    return($self);
}


my $codabar=q|0123456789-$:/.+ABCD|;

my @barcodabar=qw(
    11111221 11112211 11121121 22111111 11211211
    21111211 12111121 12112111 12211111 21121111
    11122111 11221111 21112121 21211121 21212111
    11212121 11221211 12121121 12121121 11122211
);

sub encode_char {
        my $self=shift @_;
        my $char=uc(shift @_);
        return($barcodabar[index($codabar,$char)]);
}

1;