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

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:  * CodeNineThree.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\CodeNineThree;
 22:  *
 23:  * CodeNineThree Barcode type class
 24:  * CODE 93 - USS-93
 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 CodeNineThree extends \Com\Tecnick\Barcode\Type\Linear\CodeThreeNineExtCheck
 35: {
 36:     /**
 37:      * Barcode format
 38:      *
 39:      * @var string
 40:      */
 41:     protected $format = 'C93';
 42: 
 43:     /**
 44:      * Map characters to barcodes
 45:      *
 46:      * @var array
 47:      */
 48:     protected $chbar = array(
 49:         32  => '311211', // space
 50:         36  => '321111', // $
 51:         37  => '211131', // %
 52:         42  => '111141', // start-stop
 53:         43  => '113121', // +
 54:         45  => '121131', // -
 55:         46  => '311112', // .
 56:         47  => '112131', // /
 57:         48  => '131112', // 0
 58:         49  => '111213', // 1
 59:         50  => '111312', // 2
 60:         51  => '111411', // 3
 61:         52  => '121113', // 4
 62:         53  => '121212', // 5
 63:         54  => '121311', // 6
 64:         55  => '111114', // 7
 65:         56  => '131211', // 8
 66:         57  => '141111', // 9
 67:         65  => '211113', // A
 68:         66  => '211212', // B
 69:         67  => '211311', // C
 70:         68  => '221112', // D
 71:         69  => '221211', // E
 72:         70  => '231111', // F
 73:         71  => '112113', // G
 74:         72  => '112212', // H
 75:         73  => '112311', // I
 76:         74  => '122112', // J
 77:         75  => '132111', // K
 78:         76  => '111123', // L
 79:         77  => '111222', // M
 80:         78  => '111321', // N
 81:         79  => '121122', // O
 82:         80  => '131121', // P
 83:         81  => '212112', // Q
 84:         82  => '212211', // R
 85:         83  => '211122', // S
 86:         84  => '211221', // T
 87:         85  => '221121', // U
 88:         86  => '222111', // V
 89:         87  => '112122', // W
 90:         88  => '112221', // X
 91:         89  => '122121', // Y
 92:         90  => '123111', // Z
 93:         128 => '121221', // ($)
 94:         129 => '311121', // (/)
 95:         130 => '122211', // (+)
 96:         131 => '312111'  // (%)
 97:     );
 98: 
 99:     /**
100:      * Map for extended characters
101:      *
102:      * @var array
103:      */
104:     protected $extcodes = array();
105: 
106:     /**
107:      * Characters used for checksum
108:      *
109:      * @var array
110:      */
111:     protected $chksum = array(
112:         '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
113:         'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
114:         'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
115:         'W', 'X', 'Y', 'Z', '-', '.', ' ', '$', '/', '+', '%',
116:         '<', '=', '>', '?'
117:     );
118: 
119:     /**
120:      * Calculate CODE 93 checksum (modulo 47).
121:      *
122:      * @param $code (string) code to represent.
123:      *
124:      * @return char checksum.
125:      */
126:     protected function getChecksum($code)
127:     {
128:         // translate special characters
129:         $code = strtr($code, chr(128).chr(131).chr(129).chr(130), '<=>?');
130:         $clen = strlen($code);
131:         // calculate check digit C
132:         $pck = 1;
133:         $check = 0;
134:         for ($idx = ($clen - 1); $idx >= 0; --$idx) {
135:             $key = array_keys($this->chksum, $code[$idx]);
136:             $check += ($key[0] * $pck);
137:             ++$pck;
138:             if ($pck > 20) {
139:                 $pck = 1;
140:             }
141:         }
142:         $check %= 47;
143:         $chk = $this->chksum[$check];
144:         $code .= $chk;
145:         // calculate check digit K
146:         $pck = 1;
147:         $check = 0;
148:         for ($idx = $clen; $idx >= 0; --$idx) {
149:             $key = array_keys($this->chksum, $code[$idx]);
150:             $check += ($key[0] * $pck);
151:             ++$pck;
152:             if ($pck > 15) {
153:                 $pck = 1;
154:             }
155:         }
156:         $check %= 47;
157:         $key = $this->chksum[$check];
158:         $checksum = $chk.$key;
159:         // restore special characters
160:         $checksum = strtr($checksum, '<=>?', chr(128).chr(131).chr(129).chr(130));
161:         return $checksum;
162:     }
163: 
164:     /**
165:      * Get the bars array
166:      *
167:      * @throws BarcodeException in case of error
168:      */
169:     protected function setBars()
170:     {
171:         $this->extcodes = array(
172:             chr(131).'U', chr(128).'A', chr(128).'B', chr(128).'C', chr(128).'D', chr(128).'E', chr(128).'F',
173:             chr(128).'G', chr(128).'H', chr(128).'I', chr(128).'J', chr(128).'K', chr(128).'L', chr(128).'M',
174:             chr(128).'N', chr(128).'O', chr(128).'P', chr(128).'Q', chr(128).'R', chr(128).'S', chr(128).'T',
175:             chr(128).'U', chr(128).'V', chr(128).'W', chr(128).'X', chr(128).'Y', chr(128).'Z', chr(131).'A',
176:             chr(131).'B', chr(131).'C', chr(131).'D', chr(131).'E', ' ', chr(129).'A', chr(129).'B',
177:             chr(129).'C', chr(129).'D', chr(129).'E', chr(129).'F', chr(129).'G', chr(129).'H', chr(129).'I',
178:             chr(129).'J', chr(129).'K', chr(129).'L', '-', '.', chr(129).'O', '0', '1', '2', '3', '4', '5',
179:             '6', '7', '8', '9', chr(129).'Z', chr(131).'F', chr(131).'G', chr(131).'H', chr(131).'I',
180:             chr(131).'J', chr(131).'V', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
181:             'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', chr(131).'K', chr(131).'L',
182:             chr(131).'M', chr(131).'N', chr(131).'O', chr(131).'W', chr(130).'A',
183:             chr(130).'B', chr(130).'C', chr(130).'D', chr(130).'E', chr(130).'F', chr(130).'G', chr(130).'H',
184:             chr(130).'I', chr(130).'J', chr(130).'K', chr(130).'L', chr(130).'M', chr(130).'N', chr(130).'O',
185:             chr(130).'P', chr(130).'Q', chr(130).'R', chr(130).'S', chr(130).'T', chr(130).'U', chr(130).'V',
186:             chr(130).'W', chr(130).'X', chr(130).'Y', chr(130).'Z', chr(131).'P', chr(131).'Q', chr(131).'R',
187:             chr(131).'S', chr(131).'T'
188:         );
189:         $this->ncols = 0;
190:         $this->nrows = 1;
191:         $this->bars = array();
192:         $this->formatCode();
193:         $clen = strlen($this->extcode);
194:         for ($chr = 0; $chr < $clen; ++$chr) {
195:             $char = ord($this->extcode[$chr]);
196:             for ($pos = 0; $pos < 6; ++$pos) {
197:                 $bar_width = intval($this->chbar[$char][$pos]);
198:                 if (($pos % 2) == 0) {
199:                     $this->bars[] = array($this->ncols, 0, $bar_width, 1);
200:                 }
201:                 $this->ncols += $bar_width;
202:             }
203:         }
204:         $this->bars[] = array($this->ncols, 0, 1, 1);
205:         $this->ncols += 1;
206:     }
207: }
208: 
 

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