| 1 | package GD::Barcode::Code39; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use GD::Barcode; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use parent qw(Exporter); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use vars qw($VERSION @ISA $errStr); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | @ISA = qw(GD::Barcode Exporter); | |||||||||
| 9 | 1 | our $VERSION = '2.02'; | |||||||||
| 10 | 1 | my $code39Bar = { | |||||||||
| 11 | '0' => '000110100', | ||||||||||
| 12 | '1' => '100100001', | ||||||||||
| 13 | '2' => '001100001', | ||||||||||
| 14 | '3' => '101100000', | ||||||||||
| 15 | '4' => '000110001', | ||||||||||
| 16 | '5' => '100110000', | ||||||||||
| 17 | '6' => '001110000', | ||||||||||
| 18 | '7' => '000100101', | ||||||||||
| 19 | '8' => '100100100', | ||||||||||
| 20 | '9' => '001100100', | ||||||||||
| 21 | 'A' => '100001001', | ||||||||||
| 22 | 'B' => '001001001', | ||||||||||
| 23 | 'C' => '101001000', | ||||||||||
| 24 | 'D' => '000011001', | ||||||||||
| 25 | 'E' => '100011000', | ||||||||||
| 26 | 'F' => '001011000', | ||||||||||
| 27 | 'G' => '000001101', | ||||||||||
| 28 | 'H' => '100001100', | ||||||||||
| 29 | 'I' => '001001100', | ||||||||||
| 30 | 'J' => '000011100', | ||||||||||
| 31 | 'K' => '100000011', | ||||||||||
| 32 | 'L' => '001000011', | ||||||||||
| 33 | 'M' => '101000010', | ||||||||||
| 34 | 'N' => '000010011', | ||||||||||
| 35 | 'O' => '100010010', | ||||||||||
| 36 | 'P' => '001010010', | ||||||||||
| 37 | 'Q' => '000000111', | ||||||||||
| 38 | 'R' => '100000110', | ||||||||||
| 39 | 'S' => '001000110', | ||||||||||
| 40 | 'T' => '000010110', | ||||||||||
| 41 | 'U' => '110000001', | ||||||||||
| 42 | 'V' => '011000001', | ||||||||||
| 43 | 'W' => '111000000', | ||||||||||
| 44 | 'X' => '010010001', | ||||||||||
| 45 | 'Y' => '110010000', | ||||||||||
| 46 | 'Z' => '011010000', | ||||||||||
| 47 | '-' => '010000101', | ||||||||||
| 48 | '*' => '010010100', | ||||||||||
| 49 | '+' => '010001010', | ||||||||||
| 50 | '$' => '010101000', | ||||||||||
| 51 | '%' => '000101010', | ||||||||||
| 52 | '/' => '010100010', | ||||||||||
| 53 | '.' => '110000100', | ||||||||||
| 54 | ' ' => '011000100' | ||||||||||
| 55 | }; | ||||||||||
| 56 | |||||||||||
| 57 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 58 | 1 | my ( $sClass, $sTxt ) = @_; | |||||||||
| 59 | 1 | $errStr = ''; | |||||||||
| 60 | 1 | my $oThis = {}; | |||||||||
| 61 | 1 | bless $oThis, $sClass; | |||||||||
| 62 | 1 | ▶ | return if ( $errStr = $oThis->init($sTxt) ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 1 | return $oThis; | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | 1 | ▶ | sub init { | ||||||||
|
Subroutine
init: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 67 | 1 | my ( $oThis, $sTxt ) = @_; | |||||||||
| 68 | |||||||||||
| 69 | #Check | ||||||||||
| 70 | 1 | ▶ | return 'Invalid Characters' if ( $sTxt =~ /[^0-9A-Z\-*+\$%\/. ]/ ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | 1 | $oThis->{text} = $sTxt; | |||||||||
| 72 | 1 | return ''; | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 1 | ▶ | sub barcode { | ||||||||
|
Subroutine
barcode: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 76 | 1 | my ($oThis) = @_; | |||||||||
| 77 | 1 | my ($sTxt); | |||||||||
| 78 | 1 | my ( $sWk, $sRes ); | |||||||||
| 79 | |||||||||||
| 80 | 1 | $sTxt = $oThis->{text}; | |||||||||
| 81 | 1 | $sRes = ''; | |||||||||
| 82 | 1 | foreach my $sWk ( split( //, $sTxt ) ) { | |||||||||
| 83 | 7 | $sRes .= GD::Barcode::dumpCode( $code39Bar->{$sWk} . '0' ); | |||||||||
| 84 | } | ||||||||||
| 85 | 1 | return $sRes; | |||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | 0 | ▶ | sub plot { | ||||||||
|
Subroutine
plot: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 89 | 0 | my ( $oThis, %hParam ) = @_; | |||||||||
| 90 | |||||||||||
| 91 | #Barcode Pattern | ||||||||||
| 92 | 0 | my $sTxtWk = $oThis->{text}; | |||||||||
| 93 | 0 | my $sPtn = $oThis->barcode(); | |||||||||
| 94 | |||||||||||
| 95 | #Create Image | ||||||||||
| 96 | 0 | ▶ | my $iHeight = ( $hParam{Height} ) ? $hParam{Height} : 50; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | 0 | my ( $oGd, $cBlack ); | |||||||||
| 98 | 0 | ▶ | if ( $hParam{NoText} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 99 | 0 | ( $oGd, $cBlack ) = | |||||||||
| 100 | GD::Barcode::plot( $sPtn, length($sPtn), $iHeight, 0, 0 ); | ||||||||||
| 101 | } | ||||||||||
| 102 | else { | ||||||||||
| 103 | 0 | require GD; | |||||||||
| 104 | 0 | my ( $fW, $fH ) = ( GD::Font->Small->width, GD::Font->Small->height ); | |||||||||
| 105 | 0 | my $iWidth = length($sPtn); | |||||||||
| 106 | |||||||||||
| 107 | #Bar Image | ||||||||||
| 108 | 0 | ( $oGd, $cBlack ) = | |||||||||
| 109 | GD::Barcode::plot( $sPtn, $iWidth, $iHeight, $fH, 0 ); | ||||||||||
| 110 | |||||||||||
| 111 | #String | ||||||||||
| 112 | 0 | $oGd->string( | |||||||||
| 113 | GD::Font->Small, | ||||||||||
| 114 | ( length($sPtn) - $fW * ( length($sTxtWk) ) ) / 2, | ||||||||||
| 115 | $iHeight - $fH, | ||||||||||
| 116 | $sTxtWk, $cBlack | ||||||||||
| 117 | ); | ||||||||||
| 118 | } | ||||||||||
| 119 | 0 | return $oGd; | |||||||||
| 120 | } | ||||||||||
| 121 | 1 | 1; | |||||||||
| 122 | __END__ | ||||||||||