| 1 | package GD::Barcode::ITF; | ||||||||||
| 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 | |||||||||||
| 11 | 2 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 12 | 2 | my ( $sClass, $sTxt ) = @_; | |||||||||
| 13 | 2 | $errStr = ''; | |||||||||
| 14 | 2 | my $oThis = {}; | |||||||||
| 15 | 2 | bless $oThis, $sClass; | |||||||||
| 16 | 2 | ▶ | return if ( $errStr = $oThis->init($sTxt) ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 2 | return $oThis; | |||||||||
| 18 | } | ||||||||||
| 19 | |||||||||||
| 20 | 2 | ▶ | sub init { | ||||||||
|
Subroutine
init: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 21 | 2 | my ( $oThis, $sTxt ) = @_; | |||||||||
| 22 | |||||||||||
| 23 | #Check | ||||||||||
| 24 | 2 | ▶ | return 'Invalid Characters' if ( $sTxt =~ /[^0-9]/ ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | |||||||||||
| 26 | #Not Set Check | ||||||||||
| 27 | 2 | ▶ | if ( length($sTxt) % 2 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 1 | $sTxt .= calcITFCD($sTxt); | |||||||||
| 29 | } | ||||||||||
| 30 | 2 | $oThis->{text} = $sTxt; | |||||||||
| 31 | 2 | return ''; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 1 | ▶ | sub calcITFCD { | ||||||||
|
Subroutine
calcITFCD: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||
| 35 | 1 | my ($sTxt) = @_; | |||||||||
| 36 | 1 | my ( $i, $iSum ); | |||||||||
| 37 | |||||||||||
| 38 | 1 | $iSum = 0; | |||||||||
| 39 | 1 | ▶ | for ( $i = 0 ; $i < length($sTxt) ; $i++ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 13 | ▶ | $iSum += substr( $sTxt, $i, 1 ) * ( ( $i % 2 ) ? 1 : 3 ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | } | ||||||||||
| 42 | 1 | $iSum %= 10; | |||||||||
| 43 | 1 | ▶ | $iSum = ( $iSum == 0 ) ? 0 : ( 10 - $iSum ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 1 | return "$iSum"; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 2 | ▶ | sub barcode { | ||||||||
|
Subroutine
barcode: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 48 | 2 | my ($oThis) = @_; | |||||||||
| 49 | 2 | my ( $i, $sRes ); | |||||||||
| 50 | 2 | my $sTxt = $oThis->{text}; | |||||||||
| 51 | 2 | my $rhPtn = { | |||||||||
| 52 | '0' => '00110', | ||||||||||
| 53 | '1' => '10001', | ||||||||||
| 54 | '2' => '01001', | ||||||||||
| 55 | '3' => '11000', | ||||||||||
| 56 | '4' => '00101', | ||||||||||
| 57 | '5' => '10100', | ||||||||||
| 58 | '6' => '01100', | ||||||||||
| 59 | '7' => '00011', | ||||||||||
| 60 | '8' => '10010', | ||||||||||
| 61 | '9' => '01010' | ||||||||||
| 62 | }; | ||||||||||
| 63 | |||||||||||
| 64 | 2 | $sRes = ''; | |||||||||
| 65 | 2 | $sRes .= '1010'; #START | |||||||||
| 66 | 2 | ▶ | for ( $i = 0 ; $i < length($sTxt) ; $i += 2 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 14 | my $sBlack = $rhPtn->{ substr( $sTxt, $i, 1 ) }; | |||||||||
| 68 | 14 | my $sWhite = $rhPtn->{ substr( $sTxt, $i + 1, 1 ) }; | |||||||||
| 69 | 14 | ▶ | for ( my $j = 0 ; $j < length($sBlack) ; $j++ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 70 | ▶ | $sRes .= ( substr( $sBlack, $j, 1 ) eq '1' ) ? '1' x 3 : '1'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | 70 | ▶ | $sRes .= ( substr( $sWhite, $j, 1 ) eq '1' ) ? '0' x 3 : '0'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | } | ||||||||||
| 73 | } | ||||||||||
| 74 | 2 | $sRes .= '1' x 3 . '01'; #STOP | |||||||||
| 75 | 2 | return $sRes; | |||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | 0 | ▶ | sub plot { | ||||||||
|
Subroutine
plot: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 79 | 0 | my ( $oThis, %hParam ) = @_; | |||||||||
| 80 | |||||||||||
| 81 | 0 | my $sTxtWk = $oThis->{text}; | |||||||||
| 82 | 0 | my $sPtn = $oThis->barcode(); | |||||||||
| 83 | |||||||||||
| 84 | #Create Image | ||||||||||
| 85 | 0 | require GD; | |||||||||
| 86 | 0 | ▶ | my $iHeight = ( $hParam{Height} ) ? $hParam{Height} : 50; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | 0 | my ( $oGd, $cBlack ); | |||||||||
| 88 | 0 | ▶ | if ( $hParam{NoText} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 89 | 0 | ( $oGd, $cBlack ) = | |||||||||
| 90 | GD::Barcode::plot( $sPtn, length($sPtn), $iHeight, 0, 0 ); | ||||||||||
| 91 | } | ||||||||||
| 92 | else { | ||||||||||
| 93 | 0 | my ( $fW, $fH ) = ( GD::Font->Small->width, GD::Font->Small->height ); | |||||||||
| 94 | 0 | my $iWidth = length($sPtn); | |||||||||
| 95 | |||||||||||
| 96 | #Bar Image | ||||||||||
| 97 | 0 | ( $oGd, $cBlack ) = | |||||||||
| 98 | GD::Barcode::plot( $sPtn, $iWidth, $iHeight, $fH, 0 ); | ||||||||||
| 99 | |||||||||||
| 100 | #String | ||||||||||
| 101 | 0 | $oGd->string( | |||||||||
| 102 | GD::Font->Small, | ||||||||||
| 103 | ( length($sPtn) - $fW * ( length($sTxtWk) ) ) / 2, | ||||||||||
| 104 | $iHeight - $fH, | ||||||||||
| 105 | $sTxtWk, $cBlack | ||||||||||
| 106 | ); | ||||||||||
| 107 | } | ||||||||||
| 108 | 0 | return $oGd; | |||||||||
| 109 | } | ||||||||||
| 110 | 1 | 1; | |||||||||
| 111 | __END__ | ||||||||||