source-class-Com.Tecnick.Barcode.Type.Square.QrCode.Split

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:  * Split.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\Square\QrCode;
 17: 
 18: use \Com\Tecnick\Barcode\Exception as BarcodeException;
 19: use \Com\Tecnick\Barcode\Type\Square\QrCode\Data;
 20: use \Com\Tecnick\Barcode\Type\Square\QrCode\ByteStream;
 21: 
 22: /**
 23:  * Com\Tecnick\Barcode\Type\Square\QrCode\Split
 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 Split
 34: {
 35:     /**
 36:      * EncodingMode class object
 37:      *
 38:      * @var \Com\Tecnick\Barcode\Type\Square\QrCode\EncodingMode
 39:      */
 40:     protected $bsObj;
 41: 
 42:     /**
 43:      * Input items
 44:      *
 45:      * @var array
 46:      */
 47:     protected $items = array();
 48: 
 49:     /**
 50:      * QR code version.
 51:      * The Size of QRcode is defined as version. Version is an integer value from 1 to 40.
 52:      * Version 1 is 21*21 matrix. And 4 modules increases whenever 1 version increases.
 53:      * So version 40 is 177*177 matrix.
 54:      *
 55:      * @var int
 56:      */
 57:     protected $version = 0;
 58: 
 59:     /**
 60:      * Encoding mode
 61:      *
 62:      * @var int
 63:      */
 64:     protected $hint = 2;
 65: 
 66:     /**
 67:      * Initialize
 68:      *
 69:      * @param ByteStream   $bsObj   ByteStream Class object
 70:      * @param int          $hint    Encoding mode
 71:      * @param int          $version Code version
 72:      */
 73:     public function __construct($bsObj, $hint, $version)
 74:     {
 75:         $this->bsObj = $bsObj;
 76:         $this->items = array();
 77:         $this->hint = $hint;
 78:         $this->version = $version;
 79:     }
 80: 
 81:     /**
 82:      * Split the input string
 83:      *
 84:      * @param string $data Data
 85:      *
 86:      * @return array items
 87:      */
 88:     public function getSplittedString($data)
 89:     {
 90:         while (strlen($data) > 0) {
 91:             $mode = $this->bsObj->getEncodingMode($data, 0);
 92:             switch ($mode) {
 93:                 case Data::$encodingModes['NM']:
 94:                     $length = $this->eatNum($data);
 95:                     break;
 96:                 case Data::$encodingModes['AN']:
 97:                     $length = $this->eatAn($data);
 98:                     break;
 99:                 case Data::$encodingModes['KJ']:
100:                     if ($this->hint == Data::$encodingModes['KJ']) {
101:                         $length = $this->eatKanji($data);
102:                     } else {
103:                         $length = $this->eat8($data);
104:                     }
105:                     break;
106:                 default:
107:                     $length = $this->eat8($data);
108:                     break;
109:             }
110:             if ($length == 0) {
111:                 break;
112:             }
113:             if ($length < 0) {
114:                 throw new BarcodeException('Error while splitting the input data');
115:             }
116:             $data = substr($data, $length);
117:         }
118:         return $this->items;
119:     }
120: 
121:     /**
122:      * eatNum
123:      *
124:      * @param string $data Data
125:      *
126:      * @return int run
127:      */
128:     protected function eatNum($data)
129:     {
130:         $lng = $this->bsObj->getLengthIndicator(Data::$encodingModes['NM']);
131:         $pos = 0;
132:         while ($this->bsObj->isDigitAt($data, $pos)) {
133:             $pos++;
134:         }
135:         $mode = $this->bsObj->getEncodingMode($data, $pos);
136:         if ($mode == Data::$encodingModes['8B']) {
137:             $dif = $this->bsObj->estimateBitsModeNum($pos) + 4 + $lng
138:                 + $this->bsObj->estimateBitsMode8(1)         // + 4 + l8
139:                 - $this->bsObj->estimateBitsMode8($pos + 1); // - 4 - l8
140:             if ($dif > 0) {
141:                 return $this->eat8($data);
142:             }
143:         }
144:         if ($mode == Data::$encodingModes['AN']) {
145:             $dif = $this->bsObj->estimateBitsModeNum($pos) + 4 + $lng
146:                 + $this->bsObj->estimateBitsModeAn(1)        // + 4 + la
147:                 - $this->bsObj->estimateBitsModeAn($pos + 1);// - 4 - la
148:             if ($dif > 0) {
149:                 return $this->eatAn($data);
150:             }
151:         }
152:         $this->items = $this->bsObj->appendNewInputItem(
153:             $this->items,
154:             Data::$encodingModes['NM'],
155:             $pos,
156:             str_split($data)
157:         );
158:         return $pos;
159:     }
160: 
161:     /**
162:      * eatAn
163:      *
164:      * @param string $data Data
165:      * @return int run
166:      */
167:     protected function eatAn($data)
168:     {
169:         $lag = $this->bsObj->getLengthIndicator(Data::$encodingModes['AN']);
170:         $lng = $this->bsObj->getLengthIndicator(Data::$encodingModes['NM']);
171:         $pos =1 ;
172:         while ($this->bsObj->isAlphanumericAt($data, $pos)) {
173:             if ($this->bsObj->isDigitAt($data, $pos)) {
174:                 $qix = $pos;
175:                 while ($this->bsObj->isDigitAt($data, $qix)) {
176:                     $qix++;
177:                 }
178:                 $dif = $this->bsObj->estimateBitsModeAn($pos) // + 4 + lag
179:                     + $this->bsObj->estimateBitsModeNum($qix - $pos) + 4 + $lng
180:                     - $this->bsObj->estimateBitsModeAn($qix); // - 4 - la
181:                 if ($dif < 0) {
182:                     break;
183:                 } else {
184:                     $pos = $qix;
185:                 }
186:             } else {
187:                 $pos++;
188:             }
189:         }
190:         if (!$this->bsObj->isAlphanumericAt($data, $pos)) {
191:             $dif = $this->bsObj->estimateBitsModeAn($pos) + 4 + $lag
192:                 + $this->bsObj->estimateBitsMode8(1) // + 4 + l8
193:                 - $this->bsObj->estimateBitsMode8($pos + 1); // - 4 - l8
194:             if ($dif > 0) {
195:                 return $this->eat8($data);
196:             }
197:         }
198:         $this->items = $this->bsObj->appendNewInputItem(
199:             $this->items,
200:             Data::$encodingModes['AN'],
201:             $pos,
202:             str_split($data)
203:         );
204:         return $pos;
205:     }
206: 
207:     /**
208:      * eatKanji
209:      *
210:      * @param string $data Data
211:      * @return int run
212:      */
213:     protected function eatKanji($data)
214:     {
215:         $pos = 0;
216:         while ($this->bsObj->getEncodingMode($data, $pos) == Data::$encodingModes['KJ']) {
217:             $pos += 2;
218:         }
219:         $this->items = $this->bsObj->appendNewInputItem(
220:             $this->items,
221:             Data::$encodingModes['KJ'],
222:             $pos,
223:             str_split($data)
224:         );
225:         return $pos;
226:     }
227: 
228:     /**
229:      * eat8
230:      *
231:      * @param string $data Data
232:      * @return int run
233:      */
234:     protected function eat8($data)
235:     {
236:         $lag = $this->bsObj->getLengthIndicator(Data::$encodingModes['AN']);
237:         $lng = $this->bsObj->getLengthIndicator(Data::$encodingModes['NM']);
238:         $pos = 1;
239:         $dataStrLen = strlen($data);
240:         while ($pos < $dataStrLen) {
241:             $mode = $this->bsObj->getEncodingMode($data, $pos);
242:             if ($mode == Data::$encodingModes['KJ']) {
243:                 break;
244:             }
245:             if ($mode == Data::$encodingModes['NM']) {
246:                 $qix = $pos;
247:                 while ($this->bsObj->isDigitAt($data, $qix)) {
248:                     $qix++;
249:                 }
250:                 $dif = $this->bsObj->estimateBitsMode8($pos) // + 4 + l8
251:                     + $this->bsObj->estimateBitsModeNum($qix - $pos) + 4 + $lng
252:                     - $this->bsObj->estimateBitsMode8($qix); // - 4 - l8
253:                 if ($dif < 0) {
254:                     break;
255:                 } else {
256:                     $pos = $qix;
257:                 }
258:             } elseif ($mode == Data::$encodingModes['AN']) {
259:                 $qix = $pos;
260:                 while ($this->bsObj->isAlphanumericAt($data, $qix)) {
261:                     $qix++;
262:                 }
263:                 $dif = $this->bsObj->estimateBitsMode8($pos)  // + 4 + l8
264:                     + $this->bsObj->estimateBitsModeAn($qix - $pos) + 4 + $lag
265:                     - $this->bsObj->estimateBitsMode8($qix); // - 4 - l8
266:                 if ($dif < 0) {
267:                     break;
268:                 } else {
269:                     $pos = $qix;
270:                 }
271:             } else {
272:                 $pos++;
273:             }
274:         }
275:         $this->items = $this->bsObj->appendNewInputItem(
276:             $this->items,
277:             Data::$encodingModes['8B'],
278:             $pos,
279:             str_split($data)
280:         );
281:         return $pos;
282:     }
283: }
284: 
 

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