| 1 | package PDF::API2::Resource::XObject::Form::BarCode; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use base 'PDF::API2::Resource::XObject::Form::Hybrid'; | ||||||||||||||||||||||||||
|
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 | 2 | ▶ | use PDF::API2::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use PDF::API2::Basic::PDF::Utils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | PDF::API2::Resource::XObject::Form::BarCode - Base class for one-dimensional barcodes | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 METHODS | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =over | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =item $barcode = PDF::API2::Resource::XObject::Form::BarCode->new($pdf, %options) | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | Creates a barcode form resource. | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =cut | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | sub new { | ||||||||||||||||||||||||||||
| 28 | 6 | ▶ | my ($class, $pdf, %options) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=9 SCAR=22.7
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | 6 | my $self = $class->SUPER::new($pdf); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 6 | $self->{' bfont'} = $options{'-font'}; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 6 | ▶ | $self->{' umzn'} = $options{'-umzn'} || 0; # (u)pper (m)ending (z)o(n)e | ||||||||||||||||||||||||||
|
Condition50%1/2
$options{'-umzn'} || 0
MC/DC0%0/1
$options{'-umzn'} || 0
$options{'-umzn'}
Truth table50%1/2
A
A= $options{'-umzn'}
| |||||||||||||||||||||||||||||
| 34 | 6 | ▶ | $self->{' lmzn'} = $options{'-lmzn'} || 0; # (l)ower (m)ending (z)o(n)e | ||||||||||||||||||||||||||
|
Condition100%2/2
$options{'-lmzn'} || 0
MC/DC100%1/1
$options{'-lmzn'} || 0
$options{'-lmzn'}
Truth table100%2/2
A
A= $options{'-lmzn'}
| |||||||||||||||||||||||||||||
| 35 | 6 | ▶ | $self->{' zone'} = $options{'-zone'} || 0; # barcode height | ||||||||||||||||||||||||||
|
Condition100%2/2
$options{'-zone'} || 0
MC/DC100%1/1
$options{'-zone'} || 0
$options{'-zone'}
Truth table100%2/2
A
A= $options{'-zone'}
| |||||||||||||||||||||||||||||
| 36 | 6 | ▶ | $self->{' quzn'} = $options{'-quzn'} || 0; # (qu)iet (z)o(n)e | ||||||||||||||||||||||||||
|
Condition50%1/2
$options{'-quzn'} || 0
MC/DC0%0/1
$options{'-quzn'} || 0
$options{'-quzn'}
Truth table50%1/2
A
A= $options{'-quzn'}
| |||||||||||||||||||||||||||||
| 37 | 6 | ▶ | $self->{' ofwt'} = $options{'-ofwt'} || 0.01; # (o)ver(f)low (w)id(t)h | ||||||||||||||||||||||||||
|
Condition50%1/2
$options{'-ofwt'} || 0.01
MC/DC0%0/1
$options{'-ofwt'} || 0.01
$options{'-ofwt'}
Truth table50%1/2
A
A= $options{'-ofwt'}
| |||||||||||||||||||||||||||||
| 38 | 6 | $self->{' fnsz'} = $options{'-fnsz'}; # (f)o(n)t(s)i(z)e | |||||||||||||||||||||||||||
| 39 | 6 | ▶ | $self->{' spcr'} = $options{'-spcr'} || ''; # (sp)a(c)e(r) between chars in label | ||||||||||||||||||||||||||
|
Condition50%1/2
$options{'-spcr'} || ''
MC/DC0%0/1
$options{'-spcr'} || ''
$options{'-spcr'}
Truth table50%1/2
A
A= $options{'-spcr'}
| |||||||||||||||||||||||||||||
| 40 | 6 | ▶ | $self->{' mils'} = $options{'-mils'} || 1000/72; # single barcode unit width. 1 mil = 1/1000 of one inch. 1000/72 - for backward compatibility | ||||||||||||||||||||||||||
|
Condition50%1/2
$options{'-mils'} || 13.8888888888889
MC/DC0%0/1
$options{'-mils'} || 13.8888888888889
$options{'-mils'}
Truth table50%1/2
A
A= $options{'-mils'}
| |||||||||||||||||||||||||||||
| 41 | 6 | ▶ | $self->{' color'} = $options{'-color'} || 'black'; # barcode color | ||||||||||||||||||||||||||
|
Condition50%1/2
$options{'-color'} || 'black'
MC/DC0%0/1
$options{'-color'} || 'black'
$options{'-color'}
Truth table50%1/2
A
A= $options{'-color'}
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 6 | return $self; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 2 | my %bar_widths = ( | |||||||||||||||||||||||||||
| 47 | 0 => 0, | ||||||||||||||||||||||||||||
| 48 | 1 => 1, 'a' => 1, 'A' => 1, | ||||||||||||||||||||||||||||
| 49 | 2 => 2, 'b' => 2, 'B' => 2, | ||||||||||||||||||||||||||||
| 50 | 3 => 3, 'c' => 3, 'C' => 3, | ||||||||||||||||||||||||||||
| 51 | 4 => 4, 'd' => 4, 'D' => 4, | ||||||||||||||||||||||||||||
| 52 | 5 => 5, 'e' => 5, 'E' => 5, | ||||||||||||||||||||||||||||
| 53 | 6 => 6, 'f' => 6, 'F' => 6, | ||||||||||||||||||||||||||||
| 54 | 7 => 7, 'g' => 7, 'G' => 7, | ||||||||||||||||||||||||||||
| 55 | 8 => 8, 'h' => 8, 'H' => 8, | ||||||||||||||||||||||||||||
| 56 | 9 => 9, 'i' => 9, 'I' => 9, | ||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | sub encode { | ||||||||||||||||||||||||||||
| 60 | 2 | ▶ | my ($self, $string) = @_; | ||||||||||||||||||||||||||
|
Subroutine
encode: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | 2 | my @bars = map { [ $self->encode_string($_), $_ ] } split //, $string; | |||||||||||||||||||||||||||
| 62 | 2 | return @bars; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | sub encode_string { | ||||||||||||||||||||||||||||
| 66 | 17 | ▶ | my ($self, $string) = @_; | ||||||||||||||||||||||||||
|
Subroutine
encode_string: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 17 | my $bar; | |||||||||||||||||||||||||||
| 69 | 17 | foreach my $character (split //, $string) { | |||||||||||||||||||||||||||
| 70 | 17 | $bar .= $self->encode_char($character); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | 17 | return $bar; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | sub drawbar { | ||||||||||||||||||||||||||||
| 76 | 6 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||
|
Subroutine
drawbar: called CC=19 SCAR=33.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 77 | 6 | my @sets = @{shift()}; | |||||||||||||||||||||||||||
| 78 | 6 | my $caption = shift(); | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 6 | $self->fillcolor($self->{' color'}); | |||||||||||||||||||||||||||
| 81 | 6 | $self->strokecolor($self->{' color'}); | |||||||||||||||||||||||||||
| 82 | 6 | $self->linedash(); | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 6 | my $x = $self->{' quzn'}; | |||||||||||||||||||||||||||
| 85 | 6 | my $is_space_next = 0; | |||||||||||||||||||||||||||
| 86 | 6 | my $wdt_factor = $self->{' mils'} / 1000 * 72; | |||||||||||||||||||||||||||
| 87 | 6 | foreach my $set (@sets) { | |||||||||||||||||||||||||||
| 88 | 30 | my ($code, $label); | |||||||||||||||||||||||||||
| 89 | 30 | ▶ | if (ref($set)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 18 | ($code, $label) = @{$set}; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | else { | ||||||||||||||||||||||||||||
| 93 | 12 | $code = $set; | |||||||||||||||||||||||||||
| 94 | 12 | $label = undef; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 30 | my $code_width = 0; | |||||||||||||||||||||||||||
| 98 | 30 | my ($font_size, $y_label); | |||||||||||||||||||||||||||
| 99 | 30 | foreach my $bar (split //, $code) { | |||||||||||||||||||||||||||
| 100 | 172 | my $bar_width = $bar_widths{$bar} * $wdt_factor; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 172 | my ($y0, $y1); | |||||||||||||||||||||||||||
| 103 | 172 | ▶ | if ($bar =~ /[0-9]/) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 104 | 115 | $y0 = $self->{' quzn'} + $self->{' lmzn'}; | |||||||||||||||||||||||||||
| 105 | 115 | $y1 = $self->{' quzn'} + $self->{' lmzn'} + $self->{' zone'} + $self->{' umzn'}; | |||||||||||||||||||||||||||
| 106 | 115 | $y_label = $self->{' quzn'}; | |||||||||||||||||||||||||||
| 107 | 115 | ▶ | if ($self->{' fnsz'} and $self->{' lmzn'} < $self->{' fnsz'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{" fnsz"} and $self->{" lmzn"} < $self->{" fnsz"}
MC/DC0%0/2
$self->{" fnsz"} and $self->{" lmzn"} < $self->{" fnsz"}
$self->{" fnsz"}
$self->{" lmzn"} < $self->{" fnsz"}
Truth table66%2/3
A and B
A= $self->{" fnsz"}B= $self->{" lmzn"} < $self->{" fnsz"}
| |||||||||||||||||||||||||||||
| 108 | 0 | $y_label -= $self->{' fnsz'} * 0.8 - $self->{' lmzn'}; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | 115 | ▶ | $font_size = $self->{' fnsz'} || $self->{' lmzn'}; | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->{' fnsz'} || $self->{' lmzn'}
MC/DC50%1/2
$self->{' fnsz'} || $self->{' lmzn'}
$self->{' fnsz'}
$self->{' lmzn'}
Truth table66%2/3
A || B
A= $self->{' fnsz'}B= $self->{' lmzn'}
| |||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | elsif ($bar =~ /[a-z]/) { | ||||||||||||||||||||||||||||
| 113 | 57 | $y0 = $self->{' quzn'}; | |||||||||||||||||||||||||||
| 114 | 57 | $y1 = $self->{' quzn'} + $self->{' lmzn'} + $self->{' zone'} + $self->{' umzn'}; | |||||||||||||||||||||||||||
| 115 | 57 | $y_label = $self->{' quzn'} + $self->{' lmzn'} + $self->{' zone'} + $self->{' umzn'} + 2; | |||||||||||||||||||||||||||
| 116 | 57 | ▶ | $font_size = $self->{' fnsz'} || $self->{' umzn'}; | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->{' fnsz'} || $self->{' umzn'}
MC/DC50%1/2
$self->{' fnsz'} || $self->{' umzn'}
$self->{' fnsz'}
$self->{' umzn'}
Truth table66%2/3
A || B
A= $self->{' fnsz'}B= $self->{' umzn'}
| |||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | elsif ($bar =~ /[A-Z]/) { | ||||||||||||||||||||||||||||
| 119 | 0 | $y0 = $self->{' quzn'}; | |||||||||||||||||||||||||||
| 120 | 0 | $y1 = $self->{' quzn'} + $self->{' lmzn'} + $self->{' zone'}; | |||||||||||||||||||||||||||
| 121 | 0 | ▶ | $font_size = $self->{' fnsz'} || $self->{' umzn'}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{' fnsz'} || $self->{' umzn'}
MC/DC0%0/2
$self->{' fnsz'} || $self->{' umzn'}
$self->{' fnsz'}
$self->{' umzn'}
Truth table0%0/3
A || B
A= $self->{' fnsz'}B= $self->{' umzn'}
| |||||||||||||||||||||||||||||
| 122 | 0 | $y_label = $self->{' quzn'} + $self->{' lmzn'} + $self->{' zone'} + $self->{' umzn'} - $font_size; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | else { | ||||||||||||||||||||||||||||
| 125 | 0 | $y0 = $self->{' quzn'} + $self->{' lmzn'}; | |||||||||||||||||||||||||||
| 126 | 0 | $y1 = $self->{' quzn'} + $self->{' lmzn'} + $self->{' zone'} + $self->{' umzn'}; | |||||||||||||||||||||||||||
| 127 | 0 | $y_label = $self->{' quzn'}; | |||||||||||||||||||||||||||
| 128 | 0 | ▶ | $font_size = $self->{' fnsz'} || $self->{' lmzn'}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{' fnsz'} || $self->{' lmzn'}
MC/DC0%0/2
$self->{' fnsz'} || $self->{' lmzn'}
$self->{' fnsz'}
$self->{' lmzn'}
Truth table0%0/3
A || B
A= $self->{' fnsz'}B= $self->{' lmzn'}
| |||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 172 | ▶ | unless ($is_space_next or $bar eq '0') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$is_space_next or $bar eq 0
MC/DC100%2/2
$is_space_next or $bar eq 0
$is_space_next
$bar eq 0
Truth table100%3/3
A or B
A= $is_space_nextB= $bar eq 0
| |||||||||||||||||||||||||||||
| 132 | 86 | $self->linewidth($bar_width - $self->{' ofwt'}); | |||||||||||||||||||||||||||
| 133 | 86 | $self->move($x + $code_width + $bar_width / 2, $y0); | |||||||||||||||||||||||||||
| 134 | 86 | $self->line($x + $code_width + $bar_width / 2, $y1); | |||||||||||||||||||||||||||
| 135 | 86 | $self->stroke(); | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | 172 | $is_space_next = not $is_space_next; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 172 | $code_width += $bar_width; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 30 | ▶ | if (defined($label) and $self->{' lmzn'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $label and $self->{" lmzn"}
MC/DC100%2/2
defined $label and $self->{" lmzn"}
defined $label
$self->{" lmzn"}
Truth table100%3/3
A and B
A= defined $labelB= $self->{" lmzn"}
| |||||||||||||||||||||||||||||
| 143 | 1 | $label = join($self->{' spcr'}, split //, $label); | |||||||||||||||||||||||||||
| 144 | 1 | $self->textstart(); | |||||||||||||||||||||||||||
| 145 | 1 | $self->translate($x + ($code_width / 2), $y_label); | |||||||||||||||||||||||||||
| 146 | 1 | $self->font($self->{' bfont'}, $font_size); | |||||||||||||||||||||||||||
| 147 | 1 | $self->text_center($label); | |||||||||||||||||||||||||||
| 148 | 1 | $self->textend(); | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 30 | $x += $code_width; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 6 | $x += $self->{' quzn'}; | |||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 6 | ▶ | if (defined $caption) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | 0 | ▶ | my $font_size = $self->{' fnsz'} || $self->{' lmzn'}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{' fnsz'} || $self->{' lmzn'}
MC/DC0%0/2
$self->{' fnsz'} || $self->{' lmzn'}
$self->{' fnsz'}
$self->{' lmzn'}
Truth table0%0/3
A || B
A= $self->{' fnsz'}B= $self->{' lmzn'}
| |||||||||||||||||||||||||||||
| 158 | 0 | my $y_caption = $self->{' quzn'} - $font_size; | |||||||||||||||||||||||||||
| 159 | 0 | $self->textstart(); | |||||||||||||||||||||||||||
| 160 | 0 | $self->translate($x / 2, $y_caption); | |||||||||||||||||||||||||||
| 161 | 0 | $self->font($self->{' bfont'}, $font_size); | |||||||||||||||||||||||||||
| 162 | 0 | $self->text_center($caption); | |||||||||||||||||||||||||||
| 163 | 0 | $self->textend(); | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 6 | $self->{' w'} = $x; | |||||||||||||||||||||||||||
| 167 | 6 | $self->{' h'} = 2 * $self->{' quzn'} + $self->{' lmzn'} + $self->{' zone'} + $self->{' umzn'}; | |||||||||||||||||||||||||||
| 168 | 6 | $self->bbox(0, 0, $self->{' w'}, $self->{' h'}); | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | =item $width = $barcode->width() | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | =cut | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | sub width { | ||||||||||||||||||||||||||||
| 176 | 0 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||
|
Subroutine
width: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 177 | 0 | return $self->{' w'}; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | =item $height = $barcode->height() | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | =cut | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | sub height { | ||||||||||||||||||||||||||||
| 185 | 0 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||
|
Subroutine
height: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 186 | 0 | return $self->{' h'}; | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | =back | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | =cut | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 2 | 1; | |||||||||||||||||||||||||||