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

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:  * InterleavedTwoOfFiveCheck.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\InterleavedTwoOfFiveCheck;
 22:  *
 23:  * InterleavedTwoOfFiveCheck Barcode type class
 24:  * Interleaved 2 of 5 + CHECKSUM
 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 InterleavedTwoOfFiveCheck extends \Com\Tecnick\Barcode\Type\Linear\StandardTwoOfFiveCheck
 35: {
 36:     /**
 37:      * Barcode format
 38:      *
 39:      * @var string
 40:      */
 41:     protected $format = 'I25+';
 42: 
 43:     /**
 44:      * Map characters to barcodes
 45:      *
 46:      * @var array
 47:      */
 48:     protected $chbar = array(
 49:         '0' => '11221',
 50:         '1' => '21112',
 51:         '2' => '12112',
 52:         '3' => '22111',
 53:         '4' => '11212',
 54:         '5' => '21211',
 55:         '6' => '12211',
 56:         '7' => '11122',
 57:         '8' => '21121',
 58:         '9' => '12121',
 59:         'A' => '11',
 60:         'Z' => '21'
 61:     );
 62: 
 63:     /**
 64:      * Format code
 65:      */
 66:     protected function formatCode()
 67:     {
 68:         $this->extcode = $this->code.$this->getChecksum($this->code);
 69:     }
 70:     
 71:     /**
 72:      * Get the bars array
 73:      *
 74:      * @return array
 75:      *
 76:      * @throws BarcodeException in case of error
 77:      */
 78:     protected function setBars()
 79:     {
 80:         $this->formatCode();
 81:         if ((strlen($this->extcode) % 2) != 0) {
 82:             // add leading zero if code-length is odd
 83:             $this->extcode = '0'.$this->extcode;
 84:         }
 85:         // add start and stop codes
 86:         $this->extcode = 'AA'.strtolower($this->extcode).'ZA';
 87:         $this->ncols = 0;
 88:         $this->nrows = 1;
 89:         $this->bars = array();
 90:         $clen = strlen($this->extcode);
 91:         for ($idx = 0; $idx < $clen; $idx = ($idx + 2)) {
 92:             $char_bar = $this->extcode[$idx];
 93:             $char_space = $this->extcode[($idx + 1)];
 94:             if ((!isset($this->chbar[$char_bar])) || (!isset($this->chbar[$char_space]))) {
 95:                 throw new BarcodeException('Invalid character sequence: '.$char_bar.$char_space);
 96:             }
 97:             // create a bar-space sequence
 98:             $seq = '';
 99:             $chrlen = strlen($this->chbar[$char_bar]);
100:             for ($pos = 0; $pos < $chrlen; ++$pos) {
101:                 $seq .= $this->chbar[$char_bar][$pos].$this->chbar[$char_space][$pos];
102:             }
103:             $seqlen = strlen($seq);
104:             for ($pos = 0; $pos < $seqlen; ++$pos) {
105:                 $bar_width = intval($seq[$pos]);
106:                 if ((($pos % 2) == 0) && ($bar_width > 0)) {
107:                     $this->bars[] = array($this->ncols, 0, $bar_width, 1);
108:                 }
109:                 $this->ncols += $bar_width;
110:             }
111:         }
112:         --$this->ncols;
113:     }
114: }
115: 
 

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