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 /** 0024 * @see Zend_Barcode_Object_ObjectAbstract 0025 */ 0026 // require_once 'Zend/Barcode/Object/ObjectAbstract.php'; 0027 0028 /** 0029 * @see Zend_Validate_Barcode 0030 */ 0031 // require_once 'Zend/Validate/Barcode.php'; 0032 0033 /** 0034 * Class for generate Interleaved 2 of 5 barcode 0035 * 0036 * @category Zend 0037 * @package Zend_Barcode 0038 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0039 * @license http://framework.zend.com/license/new-bsd New BSD License 0040 */ 0041 class Zend_Barcode_Object_Code25 extends Zend_Barcode_Object_ObjectAbstract 0042 { 0043 /** 0044 * Coding map 0045 * - 0 = narrow bar 0046 * - 1 = wide bar 0047 * @var array 0048 */ 0049 protected $_codingMap = array( 0050 '0' => '00110', 0051 '1' => '10001', 0052 '2' => '01001', 0053 '3' => '11000', 0054 '4' => '00101', 0055 '5' => '10100', 0056 '6' => '01100', 0057 '7' => '00011', 0058 '8' => '10010', 0059 '9' => '01010', 0060 ); 0061 0062 /** 0063 * Width of the barcode (in pixels) 0064 * @return integer 0065 */ 0066 protected function _calculateBarcodeWidth() 0067 { 0068 $quietZone = $this->getQuietZone(); 0069 $startCharacter = (2 * $this->_barThickWidth + 4 * $this->_barThinWidth) * $this->_factor; 0070 $characterLength = (3 * $this->_barThinWidth + 2 * $this->_barThickWidth + 5 * $this->_barThinWidth) 0071 * $this->_factor; 0072 $encodedData = strlen($this->getText()) * $characterLength; 0073 $stopCharacter = (2 * $this->_barThickWidth + 4 * $this->_barThinWidth) * $this->_factor; 0074 return $quietZone + $startCharacter + $encodedData + $stopCharacter + $quietZone; 0075 } 0076 0077 /** 0078 * Partial check of interleaved 2 of 5 barcode 0079 * @return void 0080 */ 0081 protected function _checkParams() 0082 { 0083 $this->_checkRatio(); 0084 } 0085 0086 /** 0087 * Prepare array to draw barcode 0088 * @return array 0089 */ 0090 protected function _prepareBarcode() 0091 { 0092 $barcodeTable = array(); 0093 0094 // Start character (30301) 0095 $barcodeTable[] = array(1 , $this->_barThickWidth , 0 , 1); 0096 $barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1); 0097 $barcodeTable[] = array(1 , $this->_barThickWidth , 0 , 1); 0098 $barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1); 0099 $barcodeTable[] = array(1 , $this->_barThinWidth , 0 , 1); 0100 $barcodeTable[] = array(0 , $this->_barThinWidth); 0101 0102 $text = str_split($this->getText()); 0103 foreach ($text as $char) { 0104 $barcodeChar = str_split($this->_codingMap[$char]); 0105 foreach ($barcodeChar as $c) { 0106 /* visible, width, top, length */ 0107 $width = $c ? $this->_barThickWidth : $this->_barThinWidth; 0108 $barcodeTable[] = array(1 , $width , 0 , 1); 0109 $barcodeTable[] = array(0 , $this->_barThinWidth); 0110 } 0111 } 0112 0113 // Stop character (30103) 0114 $barcodeTable[] = array(1 , $this->_barThickWidth , 0 , 1); 0115 $barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1); 0116 $barcodeTable[] = array(1 , $this->_barThinWidth , 0 , 1); 0117 $barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1); 0118 $barcodeTable[] = array(1 , $this->_barThickWidth , 0 , 1); 0119 return $barcodeTable; 0120 } 0121 0122 /** 0123 * Get barcode checksum 0124 * 0125 * @param string $text 0126 * @return int 0127 */ 0128 public function getChecksum($text) 0129 { 0130 $this->_checkText($text); 0131 $factor = 3; 0132 $checksum = 0; 0133 0134 for ($i = strlen($text); $i > 0; $i --) { 0135 $checksum += intval($text{$i - 1}) * $factor; 0136 $factor = 4 - $factor; 0137 } 0138 0139 $checksum = (10 - ($checksum % 10)) % 10; 0140 0141 return $checksum; 0142 } 0143 }