blib/lib/PDF/Reuse/Barcode.pm

filter: Statementstmt 36.5% 153 / 419 Branchbran 27.4% 34 / 124 Conditioncond 66.6% 8 / 12 MC/DCmcdc 57.1% 4 / 7 Subroutinesub 57.6% 15 / 26 Podpod 61.9% 13 / 21 totaltotal 37.2% 227 / 609 CC 83 SCAR 32.0
CC
83
Cov
35%
UPCE
72.0
EAN13
56.0
EAN8
56.0
CRAP 24.5
↑ Summary
1 package PDF::Reuse::Barcode;
2  
3 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use PDF::Reuse;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 our $VERSION = '0.11';
10  
11 2 my ($str, $xsize, $ysize, $height, $sPtn, @sizes, $length, $value, %default);
12 2 my $qrcode = 0;
13  
14 # The point size barcode text has always used. The overflow handling below
15 # keys off this so pre-0.10 output stays byte-identical; the two must not
16 # drift apart.
17 2 our $DEFAULT_TEXTSIZE = 10;
18  
19 # Tallest glyph, in em above the baseline, that a barcode value can put on
20 # the page: 750/1000, the AFM bbox ury of Courier's bar glyph. Code128
21 # accepts the whole printable ASCII range, so the ceiling has to cover it
22 # rather than just the digits at 622 -- Code39 alone reaches 662 with a
23 # dollar sign, which overprinted above 32 point. Deliberately the maximum
24 # and not a per-value measurement: over-lifting costs a little whitespace
25 # above the text, under-lifting puts glyphs through the bars and breaks
26 # scanning.
27 #
28 # The font itself goes higher -- accented capitals reach 805 -- but every
29 # symbology here rejects high-byte characters at validation, so those
30 # glyphs cannot reach the page through this module.
31 2 my $GLYPH_HEIGHT_EM = 0.75;
32  
33 # How far general2() lifts the bars to keep them clear of taller text. Set by
34 # standardEnd() before it calls general2(); left at 0 by the EAN and UPC
35 # paths, which render their text at a fixed 10 point and must not move.
36 2 my $textLift = 0;
37  
38 sub init
39 11 ▶{ %default = ( value => '0000000',
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
40 x => 0,
41 y => 0,
42 size => 1,
43 xsize => 1,
44 ysize => 1,
45 rotate => 0,
46 background => '1 1 1',
47 graybackground => 1,
48 drawbackground => 1,
49 text => 'yes',
50 prolong => 0,
51 hide_asterisk => 0,
52 modulesize => 1,
53 textsize => $DEFAULT_TEXTSIZE,
54 qr_ecc => 'M',
55 qr_version => 1,
56 qr_padding => 0,
57 mode => 'graphic');
58 11 $str = '';
59 11 $xsize = 1;
60 11 $ysize = 1;
61 11 $height = 37;
62 11 $sPtn = '';
63 11 @sizes = ();
64 11 $length = 0;
65 11 $textLift = 0;
66 11 $qrcode = 0;
67 11 $value = ''
68 }
69  
70  
71 sub general1
72 11 ▶{ $default{'xsize'} = 1 unless ($default{'xsize'} != 0);
Subroutine general1: called CC=5 SCAR=19.4
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless $default{"xsize"} != 0 0 11 11
73 11 ▶ $default{'ysize'} = 1 unless ($default{'ysize'} != 0);
Branch: 1 branch
BranchTrueFalseTotal
unless $default{"ysize"} != 0 0 11 11
74 11 ▶ $default{'size'} = 1 unless ($default{'size'} != 0);
Branch: 1 branch
BranchTrueFalseTotal
unless $default{"size"} != 0 0 11 11
75 11 $xsize = $default{'xsize'} * $default{'size'};
76 11 $ysize = $default{'ysize'} * $default{'size'};
77 11 $str = "q\n";
78 11 $str .= "$xsize 0 0 $ysize $default{'x'} $default{'y'} cm\n";
79 11 ▶ if ($default{'rotate'} != 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($default{"rotate"} != 0) 0 11 11
80 0 { my $radian = sprintf("%.6f", $default{'rotate'} / 57.2957795); # approx.
81 0 my $Cos = sprintf("%.6f", cos($radian));
82 0 my $Sin = sprintf("%.6f", sin($radian));
83 0 my $negSin = $Sin * -1;
84 0 $str .= "$Cos $Sin $negSin $Cos 0 0 cm\n";
85 }
86 }
87  
88 sub general2
89 11 ▶{ if ($qrcode)
Subroutine general2: called CC=8 SCAR=22.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if ($qrcode) { } 3 8 11
90 3 { my $m = $default{'modulesize'};
91 3 my @rows = split(/\n/, $sPtn);
92 3 $length = length($rows[0]) * $m;
93 3 $height = (1 + scalar(@rows)) * $m;
94 3 my $step = 1;
95  
96 3 ▶ if ($default{'drawbackground'})
Branch: 1 branch
BranchTrueFalseTotal
if ($default{"drawbackground"}) 2 1 3
97 2 { $str .= "$default{'graybackground'} g\n";
98 2 $str .= "0 0 $length $height re\n";
99 2 $str .= 'f*' . "\n";
100 2 $str .= "0 g\n";
101 }
102 3 prAdd($str);
103  
104 3 @sizes = prFontSize(12);
105  
106 3 $str = Qr( 0, $step, $sPtn);
107 }
108 else
109 8 { $length = 20 + (length($sPtn) * 0.9);
110 8 $height = 38 + $textLift;
111 8 my $step = 9 + $textLift;
112 8 my $prolong = 0;
113 8 ▶ if ($default{'prolong'} > 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($default{"prolong"} > 1) 0 8 8
114 0 { $prolong = $default{'prolong'};
115 0 $height = 26 + ($prolong * 12) + $textLift;
116 }
117 8 ▶ if ($default{'drawbackground'})
Branch: 1 branch
BranchTrueFalseTotal
if ($default{"drawbackground"}) 8 0 8
118 8 { $str .= "$default{'background'} rg\n";
119 8 $str .= "0 0 $length $height re\n";
120 8 $str .= 'f*' . "\n";
121 8 $str .= "0 0 0 rg\n";
122 }
123  
124 8 prAdd($str);
125  
126 8 @sizes = prFontSize(12);
127  
128 8 $str = Bar( 10, $step, $sPtn);
129  
130 8 $prolong--;
131  
132 8 ▶ if ($prolong > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($prolong > 0) 0 8 8
133 0 { $sPtn =~ s/G/1/go;
134 0 ▶ while ($prolong > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($prolong > 0) 0 0 0
135 0 ▶ { if ($prolong > 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($prolong > 1) { } 0 0 0
136 0 { $prolong--;
137 0 $step += 12;
138 }
139 else
140 0 { $step += (12 * $prolong);
141 0 $prolong = 0;
142 }
143 0 $str .= Bar( 10, $step, $sPtn);
144 }
145 }
146 }
147  
148 11 $str .= "B\n";
149 11 prAdd($str);
150  
151 }
152  
153  
154 sub general3
155 11 ▶{ $str = "Q\n";
Subroutine general3: called CC=1 SCAR=0.0
Pod undocumented
156 11 prAdd($str);
157 11 prFontSize($sizes[1]);
158 }
159  
160 # textsize reaches a PDF text operator directly, so a non-numeric or
161 # non-positive value would emit an invalid or invisible Tf rather than
162 # failing anywhere useful.
163 sub text_size
164 11 ▶{ my $textsize = $default{'textsize'};
Subroutine text_size: called CC=5 SCAR=24.5
Pod undocumented
165 11 ▶ return $textsize
Branch: 1 branch
BranchTrueFalseTotal
if defined $textsize and $textsize =~ /^\d*\.?\d+$/ and $textsize > 0 11 0 11
Condition33%2/6
defined $textsize and $textsize =~ /^\d*\.?\d+$/ and $textsize > 0
!ll&&!rl&&r
0011
defined $textsize and $textsize =~ /^\d*\.?\d+$/
!ll&&!rl&&r
0011
MC/DC0%0/3
defined $textsize and $textsize =~ /^\d*\.?\d+$/ and $textsize > 0
defined $textsize $textsize =~ /^\d*\.?\d+$/ $textsize > 0
Truth table25%1/4
A and B and C
A= defined $textsizeB= $textsize =~ /^\d*\.?\d+$/C= $textsize > 0
ABCresult
0XX0
10X0
1100
1111
166 if defined $textsize && $textsize =~ /^\d*\.?\d+$/ && $textsize > 0;
167 0 ▶ carp "Ignoring invalid textsize '"
Branch: 1 branch
BranchTrueFalseTotal
defined $textsize ? : 0 0 0
168 . (defined $textsize ? $textsize : 'undef')
169 . "', using $DEFAULT_TEXTSIZE";
170 0 return $DEFAULT_TEXTSIZE;
171 }
172  
173 sub standardEnd
174 11 ▶{ my $textsize = text_size();
Subroutine standardEnd: called CC=9 SCAR=22.0
Pod undocumented
175  
176 # The text baseline is fixed at 1.5 while the bars start at 9, so the
177 # 7.5 units of clearance were sized for the old hard-coded 10 point.
178 # Anything taller than that would print digits into the bar region --
179 # a scannability failure, not a cosmetic one. Lift the bars by the
180 # extra digit height instead, which preserves the clearance and leaves
181 # output at the default size untouched. Must be set before general2()
182 # draws anything.
183 11 ▶ $textLift = ($default{'text'} && $textsize > $DEFAULT_TEXTSIZE)
Branch: 1 branch
BranchTrueFalseTotal
$default{'text'} && $textsize > $PDF::Reuse::Barcode::DEFAULT_TEXTSIZE ? : 5 6 11
Condition100%3/3
$default{"text"} and $textsize > $PDF::Reuse::Barcode::DEFAULT_TEXTSIZE
!ll&&!rl&&r
155
MC/DC100%2/2
$default{"text"} and $textsize > $PDF::Reuse::Barcode::DEFAULT_TEXTSIZE
$default{"text"} $textsize > $PDF::Reuse::Barcode::DEFAULT_TEXTSIZE
Truth table100%3/3
A and B
A= $default{"text"}B= $textsize > $PDF::Reuse::Barcode::DEFAULT_TEXTSIZE
ABresult
0X0
100
111
184 ? ($textsize * $GLYPH_HEIGHT_EM)
185 - ($DEFAULT_TEXTSIZE * $GLYPH_HEIGHT_EM)
186 : 0;
187  
188 11 general2();
189  
190 11 ▶ if ($default{'text'})
Branch: 1 branch
BranchTrueFalseTotal
if ($default{"text"}) 10 1 11
191 10 { my @vec = prFont('C');
192 10 prFontSize($textsize);
193 # Courier is monospaced at 600/1000 em, so this is the exact
194 # rendered width, not an estimate. At the default size of 10 it
195 # reproduces the constant 6 this replaced.
196 10 my $textLength = length($value) * $textsize * 0.6;
197 10 my $start = ($length - $textLength) / 2;
198 # Text wider than the barcode overflows the background box. That has
199 # always been possible -- a short QR value at the default size
200 # already does it -- so the box is only extended when the caller
201 # asked for a larger size than the default. Extending it
202 # unconditionally would change pre-0.10 output, and clamping would
203 # silently ignore what was asked for.
204 #
205 # Only the two side strips are painted, never the span the barcode
206 # occupies: this runs after general2() has drawn the bars, so a
207 # full-width rectangle here would cover them.
208 10 ▶ if ($textsize > $DEFAULT_TEXTSIZE && $textLength > $length)
Branch: 1 branch
BranchTrueFalseTotal
if ($textsize > $PDF::Reuse::Barcode::DEFAULT_TEXTSIZE and $textLength > $length) 3 7 10
Condition100%3/3
$textsize > $PDF::Reuse::Barcode::DEFAULT_TEXTSIZE and $textLength > $length
!ll&&!rl&&r
523
MC/DC100%2/2
$textsize > $PDF::Reuse::Barcode::DEFAULT_TEXTSIZE and $textLength > $length
$textsize > $PDF::Reuse::Barcode::DEFAULT_TEXTSIZE $textLength > $length
Truth table100%3/3
A and B
A= $textsize > $PDF::Reuse::Barcode::DEFAULT_TEXTSIZEB= $textLength > $length
ABresult
0X0
100
111
209 3 { my $extra = ($textLength - $length) / 2;
210 3 $start = 0 - $extra;
211 3 ▶ if ($default{'drawbackground'})
Branch: 1 branch
BranchTrueFalseTotal
if ($default{"drawbackground"}) 2 1 3
212 { my ($colour, $op) = $qrcode
213 ? ($default{'graybackground'}, 'g')
214 2 ▶ : ($default{'background'}, 'rg');
Branch: 1 branch
BranchTrueFalseTotal
$qrcode ? : 1 1 2
215 2 prAdd(sprintf("q %s %s %s 0 %s %s re f* %s 0 %s %s re f* Q\n",
216 $colour, $op,
217 -$extra, $extra, $height,
218 $length, $extra, $height));
219 }
220 }
221 10 ▶ if ($qrcode) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qrcode) { } 3 7 10
222 3 my $quiet = sprintf("%.2f", 4 * $default{'modulesize'});
223 3 prText($start, 0-$quiet, $value);
224 }
225 else {
226 7 prText($start, 1.5, $value);
227 }
228 10 prFont($vec[3]);
229 }
230 11 general3();
231  
232 11 1;
233 }
234  
235 sub Bar
236 8 ▶{ my ($x, $y, $pattern) = @_;
Subroutine Bar: called CC=4 SCAR=14.0
Pod undocumented
237 8 my $yEnd = $y + 20;
238 8 my $yG = $y - 3;
239  
240 8 my $string = "0.92 w\n 0 0 0 RG\n";
241 8 for (split(//, $pattern))
242 1056 ▶ { if ($_ eq '1')
Branch: 2 branches
BranchTrueFalseTotal
if ($_ eq '1') { } 590 466 1056
elsif ($_ eq 'G') { } 0 466 466
243 590 { $string .= "$x $yEnd m\n $x $y l\n";
244 }
245 elsif($_ eq 'G')
246 0 { $string .= "$x $yEnd m\n $x $yG l\n";
247 }
248 1056 $x = sprintf("%.2f", $x + 0.91);
249 }
250 8 return $string;
251 }
252  
253  
254 sub Qr
255 3 ▶{ my ($x, $y, $pattern) = @_;
Subroutine Qr: called CC=4 SCAR=13.9
Pod undocumented
256 3 my $xStart = sprintf("%.2f", $x);
257  
258 3 my $m = $default{'modulesize'};
259 3 my $s = $default{'qr_padding'};
260 3 my $space = sprintf('%.2f', $m + $s);#
261  
262 3 my $string = "0.01 w\n 0 G\n";
263 3 my @rows = split(/\n/, $pattern);
264 3 for my $row (reverse @rows) {
265 87 my $yEnd = sprintf("%.2f", $y + $m);
266 87 for (split(//, $row))
267 2523 { my $xEnd = sprintf("%.2f", $x + $m);
268 2523 ▶ if ($_ eq '1')
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq 1) 690 1833 2523
269 690 { $string .= "$x $y $m $m re\nf\n";
270 }
271 2523 $x = sprintf("%.2f", $x + $space);
272 }
273 87 $x = $xStart;
274 87 $y = sprintf("%.2f", $y + $space);
275 }
276 3 return $string;
277 }
278  
279 sub Code128
280 0 ▶{ eval 'require Barcode::Code128';
Subroutine Code128: not called CC=4 SCAR=30.0
Pod documented
281 0 init();
282 0 my %param = @_;
283 0 for (keys %param)
284 0 { my $lc = lc($_);
285 0 ▶ if (exists $default{$lc})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $default{$lc}) { } 0 0 0
286 0 { $default{$lc} = $param{$_};
287 }
288 else
289 0 { print STDERR "Unknown parameter $_ , not used \n";
290 }
291 }
292 0 $value = $default{'value'};
293  
294 0 general1();
295  
296 0 my $oGDBar = Barcode::Code128->new();
297 0 ▶ if (! $oGDBar)
Branch: 1 branch
BranchTrueFalseTotal
if (not $oGDBar) { } 0 0 0
298 0 { die "The translation of $value to barcodes didn't succeed, aborts\n";
299 }
300 else
301 {
302 0 $sPtn = $oGDBar->barcode($value);
303 0 $sPtn =~ tr/#/1/;
304 0 $sPtn =~ tr/ /0/;
305 }
306 0 standardEnd();
307 0 1;
308 }
309  
310  
311 sub Code39
312 8 ▶{ eval 'require GD::Barcode::Code39';
Subroutine Code39: called CC=5 SCAR=17.1
Pod documented
313 8 init();
314 8 my %param = @_;
315 8 for (keys %param)
316 30 { my $lc = lc($_);
317 30 ▶ if (exists $default{$lc})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $default{$lc}) { } 30 0 30
318 30 { $default{$lc} = $param{$_};
319 }
320 else
321 0 { print STDERR "Unknown parameter $_ , not used \n";
322 }
323 }
324 8 $value = $default{'value'};
325  
326 8 general1();
327  
328 8 my $oGDBar = GD::Barcode::Code39->new($value);
329 8 ▶ if (! $oGDBar)
Branch: 1 branch
BranchTrueFalseTotal
if (not $oGDBar) { } 0 8 8
330 0 { die "$GD::Barcode::Code39::errStr\n";
331 }
332 else
333 8 { $sPtn = $oGDBar->barcode();
334 }
335 8 ▶ if ($default{hide_asterisk})
Branch: 1 branch
BranchTrueFalseTotal
if ($default{"hide_asterisk"}) 0 8 8
336 0 { $value =~ s/^\*//;
337 0 $value =~ s/\*$//;
338 }
339 8 standardEnd();
340 8 1;
341 }
342  
343 sub COOP2of5
344 0 ▶{ eval 'require GD::Barcode::COOP2of5';
Subroutine COOP2of5: not called CC=4 SCAR=30.0
Pod documented
345 0 init();
346 0 my %param = @_;
347 0 for (keys %param)
348 0 { my $lc = lc($_);
349 0 ▶ if (exists $default{$lc})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $default{$lc}) { } 0 0 0
350 0 { $default{$lc} = $param{$_};
351 }
352 else
353 0 { print STDERR "Unknown parameter $_ , not used \n";
354 }
355 }
356 0 $value = $default{'value'};
357  
358 0 general1();
359  
360 0 my $oGDBar = GD::Barcode::COOP2of5->new($value);
361 0 ▶ if (! $oGDBar)
Branch: 1 branch
BranchTrueFalseTotal
if (not $oGDBar) { } 0 0 0
362 0 { die "$GD::Barcode::COOP2of5::errStr\n";
363 }
364 else
365 0 { $sPtn = $oGDBar->barcode();
366 }
367  
368 0 standardEnd();
369 0 1;
370 }
371  
372 sub IATA2of5
373 0 ▶{ eval 'require GD::Barcode::IATA2of5';
Subroutine IATA2of5: not called CC=4 SCAR=30.0
Pod documented
374 0 init();
375 0 my %param = @_;
376 0 for (keys %param)
377 0 { my $lc = lc($_);
378 0 ▶ if (exists $default{$lc})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $default{$lc}) { } 0 0 0
379 0 { $default{$lc} = $param{$_};
380 }
381 else
382 0 { print STDERR "Unknown parameter $_ , not used \n";
383 }
384 }
385 0 $value = $default{'value'};
386  
387 0 general1();
388  
389 0 my $oGDBar = GD::Barcode::IATA2of5->new($value);
390 0 ▶ if (! $oGDBar)
Branch: 1 branch
BranchTrueFalseTotal
if (not $oGDBar) { } 0 0 0
391 0 { die "$GD::Barcode::IATA2of5::errStr\n";
392 }
393 else
394 0 { $sPtn = $oGDBar->barcode();
395 }
396  
397 0 standardEnd();
398 0 1;
399  
400 }
401  
402 sub Industrial2of5
403 0 ▶{ eval 'require GD::Barcode::Industrial2of5';
Subroutine Industrial2of5: not called CC=4 SCAR=30.0
Pod documented
404 0 init();
405 0 my %param = @_;
406 0 for (keys %param)
407 0 { my $lc = lc($_);
408 0 ▶ if (exists $default{$lc})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $default{$lc}) { } 0 0 0
409 0 { $default{$lc} = $param{$_};
410 }
411 else
412 0 { print STDERR "Unknown parameter $_ , not used \n";
413 }
414 }
415 0 $value = $default{'value'};
416  
417 0 general1();
418  
419 0 my $oGDBar = GD::Barcode::Industrial2of5->new($value);
420 0 ▶ if (! $oGDBar)
Branch: 1 branch
BranchTrueFalseTotal
if (not $oGDBar) { } 0 0 0
421 0 { die "$GD::Barcode::Industrial2of5::errStr\n";
422 }
423 else
424 0 { $sPtn = $oGDBar->barcode();
425 }
426  
427 0 standardEnd();
428 0 1;
429 }
430  
431 sub Matrix2of5
432 0 ▶{ eval 'require GD::Barcode::Matrix2of5';
Subroutine Matrix2of5: not called CC=4 SCAR=30.0
Pod documented
433 0 init();
434 0 my %param = @_;
435 0 for (keys %param)
436 0 { my $lc = lc($_);
437 0 ▶ if (exists $default{$lc})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $default{$lc}) { } 0 0 0
438 0 { $default{$lc} = $param{$_};
439 }
440 else
441 0 { print STDERR "Unknown parameter $_ , not used \n";
442 }
443 }
444 0 $value = $default{'value'};
445  
446 0 general1();
447  
448 0 my $oGDBar = GD::Barcode::Matrix2of5->new($value);
449 0 ▶ if (! $oGDBar)
Branch: 1 branch
BranchTrueFalseTotal
if (not $oGDBar) { } 0 0 0
450 0 { die "$GD::Barcode::Matrix2of5::errStr\n";
451 }
452 else
453 0 { $sPtn = $oGDBar->barcode();
454 }
455  
456 0 standardEnd();
457 0 1;
458 }
459  
460 sub NW7
461 0 ▶{ eval 'require GD::Barcode::NW7';
Subroutine NW7: not called CC=4 SCAR=30.0
Pod documented
462 0 init();
463 0 my %param = @_;
464 0 for (keys %param)
465 0 { my $lc = lc($_);
466 0 ▶ if (exists $default{$lc})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $default{$lc}) { } 0 0 0
467 0 { $default{$lc} = $param{$_};
468 }
469 else
470 0 { print STDERR "Unknown parameter $_ , not used \n";
471 }
472 }
473 0 $value = $default{'value'};
474  
475 0 general1();
476  
477 0 my $oGDBar = GD::Barcode::NW7->new($value);
478 0 ▶ if (! $oGDBar)
Branch: 1 branch
BranchTrueFalseTotal
if (not $oGDBar) { } 0 0 0
479 0 { die "$GD::Barcode::NW7::errStr\n";
480 }
481 else
482 0 { $sPtn = $oGDBar->barcode();
483 }
484  
485 0 standardEnd();
486 0 1;
487 }
488  
489  
490  
491 sub EAN13
492 0 ▶{ eval 'require GD::Barcode::EAN13';
Subroutine EAN13: not called CC=7 SCAR=40.3
Pod documented
493 0 init();
494 0 my %param = @_;
495 0 for (keys %param)
496 0 { my $lc = lc($_);
497 0 ▶ if (exists $default{$lc})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $default{$lc}) { } 0 0 0
498 0 { $default{$lc} = $param{$_};
499 }
500 else
501 0 { print STDERR "Unknown parameter $_ , not used \n";
502 }
503 }
504 0 $value = $default{'value'};
505  
506 0 general1();
507  
508 0 ▶ if ($value =~ m'([^0-9]+)'o)
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /([^0-9]+)/o) 0 0 0
509 0 { die "Invalid character $1, aborts\n";
510 }
511  
512 0 ▶ if (length($value) == 12)
Branch: 1 branch
BranchTrueFalseTotal
if (length $value == 12) 0 0 0
513 0 { $value .= GD::Barcode::EAN13::calcEAN13CD($value);
514 }
515 0 my $oGDBar = GD::Barcode::EAN13->new($value);
516 0 ▶ if (! $oGDBar)
Branch: 1 branch
BranchTrueFalseTotal
if (not $oGDBar) { } 0 0 0
517 0 { die "$GD::Barcode::EAN13::errStr\n";
518 }
519 else
520 0 { $sPtn = $oGDBar->barcode();
521 }
522 0 general2();
523  
524 0 ▶ if ($default{'text'})
Branch: 1 branch
BranchTrueFalseTotal
if ($default{"text"}) 0 0 0
525 0 { my $siffra = substr($value, 0, 1);
526 0 my $del1 = substr($value, 1, 6);
527 0 my $del2 = substr($value, 7, 6);
528  
529 0 my @vec = prFont('C');
530  
531 0 prFontSize(10);
532  
533 0 prText(1, 2, $siffra);
534 0 prText(14, 2, $del1);
535 0 prText(56, 2, $del2);
536  
537 0 prFont($vec[3]);
538 }
539 0 general3;
540 0 1;
541 }
542  
543 sub EAN8
544 0 ▶{ eval 'require GD::Barcode::EAN8';
Subroutine EAN8: not called CC=7 SCAR=40.3
Pod documented
545 0 init();
546 0 my %param = @_;
547 0 for (keys %param)
548 0 { my $lc = lc($_);
549 0 ▶ if (exists $default{$lc})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $default{$lc}) { } 0 0 0
550 0 { $default{$lc} = $param{$_};
551 }
552 else
553 0 { print STDERR "Unknown parameter $_ , not used \n";
554 }
555 }
556 0 $value = $default{'value'};
557  
558 0 general1();
559  
560 0 ▶ if ($value =~ m'([^0-9]+)'o)
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /([^0-9]+)/o) 0 0 0
561 0 { die "Invalid character $1, aborts\n";
562 }
563  
564 0 ▶ if (length($value) == 7)
Branch: 1 branch
BranchTrueFalseTotal
if (length $value == 7) 0 0 0
565 0 { $value .= GD::Barcode::EAN8::calcEAN8CD($value);
566 }
567 0 my $oGDBar = GD::Barcode::EAN8->new($value);
568 0 ▶ if (! $oGDBar)
Branch: 1 branch
BranchTrueFalseTotal
if (not $oGDBar) { } 0 0 0
569 0 { die "$GD::Barcode::EAN8::errStr\n";
570 }
571 else
572 0 { $sPtn = $oGDBar->barcode();
573 }
574 0 general2();
575  
576 0 ▶ if ($default{'text'})
Branch: 1 branch
BranchTrueFalseTotal
if ($default{"text"}) 0 0 0
577 0 { my $del1 = substr($value, 0, 4);
578 0 my $del2 = substr($value, 4, 4);
579 0 my @vec = prFont('C');
580 0 prFontSize(10);
581 0 prText(14, 2, $del1);
582 0 prText(42.5, 2, $del2);
583 0 prFont($vec[3]);
584 }
585 0 general3;
586 0 1;
587 }
588  
589 sub ITF
590 0 ▶{ eval 'require GD::Barcode::ITF';
Subroutine ITF: not called CC=4 SCAR=30.0
Pod documented
591 0 init();
592 0 my %param = @_;
593 0 for (keys %param)
594 0 { my $lc = lc($_);
595 0 ▶ if (exists $default{$lc})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $default{$lc}) { } 0 0 0
596 0 { $default{$lc} = $param{$_};
597 }
598 else
599 0 { print STDERR "Unknown parameter $_ , not used \n";
600 }
601 }
602 0 $value = $default{'value'};
603  
604 0 general1();
605  
606 0 my $oGDBar = GD::Barcode::ITF->new($value);
607 0 ▶ if (! $oGDBar)
Branch: 1 branch
BranchTrueFalseTotal
if (not $oGDBar) { } 0 0 0
608 0 { die "$GD::Barcode::ITF::errStr\n";
609 }
610 else
611 0 { $sPtn = $oGDBar->barcode();
612 }
613  
614 0 standardEnd();
615 0 1;
616 }
617  
618 sub UPCA
619 0 ▶{ eval 'require GD::Barcode::UPCA';
Subroutine UPCA: not called CC=7 SCAR=40.3
Pod documented
620 0 init();
621 0 my %param = @_;
622 0 for (keys %param)
623 0 { my $lc = lc($_);
624 0 ▶ if (exists $default{$lc})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $default{$lc}) { } 0 0 0
625 0 { $default{$lc} = $param{$_};
626 }
627 else
628 0 { print STDERR "Unknown parameter $_ , not used \n";
629 }
630 }
631 0 $value = $default{'value'};
632  
633 0 general1();
634  
635 0 ▶ if ($value =~ m'([^0-9]+)'o)
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /([^0-9]+)/o) 0 0 0
636 0 { die "Invalid character $1, aborts\n";
637 }
638  
639 0 ▶ if (length($value) == 11)
Branch: 1 branch
BranchTrueFalseTotal
if (length $value == 11) 0 0 0
640 0 { $value .= GD::Barcode::UPCA::calcUPCACD($value);
641 }
642 0 my $oGDBar = GD::Barcode::UPCA->new($value);
643 0 ▶ if (! $oGDBar)
Branch: 1 branch
BranchTrueFalseTotal
if (not $oGDBar) { } 0 0 0
644 0 { die "$GD::Barcode::UPCA::errStr\n";
645 }
646 else
647 0 { $sPtn = $oGDBar->barcode();
648 }
649 0 general2();
650  
651 0 ▶ if ($default{'text'})
Branch: 1 branch
BranchTrueFalseTotal
if ($default{"text"}) 0 0 0
652 0 { my $siffra1 = substr($value, 0, 1);
653 0 my $del1 = substr($value, 1, 5);
654 0 my $del2 = substr($value, 6, 5);
655 0 my $siffra2 = substr($value, 11, 1);
656  
657 0 my @vec = prFont('C');
658  
659 0 prFontSize(10);
660  
661 0 prText(2, 2, $siffra1);
662 0 prText(20, 2, $del1);
663 0 prText(56, 2, $del2);
664 0 prText(97, 2, $siffra2);
665  
666 0 prFont($vec[3]);
667 }
668 0 general3;
669 0 1;
670 }
671  
672 sub UPCE
673 0 ▶{ eval 'require GD::Barcode::UPCE';
Subroutine UPCE: not called CC=8 SCAR=42.8
Pod documented
674 0 init();
675 0 my %param = @_;
676 0 for (keys %param)
677 0 { my $lc = lc($_);
678 0 ▶ if (exists $default{$lc})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $default{$lc}) { } 0 0 0
679 0 { $default{$lc} = $param{$_};
680 }
681 else
682 0 { print STDERR "Unknown parameter $_ , not used \n";
683 }
684 }
685 0 $value = $default{'value'};
686  
687 0 general1();
688  
689 0 ▶ if ($value =~ m'([^0-9]+)'o)
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /([^0-9]+)/o) 0 0 0
690 0 { die "Invalid character $1, aborts\n";
691 }
692  
693 0 ▶ if (length($value) == 6)
Branch: 2 branches
BranchTrueFalseTotal
if (length $value == 6) { } 0 0 0
elsif (length $value == 7) { } 0 0 0
694 0 { $value = '0' . $value;
695 0 my $cd = GD::Barcode::UPCE::calcUPCECD($value);
696 0 $value .= $cd;
697 }
698 elsif (length($value) == 7)
699 0 { my $cd = GD::Barcode::UPCE::calcUPCECD($value);
700 0 $value .= $cd;
701 }
702 0 my $oGDBar = GD::Barcode::UPCE->new($value);
703 0 ▶ if (! $oGDBar)
Branch: 1 branch
BranchTrueFalseTotal
if (not $oGDBar) { } 0 0 0
704 0 { die "$GD::Barcode::UPCE::errStr\n";
705 }
706 else
707 0 { $sPtn = $oGDBar->barcode();
708 }
709 0 general2();
710  
711 0 ▶ if ($default{'text'})
Branch: 1 branch
BranchTrueFalseTotal
if ($default{"text"}) 0 0 0
712 0 { my $siffra = substr($value, 0, 1);
713 0 my $del1 = substr($value, 1, 6);
714 0 my $del2 = substr($value, 7, 1);
715  
716 0 my @vec = prFont('C');
717  
718 0 prFontSize(10);
719  
720 0 prText(2, 2, $siffra);
721 0 prText(14, 2, $del1);
722 0 prText(58, 2, $del2);
723  
724 0 prFont($vec[3]);
725 }
726 0 general3;
727 0 1;
728 }
729  
730 sub QRcode
731 3 ▶{ eval 'require GD::Barcode::QRcode';
Subroutine QRcode: called CC=4 SCAR=14.1
Pod documented
732 # init() resets per-call state, so the flag has to be set after it,
733 # not before -- setting it first meant init() wiped it.
734 3 init();
735 3 $qrcode = 1;
736 3 my %param = @_;
737 3 for (keys %param)
738 12 { my $lc = lc($_);
739 12 ▶ if (exists $default{$lc})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $default{$lc}) { } 12 0 12
740 12 { $default{$lc} = $param{$_};
741 }
742 else
743 0 { print STDERR "Unknown parameter $_ , not used \n";
744 }
745 }
746 3 $value = $default{'value'};
747  
748 3 general1();
749  
750 3 my $oGDBar = GD::Barcode::QRcode->new($value, {Ecc => $default{'qr_ecc'}, Version=>$default{'qr_version'}, ModuleSize => $default{'size'}});
751 3 ▶ if (! $oGDBar)
Branch: 1 branch
BranchTrueFalseTotal
if (not $oGDBar) { } 0 3 3
752 0 { die "$GD::Barcode::QRcode::errStr\n";
753 }
754 else
755 3 { $sPtn = $oGDBar->barcode();
756 }
757 3 standardEnd();
758 3 1;
759 }
760  
761  
762 2 1;
763  
764  
765 __END__
↑ Summary