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

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:  * CodeOneTwoEight.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\CodeOneTwoEight;
 22:  *
 23:  * CodeOneTwoEight Barcode type class
 24:  * CODE 128
 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 CodeOneTwoEight extends \Com\Tecnick\Barcode\Type\Linear\CodeOneTwoEight\Process
 35: {
 36:     /**
 37:      * Barcode format
 38:      *
 39:      * @var string
 40:      */
 41:     protected $format = 'C128';
 42: 
 43:     /**
 44:      * Map characters to barcodes
 45:      *
 46:      * @var array
 47:      */
 48:     protected $chbar = array(
 49:         '212222', // 00
 50:         '222122', // 01
 51:         '222221', // 02
 52:         '121223', // 03
 53:         '121322', // 04
 54:         '131222', // 05
 55:         '122213', // 06
 56:         '122312', // 07
 57:         '132212', // 08
 58:         '221213', // 09
 59:         '221312', // 10
 60:         '231212', // 11
 61:         '112232', // 12
 62:         '122132', // 13
 63:         '122231', // 14
 64:         '113222', // 15
 65:         '123122', // 16
 66:         '123221', // 17
 67:         '223211', // 18
 68:         '221132', // 19
 69:         '221231', // 20
 70:         '213212', // 21
 71:         '223112', // 22
 72:         '312131', // 23
 73:         '311222', // 24
 74:         '321122', // 25
 75:         '321221', // 26
 76:         '312212', // 27
 77:         '322112', // 28
 78:         '322211', // 29
 79:         '212123', // 30
 80:         '212321', // 31
 81:         '232121', // 32
 82:         '111323', // 33
 83:         '131123', // 34
 84:         '131321', // 35
 85:         '112313', // 36
 86:         '132113', // 37
 87:         '132311', // 38
 88:         '211313', // 39
 89:         '231113', // 40
 90:         '231311', // 41
 91:         '112133', // 42
 92:         '112331', // 43
 93:         '132131', // 44
 94:         '113123', // 45
 95:         '113321', // 46
 96:         '133121', // 47
 97:         '313121', // 48
 98:         '211331', // 49
 99:         '231131', // 50
100:         '213113', // 51
101:         '213311', // 52
102:         '213131', // 53
103:         '311123', // 54
104:         '311321', // 55
105:         '331121', // 56
106:         '312113', // 57
107:         '312311', // 58
108:         '332111', // 59
109:         '314111', // 60
110:         '221411', // 61
111:         '431111', // 62
112:         '111224', // 63
113:         '111422', // 64
114:         '121124', // 65
115:         '121421', // 66
116:         '141122', // 67
117:         '141221', // 68
118:         '112214', // 69
119:         '112412', // 70
120:         '122114', // 71
121:         '122411', // 72
122:         '142112', // 73
123:         '142211', // 74
124:         '241211', // 75
125:         '221114', // 76
126:         '413111', // 77
127:         '241112', // 78
128:         '134111', // 79
129:         '111242', // 80
130:         '121142', // 81
131:         '121241', // 82
132:         '114212', // 83
133:         '124112', // 84
134:         '124211', // 85
135:         '411212', // 86
136:         '421112', // 87
137:         '421211', // 88
138:         '212141', // 89
139:         '214121', // 90
140:         '412121', // 91
141:         '111143', // 92
142:         '111341', // 93
143:         '131141', // 94
144:         '114113', // 95
145:         '114311', // 96
146:         '411113', // 97
147:         '411311', // 98
148:         '113141', // 99
149:         '114131', // 100
150:         '311141', // 101
151:         '411131', // 102
152:         '211412', // 103 START A
153:         '211214', // 104 START B
154:         '211232', // 105 START C
155:         '233111', // STOP
156:         '200000'  // END
157:     );
158: 
159:     /**
160:      * Map ASCII characters for code A (ASCII 00 - 95)
161:      *
162:      * @var array
163:      */
164:     protected $keys_a = '';
165: 
166:     /**
167:      * Map ASCII characters for code B (ASCII 32 - 127)
168:      *
169:      * @var array
170:      */
171:     protected $keys_b = '';
172: 
173:     /**
174:      * Map special FNC codes for Code Set A (FNC 1-4)
175:      *
176:      * @var array
177:      */
178:     protected $fnc_a = array(241 => 102, 242 => 97, 243 => 96, 244 => 101);
179: 
180:     /**
181:      * Map special FNC codes for Code Set B (FNC 1-4)
182:      *
183:      * @var array
184:      */
185:     protected $fnc_b = array(241 => 102, 242 => 97, 243 => 96, 244 => 100);
186: 
187:     /**
188:      * Set the ASCII maps values
189:      */
190:     protected function setAsciiMaps()
191:     {
192:         // 128A (Code Set A) - ASCII characters 00 to 95 (0-9, A-Z and control codes), special characters
193:         $this->keys_a = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_'
194:             .chr(0).chr(1).chr(2).chr(3).chr(4).chr(5).chr(6).chr(7).chr(8).chr(9)
195:             .chr(10).chr(11).chr(12).chr(13).chr(14).chr(15).chr(16).chr(17).chr(18).chr(19)
196:             .chr(20).chr(21).chr(22).chr(23).chr(24).chr(25).chr(26).chr(27).chr(28).chr(29)
197:             .chr(30).chr(31);
198: 
199:         // 128B (Code Set B) - ASCII characters 32 to 127 (0-9, A-Z, a-z), special characters
200:         $this->keys_b = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]'
201:             .'^_`abcdefghijklmnopqrstuvwxyz{|}~'.chr(127);
202:     }
203: 
204:     /**
205:      * Get the coe point array
206:      *
207:      * @throws BarcodeException in case of error
208:      */
209:     protected function getCodeData()
210:     {
211:         $code = $this->code;
212:         // array of symbols
213:         $code_data = array();
214:         // split code into sequences
215:         $sequence = $this->getNumericSequence($code);
216:         // process the sequence
217:         $startid = 0;
218:         foreach ($sequence as $key => $seq) {
219:             $processMethod = 'processSequence'.$seq[0];
220:             $this->$processMethod($sequence, $code_data, $startid, $key, $seq);
221:         }
222:         return $this->finalizeCodeData($code_data, $startid);
223:     }
224: 
225:     /**
226:      * Process the A sequence
227:      *
228:      * @param array  $sequence   Sequence to process
229:      * @param array  $code_data  Array of codepoints to alter
230:      * @param string $code       Code to process
231:      * @param int    $startid    Start ID
232:      * @param int    $key        Sequence current key
233:      * @param string $seq        Sequence current value
234:      *
235:      * @throws BarcodeException in case of error
236:      */
237:     protected function processSequenceA(&$sequence, &$code_data, &$startid, $key, $seq)
238:     {
239:         if ($key == 0) {
240:             $startid = 103;
241:         } elseif ($sequence[($key - 1)][0] != 'A') {
242:             if (($seq[2] == 1)
243:                 && ($key > 0)
244:                 && ($sequence[($key - 1)][0] == 'B')
245:                 && (!isset($sequence[($key - 1)][3]))
246:             ) {
247:                 // single character shift
248:                 $code_data[] = 98;
249:                 // mark shift
250:                 $sequence[$key][3] = true;
251:             } elseif (!isset($sequence[($key - 1)][3])) {
252:                 $code_data[] = 101;
253:             }
254:         }
255:         $this->getCodeDataA($code_data, $seq[1], $seq[2]);
256:     }
257: 
258:     /**
259:      * Process the B sequence
260:      *
261:      * @param array  $sequence   Sequence to process
262:      * @param array  $code_data  Array of codepoints to alter
263:      * @param string $code       Code to process
264:      * @param int    $startid    Start ID
265:      * @param int    $key        Sequence current key
266:      * @param string $seq        Sequence current value
267:      *
268:      * @throws BarcodeException in case of error
269:      */
270:     protected function processSequenceB(&$sequence, &$code_data, &$startid, $key, $seq)
271:     {
272:         if ($key == 0) {
273:             $this->processSequenceBA($sequence, $code_data, $startid, $key, $seq);
274:         } elseif ($sequence[($key - 1)][0] != 'B') {
275:             $this->processSequenceBB($sequence, $code_data, $key, $seq);
276:         }
277:         $this->getCodeDataB($code_data, $seq[1], $seq[2]);
278:     }
279: 
280:     /**
281:      * Process the B-A sequence
282:      *
283:      * @param array  $sequence   Sequence to process
284:      * @param array  $code_data  Array of codepoints to alter
285:      * @param string $code       Code to process
286:      * @param int    $startid    Start ID
287:      * @param int    $key        Sequence current key
288:      * @param string $seq        Sequence current value
289:      *
290:      * @throws BarcodeException in case of error
291:      */
292:     protected function processSequenceBA(&$sequence, &$code_data, &$startid, $key, $seq)
293:     {
294:         $tmpchr = ord($seq[1][0]);
295:         if (($seq[2] == 1)
296:             && ($tmpchr >= 241)
297:             && ($tmpchr <= 244)
298:             && isset($sequence[($key + 1)])
299:             && ($sequence[($key + 1)][0] != 'B')
300:         ) {
301:             switch ($sequence[($key + 1)][0]) {
302:                 case 'A':
303:                     $startid = 103;
304:                     $sequence[$key][0] = 'A';
305:                     $code_data[] = $this->fnc_a[$tmpchr];
306:                     break;
307:                 case 'C':
308:                     $startid = 105;
309:                     $sequence[$key][0] = 'C';
310:                     $code_data[] = $this->fnc_a[$tmpchr];
311:                     break;
312:             }
313:         } else {
314:             $startid = 104;
315:         }
316:     }
317: 
318:     /**
319:      * Process the B-B sequence
320:      *
321:      * @param array  $sequence   Sequence to process
322:      * @param array  $code_data  Array of codepoints to alter
323:      * @param string $code       Code to process
324:      * @param int    $key        Sequence current key
325:      * @param string $seq        Sequence current value
326:      *
327:      * @throws BarcodeException in case of error
328:      */
329:     protected function processSequenceBB(&$sequence, &$code_data, $key, $seq)
330:     {
331:         if (($seq[2] == 1)
332:             && ($key > 0)
333:             && ($sequence[($key - 1)][0] == 'A')
334:             && (!isset($sequence[($key - 1)][3]))
335:         ) {
336:             // single character shift
337:             $code_data[] = 98;
338:             // mark shift
339:             $sequence[$key][3] = true;
340:         } elseif (!isset($sequence[($key - 1)][3])) {
341:             $code_data[] = 100;
342:         }
343:     }
344: 
345:     /**
346:      * Process the C sequence
347:      *
348:      * @param array  $sequence   Sequence to process
349:      * @param array  $code_data  Array of codepoints to alter
350:      * @param string $code       Code to process
351:      * @param int    $startid    Start ID
352:      * @param int    $key        Sequence current key
353:      * @param string $seq        Sequence current value
354:      *
355:      * @throws BarcodeException in case of error
356:      */
357:     protected function processSequenceC(&$sequence, &$code_data, &$startid, $key, $seq)
358:     {
359:         if ($key == 0) {
360:             $startid = 105;
361:         } elseif ($sequence[($key - 1)][0] != 'C') {
362:             $code_data[] = 99;
363:         }
364:         $this->getCodeDataC($code_data, $seq[1]);
365:     }
366: 
367:     /**
368:      * Get the bars array
369:      *
370:      * @throws BarcodeException in case of error
371:      */
372:     protected function setBars()
373:     {
374:         $this->setAsciiMaps();
375:         $code_data = $this->getCodeData();
376:         $this->ncols = 0;
377:         $this->nrows = 1;
378:         $this->bars = array();
379:         foreach ($code_data as $val) {
380:             $seq = $this->chbar[$val];
381:             for ($pos = 0; $pos < 6; ++$pos) {
382:                 $bar_width = intval($seq[$pos]);
383:                 if ((($pos % 2) == 0) && ($bar_width > 0)) {
384:                     $this->bars[] = array($this->ncols, 0, $bar_width, 1);
385:                 }
386:                 $this->ncols += $bar_width;
387:             }
388:         }
389:     }
390: }
391: 
 

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