source-class-Com.Tecnick.Barcode.Type.Linear.EanTwo

It appears that you are using AdBlocking software. The cost of running this website is covered by advertisements. If you like it please feel free to a small amount of money to secure the future of this website.
Overview

Classes

Exceptions

  1: <?php
  2: /**
  3:  * EanTwo.php
  4:  *
  5:  * @since       2015-02-21
  6:  * @category    Library
  7:  * @package     Barcode
  8:  * @author      Nicola Asuni <info@tecnick.com>
  9:  * @copyright   2010-2016 Nicola Asuni - Tecnick.com LTD
 10:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 11:  * @link        https://github.com/tecnickcom/tc-lib-barcode
 12:  *
 13:  * This file is part of tc-lib-barcode software library.
 14:  */
 15: 
 16: namespace Com\Tecnick\Barcode\Type\Linear;
 17: 
 18: use \Com\Tecnick\Barcode\Exception as BarcodeException;
 19: 
 20: /**
 21:  * Com\Tecnick\Barcode\Type\Linear\EanTwo;
 22:  *
 23:  * EanTwo Barcode type class
 24:  * EAN 2-Digits UPC-Based Extension
 25:  *
 26:  * @since       2015-02-21
 27:  * @category    Library
 28:  * @package     Barcode
 29:  * @author      Nicola Asuni <info@tecnick.com>
 30:  * @copyright   2010-2016 Nicola Asuni - Tecnick.com LTD
 31:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 32:  * @link        https://github.com/tecnickcom/tc-lib-barcode
 33:  */
 34: class EanTwo extends \Com\Tecnick\Barcode\Type\Linear
 35: {
 36:     /**
 37:      * Barcode format
 38:      *
 39:      * @var string
 40:      */
 41:     protected $format = 'EAN2';
 42: 
 43:     /**
 44:      * Fixed code length
 45:      *
 46:      * @var int
 47:      */
 48:     protected $code_length = 2;
 49:     
 50:     /**
 51:      * Map characters to barcodes
 52:      *
 53:      * @var array
 54:      */
 55:     protected $chbar = array(
 56:         'A' => array( // left odd parity
 57:             '0'=>'0001101',
 58:             '1'=>'0011001',
 59:             '2'=>'0010011',
 60:             '3'=>'0111101',
 61:             '4'=>'0100011',
 62:             '5'=>'0110001',
 63:             '6'=>'0101111',
 64:             '7'=>'0111011',
 65:             '8'=>'0110111',
 66:             '9'=>'0001011'
 67:         ),
 68:         'B' => array( // left even parity
 69:             '0'=>'0100111',
 70:             '1'=>'0110011',
 71:             '2'=>'0011011',
 72:             '3'=>'0100001',
 73:             '4'=>'0011101',
 74:             '5'=>'0111001',
 75:             '6'=>'0000101',
 76:             '7'=>'0010001',
 77:             '8'=>'0001001',
 78:             '9'=>'0010111'
 79:         )
 80:     );
 81: 
 82:     /**
 83:      * Map parities
 84:      *
 85:      * @var array
 86:      */
 87:     protected $parities = array(
 88:         '0' => array('A','A'),
 89:         '1' => array('A','B'),
 90:         '2' => array('B','A'),
 91:         '3' => array('B','B')
 92:     );
 93: 
 94:     /**
 95:      * Calculate checksum
 96:      *
 97:      * @param $code (string) code to represent.
 98:      *
 99:      * @return char checksum.
100:      */
101:     protected function getChecksum($code)
102:     {
103:         return (intval($code) % 4);
104:     }
105: 
106:     /**
107:      * Format code
108:      */
109:     protected function formatCode()
110:     {
111:         $this->extcode = str_pad($this->code, $this->code_length, '0', STR_PAD_LEFT);
112:     }
113:     
114:     /**
115:      * Get the bars array
116:      *
117:      * @throws BarcodeException in case of error
118:      */
119:     protected function setBars()
120:     {
121:         $this->formatCode();
122:         $chk = $this->getChecksum($this->extcode);
123:         $parity = $this->parities[$chk];
124:         $seq = '1011'; // left guard bar
125:         $seq .= $this->chbar[$parity[0]][$this->extcode[0]];
126:         $len = strlen($this->extcode);
127:         for ($pos = 1; $pos < $len; ++$pos) {
128:             $seq .= '01'; // separator
129:             $seq .= $this->chbar[$parity[$pos]][$this->extcode[$pos]];
130:         }
131:         $this->processBinarySequence($seq);
132:     }
133: }
134: 
 

© 2004-2017 – Nicola Asuni - Tecnick.com - All rights reserved.
about - disclaimer - privacy