API3/Compat/API2/Resource/XObject/Form/BarCode.pm

filter: Statementstmt 17.7% 22 / 124 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 22 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 46.6% 7 / 15 Podpod 62.5% 5 / 8 totaltotal 16.9% 34 / 201 CC 21 SCAR 50.2
CC
21
Cov
13%
drawbar
306.0
new
20.0
encode_string
6.0
CRAP 151.7
« API3/Compat/API2/Resource/CIDFont/CJKFont.pm ↑ Summary API3/Compat/API2/Basic/TTF/Coverage.pm »
1 #=======================================================================
2 # ____ ____ _____ _ ____ ___ ____
3 # | _ \| _ \| ___| _ _ / \ | _ \_ _| |___ \
4 # | |_) | | | | |_ (_) (_) / _ \ | |_) | | __) |
5 # | __/| |_| | _| _ _ / ___ \| __/| | / __/
6 # |_| |____/|_| (_) (_) /_/ \_\_| |___| |_____|
7 #
8 # A Perl Module Chain to faciliate the Creation and Modification
9 # of High-Quality "Portable Document Format (PDF)" Files.
10 #
11 # Copyright 1999-2005 Alfred Reibenschuh <areibens@cpan.org>.
12 #
13 #=======================================================================
14 #
15 # This library is free software; you can redistribute it and/or
16 # modify it under the terms of the GNU Lesser General Public
17 # License as published by the Free Software Foundation; either
18 # version 2 of the License, or (at your option) any later version.
19 #
20 # This library is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 # Lesser General Public License for more details.
24 #
25 # You should have received a copy of the GNU Lesser General Public
26 # License along with this library; if not, write to the
27 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 # Boston, MA 02111-1307, USA.
29 #
30 # $Id: BarCode.pm,v 2.0 2005/11/16 02:18:23 areibens Exp $
31 #
32 #=======================================================================
33 package PDF::API3::Compat::API2::Resource::XObject::Form::BarCode;
34
35 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
36
37 1 ▶ use PDF::API3::Compat::API2::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 ▶ use PDF::API3::Compat::API2::Basic::PDF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶ use PDF::API3::Compat::API2::Resource::XObject::Form::Hybrid;
Subroutine BEGIN: called CC=1 SCAR=0.0
40
41 1 ▶ use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
42
43 1 ▶ use vars qw(@ISA $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
44
45 1 @ISA = qw( PDF::API3::Compat::API2::Resource::XObject::Form::Hybrid );
46
47 1 ( $VERSION ) = sprintf '%i.%03i', split(/\./,('$Revision: 2.0 $' =~ /Revision: (\S+)\s/)[0]); # $Date: 2005/11/16 02:18:23 $
48
49 }
50 1 ▶no warnings qw[ deprecated recursion uninitialized ];
Subroutine BEGIN: called CC=1 SCAR=0.0
51
52 =item $res = PDF::API3::Compat::API2::Resource::XObject::Form::BarCode->new $pdf, %opts
53
54 Returns a barcode-form object.
55
56 =cut
57
58 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
59 0 my ($class,$pdf,%opts) = @_;
60 0 my $self;
61
62 0 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
63
64 0 $self=$class->SUPER::new($pdf);
65
66 0 $self->{' bfont'}=$opts{-font};
67
68 0 $self->{' umzn'}=$opts{-umzn}; # (u)pper (m)ending (z)o(n)e
69 0 $self->{' lmzn'}=$opts{-lmzn}; # (l)ower (m)ending (z)o(n)e
70 0 $self->{' zone'}=$opts{-zone};
71 0 $self->{' quzn'}=$opts{-quzn}; # (qu)iet (z)o(n)e
72 0 ▶ $self->{' ofwt'}=$opts{-ofwt}||0.01; # (o)ver(f)low (w)id(t)h
Condition0%0/2
$opts{'-ofwt'} || 0.01
l!l
00
MC/DC0%0/1
$opts{'-ofwt'} || 0.01
$opts{'-ofwt'}
Truth table0%0/2
A
A= $opts{'-ofwt'}
Aresult
11
00
73 0 $self->{' fnsz'}=$opts{-fnsz}; # (f)o(n)t(s)i(z)e
74 0 ▶ $self->{' spcr'}=$opts{-spcr}||'';
Condition0%0/2
$opts{'-spcr'} || ''
l!l
00
MC/DC0%0/1
$opts{'-spcr'} || ''
$opts{'-spcr'}
Truth table0%0/2
A
A= $opts{'-spcr'}
Aresult
11
00
75
76 0 return($self);
77 }
78
79 =item $res = PDF::API3::Compat::API2::Resource::XObject::Form::BarCode->new_api $api, %opts
80
81 Returns a barcode-form object. This method is different from 'new' that
82 it needs an PDF::API3::Compat::API2-object rather than a Text::PDF::File-object.
83
84 =cut
85
86 0 ▶sub new_api {
Subroutine new_api: not called CC=1 SCAR=6.9
Pod documented
87 0 my ($class,$api,@opts)=@_;
88
89 0 my $obj=$class->new($api->{pdf},@opts);
90 0 $obj->{' api'}=$api;
91
92 0 return($obj);
93 }
94
95 0 ▶sub outobjdeep {
Subroutine outobjdeep: not called CC=1 SCAR=6.9
Pod documented
96 0 my ($self, @opts) = @_;
97 0 $self->SUPER::outobjdeep(@opts);
98 }
99
100 1 my %bar_wdt=(
101 0 => 0,
102 1 => 1,
103 2 => 2,
104 3 => 3,
105 4 => 4,
106 5 => 5,
107 6 => 6,
108 7 => 7,
109 8 => 8,
110 9 => 9,
111 'a' => 1,
112 'b' => 2,
113 'c' => 3,
114 'd' => 4,
115 'e' => 5,
116 'f' => 6,
117 'g' => 7,
118 'h' => 8,
119 'i' => 9,
120 'A' => 1,
121 'B' => 2,
122 'C' => 3,
123 'D' => 4,
124 'E' => 5,
125 'F' => 6,
126 'G' => 7,
127 'H' => 8,
128 'I' => 9,
129 );
130
131 0 ▶sub encode {
Subroutine encode: not called CC=1 SCAR=6.9
Pod undocumented
132 0 my $self=shift @_;
133 0 my $string=shift @_;
134 0 my @bar;
135
136 0 my @c=split(//,$string);
137
138 0 @bar = map { [ $self->encode_string($_), $_ ] } @c;
139
140 0 return(@bar);
141 }
142
143 0 ▶sub encode_string {
Subroutine encode_string: not called CC=2 SCAR=17.9
Pod undocumented
144 0 my $self=shift @_;
145 0 my $string=shift @_;
146 0 my $bar;
147 0 my @c=split(//,$string);
148
149 0 foreach my $char (@c) {
150 0 $bar.=$self->encode_char($char);
151 }
152 0 return($bar);
153 }
154
155 0 ▶sub drawbar {
Subroutine drawbar: not called CC=17 SCAR=57.2
Pod undocumented
156 0 my $self=shift @_;
157 0 my @bar=@{shift @_};
158 0 my $bartext=shift @_;
159 0 my $ext=shift @_;
160
161 0 my $x=$self->{' quzn'};
162 0 my ($code,$str,$f,$t,$l,$h,$xo);
163 0 $self->fillcolor('black');
164 0 $self->strokecolor('black');
165
166 0 my $bw=1;
167 0 foreach my $b (@bar) {
168 0 ▶ if(ref($b)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $b) { } 0 0 0
169 0 ($code,$str)=@{$b};
170 } else {
171 0 $code=$b;
172 0 $str=undef;
173 }
174 0 $xo=0;
175 0 foreach my $c (split(//,$code)) {
176 0 my $w=$bar_wdt{$c};
177 0 $xo+=$w/2;
178 0 ▶ if($c=~/[0-9]/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($c =~ /[0-9]/) { } 0 0 0
elsif ($c =~ /[a-z]/) { } 0 0 0
elsif ($c =~ /[A-Z]/) { } 0 0 0
179 0 $l=$self->{' quzn'} + $self->{' lmzn'};
180 0 $h=$self->{' quzn'} + $self->{' lmzn'} + $self->{' zone'} + $self->{' umzn'};
181 0 $t=$self->{' quzn'};
182 0 ▶ $f=$self->{' fnsz'}||$self->{' lmzn'};
Condition0%0/3
$self->{' fnsz'} || $self->{' lmzn'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{' fnsz'} || $self->{' lmzn'}
$self->{' fnsz'} $self->{' lmzn'}
Truth table0%0/3
A || B
A= $self->{' fnsz'}B= $self->{' lmzn'}
ABresult
1X1
011
000
183 } elsif($c=~/[a-z]/) {
184 0 $l=$self->{' quzn'};
185 0 $h=$self->{' quzn'} + $self->{' lmzn'} + $self->{' zone'} + $self->{' umzn'};
186 0 $t=$self->{' quzn'} + $self->{' lmzn'} + $self->{' zone'} + $self->{' umzn'};
187 0 ▶ $f=$self->{' fnsz'}||$self->{' umzn'};
Condition0%0/3
$self->{' fnsz'} || $self->{' umzn'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{' fnsz'} || $self->{' umzn'}
$self->{' fnsz'} $self->{' umzn'}
Truth table0%0/3
A || B
A= $self->{' fnsz'}B= $self->{' umzn'}
ABresult
1X1
011
000
188 } elsif($c=~/[A-Z]/) {
189 0 $l=$self->{' quzn'};
190 0 $h=$self->{' quzn'} + $self->{' lmzn'} + $self->{' zone'};
191 0 ▶ $f=$self->{' fnsz'}||$self->{' umzn'};
Condition0%0/3
$self->{' fnsz'} || $self->{' umzn'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{' fnsz'} || $self->{' umzn'}
$self->{' fnsz'} $self->{' umzn'}
Truth table0%0/3
A || B
A= $self->{' fnsz'}B= $self->{' umzn'}
ABresult
1X1
011
000
192 0 $t=$self->{' quzn'} + $self->{' lmzn'} + $self->{' zone'} + $self->{' umzn'} - $f;
193 } else {
194 0 $l=$self->{' quzn'} + $self->{' lmzn'};
195 0 $h=$self->{' quzn'} + $self->{' lmzn'} + $self->{' zone'} + $self->{' umzn'};
196 0 $t=$self->{' quzn'};
197 0 ▶ $f=$self->{' fnsz'}||$self->{' lmzn'};
Condition0%0/3
$self->{' fnsz'} || $self->{' lmzn'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{' fnsz'} || $self->{' lmzn'}
$self->{' fnsz'} $self->{' lmzn'}
Truth table0%0/3
A || B
A= $self->{' fnsz'}B= $self->{' lmzn'}
ABresult
1X1
011
000
198 }
199 0 ▶ if($bw) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bw) { } 0 0 0
200 0 ▶ if($c ne '0') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c ne 0) 0 0 0
201 0 $self->linewidth($w-$self->{' ofwt'});
202 0 $self->move($x+$xo,$l);
203 0 $self->line($x+$xo,$h);
204 0 $self->stroke;
205 }
206 0 $bw=0;
207 } else {
208 0 $bw=1;
209 }
210 0 $xo+=$w/2;
211 }
212 0 ▶ if(defined($str) && ($self->{' lmzn'}>0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $str and $self->{" lmzn"} > 0) 0 0 0
Condition0%0/3
defined $str and $self->{" lmzn"} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $str and $self->{" lmzn"} > 0
defined $str $self->{" lmzn"} > 0
Truth table0%0/3
A and B
A= defined $strB= $self->{" lmzn"} > 0
ABresult
0X0
100
111
213 0 $str=join($self->{' spcr'},split(//,$str));
214 0 $self->textstart;
215 0 $self->translate($x+($xo/2),$t);
216 0 $self->font($self->{' bfont'},$f);
217 0 $self->text_center($str);
218 0 $self->textend;
219 }
220 0 $x+=$xo;
221 }
222 0 ▶ if(defined $bartext) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bartext) 0 0 0
223 0 ▶ $f=$self->{' fnsz'}||$self->{' lmzn'};
Condition0%0/3
$self->{' fnsz'} || $self->{' lmzn'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{' fnsz'} || $self->{' lmzn'}
$self->{' fnsz'} $self->{' lmzn'}
Truth table0%0/3
A || B
A= $self->{' fnsz'}B= $self->{' lmzn'}
ABresult
1X1
011
000
224 0 $t=$self->{' quzn'}-$f;
225 0 $self->textstart;
226 0 $self->translate(($self->{' quzn'}+$x)/2,$t);
227 0 $self->font($self->{' bfont'},$f);
228 0 $self->text_center($bartext);
229 0 $self->textend;
230 }
231 0 $self->{' w'}=$self->{' quzn'}+$x;
232 0 $self->{' h'}=2*$self->{' quzn'} + $self->{' lmzn'} + $self->{' zone'} + $self->{' umzn'};
233 0 $self->{BBox}=PDFArray(PDFNum(0),PDFNum(0),PDFNum($self->{' w'}),PDFNum($self->{' h'}));
234 }
235
236 =item $wd = $bc->width
237
238 =cut
239
240 0 ▶sub width {
Subroutine width: not called CC=1 SCAR=6.9
Pod documented
241 0 my $self = shift @_;
242 0 return($self->{' w'});
243 }
244
245 =item $ht = $bc->height
246
247 =cut
248
249 0 ▶sub height {
Subroutine height: not called CC=1 SCAR=6.9
Pod documented
250 0 my $self = shift @_;
251 0 return($self->{' h'});
252 }
253
254 1 1;
255
256 __END__
« API3/Compat/API2/Resource/CIDFont/CJKFont.pm ↑ Summary API3/Compat/API2/Basic/TTF/Coverage.pm »