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

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:  * UpcE.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\UpcE;
 22:  *
 23:  * UpcE Barcode type class
 24:  * UPC-E
 25:  *
 26:  * UPC-E is a variation of UPC-A which allows for a more compact barcode by eliminating "extra" zeros.
 27:  * Since the resulting UPC-E barcode is about half the size as an UPC-A barcode, UPC-E is generally used on products
 28:  * with very small packaging where a full UPC-A barcode couldn't reasonably fit.
 29:  *
 30:  * @since       2015-02-21
 31:  * @category    Library
 32:  * @package     Barcode
 33:  * @author      Nicola Asuni <info@tecnick.com>
 34:  * @copyright   2010-2016 Nicola Asuni - Tecnick.com LTD
 35:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 36:  * @link        https://github.com/tecnickcom/tc-lib-barcode
 37:  */
 38: class UpcE extends \Com\Tecnick\Barcode\Type\Linear\UpcA
 39: {
 40:     /**
 41:      * Barcode format
 42:      *
 43:      * @var string
 44:      */
 45:     protected $format = 'UPCE';
 46: 
 47:     /**
 48:      * Fixed code length
 49:      *
 50:      * @var int
 51:      */
 52:     protected $code_length = 12;
 53: 
 54:     /**
 55:      * Map parities
 56:      *
 57:      * @var array
 58:      */
 59:     protected $parities = array(
 60:         0 => array(
 61:             '0' => array('B','B','B','A','A','A'),
 62:             '1' => array('B','B','A','B','A','A'),
 63:             '2' => array('B','B','A','A','B','A'),
 64:             '3' => array('B','B','A','A','A','B'),
 65:             '4' => array('B','A','B','B','A','A'),
 66:             '5' => array('B','A','A','B','B','A'),
 67:             '6' => array('B','A','A','A','B','B'),
 68:             '7' => array('B','A','B','A','B','A'),
 69:             '8' => array('B','A','B','A','A','B'),
 70:             '9' => array('B','A','A','B','A','B')
 71:         ),
 72:         1 => array(
 73:             '0' => array('A','A','A','B','B','B'),
 74:             '1' => array('A','A','B','A','B','B'),
 75:             '2' => array('A','A','B','B','A','B'),
 76:             '3' => array('A','A','B','B','B','A'),
 77:             '4' => array('A','B','A','A','B','B'),
 78:             '5' => array('A','B','B','A','A','B'),
 79:             '6' => array('A','B','B','B','A','A'),
 80:             '7' => array('A','B','A','B','A','B'),
 81:             '8' => array('A','B','A','B','B','A'),
 82:             '9' => array('A','B','B','A','B','A')
 83:         )
 84:     );
 85: 
 86:     /**
 87:      * Get the pre-formatted code
 88:      *
 89:      * @param string $code Code to convert.
 90:      *
 91:      * @return string
 92:      */
 93:     protected function convertUpceCode($code)
 94:     {
 95:         // convert UPC-A to UPC-E
 96:         $tmp = substr($code, 4, 3);
 97:         if (($tmp == '000') || ($tmp == '100') || ($tmp == '200')) {
 98:             // manufacturer code ends in 000, 100, or 200
 99:             return substr($code, 2, 2).substr($code, 9, 3).substr($code, 4, 1);
100:         }
101:         $tmp = substr($code, 5, 2);
102:         if ($tmp == '00') {
103:             // manufacturer code ends in 00
104:             return substr($code, 2, 3).substr($code, 10, 2).'3';
105:         }
106:         $tmp = substr($code, 6, 1);
107:         if ($tmp == '0') {
108:             // manufacturer code ends in 0
109:             return substr($code, 2, 4).substr($code, 11, 1).'4';
110:         }
111:         // manufacturer code does not end in zero
112:         return substr($code, 2, 5).substr($code, 11, 1);
113:     }
114:     
115:     /**
116:      * Get the bars array
117:      *
118:      * @throws BarcodeException in case of error
119:      */
120:     protected function setBars()
121:     {
122:         $this->formatCode();
123:         $upce_code = $this->convertUpceCode($this->extcode);
124:         $seq = '101'; // left guard bar
125:         $parity = $this->parities[$this->extcode[1]][$this->check];
126:         for ($pos = 0; $pos < 6; ++$pos) {
127:             $seq .= $this->chbar[$parity[$pos]][$upce_code[$pos]];
128:         }
129:         $seq .= '010101'; // right guard bar
130:         $this->processBinarySequence($seq);
131:     }
132: }
133: 
 

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