Merge pull request #2890 from solgenomics/topic/check_login_always
[sgn.git] / lib / CXGN / ZPL.pm
blob3adbe6970cdc7057f4ef7387379a4490bcb34d07
2 package CXGN::ZPL;
4 use Moose;
6 has 'font' => ( is => 'rw',
7 isa => 'Str',
8 default => 'AA',
9 );
11 has 'print_width' => ( is => 'rw',
12 isa => 'Num',
15 has 'label_length' => ( is => 'rw',
16 isa => 'Num',
19 has 'command_list' => ( is => 'rw',
20 isa => 'ArrayRef',
23 sub start_sequence {
24 my $self = shift;
25 $self->add("^XA");
28 sub label_format {
29 my $self = shift;
30 my $label_length = $self->label_length();
31 my $print_width = $self->print_width();
32 $self->add("^LL$label_length^PW$print_width");
35 sub new_element {
36 my $self = shift;
37 my ($type, $x, $y, $size, $value) = @_;
39 my %dispatcher = (
40 ZebraText => \&text,
41 Code128 => \&code128,
42 QRCode => \&qrcode,
45 if (exists $dispatcher{$type}) {
46 $dispatcher{$type}( $self, $x, $y, $size, $value);
50 sub code128 {
51 my $self = shift;
52 my ($x, $y, $size, $value) = @_;
53 my $height = $size * 25;
54 $self->add("^FO$x,$y^BCN,$height,N,N,N^FD $value^FS");
57 sub qrcode {
58 my $self = shift;
59 my ($x, $y, $size, $value) = @_;
60 $y = $y - 10; #adjust for 10 dot offset
61 $self->add("^FO$x,$y^BQ,,$size^FDMA,$value^FS");
64 sub text {
65 my $self = shift;
66 my ($x, $y, $size, $value) = @_;
67 my $font = $self->font();
68 $self->add("^FO$x,$y^$font,$size^FD$value^FS");
71 sub end_sequence {
72 my $self = shift;
73 $self->add("^XZ");
76 sub add {
77 my $self = shift;
78 my $command = shift;
79 my $command_list = $self->command_list();
80 push @$command_list, $command;
81 $self->command_list($command_list);
84 sub render {
85 my $self = shift;
86 my $zpl = "";
87 foreach my $c (@{$self->command_list()}) {
88 $zpl .= "$c\n";
90 return $zpl;