File indexing completed on 2024-12-22 05:36:28

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Barcode
0017  * @subpackage Object
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 /** @see Zend_Barcode_Object_Code25 */
0024 // require_once 'Zend/Barcode/Object/Code25.php';
0025 
0026 /** @see Zend_Validate_Barcode */
0027 // require_once 'Zend/Validate/Barcode.php';
0028 
0029 /**
0030  * Class for generate Interleaved 2 of 5 barcode
0031  *
0032  * @category   Zend
0033  * @package    Zend_Barcode
0034  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0035  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0036  */
0037 class Zend_Barcode_Object_Code25interleaved extends Zend_Barcode_Object_Code25
0038 {
0039     /**
0040      * Drawing of bearer bars
0041      * @var boolean
0042      */
0043     private $_withBearerBars = false;
0044 
0045     /**
0046      * Default options for Code25interleaved barcode
0047      * @return void
0048      */
0049     protected function _getDefaultOptions()
0050     {
0051         $this->_barcodeLength = 'even';
0052     }
0053 
0054     /**
0055      * Activate/deactivate drawing of bearer bars
0056      * @param boolean $value
0057      * @return Zend_Barcode_Object_Int25
0058      */
0059     public function setWithBearerBars($value)
0060     {
0061         $this->_withBearerBars = (bool) $value;
0062         return $this;
0063     }
0064 
0065     /**
0066      * Retrieve if bearer bars are enabled
0067      * @return boolean
0068      */
0069     public function getWithBearerBars()
0070     {
0071         return $this->_withBearerBars;
0072     }
0073 
0074     /**
0075      * Width of the barcode (in pixels)
0076      * @return integer
0077      */
0078     protected function _calculateBarcodeWidth()
0079     {
0080         $quietZone       = $this->getQuietZone();
0081         $startCharacter  = (4 * $this->_barThinWidth) * $this->_factor;
0082         $characterLength = (3 * $this->_barThinWidth + 2 * $this->_barThickWidth) * $this->_factor;
0083         $encodedData     = strlen($this->getText()) * $characterLength;
0084         $stopCharacter   = ($this->_barThickWidth + 2 * $this->_barThinWidth) * $this->_factor;
0085         return $quietZone + $startCharacter + $encodedData + $stopCharacter + $quietZone;
0086     }
0087 
0088     /**
0089      * Prepare array to draw barcode
0090      * @return array
0091      */
0092     protected function _prepareBarcode()
0093     {
0094         if ($this->_withBearerBars) {
0095             $this->_withBorder = false;
0096         }
0097 
0098         // Start character (0000)
0099         $barcodeTable[] = array(1, $this->_barThinWidth, 0, 1);
0100         $barcodeTable[] = array(0, $this->_barThinWidth, 0, 1);
0101         $barcodeTable[] = array(1, $this->_barThinWidth, 0, 1);
0102         $barcodeTable[] = array(0, $this->_barThinWidth, 0, 1);
0103 
0104         // Encoded $text
0105         $text = $this->getText();
0106         for ($i = 0; $i < strlen($text); $i += 2) { // Draw 2 chars at a time
0107             $char1 = substr($text, $i, 1);
0108             $char2 = substr($text, $i + 1, 1);
0109 
0110             // Interleave
0111             for ($ibar = 0; $ibar < 5; $ibar ++) {
0112                 // Draws char1 bar (fore color)
0113                 $barWidth = (substr($this->_codingMap[$char1], $ibar, 1))
0114                           ? $this->_barThickWidth
0115                           : $this->_barThinWidth;
0116 
0117                 $barcodeTable[] = array(1, $barWidth, 0, 1);
0118 
0119                 // Left space corresponding to char2 (background color)
0120                 $barWidth = (substr($this->_codingMap[$char2], $ibar, 1))
0121                           ? $this->_barThickWidth
0122                           : $this->_barThinWidth;
0123                 $barcodeTable[] = array(0, $barWidth, 0 , 1);
0124             }
0125         }
0126 
0127         // Stop character (100)
0128         $barcodeTable[] = array(1 , $this->_barThickWidth, 0, 1);
0129         $barcodeTable[] = array(0 , $this->_barThinWidth,  0, 1);
0130         $barcodeTable[] = array(1 , $this->_barThinWidth,  0, 1);
0131         return $barcodeTable;
0132     }
0133 
0134     /**
0135      * Drawing of bearer bars (if enabled)
0136      *
0137      * @return void
0138      */
0139     protected function _postDrawBarcode()
0140     {
0141         if (!$this->_withBearerBars) {
0142             return;
0143         }
0144 
0145         $width  = $this->_barThickWidth * $this->_factor;
0146         $point1 = $this->_rotate(-1, -1);
0147         $point2 = $this->_rotate($this->_calculateWidth() - 1, -1);
0148         $point3 = $this->_rotate($this->_calculateWidth() - 1, $width - 1);
0149         $point4 = $this->_rotate(-1, $width - 1);
0150         $this->_addPolygon(array(
0151             $point1,
0152             $point2,
0153             $point3,
0154             $point4,
0155         ));
0156         $point1 = $this->_rotate(
0157             0,
0158             0 + $this->_barHeight * $this->_factor - 1
0159         );
0160         $point2 = $this->_rotate(
0161             $this->_calculateWidth() - 1,
0162             0 + $this->_barHeight * $this->_factor - 1
0163         );
0164         $point3 = $this->_rotate(
0165             $this->_calculateWidth() - 1,
0166             0 + $this->_barHeight * $this->_factor - $width
0167         );
0168         $point4 = $this->_rotate(
0169             0,
0170             0 + $this->_barHeight * $this->_factor - $width
0171         );
0172         $this->_addPolygon(array(
0173             $point1,
0174             $point2,
0175             $point3,
0176             $point4,
0177         ));
0178     }
0179 }