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

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:  * Codabar.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\Codabar;
 22:  *
 23:  * Codabar Barcode type class
 24:  *
 25:  * @since       2015-02-21
 26:  * @category    Library
 27:  * @package     Barcode
 28:  * @author      Nicola Asuni <info@tecnick.com>
 29:  * @copyright   2010-2016 Nicola Asuni - Tecnick.com LTD
 30:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 31:  * @link        https://github.com/tecnickcom/tc-lib-barcode
 32:  */
 33: class Codabar extends \Com\Tecnick\Barcode\Type\Linear
 34: {
 35:     /**
 36:      * Barcode format
 37:      *
 38:      * @var string
 39:      */
 40:     protected $format = 'CODABAR';
 41: 
 42:     /**
 43:      * Map characters to barcodes
 44:      *
 45:      * @var array
 46:      */
 47:     protected $chbar = array(
 48:         '0' => '11111221',
 49:         '1' => '11112211',
 50:         '2' => '11121121',
 51:         '3' => '22111111',
 52:         '4' => '11211211',
 53:         '5' => '21111211',
 54:         '6' => '12111121',
 55:         '7' => '12112111',
 56:         '8' => '12211111',
 57:         '9' => '21121111',
 58:         '-' => '11122111',
 59:         '$' => '11221111',
 60:         ':' => '21112121',
 61:         '/' => '21211121',
 62:         '.' => '21212111',
 63:         '+' => '11222221',
 64:         'A' => '11221211',
 65:         'B' => '12121121',
 66:         'C' => '11121221',
 67:         'D' => '11122211'
 68:     );
 69: 
 70:     /**
 71:      * Format code
 72:      */
 73:     protected function formatCode()
 74:     {
 75:         $this->extcode = 'A'.strtoupper($this->code).'A';
 76:     }
 77: 
 78:     /**
 79:      * Get the bars array
 80:      *
 81:      * @return array
 82:      *
 83:      * @throws BarcodeException in case of error
 84:      */
 85:     protected function setBars()
 86:     {
 87:         $this->ncols = 0;
 88:         $this->nrows = 1;
 89:         $this->bars = array();
 90:         $this->formatCode();
 91:         $clen = strlen($this->extcode);
 92:         for ($chr = 0; $chr < $clen; ++$chr) {
 93:             $char = $this->extcode[$chr];
 94:             if (!isset($this->chbar[$char])) {
 95:                 throw new BarcodeException('Invalid character: chr('.ord($char).')');
 96:             }
 97:             for ($pos = 0; $pos < 8; ++$pos) {
 98:                 $bar_width = intval($this->chbar[$char][$pos]);
 99:                 if (($pos % 2) == 0) {
100:                     $this->bars[] = array($this->ncols, 0, $bar_width, 1);
101:                 }
102:                 $this->ncols += $bar_width;
103:             }
104:         }
105:         --$this->ncols;
106:     }
107: }
108: 
 

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