source-class-Com.Tecnick.Barcode.Type.Raw

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:  * Raw.php
 4:  *
 5:  * @since       2015-02-21
 6:  * @category    Library
 7:  * @package     Barcode
 8:  * @author      Nicola Asuni <info@tecnick.com>
 9:  * @copyright   2015-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;
17: 
18: use \Com\Tecnick\Barcode\Exception as BarcodeException;
19: 
20: /**
21:  * Com\Tecnick\Barcode\Type\Raw
22:  *
23:  * Raw Barcode type class
24:  * RAW MODE (comma-separated rows)
25:  *
26:  * @since       2015-02-21
27:  * @category    Library
28:  * @package     Barcode
29:  * @author      Nicola Asuni <info@tecnick.com>
30:  * @copyright   2015-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 Raw extends \Com\Tecnick\Barcode\Type
35: {
36:     /**
37:      * Get the pre-formatted code
38:      *
39:      * @return string
40:      */
41:     protected function getCodeRows()
42:     {
43:         if (is_array($this->code)) {
44:             return $this->code;
45:         }
46:         // remove spaces and newlines
47:         $code = preg_replace('/[\s]*/s', '', $this->code);
48:         // remove trailing brackets or commas
49:         $code = preg_replace('/^[\[,]+/', '', $code);
50:         $code = preg_replace('/[\],]+$/', '', $code);
51:         // convert bracket -separated to comma-separated
52:         $code = preg_replace('/[\]][\[]$/', ',', $code);
53:         return explode(',', $code);
54:     }
55: 
56:     /**
57:      * Get the bars array
58:      *
59:      * @throws BarcodeException in case of error
60:      */
61:     protected function setBars()
62:     {
63:         $rows = $this->getCodeRows();
64:         if (empty($rows)) {
65:             throw new BarcodeException('Empty input string');
66:         }
67:         $this->nrows = count($rows);
68:         if (is_array($rows[0])) {
69:             $this->ncols = count($rows[0]);
70:         } else {
71:             $this->ncols = strlen($rows[0]);
72:         }
73:         if (empty($this->ncols)) {
74:             throw new BarcodeException('Empty columns');
75:         }
76:         $this->bars = array();
77:         foreach ($rows as $posy => $row) {
78:             if (!is_array($row)) {
79:                 $row = str_split($row, 1);
80:             }
81:             $prevcol = '';
82:             $bar_width = 0;
83:             $row[] = '0';
84:             for ($posx = 0; $posx <= $this->ncols; ++$posx) {
85:                 if ($row[$posx] != $prevcol) {
86:                     if ($prevcol == '1') {
87:                         $this->bars[] = array(($posx - $bar_width), $posy, $bar_width, 1);
88:                     }
89:                     $bar_width = 0;
90:                 }
91:                 ++$bar_width;
92:                 $prevcol = $row[$posx];
93:             }
94:         }
95:     }
96: }
97: 
 

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