| 1 | package GD::Barcode; | ||||||||||||||
| 2 | 1 | require Exporter; | |||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 1 | ▶ | use vars qw($VERSION @ISA $errStr); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 1 | @ISA = qw(Exporter); | |||||||||||||
| 6 | 1 | $VERSION=1.15; | |||||||||||||
| 7 | 1 | my @aLoaded = (); | |||||||||||||
| 8 | #------------------------------------------------------------------------------ | ||||||||||||||
| 9 | # new (for GD::Barcode) | ||||||||||||||
| 10 | #------------------------------------------------------------------------------ | ||||||||||||||
| 11 | sub new($$$;$) { | ||||||||||||||
| 12 | 0 | ▶ | my($sClass, $sType, $sTxt, $rhPrm) = @_; | ||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||
| 13 | 0 | my $oThis = {}; | |||||||||||||
| 14 | 0 | ▶ | unless(grep(/^$sType$/, @aLoaded)) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 15 | 0 | eval "require 'GD/Barcode/$sType.pm';"; | |||||||||||||
| 16 | 0 | ▶ | if($@) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 17 | 0 | $errStr = "Can't load $sType : $@"; | |||||||||||||
| 18 | 0 | return undef; | |||||||||||||
| 19 | } | ||||||||||||||
| 20 | 0 | push(@aLoaded, $sType); | |||||||||||||
| 21 | } | ||||||||||||||
| 22 | 0 | bless $oThis, "GD::Barcode::$sType"; | |||||||||||||
| 23 | 0 | ▶ | return undef if($errStr = $oThis->init($sTxt, $rhPrm)); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 24 | 0 | return $oThis; | |||||||||||||
| 25 | } | ||||||||||||||
| 26 | #------------------------------------------------------------------------------ | ||||||||||||||
| 27 | # barPtn (for GD::Barcode) | ||||||||||||||
| 28 | #------------------------------------------------------------------------------ | ||||||||||||||
| 29 | sub barPtn { | ||||||||||||||
| 30 | 0 | ▶ | my($bar, $table) = @_; | ||||||||||||
|
Subroutine
barPtn: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 31 | 0 | my($sWk, $sRes); | |||||||||||||
| 32 | |||||||||||||||
| 33 | 0 | $sRes = ''; | |||||||||||||
| 34 | 0 | foreach $sWk (split(//, $bar)) { | |||||||||||||
| 35 | 0 | $sRes .= $table->{$sWk}; | |||||||||||||
| 36 | } | ||||||||||||||
| 37 | 0 | return $sRes; | |||||||||||||
| 38 | } | ||||||||||||||
| 39 | #------------------------------------------------------------------------------ | ||||||||||||||
| 40 | # dumpCode (for GD::Barcode) for Code39, NW7... | ||||||||||||||
| 41 | #------------------------------------------------------------------------------ | ||||||||||||||
| 42 | sub dumpCode { | ||||||||||||||
| 43 | 0 | ▶ | my( $sCode ) = @_; | ||||||||||||
|
Subroutine
dumpCode: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||
| 44 | 0 | my($sWk, $sRes, $sClr); | |||||||||||||
| 45 | |||||||||||||||
| 46 | #Init | ||||||||||||||
| 47 | 0 | $sRes = ''; | |||||||||||||
| 48 | 0 | $sClr = '1'; # 1: Black, 0:White | |||||||||||||
| 49 | |||||||||||||||
| 50 | 0 | foreach $sWk (split(//, $sCode)) { | |||||||||||||
| 51 | 0 | ▶ | $sRes .= ($sWk eq '1')? $sClr x 3 : $sClr; #3 times or Normal | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 52 | 0 | ▶ | $sClr = ($sClr eq '0')? '1': '0'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 53 | } | ||||||||||||||
| 54 | 0 | return $sRes; | |||||||||||||
| 55 | } | ||||||||||||||
| 56 | #------------------------------------------------------------------------------ | ||||||||||||||
| 57 | # plot (for GD::Barcode) | ||||||||||||||
| 58 | #------------------------------------------------------------------------------ | ||||||||||||||
| 59 | sub plot($$$$$) { | ||||||||||||||
| 60 | 0 | ▶ | my($sBarcode, $iWidth, $iHeight, $fH, $iStart) = @_; | ||||||||||||
|
Subroutine
plot: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||
| 61 | #Create Image | ||||||||||||||
| 62 | 0 | my ($gdNew, $cWhite, $cBlack); | |||||||||||||
| 63 | 0 | eval { | |||||||||||||
| 64 | 0 | $gdNew = GD::Image->new($iWidth, $iHeight); | |||||||||||||
| 65 | 0 | $cWhite = $gdNew->colorAllocate(255, 255, 255); | |||||||||||||
| 66 | 0 | $cBlack = $gdNew->colorAllocate( 0, 0, 0); | |||||||||||||
| 67 | |||||||||||||||
| 68 | 0 | my $iPos =$iStart; | |||||||||||||
| 69 | 0 | foreach my $cWk (split(//,$sBarcode)) { | |||||||||||||
| 70 | 0 | ▶ | if($cWk eq '0') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 71 | 0 | $gdNew->line($iPos, 0, $iPos, $iHeight - $fH, $cWhite); | |||||||||||||
| 72 | } | ||||||||||||||
| 73 | elsif ($cWk eq 'G') { | ||||||||||||||
| 74 | 0 | $gdNew->line($iPos, 0, $iPos, $iHeight - 2*($fH/3), $cBlack); | |||||||||||||
| 75 | } | ||||||||||||||
| 76 | else { #$cWk eq "1" etc. | ||||||||||||||
| 77 | 0 | $gdNew->line($iPos, 0, $iPos, $iHeight - $fH, $cBlack); | |||||||||||||
| 78 | } | ||||||||||||||
| 79 | 0 | $iPos++; | |||||||||||||
| 80 | } | ||||||||||||||
| 81 | }; | ||||||||||||||
| 82 | 0 | return ($gdNew, $cBlack); | |||||||||||||
| 83 | } | ||||||||||||||
| 84 | #------------------------------------------------------------------------------ | ||||||||||||||
| 85 | # Text (for GD::Barcode) | ||||||||||||||
| 86 | #------------------------------------------------------------------------------ | ||||||||||||||
| 87 | sub Text($) { | ||||||||||||||
| 88 | 0 | ▶ | my($oThis) = @_; | ||||||||||||
|
Subroutine
Text: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 89 | 0 | return $oThis->{text}; | |||||||||||||
| 90 | } | ||||||||||||||
| 91 | 1 | 1; | |||||||||||||
| 92 | __END__ | ||||||||||||||