home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / NW7.pm < prev    next >
Encoding:
Perl POD Document  |  2003-06-02  |  4.7 KB  |  184 lines

  1. package GD::Barcode::NW7;
  2. use strict;
  3. BEGIN { eval{require 'GD.pm';}; };
  4. use GD::Barcode;
  5. require Exporter;
  6. use vars qw($VERSION @ISA $errStr);
  7. @ISA = qw(GD::Barcode Exporter);
  8. $VERSION=1.10;
  9. my $nw7Bar = {
  10.  '0' => '0000011',
  11.  '1' => '0000110',
  12.  '2' => '0001001',
  13.  '3' => '1100000',
  14.  '4' => '0010010',
  15.  '5' => '1000010',
  16.  '6' => '0100001',
  17.  '7' => '0100100',
  18.  '8' => '0110000',
  19.  '9' => '1001000',
  20.  '-' => '0001100',
  21.  '$' => '0011000',
  22.  ':' => '1000101',
  23.  '/' => '1010001',
  24.  '.' => '1010100',
  25.  '+' => '0010101',
  26.  'A' => '0011010',
  27.  'B' => '0101001',
  28.  'C' => '0001011',
  29.  'D' => '0001110'
  30. };
  31. #------------------------------------------------------------------------------
  32. # new (for GD::Barcode::NW7)
  33. #------------------------------------------------------------------------------
  34. sub new($$) {
  35.   my($sClass, $sTxt) = @_;
  36.   $errStr ='';
  37.   my $oThis = {};
  38.   bless $oThis;
  39.   return undef if($errStr = $oThis->init($sTxt));
  40.   return $oThis;
  41. }
  42. #------------------------------------------------------------------------------
  43. # init (for GD::Barcode::NW7)
  44. #------------------------------------------------------------------------------
  45. sub init($$\%){
  46.         my($oThis, $sTxt) =@_;
  47. #Check
  48.     return 'Invalid Characters' if($sTxt =~ /[^0-9\-\$:\/.+ABCD]/);
  49.  
  50. #CalcCd
  51.         $oThis->{text} = $sTxt;
  52.         return '';
  53. }
  54. #------------------------------------------------------------------------------
  55. # barcode (for GD::Barcode::NW7)
  56. #------------------------------------------------------------------------------
  57. sub barcode($) {
  58.         my($oThis) = @_;
  59.     my($sWk, $sRes);
  60.  
  61.         my $sTxt = $oThis->{text};
  62.     $sRes = '';
  63.     foreach $sWk (split(//, $sTxt)) {
  64.       $sRes .= GD::Barcode::dumpCode( $nw7Bar->{$sWk} .'0' );
  65.     }
  66.     return $sRes;
  67. }
  68. #------------------------------------------------------------------------------
  69. # plot (for GD::Barcode::NW7)
  70. #------------------------------------------------------------------------------
  71. sub plot($%) {
  72.   my($oThis, %hParam) =@_;
  73.  
  74.   my $sTxt = $oThis->{text};
  75.   my $sPtn = $oThis->barcode();
  76. #Create Image
  77.   my $iHeight = ($hParam{Height})? $hParam{Height} : 50;
  78.   my ($oGd, $cBlack);
  79.   if($hParam{NoText}) {
  80.         ($oGd, $cBlack) = GD::Barcode::plot($sPtn, length($sPtn), $iHeight, 0, 0);
  81.   }
  82.   else {
  83.         my($fW,$fH) = (GD::Font->Small->width, GD::Font->Small->height);
  84.         my $iWidth = length($sPtn);
  85.         #Bar Image
  86.         ($oGd, $cBlack) = GD::Barcode::plot($sPtn, $iWidth, $iHeight, $fH, 0);
  87.  
  88.         #String
  89.         $oGd->string(GD::Font->Small, (length($sPtn)-$fW*(length($sTxt)))/2, $iHeight - $fH, 
  90.                                                 $sTxt, $cBlack);
  91.   }
  92.   return $oGd;
  93. }
  94. 1;
  95. __END__
  96.  
  97.  
  98.  
  99. =head1 NAME
  100.  
  101. GD::Barcode::NW7 - Create NW7 barcode image with GD
  102.  
  103. =head1 SYNOPSIS
  104.  
  105. I<ex. CGI>
  106.  
  107.   use GD::Barcode::NW7;
  108.   binmode(STDOUT);
  109.   print "Content-Type: image/png\n\n";
  110.   print GD::Barcode::NW7->new('123456789012')->plot->png;
  111.  
  112. I<with Error Check>
  113.  
  114.   my $oGdBar = GD::Barcode::NW7->new('123456789E');
  115.   die $GD::Barcode::NW7::errStr unless($oGdBar);        #Invalid Characters
  116.  
  117. =head1 DESCRIPTION
  118.  
  119. GD::Barcode::NW7 is a subclass of GD::Barcode and allows you to
  120. create NW7 barcode image with GD.
  121. This module based on "Generate Barcode Ver 1.02 By Shisei Hanai 97/08/22".
  122.  
  123. =head2 new
  124.  
  125. I<$oGdBar> = GD::Barcode::NW7->new(I<$sTxt>);
  126.  
  127. Constructor.
  128. Creates a GD::Barcode::NW7 object for I<$sTxt>.
  129. I<$sTxt> has variable length string with (0-9, - $ / . + ABCD).
  130.  
  131. =head2 plot()
  132.  
  133. I<$oGd> = $oGdBar->plot([Height => I<$iHeight>, NoText => I<0 | 1>]);
  134.  
  135. creates GD object with barcode image for the I<$sTxt> specified at L<new> method.
  136. I<$iHeight> is height of the image. If I<NoText> is 1, the image has no text image of I<$sTxt>.
  137.  
  138.  ex.
  139.   my $oGdB = GD::Barcode::NW7->new('123456789012');
  140.   my $oGD = $oGdB->plot(NoText=>1, Height => 20);
  141.   # $sGD is a GD image with Height=>20 pixels, with no text.
  142.  
  143. =head2 barcode()
  144.  
  145. I<$sPtn> = $oGdBar->barcode();
  146.  
  147. returns a barcode pattern in string with '1' and '0'.
  148. '1' means black, '0' means white.
  149.  
  150.  ex.
  151.   my $oGdB = GD::Barcode::NW7->new('123456789012');
  152.   my $sPtn = $oGdB->barcode();
  153.   # $sPtn = '';
  154.  
  155. =head2 $errStr
  156.  
  157. $GD::Barcode::NW7::errStr
  158.  
  159. has error message.
  160.  
  161. =head2 $text
  162.  
  163. $oGdBar->{$text}
  164.  
  165. has barcode text based on I<$sTxt> specified in L<new> method.
  166.  
  167. =head1 AUTHOR
  168.  
  169. Kawai Takanori GCD00051@nifty.ne.jp
  170.  
  171. =head1 COPYRIGHT
  172.  
  173. The GD::Barocde::NW7 module is Copyright (c) 2000 Kawai Takanori. Japan.
  174. All rights reserved.
  175.  
  176. You may distribute under the terms of either the GNU General Public
  177. License or the Artistic License, as specified in the Perl README file.
  178.  
  179. =head1 SEE ALSO
  180.  
  181. GD::Barcode
  182.  
  183. =cut
  184.