linea21-externals
[ class tree: linea21-externals ] [ index: linea21-externals ] [ all elements ]

Source for file BarcodeObject

Documentation is available at BarcodeObject

  1. <?php
  2. //============================================================+
  3. // File name   : i25aobject.php
  4. // Begin       : 2002-07-31
  5. // Last Update : 2004-12-29
  6. // Author      : Karim Mribti [barcode@mribti.com]
  7. //             : Nicola Asuni [info@tecnick.com]
  8. // Version     : 0.0.8a  2001-04-01 (original code)
  9. // License     : GNU LGPL (Lesser General Public License) 2.1
  10. //               http://www.gnu.org/copyleft/lesser.txt
  11. // Source Code : http://www.mribti.com/barcode/
  12. //
  13. // Description : I25 Barcode Render Class for PHP using
  14. //               the GD graphics library.
  15. //               Interleaved 2 of 5 is a numeric only bar code
  16. //               with a optional check number.
  17. //
  18. // NOTE:
  19. // This version contains changes by Nicola Asuni:
  20. //  - porting to PHP5
  21. //  - code style and formatting
  22. //  - automatic php documentation in PhpDocumentor Style
  23. //    (www.phpdoc.org)
  24. //  - minor bug fixing
  25. //============================================================+
  26.  
  27. /**
  28.  * I25 Barcode Render Class for PHP using the GD graphics library.<br<
  29.  * Interleaved 2 of 5 is a numeric only bar code with a optional check number.
  30.  * @author Karim Mribti, Nicola Asuni
  31.  * @name BarcodeObject
  32.  * @package linea21.externals
  33.  * @subpackage com.tecnick.tcpdf
  34.  * @version 0.0.8a  2001-04-01 (original code)
  35.  * @since 2001-03-25
  36.  * @license http://www.gnu.org/copyleft/lesser.html LGPL
  37.  */
  38.  
  39. /**
  40.  * I25 Barcode Render Class for PHP using the GD graphics library.<br<
  41.  * Interleaved 2 of 5 is a numeric only bar code with a optional check number.
  42.  * @author Karim Mribti, Nicola Asuni
  43.  * @name BarcodeObject
  44.  * @package linea21.externals
  45.  * @subpackage com.tecnick.tcpdf
  46.  * @version 0.0.8a  2001-04-01 (original code)
  47.  * @since 2001-03-25
  48.  * @license http://www.gnu.org/copyleft/lesser.html LGPL
  49.  */
  50. class I25Object extends BarcodeObject {
  51.     
  52.     /**
  53.      * Class Constructor.
  54.      * @param int $Width Image width in pixels.
  55.      * @param int $Height Image height in pixels.
  56.      * @param int $Style Barcode style.
  57.      * @param int $Value value to print on barcode.
  58.      */
  59.     public function __construct($Width$Height$Style$Value{
  60.         parent::__construct($Width$Height$Style);
  61.         $this->mValue $Value;
  62.         $this->mCharSet = array (
  63.         /* 0 */ "00110",
  64.         /* 1 */ "10001",
  65.         /* 2 */ "01001",
  66.         /* 3 */ "11000",
  67.         /* 4 */ "00101",
  68.         /* 5 */ "10100",
  69.         /* 6 */ "01100",
  70.         /* 7 */ "00011",
  71.         /* 8 */ "10010",
  72.         /* 9 */ "01010"
  73.         );
  74.     }
  75.     
  76.     /**
  77.      * Returns barcode size.
  78.      * @param int $xres Horizontal resolution.
  79.      * @return barcode size.
  80.      * @access private
  81.      */
  82.     private function GetSize($xres{
  83.         $len strlen($this->mValue);
  84.  
  85.         if ($len == 0)  {
  86.             $this->mError = "Null value";
  87.             return false;
  88.         }
  89.  
  90.         for ($i=0;$i<$len;$i++{
  91.             if ((ord($this->mValue[$i])<48|| (ord($this->mValue[$i])>57)) {
  92.                 $this->mError = "I25 is numeric only";
  93.                 return false;
  94.             }
  95.         }
  96.  
  97.         if (($len%2!= 0{
  98.             $this->mError = "The length of barcode value must be even";
  99.             return false;
  100.         }
  101.         $StartSize BCD_I25_NARROW_BAR 4  $xres;
  102.         $StopSize  BCD_I25_WIDE_BAR $xres BCD_I25_NARROW_BAR $xres;
  103.         $cPos 0;
  104.         $sPos 0;
  105.         do {
  106.             $c1    $this->mValue[$cPos];
  107.             $c2    $this->mValue[$cPos+1];
  108.             $cset1 $this->mCharSet[$c1];
  109.             $cset2 $this->mCharSet[$c2];
  110.  
  111.             for ($i=0;$i<5;$i++{
  112.                 $type1 ($cset1[$i]==0(BCD_I25_NARROW_BAR  $xres(BCD_I25_WIDE_BAR $xres);
  113.                 $type2 ($cset2[$i]==0(BCD_I25_NARROW_BAR  $xres(BCD_I25_WIDE_BAR $xres);
  114.                 $sPos += ($type1 $type2);
  115.             }
  116.             $cPos+=2;
  117.         while ($cPos<$len);
  118.  
  119.         return $sPos $StartSize $StopSize;
  120.     }
  121.  
  122.     /**
  123.      * Draws the start code.
  124.      * @param int $DrawPos Drawing position.
  125.      * @param int $yPos Vertical position.
  126.      * @param int $ySize Vertical size.
  127.      * @param int $xres Horizontal resolution.
  128.      * @return int drawing position.
  129.      * @access private
  130.      */
  131.     private function DrawStart($DrawPos$yPos$ySize$xres{
  132.         /* Start code is "0000" */
  133.         $this->DrawSingleBar($DrawPos$yPosBCD_I25_NARROW_BAR  $xres $ySize);
  134.         $DrawPos += BCD_I25_NARROW_BAR  $xres;
  135.         $DrawPos += BCD_I25_NARROW_BAR  $xres;
  136.         $this->DrawSingleBar($DrawPos$yPosBCD_I25_NARROW_BAR  $xres $ySize);
  137.         $DrawPos += BCD_I25_NARROW_BAR  $xres;
  138.         $DrawPos += BCD_I25_NARROW_BAR  $xres;
  139.         return $DrawPos;
  140.     }
  141.     
  142.     /**
  143.      * Draws the stop code.
  144.      * @param int $DrawPos Drawing position.
  145.      * @param int $yPos Vertical position.
  146.      * @param int $ySize Vertical size.
  147.      * @param int $xres Horizontal resolution.
  148.      * @return int drawing position.
  149.      * @access private
  150.      */
  151.     private function DrawStop($DrawPos$yPos$ySize$xres{
  152.         /* Stop code is "100" */
  153.         $this->DrawSingleBar($DrawPos$yPosBCD_I25_WIDE_BAR $xres $ySize);
  154.         $DrawPos += BCD_I25_WIDE_BAR  $xres;
  155.         $DrawPos += BCD_I25_NARROW_BAR  $xres;
  156.         $this->DrawSingleBar($DrawPos$yPosBCD_I25_NARROW_BAR  $xres $ySize);
  157.         $DrawPos += BCD_I25_NARROW_BAR  $xres;
  158.         return $DrawPos;
  159.     }
  160.  
  161.     /**
  162.      * Draws the barcode object.
  163.      * @param int $xres Horizontal resolution.
  164.      * @return bool true in case of success.
  165.      */
  166.     public function DrawObject($xres{
  167.         $len strlen($this->mValue);
  168.  
  169.         if (($size $this->GetSize($xres))==0{
  170.             return false;
  171.         }
  172.  
  173.         $cPos  0;
  174.  
  175.         if ($this->mStyle BCS_DRAW_TEXT$ysize $this->mHeight - BCD_DEFAULT_MAR_Y1 BCD_DEFAULT_MAR_Y2 $this->GetFontHeight($this->mFont);
  176.         else $ysize $this->mHeight - BCD_DEFAULT_MAR_Y1 BCD_DEFAULT_MAR_Y2;
  177.  
  178.         if ($this->mStyle BCS_ALIGN_CENTER$sPos = (integer)(($this->mWidth - $size 2);
  179.         else if ($this->mStyle BCS_ALIGN_RIGHT$sPos $this->mWidth - $size;
  180.         else $sPos 0;
  181.  
  182.         if ($this->mStyle BCS_DRAW_TEXT{
  183.             if ($this->mStyle BCS_STRETCH_TEXT{
  184.                 /* Stretch */
  185.                 for ($i=0;$i<$len;$i++{
  186.                     $this->DrawChar($this->mFont$sPos+BCD_I25_NARROW_BAR*4*$xres+($size/$len)*$i,
  187.                     $ysize BCD_DEFAULT_MAR_Y1 BCD_DEFAULT_TEXT_OFFSET $this->mValue[$i]);
  188.                 }
  189.             }else {/* Center */
  190.             $text_width $this->GetFontWidth($this->mFontstrlen($this->mValue);
  191.             $this->DrawText($this->mFont$sPos+(($size-$text_width)/2)+(BCD_I25_NARROW_BAR*4*$xres),
  192.             $ysize BCD_DEFAULT_MAR_Y1 BCD_DEFAULT_TEXT_OFFSET$this->mValue);
  193.             }
  194.         }
  195.  
  196.         $sPos $this->DrawStart($sPosBCD_DEFAULT_MAR_Y1$ysize$xres);
  197.         do {
  198.             $c1 $this->mValue[$cPos];
  199.             $c2 $this->mValue[$cPos+1];
  200.             $cset1 $this->mCharSet[$c1];
  201.             $cset2 $this->mCharSet[$c2];
  202.  
  203.             for ($i=0;$i<5;$i++{
  204.                 $type1 ($cset1[$i]==0(BCD_I25_NARROW_BAR $xres(BCD_I25_WIDE_BAR $xres);
  205.                 $type2 ($cset2[$i]==0(BCD_I25_NARROW_BAR $xres(BCD_I25_WIDE_BAR $xres);
  206.                 $this->DrawSingleBar($sPosBCD_DEFAULT_MAR_Y1$type1 $ysize);
  207.                 $sPos += ($type1 $type2);
  208.             }
  209.             $cPos+=2;
  210.         while ($cPos<$len);
  211.         $sPos =  $this->DrawStop($sPosBCD_DEFAULT_MAR_Y1$ysize$xres);
  212.         return true;
  213.     }
  214. }
  215.  
  216. //============================================================+
  217. // END OF FILE
  218. //============================================================+
  219. ?>

Documentation generated on Fri, 16 Oct 2009 09:28:38 +0200 by phpDocumentor 1.4.1